- Timestamp:
- 09/03/09 17:48:50 (15 years ago)
- Location:
- branches/gp-algorithms-refactoring-#720
- Files:
-
- 7 added
- 10 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/AlgorithmBase.cs
r2328 r2331 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.DataAnalysis;28 27 using HeuristicLab.Evolutionary; 29 using HeuristicLab.GP.Interfaces;30 28 using HeuristicLab.Logging; 31 using HeuristicLab.Modeling;32 29 using HeuristicLab.Operators; 33 30 using HeuristicLab.Random; 34 31 using HeuristicLab.Selection; 35 using HeuristicLab. Operators.Programmable;36 37 namespace HeuristicLab.GP. StructureIdentification{38 public abstract class AlgorithmBase : ItemBase , IAlgorithm, IStochasticAlgorithm{32 using HeuristicLab.GP.Operators; 33 34 namespace HeuristicLab.GP.Algorithms { 35 public abstract class AlgorithmBase : ItemBase { 39 36 public virtual string Name { get { return "GP"; } } 40 37 public virtual string Description { get { return "TODO"; } } 41 42 public abstract Dataset Dataset { get; set; }43 public abstract int TargetVariable { get; set; }44 38 45 39 public virtual double MutationRate { … … 71 65 } 72 66 73 private IAnalyzerModel model;74 public virtual IAnalyzerModel Model {75 get {76 if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result.");77 if (model == null) {78 IScope bestModelScope = engine.GlobalScope.SubScopes[0];79 model = CreateGPModel(bestModelScope);80 }81 return model;82 }83 }84 85 67 public virtual int Elites { 86 68 get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; } … … 101 83 get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; } 102 84 set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; } 103 }104 105 public virtual bool UseEstimatedTargetValue {106 get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; }107 set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; }108 85 } 109 86 … … 128 105 MaxTreeHeight = 10; 129 106 Parents = 2000; 130 UseEstimatedTargetValue = false;131 107 } 132 108 … … 141 117 142 118 IOperator globalInjector = CreateGlobalInjector(); 143 IOperator treeEvaluatorInjector = new HL2TreeEvaluatorInjector();144 119 IOperator initialization = CreateInitialization(); 145 120 IOperator funLibInjector = CreateFunctionLibraryInjector(); … … 149 124 150 125 IOperator treeCreator = CreateTreeCreator(); 151 152 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();153 evaluator.GetVariableInfo("MSE").ActualName = "Quality";154 evaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";155 evaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";156 evaluator.Name = "Evaluator";157 126 158 127 IOperator crossover = CreateCrossover(); … … 165 134 seq.AddSubOperator(problemInjector); 166 135 seq.AddSubOperator(globalInjector); 167 seq.AddSubOperator(treeEvaluatorInjector);168 136 seq.AddSubOperator(funLibInjector); 169 137 seq.AddSubOperator(initialization); 170 138 seq.AddSubOperator(mainLoop); 171 139 seq.AddSubOperator(cleanUp); 172 seq.AddSubOperator(CreateModelAnalysisOperator());173 140 174 141 initialization.AddSubOperator(treeCreator); 175 initialization.AddSubOperator(evaluator);176 142 177 143 mainLoop.AddSubOperator(selector); … … 185 151 } 186 152 187 protected internal virtual IOperator CreateModelAnalysisOperator() {188 CombinedOperator op = new CombinedOperator();189 SequentialProcessor seq = new SequentialProcessor();190 SolutionExtractor extractor = new SolutionExtractor();191 extractor.GetVariableInfo("Scope").ActualName = "BestValidationSolution";192 SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();193 SequentialProcessor solutionProc = new SequentialProcessor();194 195 seq.AddSubOperator(extractor);196 seq.AddSubOperator(seqSubScopeProc);197 seqSubScopeProc.AddSubOperator(solutionProc);198 199 HL2TreeEvaluatorInjector evaluatorInjector = new HL2TreeEvaluatorInjector();200 evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));201 evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";202 203 #region MSE204 MeanSquaredErrorEvaluator trainingMseEvaluator = new MeanSquaredErrorEvaluator();205 trainingMseEvaluator.Name = "TrainingMseEvaluator";206 trainingMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";207 trainingMseEvaluator.GetVariableInfo("MSE").ActualName = "TrainingMSE";208 trainingMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";209 trainingMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";210 MeanSquaredErrorEvaluator validationMseEvaluator = new MeanSquaredErrorEvaluator();211 validationMseEvaluator.Name = "ValidationMseEvaluator";212 validationMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";213 validationMseEvaluator.GetVariableInfo("MSE").ActualName = "ValidationMSE";214 validationMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";215 validationMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";216 MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator();217 testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator";218 testMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";219 testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestMSE";220 testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";221 testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";222 #endregion223 #region MAPE224 MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();225 trainingMapeEvaluator.Name = "TrainingMapeEvaluator";226 trainingMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";227 trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";228 trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";229 trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";230 MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();231 validationMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";232 validationMapeEvaluator.Name = "ValidationMapeEvaluator";233 validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";234 validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";235 validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";236 MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();237 testMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";238 testMapeEvaluator.Name = "TestMapeEvaluator";239 testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE";240 testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";241 testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";242 #endregion243 #region MAPRE244 MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();245 trainingMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";246 trainingMapreEvaluator.Name = "TrainingMapreEvaluator";247 trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";248 trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";249 trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";250 MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();251 validationMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";252 validationMapreEvaluator.Name = "ValidationMapreEvaluator";253 validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";254 validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";255 validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";256 MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();257 testMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";258 testMapreEvaluator.Name = "TestMapreEvaluator";259 testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";260 testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";261 testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";262 #endregion MAPRE263 #region R2264 CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator();265 trainingR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";266 trainingR2Evaluator.Name = "TrainingR2Evaluator";267 trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2";268 trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";269 trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";270 CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator();271 validationR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";272 validationR2Evaluator.Name = "ValidationR2Evaluator";273 validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";274 validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";275 validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";276 CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator();277 testR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";278 testR2Evaluator.Name = "TestR2Evaluator";279 testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2";280 testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";281 testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";282 #endregion283 #region VAF284 VarianceAccountedForEvaluator trainingVAFEvaluator = new VarianceAccountedForEvaluator();285 trainingVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";286 trainingVAFEvaluator.Name = "TrainingVAFEvaluator";287 trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = "TrainingVAF";288 trainingVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";289 trainingVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";290 VarianceAccountedForEvaluator validationVAFEvaluator = new VarianceAccountedForEvaluator();291 validationVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";292 validationVAFEvaluator.Name = "ValidationVAFEvaluator";293 validationVAFEvaluator.GetVariableInfo("VAF").ActualName = "ValidationVAF";294 validationVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";295 validationVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";296 VarianceAccountedForEvaluator testVAFEvaluator = new VarianceAccountedForEvaluator();297 testVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";298 testVAFEvaluator.Name = "TestVAFEvaluator";299 testVAFEvaluator.GetVariableInfo("VAF").ActualName = "TestVAF";300 testVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";301 testVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";302 #endregion303 304 solutionProc.AddSubOperator(evaluatorInjector);305 solutionProc.AddSubOperator(trainingMseEvaluator);306 solutionProc.AddSubOperator(validationMseEvaluator);307 solutionProc.AddSubOperator(testMseEvaluator);308 solutionProc.AddSubOperator(trainingMapeEvaluator);309 solutionProc.AddSubOperator(validationMapeEvaluator);310 solutionProc.AddSubOperator(testMapeEvaluator);311 solutionProc.AddSubOperator(trainingMapreEvaluator);312 solutionProc.AddSubOperator(validationMapreEvaluator);313 solutionProc.AddSubOperator(testMapreEvaluator);314 solutionProc.AddSubOperator(trainingR2Evaluator);315 solutionProc.AddSubOperator(validationR2Evaluator);316 solutionProc.AddSubOperator(testR2Evaluator);317 solutionProc.AddSubOperator(trainingVAFEvaluator);318 solutionProc.AddSubOperator(validationVAFEvaluator);319 solutionProc.AddSubOperator(testVAFEvaluator);320 321 #region variable impacts322 // calculate and set variable impacts323 VariableNamesExtractor namesExtractor = new VariableNamesExtractor();324 namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";325 PredictorBuilder predictorBuilder = new PredictorBuilder();326 predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";327 predictorBuilder.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));328 329 VariableEvaluationImpactCalculator evaluationImpactCalculator = new VariableEvaluationImpactCalculator();330 evaluationImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";331 evaluationImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";332 VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();333 qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";334 qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";335 336 solutionProc.AddSubOperator(namesExtractor);337 solutionProc.AddSubOperator(predictorBuilder);338 solutionProc.AddSubOperator(evaluationImpactCalculator);339 solutionProc.AddSubOperator(qualityImpactCalculator);340 #endregion341 342 op.OperatorGraph.AddOperator(seq);343 op.OperatorGraph.InitialOperator = seq;344 return op;345 }346 347 153 protected internal virtual IOperator CreateProblemInjector() { 348 154 return new EmptyOperator(); 349 155 } 350 156 351 protected internal abstract IOperator CreateSelector(); 352 353 protected internal abstract IOperator CreateCrossover(); 157 protected virtual IOperator CreateSelector() { 158 return new EmptyOperator(); 159 } 160 161 protected virtual IOperator CreateCrossover() { 162 return new StandardCrossOver(); 163 } 354 164 355 165 protected internal abstract IOperator CreateTreeCreator(); -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.Designer.cs
r2326 r2331 20 20 #endregion 21 21 22 namespace HeuristicLab.GP. StructureIdentification{22 namespace HeuristicLab.GP.Algorithms { 23 23 partial class OffspringSelectionGpEditor { 24 24 /// <summary> -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffSpringSelectionGpEditor.cs
r2326 r2331 25 25 using HeuristicLab.Core; 26 26 27 namespace HeuristicLab.GP. StructureIdentification{27 namespace HeuristicLab.GP.Algorithms { 28 28 public partial class OffspringSelectionGpEditor : EditorBase { 29 29 private ChooseOperatorDialog chooseOperatorDialog; -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/OffspringSelectionGP.cs
r2326 r2331 30 30 using HeuristicLab.Selection.OffspringSelection; 31 31 32 namespace HeuristicLab.GP. StructureIdentification{32 namespace HeuristicLab.GP.Algorithms { 33 33 public class OffspringSelectionGP : StandardGP { 34 34 public override string Name { get { return "OffspringSelectionGP"; } } -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGP.cs
r2328 r2331 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.DataAnalysis;24 23 using HeuristicLab.Operators; 25 24 using HeuristicLab.Selection; 26 25 using HeuristicLab.Logging; 27 26 using HeuristicLab.Data; 28 using HeuristicLab.Operators.Programmable;29 using HeuristicLab.Modeling;30 27 using HeuristicLab.GP.Operators; 31 28 32 namespace HeuristicLab.GP. StructureIdentification{29 namespace HeuristicLab.GP.Algorithms { 33 30 public class StandardGP : AlgorithmBase, IEditable { 34 31 -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGpEditor.Designer.cs
r2326 r2331 20 20 #endregion 21 21 22 namespace HeuristicLab.GP. StructureIdentification{22 namespace HeuristicLab.GP.Algorithms { 23 23 partial class StandardGpEditor { 24 24 /// <summary> -
branches/gp-algorithms-refactoring-#720/sources/HeuristicLab.GP.Algorithms/3.2/StandardGpEditor.cs
r2326 r2331 25 25 using HeuristicLab.PluginInfrastructure; 26 26 27 namespace HeuristicLab.GP. StructureIdentification{27 namespace HeuristicLab.GP.Algorithms { 28 28 public partial class StandardGpEditor : EditorBase { 29 29 private ChooseOperatorDialog chooseOperatorDialog;
Note: See TracChangeset
for help on using the changeset viewer.