Changeset 1230 for branches/CEDMA-Refactoring-Ticket419
- Timestamp:
- 02/26/09 13:54:45 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/HeuristicLab.GP.StructureIdentification.csproj
r1201 r1230 71 71 <Compile Include="BakedTreeEvaluator.cs" /> 72 72 <Compile Include="Constant.cs" /> 73 <Compile Include="AlgorithmBase.cs" /> 73 74 <Compile Include="FunctionLibraryInjector.cs" /> 74 75 <Compile Include="OffspringSelectionGP.cs" /> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/StandardGP.cs
r1201 r1230 36 36 37 37 namespace HeuristicLab.GP.StructureIdentification { 38 public class StandardGP : ItemBase, IEditable { 38 public class StandardGP : AlgorithmBase { 39 39 40 private IntData maxGenerations = new IntData(); 40 41 public int MaxGenerations { … … 48 49 set { tournamentSize.Data = value; } 49 50 } 50 private DoubleData mutationRate = new DoubleData(); 51 public double MutationRate { 52 get { return mutationRate.Data; } 53 set { mutationRate.Data = value; } 54 } 55 private IntData parents = new IntData(); 56 private IntData populationSize = new IntData(); 57 public int PopulationSize { 58 get { return populationSize.Data; } 59 set { 60 populationSize.Data = value; 61 parents.Data = value * 2; 62 } 63 } 64 65 private BoolData setSeedRandomly = new BoolData(); 66 public bool SetSeedRandomly { 67 get { return setSeedRandomly.Data; } 68 set { setSeedRandomly.Data = value; } 69 } 70 71 private IntData seed = new IntData(); 72 public int Seed { 73 get { return seed.Data; } 74 set { seed.Data = value; } 75 } 76 77 public IOperator ProblemInjector { 78 get { return algorithm.SubOperators[0]; } 79 set { 80 value.Name = "ProblemInjector"; 81 algorithm.RemoveSubOperator(0); 82 algorithm.AddSubOperator(value, 0); 83 } 84 } 85 86 private IntData elites = new IntData(); 87 public int Elites { 88 get { return elites.Data; } 89 set { elites.Data = value; } 90 } 91 92 private int maxTreeSize = 50; 93 public int MaxTreeSize { 94 get { return maxTreeSize; } 95 set { maxTreeSize = value; } 96 } 97 98 private int maxTreeHeight = 8; 99 public int MaxTreeHeight { 100 get { return maxTreeHeight; } 101 set { maxTreeHeight = value; } 102 } 103 private double punishmentFactor = 10.0; 104 private bool useEstimatedTargetValue = false; 105 private double fullTreeShakingFactor = 0.1; 106 private double onepointShakingFactor = 1.0; 107 private IOperator algorithm; 108 109 private SequentialEngine.SequentialEngine engine; 110 public IEngine Engine { 111 get { return engine; } 112 } 113 114 public StandardGP() { 51 52 public StandardGP() : base() { 115 53 PopulationSize = 10000; 116 54 MaxGenerations = 100; … … 121 59 MaxTreeHeight = 10; 122 60 engine = new SequentialEngine.SequentialEngine(); 123 CombinedOperator algo = CreateAlgorithm();61 IOperator algo = CreateAlgorithm(); 124 62 engine.OperatorGraph.AddOperator(algo); 125 63 engine.OperatorGraph.InitialOperator = algo; 126 64 } 127 65 128 private CombinedOperator CreateAlgorithm() { 129 CombinedOperator algo = new CombinedOperator(); 130 algo.Name = "StandardGP"; 131 SequentialProcessor seq = new SequentialProcessor(); 132 EmptyOperator problemInjectorPlaceholder = new EmptyOperator(); 133 RandomInjector randomInjector = new RandomInjector(); 134 randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly; 135 randomInjector.GetVariable("Seed").Value = seed; 136 randomInjector.Name = "Random Injector"; 137 VariableInjector globalInjector = CreateGlobalInjector(); 138 CombinedOperator initialization = CreateInitialization(); 139 initialization.Name = "Initialization"; 140 FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector(); 141 CombinedOperator mainLoop = CreateMainLoop(); 142 mainLoop.Name = "Main loop"; 143 144 ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator(); 145 treeCreator.Name = "Tree generator"; 146 treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 147 treeCreator.GetVariableInfo("MinTreeSize").Local = true; 148 treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3))); 149 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator(); 150 evaluator.GetVariableInfo("MSE").ActualName = "Quality"; 151 evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 152 evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 153 evaluator.Name = "Evaluator"; 154 StandardCrossOver crossover = new StandardCrossOver(); 155 crossover.Name = "Crossover"; 156 crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 157 CombinedOperator manipulator = CreateManipulator(); 158 manipulator.Name = "Manipulator"; 66 override IOperator CreateSelector() { 159 67 TournamentSelector selector = new TournamentSelector(); 160 68 selector.Name = "Selector"; … … 163 71 selector.RemoveVariable("GroupSize"); 164 72 selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize"; 165 LeftReducer cleanUp = new LeftReducer(); 166 167 seq.AddSubOperator(problemInjectorPlaceholder); 168 seq.AddSubOperator(randomInjector); 169 seq.AddSubOperator(globalInjector); 170 seq.AddSubOperator(funLibInjector); 171 seq.AddSubOperator(initialization); 172 seq.AddSubOperator(mainLoop); 173 seq.AddSubOperator(cleanUp); 174 175 initialization.AddSubOperator(treeCreator); 176 initialization.AddSubOperator(evaluator); 177 178 mainLoop.AddSubOperator(selector); 179 mainLoop.AddSubOperator(crossover); 180 mainLoop.AddSubOperator(manipulator); 181 mainLoop.AddSubOperator(evaluator); 182 algo.OperatorGraph.AddOperator(seq); 183 algo.OperatorGraph.InitialOperator = seq; 184 this.algorithm = seq; 185 return algo; 186 } 187 188 private VariableInjector CreateGlobalInjector() { 189 VariableInjector injector = new VariableInjector(); 190 injector.Name = "Global Injector"; 191 injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0))); 192 injector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", maxGenerations)); 193 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate)); 194 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize)); 195 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents)); 196 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites)); 197 injector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", tournamentSize)); 198 injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false))); 199 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData(maxTreeHeight))); 200 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData(maxTreeSize))); 201 injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0))); 202 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 203 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor))); 204 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue))); 205 return injector; 206 } 207 208 private CombinedOperator CreateManipulator() { 73 return selector; 74 } 75 76 77 override IOperator CreateCrossover() { 78 StandardCrossOver crossover = new StandardCrossOver(); 79 crossover.Name = "Crossover"; 80 crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 81 return crossover; 82 } 83 84 override IOperator CreateTreeCreator() { 85 ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator(); 86 treeCreator.Name = "Tree generator"; 87 treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 88 treeCreator.GetVariableInfo("MinTreeSize").Local = true; 89 treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3))); 90 return treeCreator; 91 } 92 93 override IOperator CreateFunctionLibraryInjector() { 94 return new FunctionLibraryInjector(); 95 } 96 97 override IOperator CreateManipulator() { 209 98 CombinedOperator manipulator = new CombinedOperator(); 99 manipulator.Name = "Manipulator"; 210 100 StochasticMultiBranch multibranch = new StochasticMultiBranch(); 211 101 FullTreeShaker fullTreeShaker = new FullTreeShaker(); … … 245 135 manipulator.OperatorGraph.InitialOperator = multibranch; 246 136 return manipulator; 137 } 138 139 override IOperator CreateBestSolutionProcessor() { 140 SequentialProcessor bestSolutionProcessor = new SequentialProcessor(); 141 MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 142 trainingMapeEvaluator.Name = "TrainingMapeEvaluator"; 143 trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE"; 144 trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 145 trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 146 MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 147 validationMapeEvaluator.Name = "ValidationMapeEvaluator"; 148 validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE"; 149 validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 150 validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 151 ProgrammableOperator progOperator = new ProgrammableOperator(); 152 progOperator.RemoveVariableInfo("Result"); 153 progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In)); 154 progOperator.Code = @" 155 int evalSolutions = EvaluatedSolutions.Data; 156 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions))); 157 "; 158 bestSolutionProcessor.AddSubOperator(trainingMapeEvaluator); 159 bestSolutionProcessor.AddSubOperator(validationMapeEvaluator); 160 bestSolutionProcessor.AddSubOperator(progOperator); 161 return bestSolutionProcessor; 247 162 } 248 163
Note: See TracChangeset
for help on using the changeset viewer.