Changeset 11026
- Timestamp:
- 06/18/14 16:55:14 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r11025 r11026 68 68 var classificationModel = (IClassificationModel)model; 69 69 var classificationProblemData = (IClassificationProblemData)ProblemData; 70 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size) .ToArray();70 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 71 71 var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices); 72 72 var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r11025 r11026 56 56 var regressionModel = (IRegressionModel)model; 57 57 var regressionProblemData = (IRegressionProblemData)ProblemData; 58 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size) .ToArray();58 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 59 59 var estimatedValues = regressionModel.GetEstimatedValues(ProblemData.Dataset, trainingIndices); // also bounds the values 60 60 var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs
r11025 r11026 58 58 private DataTableValuesCollector valuesCollector; 59 59 private ResultsCollector resultsCollector; 60 private EmptyOperator emptyOp;61 60 #endregion 62 61 … … 74 73 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; } 75 74 } 76 public I ValueParameter<IntValue> UpdateIntervalParameter {77 get { return (I ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }78 } 79 public I ValueParameter<IntValue> UpdateCounterParameter {80 get { return (I ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }81 } 82 public I ValueParameter<DoubleRange> PopulationSliceParameter {83 get { return (I ValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; }84 } 85 public I ValueParameter<DoubleValue> PruningProbabilityParameter {86 get { return (I ValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; }75 public IFixedValueParameter<IntValue> UpdateIntervalParameter { 76 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 77 } 78 public IFixedValueParameter<IntValue> UpdateCounterParameter { 79 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; } 80 } 81 public IFixedValueParameter<DoubleRange> PopulationSliceParameter { 82 get { return (IFixedValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; } 83 } 84 public IFixedValueParameter<DoubleValue> PruningProbabilityParameter { 85 get { return (IFixedValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; } 87 86 } 88 87 public ILookupParameter<IntValue> PopulationSizeParameter { … … 93 92 #region properties 94 93 protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; } } 95 protected IntValue UpdateInterval { get { return UpdateIntervalParameter.Value; } } 96 protected IntValue UpdateCounter { get { return UpdateCounterParameter.Value; } } 97 protected DoubleRange PopulationSlice { get { return PopulationSliceParameter.Value; } } 98 protected DoubleValue PruningProbability { get { return PruningProbabilityParameter.Value; } } 94 protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } } 95 96 protected int UpdateCounter { 97 get { return UpdateCounterParameter.Value.Value; } 98 set { UpdateCounterParameter.Value.Value = value; } 99 } 100 101 protected double PopulationSliceStart { 102 get { return PopulationSliceParameter.Value.Start; } 103 set { PopulationSliceParameter.Value.Start = value; } 104 } 105 106 protected double PopulationSliceEnd { 107 get { return PopulationSliceParameter.Value.End; } 108 set { PopulationSliceParameter.Value.End = value; } 109 } 110 111 protected double PruningProbability { 112 get { return PruningProbabilityParameter.Value.Value; } 113 set { PruningProbabilityParameter.Value.Value = value; } 114 } 99 115 100 116 protected bool PruneOnlyZeroImpactNodes { … … 111 127 public override void InitializeState() { 112 128 base.InitializeState(); 113 UpdateCounter .Value= 0;129 UpdateCounter = 0; 114 130 } 115 131 public override void ClearState() { 116 132 base.ClearState(); 117 UpdateCounter .Value= 0;133 UpdateCounter = 0; 118 134 } 119 135 #endregion … … 143 159 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer() { 144 160 #region add parameters 145 Parameters.Add(new ValueParameter<DoubleRange>(PopulationSliceParameterName, new DoubleRange(0.75, 1)));146 Parameters.Add(new ValueParameter<DoubleValue>(PruningProbabilityParameterName, new DoubleValue(0.5)));147 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));148 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0)));149 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName ));150 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName ));151 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, new DoubleValue(0.0)));152 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, new BoolValue(false)));161 Parameters.Add(new FixedValueParameter<DoubleRange>(PopulationSliceParameterName, "The slice of the population where pruning should be applied.", new DoubleRange(0.75, 1))); 162 Parameters.Add(new FixedValueParameter<DoubleValue>(PruningProbabilityParameterName, "The probability for pruning an individual.", new DoubleValue(0.5))); 163 Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 164 Parameters.Add(new FixedValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0))); 165 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator.")); 166 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data.")); 167 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold below which an individual should be pruned.", new DoubleValue(0.0))); 168 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false))); 153 169 Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals.")); 154 170 #endregion … … 161 177 /// <returns>Returns an int range [start, end]</returns> 162 178 private IntRange GetSliceBounds() { 163 if (PopulationSlice .Start < 0 || PopulationSlice.End < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative.");164 if (PopulationSlice .Start > 1 || PopulationSlice.End > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages.");179 if (PopulationSliceStart < 0 || PopulationSliceEnd < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative."); 180 if (PopulationSliceStart > 1 || PopulationSliceEnd > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages."); 165 181 var count = PopulationSizeParameter.ActualValue.Value; 166 var start = (int)Math.Round(PopulationSlice .Start * count);167 var end = (int)Math.Round(PopulationSlice .End * count);182 var start = (int)Math.Round(PopulationSliceStart * count); 183 var end = (int)Math.Round(PopulationSliceEnd * count); 168 184 if (end > count) end = count; 169 185 … … 173 189 174 190 private IOperation CreatePruningOperation() { 175 var o c= new OperationCollection { Parallel = true };191 var operations = new OperationCollection { Parallel = true }; 176 192 var range = GetSliceBounds(); 177 193 var qualities = Quality.Select(x => x.Value).ToArray(); … … 183 199 var random = RandomParameter.ActualValue; 184 200 201 var empty = new EmptyOperator(); 202 185 203 for (int i = 0; i < subscopes.Count; ++i) { 186 IOperator op;187 if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability .Value)188 op= PruningOperator;189 else op = emptyOp;204 IOperator @operator; 205 if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability) 206 @operator = PruningOperator; 207 else @operator = empty; 190 208 var index = indices[i]; 191 209 var subscope = subscopes[index]; 192 o c.Add(ExecutionContext.CreateChildOperation(op, subscope));210 operations.Add(ExecutionContext.CreateChildOperation(@operator, subscope)); 193 211 } 194 return o c;212 return operations; 195 213 } 196 214 197 215 public override IOperation Apply() { 198 UpdateCounter .Value++;199 if (UpdateCounter .Value != UpdateInterval.Value) return base.Apply();200 UpdateCounter .Value= 0;216 UpdateCounter++; 217 if (UpdateCounter != UpdateInterval) return base.Apply(); 218 UpdateCounter = 0; 201 219 202 220 if (prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); } … … 232 250 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Population pruning")); 233 251 resultsCollector.ResultsParameter.ActualName = ResultsParameterName; 234 235 emptyOp = new EmptyOperator();236 252 } 237 253 }
Note: See TracChangeset
for help on using the changeset viewer.