Changeset 1287 for trunk/sources/HeuristicLab.GP.StructureIdentification
- Timestamp:
- 03/08/09 12:48:18 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification
- Files:
-
- 4 deleted
- 1 edited
- 15 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/AlgorithmBase.cs
r1231 r1287 37 37 namespace HeuristicLab.GP.StructureIdentification { 38 38 public abstract class AlgorithmBase : ItemBase { 39 private DoubleData mutationRate = new DoubleData();40 39 public virtual double MutationRate { 41 get { return mutationRate.Data; } 42 set { mutationRate.Data = value; } 43 } 44 private IntData populationSize = new IntData(); 40 get { return GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data; } 41 set { GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data = value; } 42 } 45 43 public virtual int PopulationSize { 46 get { return populationSize.Data; } 47 set { 48 populationSize.Data = value; 49 } 50 } 51 52 private BoolData setSeedRandomly = new BoolData(); 44 get { return GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data; } 45 set { GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data = value; } 46 } 47 53 48 public virtual bool SetSeedRandomly { 54 get { return setSeedRandomly.Data; } 55 set { setSeedRandomly.Data = value; } 56 } 57 58 private IntData seed = new IntData(); 49 get { return GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data; } 50 set { GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data = value; } 51 } 52 59 53 public virtual int Seed { 60 get { return seed.Data; }61 set { seed.Data = value; }54 get { return GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data; } 55 set { GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data = value; } 62 56 } 63 57 … … 71 65 } 72 66 73 private IntData elites = new IntData();74 67 public virtual int Elites { 75 get { return elites.Data; } 76 set { elites.Data = value; } 77 } 78 79 private int maxTreeSize = 50; 68 get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; } 69 set { GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data = value; } 70 } 71 80 72 public virtual int MaxTreeSize { 81 get { return maxTreeSize; } 82 set { maxTreeSize = value; } 83 } 84 85 private int maxTreeHeight = 8; 73 get { return GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data; } 74 set { GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data = value; } 75 } 76 86 77 public virtual int MaxTreeHeight { 87 get { return maxTreeHeight; } 88 set { maxTreeHeight = value; } 89 } 90 91 private IntData parents = new IntData(); 78 get { return GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data; } 79 set { GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data = value; } 80 } 81 92 82 public virtual int Parents { 93 get { return parents.Data; } 94 protected set { parents.Data = value; } 95 } 96 97 private double punishmentFactor = 10.0; 98 private bool useEstimatedTargetValue = false; 83 get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; } 84 set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; } 85 } 86 87 public virtual double PunishmentFactor { 88 get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; } 89 set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; } 90 } 91 92 public virtual bool UseEstimatedTargetValue { 93 get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; } 94 set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; } 95 } 96 99 97 private IOperator algorithm; 100 98 … … 110 108 engine.OperatorGraph.AddOperator(algo); 111 109 engine.OperatorGraph.InitialOperator = algo; 112 } 113 114 internal virtual CombinedOperator CreateAlgorithm() { 110 SetSeedRandomly = true; 111 Elites = 1; 112 MutationRate = 0.15; 113 PopulationSize = 1000; 114 MaxTreeSize = 100; 115 MaxTreeHeight = 10; 116 Parents = 2000; 117 PunishmentFactor = 10; 118 UseEstimatedTargetValue = false; 119 } 120 121 protected internal virtual CombinedOperator CreateAlgorithm() { 115 122 CombinedOperator algo = new CombinedOperator(); 116 123 algo.Name = "GP"; 117 124 SequentialProcessor seq = new SequentialProcessor(); 118 EmptyOperator problemInjectorPlaceholder = new EmptyOperator();125 IOperator problemInjector = CreateProblemInjector(); 119 126 120 127 RandomInjector randomInjector = new RandomInjector(); 121 randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly;122 randomInjector.GetVariable("Seed").Value = seed;123 128 randomInjector.Name = "Random Injector"; 124 129 125 130 IOperator globalInjector = CreateGlobalInjector(); 126 131 IOperator initialization = CreateInitialization(); 127 IOperator funLibInjector = CreateFunctionLibraryInjector(); 132 IOperator funLibInjector = CreateFunctionLibraryInjector(); 128 133 IOperator mainLoop = CreateMainLoop(); 129 134 mainLoop.Name = "Main loop"; 130 135 131 136 IOperator treeCreator = CreateTreeCreator(); 132 137 133 138 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator(); 134 139 evaluator.GetVariableInfo("MSE").ActualName = "Quality"; … … 136 141 evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 137 142 evaluator.Name = "Evaluator"; 138 143 139 144 IOperator crossover = CreateCrossover(); 140 145 IOperator manipulator = CreateManipulator(); … … 143 148 LeftReducer cleanUp = new LeftReducer(); 144 149 145 seq.AddSubOperator(problemInjector Placeholder);150 seq.AddSubOperator(problemInjector); 146 151 seq.AddSubOperator(randomInjector); 147 152 seq.AddSubOperator(globalInjector); … … 164 169 } 165 170 166 internal abstract IOperator CreateSelector(); 167 168 internal abstract IOperator CreateCrossover(); 169 170 internal abstract IOperator CreateTreeCreator(); 171 172 internal abstract IOperator CreateFunctionLibraryInjector(); 173 174 internal virtual IOperator CreateGlobalInjector() { 171 protected internal virtual IOperator CreateProblemInjector() { 172 return new EmptyOperator(); 173 } 174 175 protected internal abstract IOperator CreateSelector(); 176 177 protected internal abstract IOperator CreateCrossover(); 178 179 protected internal abstract IOperator CreateTreeCreator(); 180 181 protected internal abstract IOperator CreateFunctionLibraryInjector(); 182 183 protected internal virtual IOperator CreateGlobalInjector() { 175 184 VariableInjector injector = new VariableInjector(); 176 185 injector.Name = "Global Injector"; 177 186 injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0))); 178 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate));179 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize));180 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites));187 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", new DoubleData())); 188 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", new IntData())); 189 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", new IntData())); 181 190 injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false))); 182 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData( maxTreeHeight)));183 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData( maxTreeSize)));191 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData())); 192 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData())); 184 193 injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0))); 185 194 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 186 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents));187 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData( punishmentFactor)));188 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData( useEstimatedTargetValue)));195 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", new IntData())); 196 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData())); 197 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData())); 189 198 return injector; 190 199 } 191 200 192 internal abstract IOperator CreateManipulator();193 194 internal virtual IOperator CreateInitialization() {201 protected internal abstract IOperator CreateManipulator(); 202 203 protected internal virtual IOperator CreateInitialization() { 195 204 CombinedOperator init = new CombinedOperator(); 196 205 init.Name = "Initialization"; … … 231 240 } 232 241 233 internal virtual IOperator CreateMainLoop() {242 protected internal virtual IOperator CreateMainLoop() { 234 243 CombinedOperator main = new CombinedOperator(); 235 244 SequentialProcessor seq = new SequentialProcessor(); … … 244 253 BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator(); 245 254 BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator(); 246 validationQualityCalculator.Name = "ValidationQualityCalculator"; 255 validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator"; 256 validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 247 257 validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality"; 248 258 validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality"; 249 259 validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality"; 250 DataCollector collector = new DataCollector(); 251 ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>(); 252 names.Add(new StringData("BestQuality")); 253 names.Add(new StringData("AverageQuality")); 254 names.Add(new StringData("WorstQuality")); 255 names.Add(new StringData("BestValidationQuality")); 256 names.Add(new StringData("AverageValidationQuality")); 257 names.Add(new StringData("WorstValidationQuality")); 258 LinechartInjector lineChartInjector = new LinechartInjector(); 259 lineChartInjector.GetVariableInfo("Linechart").ActualName = "Quality Linechart"; 260 lineChartInjector.GetVariable("NumberOfLines").GetValue<IntData>().Data = 6; 261 QualityLogger qualityLogger = new QualityLogger(); 262 QualityLogger validationQualityLogger = new QualityLogger(); 263 validationQualityCalculator.Name = "ValidationQualityLogger"; 264 validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 265 validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog"; 260 IOperator loggingOperator = CreateLoggingOperator(); 266 261 Counter counter = new Counter(); 267 262 counter.GetVariableInfo("Value").ActualName = "Generations"; 263 IOperator loopCondition = CreateLoopCondition(seq); 264 265 seq.AddSubOperator(childCreater); 266 seq.AddSubOperator(replacement); 267 seq.AddSubOperator(solutionStorer); 268 seq.AddSubOperator(qualityCalculator); 269 seq.AddSubOperator(validationQualityCalculator); 270 seq.AddSubOperator(loggingOperator); 271 seq.AddSubOperator(counter); 272 seq.AddSubOperator(loopCondition); 273 274 main.OperatorGraph.AddOperator(seq); 275 main.OperatorGraph.InitialOperator = seq; 276 return main; 277 } 278 279 protected internal virtual IOperator CreateLoggingOperator() { 280 return new EmptyOperator(); 281 } 282 283 protected internal virtual IOperator CreateLoopCondition(IOperator loop) { 284 SequentialProcessor seq = new SequentialProcessor(); 285 seq.Name = "Loop Condition"; 268 286 LessThanComparator comparator = new LessThanComparator(); 269 287 comparator.GetVariableInfo("LeftSide").ActualName = "Generations"; … … 273 291 cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition"; 274 292 275 seq.AddSubOperator(childCreater);276 seq.AddSubOperator(replacement);277 seq.AddSubOperator(solutionStorer);278 seq.AddSubOperator(qualityCalculator);279 seq.AddSubOperator(validationQualityCalculator);280 seq.AddSubOperator(collector);281 seq.AddSubOperator(lineChartInjector);282 seq.AddSubOperator(qualityLogger);283 seq.AddSubOperator(validationQualityLogger);284 seq.AddSubOperator(counter);285 293 seq.AddSubOperator(comparator); 286 294 seq.AddSubOperator(cond); 287 cond.AddSubOperator(seq); 288 289 main.OperatorGraph.AddOperator(seq); 290 main.OperatorGraph.InitialOperator = seq; 291 return main; 292 } 293 294 internal virtual IOperator CreateBestSolutionProcessor() { 295 296 cond.AddSubOperator(loop); 297 return seq; 298 } 299 300 protected internal virtual IOperator CreateBestSolutionProcessor() { 295 301 return new EmptyOperator(); 296 302 } 297 303 298 internal virtual IOperator CreateReplacement() {304 protected internal virtual IOperator CreateReplacement() { 299 305 CombinedOperator replacement = new CombinedOperator(); 300 306 replacement.Name = "Replacement"; … … 330 336 } 331 337 332 internalvirtual IOperator CreateChildCreater() {338 protected internal virtual IOperator CreateChildCreater() { 333 339 CombinedOperator childCreater = new CombinedOperator(); 334 340 childCreater.Name = "Create children"; … … 391 397 } 392 398 393 #region SetReferences Method 394 private void SetReferences() { 395 // SGA 399 protected VariableInjector GetVariableInjector() { 396 400 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator; 397 // SequentialProcessor in SGA401 // SequentialProcessor in GP 398 402 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator; 399 // RandomInjector 400 RandomInjector ri = (RandomInjector)algorithm.SubOperators[1]; 401 setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>(); 402 seed = ri.GetVariable("Seed").GetValue<IntData>(); 403 // VariableInjector 404 VariableInjector vi = (VariableInjector)algorithm.SubOperators[2]; 405 populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>(); 406 mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>(); 407 elites = vi.GetVariable("Elites").GetValue<IntData>(); 408 parents = vi.GetVariable("Parents").GetValue<IntData>(); 409 } 410 #endregion 403 return (VariableInjector)algorithm.SubOperators[2]; 404 } 405 406 protected RandomInjector GetRandomInjector() { 407 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator; 408 // SequentialProcessor in GP 409 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator; 410 return (RandomInjector)algorithm.SubOperators[1]; 411 } 411 412 412 413 #region Persistence Methods … … 419 420 base.Populate(node, restoredObjects); 420 421 engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects); 421 SetReferences();422 422 } 423 423 #endregion -
trunk/sources/HeuristicLab.GP.StructureIdentification/FunctionLibraryInjector.cs
r1053 r1287 36 36 private const string FUNCTIONLIBRARY = "FunctionLibrary"; 37 37 38 private StructId.Variable variable;39 private GPOperatorLibrary operatorLibrary;40 41 38 public override string Description { 42 39 get { return @"Injects a default function library for regression and classification problems."; } … … 51 48 52 49 public override IOperation Apply(IScope scope) { 50 StructId.Variable variable; 51 GPOperatorLibrary operatorLibrary; 52 53 53 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true); 54 54 int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data; … … 56 56 // remove the target-variable in case it occures in allowed features 57 57 List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable); 58 foreach(IntData t in ts) allowedFeatures.Remove(t); 59 60 InitDefaultOperatorLibrary(); 61 62 int[] allowedIndexes = new int[allowedFeatures.Count]; 63 for(int i = 0; i < allowedIndexes.Length; i++) { 64 allowedIndexes[i] = allowedFeatures[i].Data; 65 } 66 67 variable.SetConstraints(allowedIndexes, 0, 0); 68 69 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary)); 70 return null; 71 } 72 73 private void InitDefaultOperatorLibrary() { 58 foreach (IntData t in ts) allowedFeatures.Remove(t); 59 74 60 variable = new StructId.Variable(); 75 61 StructId.Constant constant = new StructId.Constant(); … … 173 159 operatorLibrary.GPOperatorGroup.AddOperator(tangens); 174 160 operatorLibrary.GPOperatorGroup.AddOperator(xor); 161 162 int[] allowedIndexes = new int[allowedFeatures.Count]; 163 for (int i = 0; i < allowedIndexes.Length; i++) { 164 allowedIndexes[i] = allowedFeatures[i].Data; 165 } 166 167 variable.SetConstraints(allowedIndexes, 0, 0); 168 169 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary)); 170 return null; 175 171 } 176 172 177 173 private void SetAllowedSubOperators(IFunction f, IFunction[] gs) { 178 foreach (IConstraint c in f.Constraints) {179 if (c is SubOperatorTypeConstraint) {174 foreach (IConstraint c in f.Constraints) { 175 if (c is SubOperatorTypeConstraint) { 180 176 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 181 177 typeConstraint.Clear(); 182 foreach (IFunction g in gs) {178 foreach (IFunction g in gs) { 183 179 typeConstraint.AddOperator(g); 184 180 } 185 } else if (c is AllSubOperatorsTypeConstraint) {181 } else if (c is AllSubOperatorsTypeConstraint) { 186 182 AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint; 187 183 typeConstraint.Clear(); 188 foreach (IFunction g in gs) {184 foreach (IFunction g in gs) { 189 185 typeConstraint.AddOperator(g); 190 186 } … … 194 190 195 191 private void SetAllowedSubOperators(IFunction f, int p, IFunction[] gs) { 196 foreach (IConstraint c in f.Constraints) {197 if (c is SubOperatorTypeConstraint) {192 foreach (IConstraint c in f.Constraints) { 193 if (c is SubOperatorTypeConstraint) { 198 194 SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint; 199 if (typeConstraint.SubOperatorIndex.Data == p) {195 if (typeConstraint.SubOperatorIndex.Data == p) { 200 196 typeConstraint.Clear(); 201 foreach (IFunction g in gs) {197 foreach (IFunction g in gs) { 202 198 typeConstraint.AddOperator(g); 203 199 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/HeuristicLab.GP.StructureIdentification.csproj
r852 r1287 71 71 <Compile Include="BakedTreeEvaluator.cs" /> 72 72 <Compile Include="Constant.cs" /> 73 <Compile Include="AlgorithmBase.cs" /> 74 <Compile Include="Evaluators\MeanAbsolutePercentageOfRangeErrorEvaluator.cs" /> 75 <Compile Include="FunctionLibraryInjector.cs" /> 76 <Compile Include="OffspringSelectionGP.cs" /> 77 <Compile Include="OffSpringSelectionGpEditor.cs"> 78 <SubType>UserControl</SubType> 79 </Compile> 80 <Compile Include="OffSpringSelectionGpEditor.Designer.cs"> 81 <DependentUpon>OffSpringSelectionGpEditor.cs</DependentUpon> 82 </Compile> 83 <Compile Include="ProblemInjector.cs" /> 84 <Compile Include="ProblemInjectorView.cs"> 85 <SubType>UserControl</SubType> 86 </Compile> 87 <Compile Include="ProblemInjectorView.Designer.cs"> 88 <DependentUpon>ProblemInjectorView.cs</DependentUpon> 89 </Compile> 90 <Compile Include="StandardGpEditor.cs"> 91 <SubType>UserControl</SubType> 92 </Compile> 93 <Compile Include="StandardGpEditor.Designer.cs"> 94 <DependentUpon>StandardGpEditor.cs</DependentUpon> 95 </Compile> 96 <Compile Include="StandardGP.cs" /> 73 97 <Compile Include="Cosinus.cs" /> 74 98 <Compile Include="Differential.cs" /> … … 98 122 <Compile Include="Sinus.cs" /> 99 123 <Compile Include="Sqrt.cs" /> 100 <Compile Include="StructIdProblemInjector.cs" />101 <Compile Include="StructIdProblemInjectorView.cs">102 <SubType>UserControl</SubType>103 </Compile>104 <Compile Include="StructIdProblemInjectorView.Designer.cs">105 <DependentUpon>StructIdProblemInjectorView.cs</DependentUpon>106 </Compile>107 124 <Compile Include="Subtraction.cs" /> 108 125 <Compile Include="SymbolicExpressionExporter.cs" /> … … 129 146 <Name>HeuristicLab.Data</Name> 130 147 </ProjectReference> 148 <ProjectReference Include="..\HeuristicLab.Evolutionary\HeuristicLab.Evolutionary.csproj"> 149 <Project>{F5614C53-153C-4A37-A608-121E1C087F07}</Project> 150 <Name>HeuristicLab.Evolutionary</Name> 151 </ProjectReference> 131 152 <ProjectReference Include="..\HeuristicLab.GP\HeuristicLab.GP.csproj"> 132 153 <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project> 133 154 <Name>HeuristicLab.GP</Name> 134 155 </ProjectReference> 156 <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj"> 157 <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project> 158 <Name>HeuristicLab.Logging</Name> 159 </ProjectReference> 160 <ProjectReference Include="..\HeuristicLab.Operators.Programmable\HeuristicLab.Operators.Programmable.csproj"> 161 <Project>{E3CCBFC6-900C-41B6-AFB8-6646DB097435}</Project> 162 <Name>HeuristicLab.Operators.Programmable</Name> 163 </ProjectReference> 135 164 <ProjectReference Include="..\HeuristicLab.Operators\HeuristicLab.Operators.csproj"> 136 165 <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project> … … 145 174 <Name>HeuristicLab.Random</Name> 146 175 </ProjectReference> 147 </ItemGroup> 148 <ItemGroup> 149 <EmbeddedResource Include="StructIdProblemInjectorView.resx"> 150 <DependentUpon>StructIdProblemInjectorView.cs</DependentUpon> 176 <ProjectReference Include="..\HeuristicLab.Selection.OffspringSelection\HeuristicLab.Selection.OffspringSelection.csproj"> 177 <Project>{205898D3-2717-4686-AF17-52409B7EC0C6}</Project> 178 <Name>HeuristicLab.Selection.OffspringSelection</Name> 179 </ProjectReference> 180 <ProjectReference Include="..\HeuristicLab.Selection\HeuristicLab.Selection.csproj"> 181 <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project> 182 <Name>HeuristicLab.Selection</Name> 183 </ProjectReference> 184 <ProjectReference Include="..\HeuristicLab.SequentialEngine\HeuristicLab.SequentialEngine.csproj"> 185 <Project>{B4BE8E53-BA06-4237-9A01-24255F880201}</Project> 186 <Name>HeuristicLab.SequentialEngine</Name> 187 </ProjectReference> 188 </ItemGroup> 189 <ItemGroup> 190 <EmbeddedResource Include="OffSpringSelectionGpEditor.resx"> 191 <DependentUpon>OffSpringSelectionGpEditor.cs</DependentUpon> 192 </EmbeddedResource> 193 <EmbeddedResource Include="ProblemInjectorView.resx"> 194 <DependentUpon>ProblemInjectorView.cs</DependentUpon> 195 </EmbeddedResource> 196 <EmbeddedResource Include="StandardGpEditor.resx"> 197 <DependentUpon>StandardGpEditor.cs</DependentUpon> 151 198 <SubType>Designer</SubType> 152 199 </EmbeddedResource> -
trunk/sources/HeuristicLab.GP.StructureIdentification/OffSpringSelectionGpEditor.Designer.cs
r1156 r1287 49 49 this.tabControl = new System.Windows.Forms.TabControl(); 50 50 this.parametersTabPage = new System.Windows.Forms.TabPage(); 51 this.selectionPressureTextBox = new System.Windows.Forms.TextBox(); 52 this.selectionPressureLabel = new System.Windows.Forms.Label(); 51 53 this.viewProblemInitializationButton = new System.Windows.Forms.Button(); 52 54 this.setProblemInitializationButton = new System.Windows.Forms.Button(); … … 58 60 this.mutationRateTextBox = new System.Windows.Forms.TextBox(); 59 61 this.mutationRateLabel = new System.Windows.Forms.Label(); 60 this.maximum GenerationsTextBox = new System.Windows.Forms.TextBox();61 this.max imumGenerationsLabel = new System.Windows.Forms.Label();62 this.maximumEvaluatedSolutionsTextBox = new System.Windows.Forms.TextBox(); 63 this.maxEvaluatedSolutionsLabel = new System.Windows.Forms.Label(); 62 64 this.randomSeedTextBox = new System.Windows.Forms.TextBox(); 63 65 this.populationSizeTextBox = new System.Windows.Forms.TextBox(); … … 101 103 // parametersTabPage 102 104 // 105 this.parametersTabPage.Controls.Add(this.selectionPressureTextBox); 106 this.parametersTabPage.Controls.Add(this.selectionPressureLabel); 103 107 this.parametersTabPage.Controls.Add(this.viewProblemInitializationButton); 104 108 this.parametersTabPage.Controls.Add(this.setProblemInitializationButton); … … 110 114 this.parametersTabPage.Controls.Add(this.mutationRateTextBox); 111 115 this.parametersTabPage.Controls.Add(this.mutationRateLabel); 112 this.parametersTabPage.Controls.Add(this.maximum GenerationsTextBox);113 this.parametersTabPage.Controls.Add(this.max imumGenerationsLabel);116 this.parametersTabPage.Controls.Add(this.maximumEvaluatedSolutionsTextBox); 117 this.parametersTabPage.Controls.Add(this.maxEvaluatedSolutionsLabel); 114 118 this.parametersTabPage.Controls.Add(this.randomSeedTextBox); 115 119 this.parametersTabPage.Controls.Add(this.populationSizeTextBox); … … 125 129 this.parametersTabPage.UseVisualStyleBackColor = true; 126 130 // 131 // selectionPressureTextBox 132 // 133 this.selectionPressureTextBox.Anchor = System.Windows.Forms.AnchorStyles.None; 134 this.selectionPressureTextBox.Location = new System.Drawing.Point(218, 130); 135 this.selectionPressureTextBox.Name = "selectionPressureTextBox"; 136 this.selectionPressureTextBox.Size = new System.Drawing.Size(186, 20); 137 this.selectionPressureTextBox.TabIndex = 17; 138 // 139 // selectionPressureLabel 140 // 141 this.selectionPressureLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 142 this.selectionPressureLabel.AutoSize = true; 143 this.selectionPressureLabel.Location = new System.Drawing.Point(65, 133); 144 this.selectionPressureLabel.Name = "selectionPressureLabel"; 145 this.selectionPressureLabel.Size = new System.Drawing.Size(145, 13); 146 this.selectionPressureLabel.TabIndex = 16; 147 this.selectionPressureLabel.Text = "Maximum &Selection Pressure:"; 148 // 127 149 // viewProblemInitializationButton 128 150 // 129 151 this.viewProblemInitializationButton.Anchor = System.Windows.Forms.AnchorStyles.None; 130 this.viewProblemInitializationButton.Location = new System.Drawing.Point(410, 2 08);152 this.viewProblemInitializationButton.Location = new System.Drawing.Point(410, 241); 131 153 this.viewProblemInitializationButton.Name = "viewProblemInitializationButton"; 132 154 this.viewProblemInitializationButton.Size = new System.Drawing.Size(53, 20); … … 139 161 // 140 162 this.setProblemInitializationButton.Anchor = System.Windows.Forms.AnchorStyles.None; 141 this.setProblemInitializationButton.Location = new System.Drawing.Point(469, 2 08);163 this.setProblemInitializationButton.Location = new System.Drawing.Point(469, 241); 142 164 this.setProblemInitializationButton.Name = "setProblemInitializationButton"; 143 165 this.setProblemInitializationButton.Size = new System.Drawing.Size(43, 20); … … 150 172 // 151 173 this.problemInitializationTextBox.Anchor = System.Windows.Forms.AnchorStyles.None; 152 this.problemInitializationTextBox.Location = new System.Drawing.Point(218, 2 08);174 this.problemInitializationTextBox.Location = new System.Drawing.Point(218, 241); 153 175 this.problemInitializationTextBox.Name = "problemInitializationTextBox"; 154 176 this.problemInitializationTextBox.ReadOnly = true; … … 165 187 this.setRandomSeedRandomlyCheckBox.TabIndex = 1; 166 188 this.setRandomSeedRandomlyCheckBox.UseVisualStyleBackColor = true; 189 this.setRandomSeedRandomlyCheckBox.CheckedChanged += new System.EventHandler(this.setRandomSeedRandomlyCheckBox_CheckedChanged); 167 190 // 168 191 // elitesTextBox 169 192 // 170 193 this.elitesTextBox.Anchor = System.Windows.Forms.AnchorStyles.None; 171 this.elitesTextBox.Location = new System.Drawing.Point(218, 1 56);194 this.elitesTextBox.Location = new System.Drawing.Point(218, 182); 172 195 this.elitesTextBox.Name = "elitesTextBox"; 173 196 this.elitesTextBox.Size = new System.Drawing.Size(186, 20); … … 178 201 this.problemInitializationLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 179 202 this.problemInitializationLabel.AutoSize = true; 180 this.problemInitializationLabel.Location = new System.Drawing.Point(65, 2 11);203 this.problemInitializationLabel.Location = new System.Drawing.Point(65, 244); 181 204 this.problemInitializationLabel.Name = "problemInitializationLabel"; 182 205 this.problemInitializationLabel.Size = new System.Drawing.Size(105, 13); … … 188 211 this.elitesLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 189 212 this.elitesLabel.AutoSize = true; 190 this.elitesLabel.Location = new System.Drawing.Point(6 5, 159);213 this.elitesLabel.Location = new System.Drawing.Point(66, 185); 191 214 this.elitesLabel.Name = "elitesLabel"; 192 215 this.elitesLabel.Size = new System.Drawing.Size(35, 13); … … 197 220 // 198 221 this.mutationRateTextBox.Anchor = System.Windows.Forms.AnchorStyles.None; 199 this.mutationRateTextBox.Location = new System.Drawing.Point(218, 1 30);222 this.mutationRateTextBox.Location = new System.Drawing.Point(218, 156); 200 223 this.mutationRateTextBox.Name = "mutationRateTextBox"; 201 224 this.mutationRateTextBox.Size = new System.Drawing.Size(186, 20); … … 206 229 this.mutationRateLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 207 230 this.mutationRateLabel.AutoSize = true; 208 this.mutationRateLabel.Location = new System.Drawing.Point(6 5, 133);231 this.mutationRateLabel.Location = new System.Drawing.Point(66, 159); 209 232 this.mutationRateLabel.Name = "mutationRateLabel"; 210 233 this.mutationRateLabel.Size = new System.Drawing.Size(77, 13); … … 212 235 this.mutationRateLabel.Text = "&Mutation Rate:"; 213 236 // 214 // maximum GenerationsTextBox215 // 216 this.maximum GenerationsTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;217 this.maximum GenerationsTextBox.Location = new System.Drawing.Point(218, 104);218 this.maximum GenerationsTextBox.Name = "maximumGenerationsTextBox";219 this.maximum GenerationsTextBox.Size = new System.Drawing.Size(186, 20);220 this.maximum GenerationsTextBox.TabIndex = 7;221 // 222 // max imumGenerationsLabel223 // 224 this.max imumGenerationsLabel.Anchor = System.Windows.Forms.AnchorStyles.None;225 this.max imumGenerationsLabel.AutoSize = true;226 this.max imumGenerationsLabel.Location = new System.Drawing.Point(65, 107);227 this.max imumGenerationsLabel.Name = "maximumGenerationsLabel";228 this.max imumGenerationsLabel.Size = new System.Drawing.Size(114, 13);229 this.max imumGenerationsLabel.TabIndex = 6;230 this.max imumGenerationsLabel.Text = "Maximum &Generations:";237 // maximumEvaluatedSolutionsTextBox 238 // 239 this.maximumEvaluatedSolutionsTextBox.Anchor = System.Windows.Forms.AnchorStyles.None; 240 this.maximumEvaluatedSolutionsTextBox.Location = new System.Drawing.Point(218, 104); 241 this.maximumEvaluatedSolutionsTextBox.Name = "maximumEvaluatedSolutionsTextBox"; 242 this.maximumEvaluatedSolutionsTextBox.Size = new System.Drawing.Size(186, 20); 243 this.maximumEvaluatedSolutionsTextBox.TabIndex = 7; 244 // 245 // maxEvaluatedSolutionsLabel 246 // 247 this.maxEvaluatedSolutionsLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 248 this.maxEvaluatedSolutionsLabel.AutoSize = true; 249 this.maxEvaluatedSolutionsLabel.Location = new System.Drawing.Point(65, 107); 250 this.maxEvaluatedSolutionsLabel.Name = "maxEvaluatedSolutionsLabel"; 251 this.maxEvaluatedSolutionsLabel.Size = new System.Drawing.Size(130, 13); 252 this.maxEvaluatedSolutionsLabel.TabIndex = 6; 253 this.maxEvaluatedSolutionsLabel.Text = "Max. E&valuated Solutions:"; 231 254 // 232 255 // randomSeedTextBox … … 331 354 this.cloneEngineButton.Click += new System.EventHandler(this.cloneEngineButton_Click); 332 355 // 333 // StandardGpEditor356 // OffspringSelectionGpEditor 334 357 // 335 358 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); … … 340 363 this.Controls.Add(this.abortButton); 341 364 this.Controls.Add(this.executeButton); 342 this.Name = " StandardGpEditor";365 this.Name = "OffspringSelectionGpEditor"; 343 366 this.Size = new System.Drawing.Size(526, 419); 344 367 this.tabControl.ResumeLayout(false); … … 353 376 354 377 private System.Windows.Forms.Button executeButton; 355 pr ivateSystem.Windows.Forms.TabControl tabControl;356 pr ivateSystem.Windows.Forms.TabPage parametersTabPage;378 protected System.Windows.Forms.TabControl tabControl; 379 protected System.Windows.Forms.TabPage parametersTabPage; 357 380 private System.Windows.Forms.Button abortButton; 358 381 private System.Windows.Forms.Button resetButton; … … 362 385 private System.Windows.Forms.Label populationSizeLabel; 363 386 private System.Windows.Forms.TabPage scopesTabPage; 364 private System.Windows.Forms.TextBox maximum GenerationsTextBox;365 private System.Windows.Forms.Label max imumGenerationsLabel;387 private System.Windows.Forms.TextBox maximumEvaluatedSolutionsTextBox; 388 private System.Windows.Forms.Label maxEvaluatedSolutionsLabel; 366 389 private System.Windows.Forms.TextBox elitesTextBox; 367 390 private System.Windows.Forms.Label elitesLabel; … … 376 399 private HeuristicLab.Core.ScopeView scopeView; 377 400 private System.Windows.Forms.Button viewProblemInitializationButton; 401 private System.Windows.Forms.TextBox selectionPressureTextBox; 402 private System.Windows.Forms.Label selectionPressureLabel; 378 403 } 379 404 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/OffSpringSelectionGpEditor.cs
r1156 r1287 34 34 private ChooseOperatorDialog chooseOperatorDialog; 35 35 36 public OffspringSelectionG pEditor OffspringSelectionGpEditor{37 get { return (OffspringSelectionG pEditor)Item; }36 public OffspringSelectionGP OffspringSelectionGP { 37 get { return (OffspringSelectionGP)Item; } 38 38 set { base.Item = value; } 39 39 } … … 42 42 InitializeComponent(); 43 43 } 44 public OffspringSelectionGpEditor(OffspringSelectionG pEditorosgp)44 public OffspringSelectionGpEditor(OffspringSelectionGP osgp) 45 45 : this() { 46 OffspringSelectionG pEditor= osgp;46 OffspringSelectionGP = osgp; 47 47 } 48 48 49 49 protected override void RemoveItemEvents() { 50 OffspringSelectionG pEditor.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);51 OffspringSelectionG pEditor.Engine.Finished -= new EventHandler(Engine_Finished);50 OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred); 51 OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished); 52 52 scopeView.Scope = null; 53 53 base.RemoveItemEvents(); 54 54 } 55 55 56 protected override void AddItemEvents() { 56 57 base.AddItemEvents(); 57 OffspringSelectionG pEditor.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);58 OffspringSelectionG pEditor.Engine.Finished += new EventHandler(Engine_Finished);58 OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred); 59 OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished); 59 60 SetDataBinding(); 60 scopeView.Scope = OffspringSelectionG pEditor.Engine.GlobalScope;61 scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope; 61 62 } 62 63 63 64 protected override void UpdateControls() { 64 65 base.UpdateControls(); 65 if (OffspringSelectionG pEditor== null) {66 if (OffspringSelectionGP == null) { 66 67 tabControl.Enabled = false; 67 68 } else { 68 69 tabControl.Enabled = true; 69 problemInitializationTextBox.Text = OffspringSelectionG pEditor.ProblemInjector.GetType().Name;70 problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name; 70 71 } 71 72 } 72 73 73 private void SetDataBinding() { 74 setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGpEditor, "SetSeedRandomly"); 75 randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "Seed"); 76 populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "PopulationSize"); 77 maximumGenerationsTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "MaxGenerations"); 78 mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "MutationRate"); 79 elitesTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "Elites"); 74 protected virtual void SetDataBinding() { 75 setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly"); 76 randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Seed"); 77 populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGP, "PopulationSize"); 78 maximumEvaluatedSolutionsTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MaxEvaluatedSolutions"); 79 selectionPressureTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SelectionPressureLimit"); 80 mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MutationRate"); 81 elitesTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Elites"); 80 82 } 81 83 82 84 #region Button Events 83 85 private void viewProblemInjectorButton_Click(object sender, EventArgs e) { 84 IView view = OffspringSelectionG pEditor.ProblemInjector.CreateView();86 IView view = OffspringSelectionGP.ProblemInjector.CreateView(); 85 87 if(view != null) 86 88 PluginManager.ControlManager.ShowControl(view); … … 90 92 if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog(); 91 93 if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) { 92 OffspringSelectionG pEditor.ProblemInjector = chooseOperatorDialog.Operator;93 problemInitializationTextBox.Text = OffspringSelectionG pEditor.ProblemInjector.GetType().Name;94 OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator; 95 problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name; 94 96 } 95 97 } … … 97 99 executeButton.Enabled = false; 98 100 abortButton.Enabled = true; 99 OffspringSelectionGpEditor.Engine.Execute(); 101 resetButton.Enabled = false; 102 OffspringSelectionGP.Engine.Execute(); 100 103 } 101 104 private void abortButton_Click(object sender, EventArgs e) { 102 StandardGP.Engine.Abort();105 OffspringSelectionGP.Engine.Abort(); 103 106 } 104 107 private void resetButton_Click(object sender, EventArgs e) { 105 StandardGP.Engine.Reset();108 OffspringSelectionGP.Engine.Reset(); 106 109 } 107 110 private void cloneEngineButton_Click(object sender, EventArgs e) { 108 IEngine clone = (IEngine) StandardGP.Engine.Clone();111 IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone(); 109 112 IEditor editor = ((IEditable)clone).CreateEditor(); 110 113 PluginManager.ControlManager.ShowControl(editor); … … 127 130 executeButton.Enabled = true; 128 131 abortButton.Enabled = false; 132 resetButton.Enabled = true; 129 133 } 130 134 } 131 135 #endregion 132 136 133 137 private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) { 138 randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked; 139 randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked; 140 } 134 141 } 135 142 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/OffspringSelectionGP.cs
r1156 r1287 34 34 using HeuristicLab.Data; 35 35 using HeuristicLab.Operators.Programmable; 36 using HeuristicLab.Selection.OffspringSelection; 36 37 37 38 namespace HeuristicLab.GP.StructureIdentification { 38 public class OffspringSelectionGP : ItemBase, IEditable { 39 private IntData maxGenerations = new IntData(); 40 public int MaxGenerations { 41 get { return maxGenerations.Data; } 42 set { maxGenerations.Data = value; } 43 } 44 45 private DoubleData mutationRate = new DoubleData(); 46 public double MutationRate { 47 get { return mutationRate.Data; } 48 set { mutationRate.Data = value; } 49 } 50 51 private IntData parents = new IntData(); 52 private IntData populationSize = new IntData(); 53 public int PopulationSize { 54 get { return populationSize.Data; } 55 set { 56 populationSize.Data = value; 57 parents.Data = value * 2; 58 } 59 } 60 61 private BoolData setSeedRandomly = new BoolData(); 62 public bool SetSeedRandomly { 63 get { return setSeedRandomly.Data; } 64 set { setSeedRandomly.Data = value; } 65 } 66 67 private IntData seed = new IntData(); 68 public int Seed { 69 get { return seed.Data; } 70 set { seed.Data = value; } 71 } 72 73 public IOperator ProblemInjector { 74 get { return algorithm.SubOperators[0]; } 75 set { 76 value.Name = "ProblemInjector"; 77 algorithm.RemoveSubOperator(0); 78 algorithm.AddSubOperator(value, 0); 79 } 80 } 81 82 private IntData elites = new IntData(); 83 public int Elites { 84 get { return elites.Data; } 85 set { elites.Data = value; } 86 } 87 88 private IntData maxTreeSize; 89 public int MaxTreeSize { 90 get { return maxTreeSize.Data; } 91 set { maxTreeSize.Data = value; } 92 } 93 94 private IntData maxTreeHeight; 95 public int MaxTreeHeight { 96 get { return maxTreeHeight.Data; } 97 set { maxTreeHeight.Data = value; } 98 } 99 100 private DoubleData maxSelectionPressure; 101 public double MaxSelectionPressure { 102 get { return maxSelectionPressure.Data; } 103 set { maxSelectionPressure.Data = value; } 104 } 105 106 private double punishmentFactor = 10.0; 107 private bool useEstimatedTargetValue = false; 108 private double fullTreeShakingFactor = 0.1; 109 private double onepointShakingFactor = 1.0; 110 private IOperator algorithm; 111 112 private SequentialEngine.SequentialEngine engine; 113 public IEngine Engine { 114 get { return engine; } 115 } 116 117 public OffspringSelectionGP() { 39 public class OffspringSelectionGP : StandardGP { 40 41 public virtual int MaxEvaluatedSolutions { 42 get { return GetVariableInjector().GetVariable("MaxEvaluatedSolutions").GetValue<IntData>().Data; } 43 set { GetVariableInjector().GetVariable("MaxEvaluatedSolutions").GetValue<IntData>().Data = value; } 44 } 45 46 public virtual double SelectionPressureLimit { 47 get { return GetVariableInjector().GetVariable("SelectionPressureLimit").GetValue<DoubleData>().Data; } 48 set { GetVariableInjector().GetVariable("SelectionPressureLimit").GetValue<DoubleData>().Data = value; } 49 } 50 51 public virtual double ComparisonFactor { 52 get { return GetVariableInjector().GetVariable("ComparisonFactor").GetValue<DoubleData>().Data; } 53 set { GetVariableInjector().GetVariable("ComparisonFactor").GetValue<DoubleData>().Data = value; } 54 } 55 56 public virtual double SuccessRatioLimit { 57 get { return GetVariableInjector().GetVariable("SuccessRatioLimit").GetValue<DoubleData>().Data; } 58 set { GetVariableInjector().GetVariable("SuccessRatioLimit").GetValue<DoubleData>().Data = value; } 59 } 60 61 public override int MaxGenerations { 62 get { throw new NotSupportedException(); } 63 set { /* ignore */ } 64 } 65 66 public override int TournamentSize { 67 get { throw new NotSupportedException(); } 68 set { /* ignore */ } 69 } 70 71 public OffspringSelectionGP() 72 : base() { 118 73 PopulationSize = 1000; 119 MaxGenerations = 100; 120 MutationRate = 0.15; 121 Elites = 1; 122 MaxSelectionPressure = 300; 123 MaxTreeHeight = 10; 124 MaxTreeSize = 100; 125 engine = new SequentialEngine.SequentialEngine(); 126 CombinedOperator algo = CreateAlgorithm(); 127 engine.OperatorGraph.AddOperator(algo); 128 engine.OperatorGraph.InitialOperator = algo; 129 } 130 131 private CombinedOperator CreateAlgorithm() { 132 CombinedOperator algo = new CombinedOperator(); 133 algo.Name = "StandardGP"; 134 SequentialProcessor seq = new SequentialProcessor(); 135 EmptyOperator problemInjectorPlaceholder = new EmptyOperator(); 136 RandomInjector randomInjector = new RandomInjector(); 137 randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly; 138 randomInjector.GetVariable("Seed").Value = seed; 139 randomInjector.Name = "Random Injector"; 140 VariableInjector globalInjector = CreateGlobalInjector(); 141 CombinedOperator initialization = CreateInialization(); 142 initialization.Name = "Initialization"; 143 FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector(); 144 CombinedOperator mainLoop = CreateMainLoop(); 145 mainLoop.Name = "Main loop"; 146 147 ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator(); 148 treeCreator.Name = "Tree generator"; 149 treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 150 treeCreator.GetVariableInfo("MinTreeSize").Local = true; 151 treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3))); 152 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator(); 153 evaluator.GetVariableInfo("MSE").ActualName = "Quality"; 154 evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 155 evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 156 evaluator.Name = "Evaluator"; 157 StandardCrossOver crossover = new StandardCrossOver(); 158 crossover.Name = "Crossover"; 159 crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 160 CombinedOperator manipulator = CreateManipulator(); 161 manipulator.Name = "Manipulator"; 162 TournamentSelector selector = new TournamentSelector(); 74 Parents = 20; 75 MaxEvaluatedSolutions = 1000000; 76 SelectionPressureLimit = 300; 77 ComparisonFactor = 1.0; 78 SuccessRatioLimit = 1.0; 79 } 80 81 protected internal override IOperator CreateGlobalInjector() { 82 VariableInjector injector = (VariableInjector)base.CreateGlobalInjector(); 83 injector.RemoveVariable("TournamentSize"); 84 injector.RemoveVariable("MaxGenerations"); 85 injector.AddVariable(new HeuristicLab.Core.Variable("MaxEvaluatedSolutions", new IntData())); 86 injector.AddVariable(new HeuristicLab.Core.Variable("ComparisonFactor", new DoubleData())); 87 injector.AddVariable(new HeuristicLab.Core.Variable("SelectionPressureLimit", new DoubleData())); 88 injector.AddVariable(new HeuristicLab.Core.Variable("SuccessRatioLimit", new DoubleData())); 89 return injector; 90 } 91 92 protected internal override IOperator CreateSelector() { 93 CombinedOperator selector = new CombinedOperator(); 163 94 selector.Name = "Selector"; 164 selector.GetVariableInfo("Selected").ActualName = "Parents"; 165 selector.GetVariableInfo("GroupSize").Local = false; 166 selector.RemoveVariable("GroupSize"); 167 selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize"; 168 LeftReducer cleanUp = new LeftReducer(); 169 170 seq.AddSubOperator(problemInjectorPlaceholder); 171 seq.AddSubOperator(randomInjector); 172 seq.AddSubOperator(globalInjector); 173 seq.AddSubOperator(funLibInjector); 174 seq.AddSubOperator(initialization); 175 seq.AddSubOperator(mainLoop); 176 seq.AddSubOperator(cleanUp); 177 178 initialization.AddSubOperator(treeCreator); 179 initialization.AddSubOperator(evaluator); 180 181 mainLoop.AddSubOperator(selector); 182 mainLoop.AddSubOperator(crossover); 183 mainLoop.AddSubOperator(manipulator); 184 mainLoop.AddSubOperator(evaluator); 185 algo.OperatorGraph.AddOperator(seq); 186 algo.OperatorGraph.InitialOperator = seq; 187 this.algorithm = seq; 188 return algo; 189 } 190 191 private VariableInjector CreateGlobalInjector() { 192 VariableInjector injector = new VariableInjector(); 193 injector.Name = "Global Injector"; 194 injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0))); 195 injector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", maxGenerations)); 196 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate)); 197 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize)); 198 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents)); 199 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites)); 200 injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false))); 201 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", maxTreeHeight)); 202 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", maxTreeSize)); 203 injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0))); 204 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 205 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor))); 206 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue))); 207 return injector; 208 } 209 210 private CombinedOperator CreateManipulator() { 211 CombinedOperator manipulator = new CombinedOperator(); 212 StochasticMultiBranch multibranch = new StochasticMultiBranch(); 213 FullTreeShaker fullTreeShaker = new FullTreeShaker(); 214 fullTreeShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 215 fullTreeShaker.GetVariableInfo("ShakingFactor").Local = true; 216 fullTreeShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(fullTreeShakingFactor))); 217 218 OnePointShaker onepointShaker = new OnePointShaker(); 219 onepointShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 220 onepointShaker.GetVariableInfo("ShakingFactor").Local = true; 221 onepointShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(onepointShakingFactor))); 222 ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation(); 223 changeNodeTypeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 224 CutOutNodeManipulation cutOutNodeManipulation = new CutOutNodeManipulation(); 225 cutOutNodeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 226 DeleteSubTreeManipulation deleteSubTreeManipulation = new DeleteSubTreeManipulation(); 227 deleteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 228 SubstituteSubTreeManipulation substituteSubTreeManipulation = new SubstituteSubTreeManipulation(); 229 substituteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 230 231 IOperator[] manipulators = new IOperator[] { 232 onepointShaker, fullTreeShaker, 233 changeNodeTypeManipulation, 234 cutOutNodeManipulation, 235 deleteSubTreeManipulation, 236 substituteSubTreeManipulation}; 237 238 DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]); 239 for (int i = 0; i < manipulators.Length; i++) { 240 probabilities.Data[i] = 1.0; 241 multibranch.AddSubOperator(manipulators[i]); 242 } 243 multibranch.GetVariableInfo("Probabilities").Local = true; 244 multibranch.AddVariable(new HeuristicLab.Core.Variable("Probabilities", probabilities)); 245 246 manipulator.OperatorGraph.AddOperator(multibranch); 247 manipulator.OperatorGraph.InitialOperator = multibranch; 248 return manipulator; 249 } 250 251 private CombinedOperator CreateInialization() { 252 CombinedOperator init = new CombinedOperator(); 253 SequentialProcessor seq = new SequentialProcessor(); 254 SubScopesCreater subScopesCreater = new SubScopesCreater(); 255 subScopesCreater.GetVariableInfo("SubScopes").ActualName = "PopulationSize"; 256 UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor(); 257 SequentialProcessor individualSeq = new SequentialProcessor(); 258 OperatorExtractor treeCreater = new OperatorExtractor(); 259 treeCreater.Name = "Tree generator (extr.)"; 260 treeCreater.GetVariableInfo("Operator").ActualName = "Tree generator"; 261 OperatorExtractor evaluator = new OperatorExtractor(); 262 evaluator.Name = "Evaluator (extr.)"; 263 evaluator.GetVariableInfo("Operator").ActualName = "Evaluator"; 264 MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator(); 265 validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality"; 266 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 267 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 268 Counter evalCounter = new Counter(); 269 evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions"; 270 271 seq.AddSubOperator(subScopesCreater); 272 seq.AddSubOperator(subScopesProc); 273 subScopesProc.AddSubOperator(individualSeq); 274 individualSeq.AddSubOperator(treeCreater); 275 individualSeq.AddSubOperator(evaluator); 276 individualSeq.AddSubOperator(validationEvaluator); 277 individualSeq.AddSubOperator(evalCounter); 278 279 init.OperatorGraph.AddOperator(seq); 280 init.OperatorGraph.InitialOperator = seq; 281 return init; 282 } 283 284 private CombinedOperator CreateMainLoop() { 285 CombinedOperator main = new CombinedOperator(); 286 SequentialProcessor seq = new SequentialProcessor(); 287 CombinedOperator childCreater = CreateChildCreater(); 95 SequentialProcessor seq = new SequentialProcessor(); 96 seq.Name = "Selector"; 97 EmptyOperator emptyOp = new EmptyOperator(); 98 ProportionalSelector femaleSelector = new ProportionalSelector(); 99 femaleSelector.GetVariableInfo("Selected").ActualName = "Parents"; 100 femaleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true; 101 102 RandomSelector maleSelector = new RandomSelector(); 103 maleSelector.GetVariableInfo("Selected").ActualName = "Parents"; 104 maleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true; 105 SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor(); 106 RightChildReducer rightChildReducer = new RightChildReducer(); 107 SubScopesMixer mixer = new SubScopesMixer(); 108 109 seqSubScopesProc.AddSubOperator(femaleSelector); 110 seqSubScopesProc.AddSubOperator(emptyOp); 111 112 seq.AddSubOperator(maleSelector); 113 seq.AddSubOperator(seqSubScopesProc); 114 seq.AddSubOperator(rightChildReducer); 115 seq.AddSubOperator(mixer); 116 117 selector.OperatorGraph.AddOperator(seq); 118 selector.OperatorGraph.InitialOperator = seq; 119 return selector; 120 } 121 122 protected internal override IOperator CreateChildCreater() { 123 CombinedOperator childCreater = new CombinedOperator(); 288 124 childCreater.Name = "Create children"; 289 CombinedOperator replacement = CreateReplacement(); 290 replacement.Name = "Replacement"; 291 BestSolutionStorer solutionStorer = CreateBestSolutionStorer(); 292 BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator(); 293 BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator(); 294 validationQualityCalculator.Name = "ValidationQualityCalculator"; 295 validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality"; 296 validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality"; 297 validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality"; 298 DataCollector collector = new DataCollector(); 299 ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>(); 300 names.Add(new StringData("BestQuality")); 301 names.Add(new StringData("AverageQuality")); 302 names.Add(new StringData("WorstQuality")); 303 names.Add(new StringData("BestValidationQuality")); 304 names.Add(new StringData("AverageValidationQuality")); 305 names.Add(new StringData("WorstValidationQuality")); 306 LinechartInjector lineChartInjector = new LinechartInjector(); 307 lineChartInjector.GetVariableInfo("Linechart").ActualName = "Quality Linechart"; 308 lineChartInjector.GetVariable("NumberOfLines").GetValue<IntData>().Data = 6; 309 QualityLogger qualityLogger = new QualityLogger(); 310 QualityLogger validationQualityLogger = new QualityLogger(); 311 validationQualityCalculator.Name = "ValidationQualityLogger"; 312 validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 313 validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog"; 314 Counter counter = new Counter(); 315 counter.GetVariableInfo("Value").ActualName = "Generations"; 316 LessThanComparator comparator = new LessThanComparator(); 317 comparator.GetVariableInfo("LeftSide").ActualName = "Generations"; 318 comparator.GetVariableInfo("RightSide").ActualName = "MaxGenerations"; 319 comparator.GetVariableInfo("Result").ActualName = "GenerationsCondition"; 320 ConditionalBranch cond = new ConditionalBranch(); 321 cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition"; 322 323 seq.AddSubOperator(childCreater); 324 seq.AddSubOperator(replacement); 325 seq.AddSubOperator(solutionStorer); 326 seq.AddSubOperator(qualityCalculator); 327 seq.AddSubOperator(validationQualityCalculator); 328 seq.AddSubOperator(collector); 329 seq.AddSubOperator(lineChartInjector); 330 seq.AddSubOperator(qualityLogger); 331 seq.AddSubOperator(validationQualityLogger); 332 seq.AddSubOperator(counter); 333 seq.AddSubOperator(comparator); 334 seq.AddSubOperator(cond); 335 cond.AddSubOperator(seq); 336 337 main.OperatorGraph.AddOperator(seq); 338 main.OperatorGraph.InitialOperator = seq; 339 return main; 340 } 341 342 private BestSolutionStorer CreateBestSolutionStorer() { 343 BestSolutionStorer solutionStorer = new BestSolutionStorer(); 344 solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 345 solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution"; 346 SequentialProcessor bestSolutionProcessor = new SequentialProcessor(); 347 MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 348 trainingMapeEvaluator.Name = "ValidationMapeEvaluator"; 349 trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE"; 350 trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 351 trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 352 MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 353 validationMapeEvaluator.Name = "ValidationMapeEvaluator"; 354 validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE"; 355 validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 356 validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 357 ProgrammableOperator progOperator = new ProgrammableOperator(); 358 progOperator.RemoveVariableInfo("Result"); 359 progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In)); 360 progOperator.Code = @" 361 int evalSolutions = EvaluatedSolutions.Data; 362 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions))); 363 "; 364 solutionStorer.AddSubOperator(bestSolutionProcessor); 365 bestSolutionProcessor.AddSubOperator(trainingMapeEvaluator); 366 bestSolutionProcessor.AddSubOperator(validationMapeEvaluator); 367 bestSolutionProcessor.AddSubOperator(progOperator); 368 return solutionStorer; 369 } 370 371 private CombinedOperator CreateReplacement() { 372 CombinedOperator replacement = new CombinedOperator(); 373 SequentialProcessor seq = new SequentialProcessor(); 374 SequentialSubScopesProcessor seqScopeProc = new SequentialSubScopesProcessor(); 375 SequentialProcessor selectedProc = new SequentialProcessor(); 376 LeftSelector leftSelector = new LeftSelector(); 377 leftSelector.GetVariableInfo("Selected").ActualName = "Elites"; 378 RightReducer rightReducer = new RightReducer(); 379 380 SequentialProcessor remainingProc = new SequentialProcessor(); 381 RightSelector rightSelector = new RightSelector(); 382 rightSelector.GetVariableInfo("Selected").ActualName = "Elites"; 383 LeftReducer leftReducer = new LeftReducer(); 384 MergingReducer mergingReducer = new MergingReducer(); 385 Sorter sorter = new Sorter(); 386 sorter.GetVariableInfo("Descending").ActualName = "Maximization"; 387 sorter.GetVariableInfo("Value").ActualName = "Quality"; 388 389 seq.AddSubOperator(seqScopeProc); 390 seqScopeProc.AddSubOperator(selectedProc); 391 selectedProc.AddSubOperator(leftSelector); 392 selectedProc.AddSubOperator(rightReducer); 393 394 seqScopeProc.AddSubOperator(remainingProc); 395 remainingProc.AddSubOperator(rightSelector); 396 remainingProc.AddSubOperator(leftReducer); 397 seq.AddSubOperator(mergingReducer); 398 seq.AddSubOperator(sorter); 399 replacement.OperatorGraph.AddOperator(seq); 400 replacement.OperatorGraph.InitialOperator = seq; 401 return replacement; 402 } 403 404 private CombinedOperator CreateChildCreater() { 405 CombinedOperator childCreater = new CombinedOperator(); 406 SequentialProcessor seq = new SequentialProcessor(); 125 SequentialProcessor seq = new SequentialProcessor(); 126 SequentialProcessor offspringSelectionSeq = new SequentialProcessor(); 407 127 OperatorExtractor selector = new OperatorExtractor(); 408 128 selector.Name = "Selector (extr.)"; 409 129 selector.GetVariableInfo("Operator").ActualName = "Selector"; 410 SequentialSubScopesProcessor seqScopesProc = new SequentialSubScopesProcessor(); 411 EmptyOperator emptyOpt = new EmptyOperator(); 130 SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor(); 131 EmptyOperator emptyOp = new EmptyOperator(); 132 OffspringSelector offspringSelector = new OffspringSelector(); 133 OffspringAnalyzer offspringAnalyzer = new OffspringAnalyzer(); 412 134 SequentialProcessor selectedProc = new SequentialProcessor(); 413 135 OperatorExtractor crossover = new OperatorExtractor(); … … 424 146 evaluator.Name = "Evaluator (extr.)"; 425 147 evaluator.GetVariableInfo("Operator").ActualName = "Evaluator"; 426 MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();427 validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";428 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";429 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";430 148 Counter evalCounter = new Counter(); 431 149 evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions"; … … 435 153 sorter.GetVariableInfo("Value").ActualName = "Quality"; 436 154 437 438 seq.AddSubOperator(selector); 439 seq.AddSubOperator(seqScopesProc); 440 seqScopesProc.AddSubOperator(emptyOpt); 441 seqScopesProc.AddSubOperator(selectedProc); 155 UniformSequentialSubScopesProcessor validationEvaluator = new UniformSequentialSubScopesProcessor(); 156 MeanSquaredErrorEvaluator validationQualityEvaluator = new MeanSquaredErrorEvaluator(); 157 validationQualityEvaluator.Name = "ValidationMeanSquaredErrorEvaluator"; 158 validationQualityEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality"; 159 validationQualityEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 160 validationQualityEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 161 162 seqSubScopesProc.AddSubOperator(emptyOp); 163 seqSubScopesProc.AddSubOperator(offspringAnalyzer); 164 165 seq.AddSubOperator(offspringSelectionSeq); 166 offspringSelectionSeq.AddSubOperator(selector); 167 offspringSelectionSeq.AddSubOperator(seqSubScopesProc); 168 offspringSelectionSeq.AddSubOperator(offspringSelector); 169 offspringSelector.AddSubOperator(offspringSelectionSeq); 170 171 offspringAnalyzer.AddSubOperator(selectedProc); 442 172 selectedProc.AddSubOperator(crossover); 443 173 selectedProc.AddSubOperator(individualProc); … … 446 176 cond.AddSubOperator(manipulator); 447 177 individualSeqProc.AddSubOperator(evaluator); 448 individualSeqProc.AddSubOperator(validationEvaluator);449 178 individualSeqProc.AddSubOperator(evalCounter); 450 selectedProc.AddSubOperator(sorter); 179 180 SequentialSubScopesProcessor seqSubScopesProc2 = new SequentialSubScopesProcessor(); 181 seq.AddSubOperator(seqSubScopesProc2); 182 seqSubScopesProc2.AddSubOperator(emptyOp); 183 184 SequentialProcessor newGenProc = new SequentialProcessor(); 185 newGenProc.AddSubOperator(sorter); 186 newGenProc.AddSubOperator(validationEvaluator); 187 seqSubScopesProc2.AddSubOperator(newGenProc); 188 189 validationEvaluator.AddSubOperator(validationQualityEvaluator); 451 190 452 191 childCreater.OperatorGraph.AddOperator(seq); … … 455 194 } 456 195 457 public IEditor CreateEditor() { 458 return new OffSpringSelectionGpEditor(this); 196 protected internal override IOperator CreateLoopCondition(IOperator loop) { 197 SequentialProcessor seq = new SequentialProcessor(); 198 seq.Name = "Loop Condition"; 199 LessThanComparator generationsComparator = new LessThanComparator(); 200 generationsComparator.GetVariableInfo("LeftSide").ActualName = "EvaluatedSolutions"; 201 generationsComparator.GetVariableInfo("RightSide").ActualName = "MaxEvaluatedSolutions"; 202 generationsComparator.GetVariableInfo("Result").ActualName = "EvaluatedSolutionsCondition"; 203 204 LessThanComparator selPresComparator = new LessThanComparator(); 205 selPresComparator.GetVariableInfo("LeftSide").ActualName = "SelectionPressure"; 206 selPresComparator.GetVariableInfo("RightSide").ActualName = "SelectionPressureLimit"; 207 selPresComparator.GetVariableInfo("Result").ActualName = "SelectionPressureCondition"; 208 209 ConditionalBranch generationsCond = new ConditionalBranch(); 210 generationsCond.GetVariableInfo("Condition").ActualName = "EvaluatedSolutionsCondition"; 211 212 ConditionalBranch selPresCond = new ConditionalBranch(); 213 selPresCond.GetVariableInfo("Condition").ActualName = "SelectionPressureCondition"; 214 215 seq.AddSubOperator(generationsComparator); 216 seq.AddSubOperator(selPresComparator); 217 seq.AddSubOperator(generationsCond); 218 generationsCond.AddSubOperator(selPresCond); 219 selPresCond.AddSubOperator(loop); 220 221 return seq; 222 } 223 224 protected internal override IOperator CreateLoggingOperator() { 225 CombinedOperator loggingOperator = new CombinedOperator(); 226 loggingOperator.Name = "Logging"; 227 SequentialProcessor seq = new SequentialProcessor(); 228 229 DataCollector collector = new DataCollector(); 230 ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>(); 231 names.Add(new StringData("BestQuality")); 232 names.Add(new StringData("AverageQuality")); 233 names.Add(new StringData("WorstQuality")); 234 names.Add(new StringData("BestValidationQuality")); 235 names.Add(new StringData("AverageValidationQuality")); 236 names.Add(new StringData("WorstValidationQuality")); 237 names.Add(new StringData("EvaluatedSolutions")); 238 names.Add(new StringData("SelectionPressure")); 239 QualityLogger qualityLogger = new QualityLogger(); 240 QualityLogger validationQualityLogger = new QualityLogger(); 241 validationQualityLogger.Name = "ValidationQualityLogger"; 242 validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 243 validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog"; 244 245 seq.AddSubOperator(collector); 246 seq.AddSubOperator(qualityLogger); 247 seq.AddSubOperator(validationQualityLogger); 248 249 loggingOperator.OperatorGraph.AddOperator(seq); 250 loggingOperator.OperatorGraph.InitialOperator = seq; 251 return loggingOperator; 252 } 253 254 255 public override IEditor CreateEditor() { 256 return new OffspringSelectionGpEditor(this); 459 257 } 460 258 … … 464 262 465 263 public override object Clone(IDictionary<Guid, object> clonedObjects) { 466 OffspringSelectionGP clone = new OffspringSelectionGP(); 467 clonedObjects.Add(Guid, clone); 468 clone.engine = (SequentialEngine.SequentialEngine)Auxiliary.Clone(Engine, clonedObjects); 264 OffspringSelectionGP clone = (OffspringSelectionGP)base.Clone(clonedObjects); 265 clone.SelectionPressureLimit = SelectionPressureLimit; 266 clone.SuccessRatioLimit = SuccessRatioLimit; 267 clone.ComparisonFactor = ComparisonFactor; 469 268 return clone; 470 269 } 471 #region SetReferences Method472 private void SetReferences() {473 // SGA474 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;475 // SequentialProcessor in SGA476 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;477 // RandomInjector478 RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];479 setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();480 seed = ri.GetVariable("Seed").GetValue<IntData>();481 // VariableInjector482 VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];483 populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();484 parents = vi.GetVariable("Parents").GetValue<IntData>();485 maxGenerations = vi.GetVariable("MaxGenerations").GetValue<IntData>();486 mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();487 elites = vi.GetVariable("Elites").GetValue<IntData>();488 maxTreeSize = vi.GetVariable("MaxTreeSize").GetValue<IntData>();489 maxTreeHeight = vi.GetVariable("MaxTreeHeight").GetValue<IntData>();490 }491 #endregion492 493 #region Persistence Methods494 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {495 XmlNode node = base.GetXmlNode(name, document, persistedObjects);496 node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));497 return node;498 }499 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {500 base.Populate(node, restoredObjects);501 engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);502 SetReferences();503 }504 #endregion505 270 } 506 271 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGP.cs
r1053 r1287 36 36 37 37 namespace HeuristicLab.GP.StructureIdentification { 38 public class StandardGP : ItemBase, IEditable { 39 private IntData maxGenerations = new IntData(); 40 public int MaxGenerations { 41 get { return maxGenerations.Data; } 42 set { maxGenerations.Data = value; } 43 } 44 45 private IntData tournamentSize = new IntData(); 46 public int TournamentSize { 47 get { return tournamentSize.Data; } 48 set { tournamentSize.Data = value; } 49 } 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; } 38 public class StandardGP : AlgorithmBase, IEditable { 39 40 public virtual int MaxGenerations { 41 get { return GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data; } 42 set { GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data = value; } 43 } 44 45 public virtual int TournamentSize { 46 get { return GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data; } 47 set { GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data = value; } 48 } 49 50 public double FullTreeShakingFactor { 51 get { return GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data; } 52 set { GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data = value; } 53 } 54 55 public double OnePointShakingFactor { 56 get { return GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data; } 57 set { GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data = value; } 58 } 59 60 public int MinInitialTreeSize { 61 get { return GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data; } 62 set { GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data = value; } 63 } 64 65 public override int MaxTreeSize { 66 get { 67 return base.MaxTreeSize; 68 } 59 69 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]; } 70 base.MaxTreeSize = value; 71 MinInitialTreeSize = value / 2; 72 } 73 } 74 75 public override int PopulationSize { 76 get { 77 return base.PopulationSize; 78 } 79 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 private int maxTreeHeight = 8; 94 private double punishmentFactor = 10.0; 95 private bool useEstimatedTargetValue = false; 96 private double fullTreeShakingFactor = 0.1; 97 private double onepointShakingFactor = 1.0; 98 private IOperator algorithm; 99 private SequentialEngine.SequentialEngine engine; 100 101 public IEngine Engine { 102 get { return engine; } 103 } 104 105 public StandardGP() { 106 PopulationSize = 100; 80 base.PopulationSize = value; 81 Parents = 2 * value; 82 } 83 } 84 85 public StandardGP() 86 : base() { 87 PopulationSize = 10000; 107 88 MaxGenerations = 100; 108 89 TournamentSize = 7; 109 90 MutationRate = 0.15; 110 91 Elites = 1; 111 engine = new SequentialEngine.SequentialEngine(); 112 CombinedOperator algo = CreateAlgorithm(); 113 engine.OperatorGraph.AddOperator(algo); 114 engine.OperatorGraph.InitialOperator = algo; 115 } 116 117 private CombinedOperator CreateAlgorithm() { 118 CombinedOperator algo = new CombinedOperator(); 119 algo.Name = "StandardGP"; 120 SequentialProcessor seq = new SequentialProcessor(); 121 EmptyOperator problemInjectorPlaceholder = new EmptyOperator(); 122 RandomInjector randomInjector = new RandomInjector(); 123 randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly; 124 randomInjector.GetVariable("Seed").Value = seed; 125 randomInjector.Name = "Random Injector"; 126 VariableInjector globalInjector = CreateGlobalInjector(); 127 CombinedOperator initialization = CreateInialization(); 128 initialization.Name = "Initialization"; 129 FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector(); 130 CombinedOperator mainLoop = CreateMainLoop(); 131 mainLoop.Name = "Main loop"; 132 133 ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator(); 134 treeCreator.Name = "Tree generator"; 135 treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 136 treeCreator.GetVariableInfo("MinTreeSize").Local = true; 137 treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3))); 138 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator(); 139 evaluator.GetVariableInfo("MSE").ActualName = "Quality"; 140 evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 141 evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 142 evaluator.Name = "Evaluator"; 143 StandardCrossOver crossover = new StandardCrossOver(); 144 crossover.Name = "Crossover"; 145 crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 146 CombinedOperator manipulator = CreateManipulator(); 147 manipulator.Name = "Manipulator"; 92 MaxTreeSize = 100; 93 MaxTreeHeight = 10; 94 FullTreeShakingFactor = 0.1; 95 OnePointShakingFactor = 1.0; 96 PunishmentFactor = 10.0; 97 UseEstimatedTargetValue = false; 98 SetSeedRandomly = true; 99 } 100 101 protected internal override IOperator CreateProblemInjector() { 102 return new ProblemInjector(); 103 } 104 105 protected internal override IOperator CreateSelector() { 148 106 TournamentSelector selector = new TournamentSelector(); 149 107 selector.Name = "Selector"; … … 152 110 selector.RemoveVariable("GroupSize"); 153 111 selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize"; 154 155 seq.AddSubOperator(problemInjectorPlaceholder); 156 seq.AddSubOperator(randomInjector); 157 seq.AddSubOperator(globalInjector); 158 seq.AddSubOperator(funLibInjector); 159 seq.AddSubOperator(initialization); 160 seq.AddSubOperator(mainLoop); 161 162 initialization.AddSubOperator(treeCreator); 163 initialization.AddSubOperator(evaluator); 164 165 mainLoop.AddSubOperator(selector); 166 mainLoop.AddSubOperator(crossover); 167 mainLoop.AddSubOperator(manipulator); 168 mainLoop.AddSubOperator(evaluator); 169 algo.OperatorGraph.AddOperator(seq); 170 algo.OperatorGraph.InitialOperator = seq; 171 this.algorithm = seq; 172 return algo; 173 } 174 175 private VariableInjector CreateGlobalInjector() { 176 VariableInjector injector = new VariableInjector(); 177 injector.Name = "Global Injector"; 178 injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0))); 179 injector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", maxGenerations)); 180 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate)); 181 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize)); 182 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents)); 183 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites)); 184 injector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", tournamentSize)); 185 injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false))); 186 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData(maxTreeHeight))); 187 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData(maxTreeSize))); 188 injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0))); 189 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 190 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor))); 191 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue))); 192 return injector; 193 } 194 195 private CombinedOperator CreateManipulator() { 112 return selector; 113 } 114 115 protected internal override IOperator CreateGlobalInjector() { 116 VariableInjector globalInjector = (VariableInjector)base.CreateGlobalInjector(); 117 globalInjector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", new IntData())); 118 globalInjector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", new IntData())); 119 globalInjector.AddVariable(new HeuristicLab.Core.Variable("FullTreeShakingFactor", new DoubleData())); 120 globalInjector.AddVariable(new HeuristicLab.Core.Variable("OnePointShakingFactor", new DoubleData())); 121 globalInjector.AddVariable(new HeuristicLab.Core.Variable("MinInitialTreeSize", new IntData())); 122 return globalInjector; 123 } 124 125 protected internal override IOperator CreateCrossover() { 126 StandardCrossOver crossover = new StandardCrossOver(); 127 crossover.Name = "Crossover"; 128 crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 129 return crossover; 130 } 131 132 protected internal override IOperator CreateTreeCreator() { 133 ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator(); 134 treeCreator.Name = "Tree generator"; 135 treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 136 treeCreator.GetVariableInfo("MinTreeSize").ActualName = "MinInitialTreeSize"; 137 return treeCreator; 138 } 139 140 protected internal override IOperator CreateFunctionLibraryInjector() { 141 return new FunctionLibraryInjector(); 142 } 143 144 protected internal override IOperator CreateManipulator() { 196 145 CombinedOperator manipulator = new CombinedOperator(); 146 manipulator.Name = "Manipulator"; 197 147 StochasticMultiBranch multibranch = new StochasticMultiBranch(); 198 148 FullTreeShaker fullTreeShaker = new FullTreeShaker(); 199 149 fullTreeShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 200 fullTreeShaker.GetVariableInfo("ShakingFactor").Local = true; 201 fullTreeShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(fullTreeShakingFactor))); 150 fullTreeShaker.GetVariableInfo("ShakingFactor").ActualName = "FullTreeShakingFactor"; 202 151 203 152 OnePointShaker onepointShaker = new OnePointShaker(); 204 153 onepointShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; 205 onepointShaker.GetVariableInfo("ShakingFactor").Local = true; 206 onepointShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(onepointShakingFactor))); 154 onepointShaker.GetVariableInfo("ShakingFactor").ActualName = "OnePointShakingFactor"; 207 155 ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation(); 208 156 changeNodeTypeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary"; … … 222 170 223 171 DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]); 224 for (int i=0;i<manipulators.Length;i++) {172 for (int i = 0; i < manipulators.Length; i++) { 225 173 probabilities.Data[i] = 1.0; 226 174 multibranch.AddSubOperator(manipulators[i]); … … 234 182 } 235 183 236 private CombinedOperator CreateInialization() { 237 CombinedOperator init = new CombinedOperator(); 184 protected internal override IOperator CreateBestSolutionProcessor() { 185 SequentialProcessor bestSolutionProcessor = new SequentialProcessor(); 186 MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator(); 187 testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator"; 188 testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestQuality"; 189 testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 190 testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 191 MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 192 trainingMapeEvaluator.Name = "TrainingMapeEvaluator"; 193 trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE"; 194 trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 195 trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 196 MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 197 validationMapeEvaluator.Name = "ValidationMapeEvaluator"; 198 validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE"; 199 validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 200 validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 201 MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 202 testMapeEvaluator.Name = "TestMapeEvaluator"; 203 testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE"; 204 testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 205 testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 206 MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 207 trainingMapreEvaluator.Name = "TrainingMapreEvaluator"; 208 trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE"; 209 trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 210 trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 211 MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 212 validationMapreEvaluator.Name = "ValidationMapreEvaluator"; 213 validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE"; 214 validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 215 validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 216 MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator(); 217 testMapreEvaluator.Name = "TestMapreEvaluator"; 218 testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE"; 219 testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 220 testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 221 CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator(); 222 trainingR2Evaluator.Name = "TrainingR2Evaluator"; 223 trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2"; 224 trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart"; 225 trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 226 CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator(); 227 validationR2Evaluator.Name = "ValidationR2Evaluator"; 228 validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2"; 229 validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 230 validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 231 CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator(); 232 testR2Evaluator.Name = "TestR2Evaluator"; 233 testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2"; 234 testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart"; 235 testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd"; 236 ProgrammableOperator progOperator = new ProgrammableOperator(); 237 progOperator.RemoveVariableInfo("Result"); 238 progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In)); 239 progOperator.Code = @" 240 int evalSolutions = EvaluatedSolutions.Data; 241 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions))); 242 "; 243 bestSolutionProcessor.AddSubOperator(testMseEvaluator); 244 bestSolutionProcessor.AddSubOperator(trainingMapeEvaluator); 245 bestSolutionProcessor.AddSubOperator(validationMapeEvaluator); 246 bestSolutionProcessor.AddSubOperator(testMapeEvaluator); 247 bestSolutionProcessor.AddSubOperator(trainingMapreEvaluator); 248 bestSolutionProcessor.AddSubOperator(validationMapreEvaluator); 249 bestSolutionProcessor.AddSubOperator(testMapreEvaluator); 250 bestSolutionProcessor.AddSubOperator(trainingR2Evaluator); 251 bestSolutionProcessor.AddSubOperator(validationR2Evaluator); 252 bestSolutionProcessor.AddSubOperator(testR2Evaluator); 253 bestSolutionProcessor.AddSubOperator(progOperator); 254 return bestSolutionProcessor; 255 } 256 257 protected internal override IOperator CreateLoggingOperator() { 258 CombinedOperator loggingOperator = new CombinedOperator(); 259 loggingOperator.Name = "Logging"; 238 260 SequentialProcessor seq = new SequentialProcessor(); 239 SubScopesCreater subScopesCreater = new SubScopesCreater(); 240 subScopesCreater.GetVariableInfo("SubScopes").ActualName = "PopulationSize"; 241 UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor(); 242 SequentialProcessor individualSeq = new SequentialProcessor(); 243 OperatorExtractor treeCreater = new OperatorExtractor(); 244 treeCreater.Name = "Tree generator (extr.)"; 245 treeCreater.GetVariableInfo("Operator").ActualName = "Tree generator"; 246 OperatorExtractor evaluator = new OperatorExtractor(); 247 evaluator.Name = "Evaluator (extr.)"; 248 evaluator.GetVariableInfo("Operator").ActualName = "Evaluator"; 249 MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator(); 250 validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality"; 251 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 252 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 253 Counter evalCounter = new Counter(); 254 evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions"; 255 256 seq.AddSubOperator(subScopesCreater); 257 seq.AddSubOperator(subScopesProc); 258 subScopesProc.AddSubOperator(individualSeq); 259 individualSeq.AddSubOperator(treeCreater); 260 individualSeq.AddSubOperator(evaluator); 261 individualSeq.AddSubOperator(validationEvaluator); 262 individualSeq.AddSubOperator(evalCounter); 263 264 init.OperatorGraph.AddOperator(seq); 265 init.OperatorGraph.InitialOperator = seq; 266 return init; 267 } 268 269 private CombinedOperator CreateMainLoop() { 270 CombinedOperator main = new CombinedOperator(); 271 SequentialProcessor seq = new SequentialProcessor(); 272 CombinedOperator childCreater = CreateChildCreater(); 273 childCreater.Name = "Create children"; 274 CombinedOperator replacement = CreateReplacement(); 275 replacement.Name = "Replacement"; 276 BestSolutionStorer solutionStorer = CreateBestSolutionStorer(); 277 BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator(); 278 BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator(); 279 validationQualityCalculator.Name = "ValidationQualityCalculator"; 280 validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality"; 281 validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality"; 282 validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality"; 261 283 262 DataCollector collector = new DataCollector(); 284 263 ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>(); … … 294 273 QualityLogger qualityLogger = new QualityLogger(); 295 274 QualityLogger validationQualityLogger = new QualityLogger(); 296 validationQuality Calculator.Name = "ValidationQualityLogger";275 validationQualityLogger.Name = "ValidationQualityLogger"; 297 276 validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 298 277 validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog"; 299 Counter counter = new Counter(); 300 counter.GetVariableInfo("Value").ActualName = "Generations"; 301 LessThanComparator comparator = new LessThanComparator(); 302 comparator.GetVariableInfo("LeftSide").ActualName = "Generations"; 303 comparator.GetVariableInfo("RightSide").ActualName = "MaxGenerations"; 304 comparator.GetVariableInfo("Result").ActualName = "GenerationsCondition"; 305 ConditionalBranch cond = new ConditionalBranch(); 306 cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition"; 307 308 seq.AddSubOperator(childCreater); 309 seq.AddSubOperator(replacement); 310 seq.AddSubOperator(solutionStorer); 311 seq.AddSubOperator(qualityCalculator); 312 seq.AddSubOperator(validationQualityCalculator); 278 313 279 seq.AddSubOperator(collector); 314 280 seq.AddSubOperator(lineChartInjector); 315 281 seq.AddSubOperator(qualityLogger); 316 282 seq.AddSubOperator(validationQualityLogger); 317 seq.AddSubOperator(counter); 318 seq.AddSubOperator(comparator); 319 seq.AddSubOperator(cond); 320 cond.AddSubOperator(seq); 321 322 main.OperatorGraph.AddOperator(seq); 323 main.OperatorGraph.InitialOperator = seq; 324 return main; 325 } 326 327 private BestSolutionStorer CreateBestSolutionStorer() { 328 BestSolutionStorer solutionStorer = new BestSolutionStorer(); 329 solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality"; 330 solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution"; 331 SequentialProcessor bestSolutionProcessor = new SequentialProcessor(); 332 MeanAbsolutePercentageErrorEvaluator mapeEvaluator = new MeanAbsolutePercentageErrorEvaluator(); 333 mapeEvaluator.Name = "ValidationMapeEvaluator"; 334 mapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE"; 335 mapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 336 mapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 337 CoefficientOfDeterminationEvaluator r2Evaluator = new CoefficientOfDeterminationEvaluator(); 338 r2Evaluator.Name = "ValidationR2Evaluator"; 339 r2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2"; 340 r2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 341 r2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 342 ProgrammableOperator progOperator = new ProgrammableOperator(); 343 progOperator.RemoveVariableInfo("Result"); 344 progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In)); 345 progOperator.Code = @" 346 int evalSolutions = EvaluatedSolutions.Data; 347 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions))); 348 "; 349 solutionStorer.AddSubOperator(bestSolutionProcessor); 350 bestSolutionProcessor.AddSubOperator(mapeEvaluator); 351 bestSolutionProcessor.AddSubOperator(r2Evaluator); 352 bestSolutionProcessor.AddSubOperator(progOperator); 353 return solutionStorer; 354 } 355 356 private CombinedOperator CreateReplacement() { 357 CombinedOperator replacement = new CombinedOperator(); 358 SequentialProcessor seq = new SequentialProcessor(); 359 SequentialSubScopesProcessor seqScopeProc = new SequentialSubScopesProcessor(); 360 SequentialProcessor selectedProc = new SequentialProcessor(); 361 LeftSelector leftSelector = new LeftSelector(); 362 leftSelector.GetVariableInfo("Selected").ActualName = "Elites"; 363 RightReducer rightReducer = new RightReducer(); 364 365 SequentialProcessor remainingProc = new SequentialProcessor(); 366 RightSelector rightSelector = new RightSelector(); 367 rightSelector.GetVariableInfo("Selected").ActualName = "Elites"; 368 LeftReducer leftReducer = new LeftReducer(); 369 MergingReducer mergingReducer = new MergingReducer(); 370 Sorter sorter = new Sorter(); 371 sorter.GetVariableInfo("Descending").ActualName = "Maximization"; 372 sorter.GetVariableInfo("Value").ActualName = "Quality"; 373 374 seq.AddSubOperator(seqScopeProc); 375 seqScopeProc.AddSubOperator(selectedProc); 376 selectedProc.AddSubOperator(leftSelector); 377 selectedProc.AddSubOperator(rightReducer); 378 379 seqScopeProc.AddSubOperator(remainingProc); 380 remainingProc.AddSubOperator(rightSelector); 381 remainingProc.AddSubOperator(leftReducer); 382 seq.AddSubOperator(mergingReducer); 383 seq.AddSubOperator(sorter); 384 replacement.OperatorGraph.AddOperator(seq); 385 replacement.OperatorGraph.InitialOperator = seq; 386 return replacement; 387 } 388 389 private CombinedOperator CreateChildCreater() { 390 CombinedOperator childCreater = new CombinedOperator(); 391 SequentialProcessor seq = new SequentialProcessor(); 392 OperatorExtractor selector = new OperatorExtractor(); 393 selector.Name = "Selector (extr.)"; 394 selector.GetVariableInfo("Operator").ActualName = "Selector"; 395 SequentialSubScopesProcessor seqScopesProc = new SequentialSubScopesProcessor(); 396 EmptyOperator emptyOpt = new EmptyOperator(); 397 SequentialProcessor selectedProc = new SequentialProcessor(); 398 OperatorExtractor crossover = new OperatorExtractor(); 399 crossover.Name = "Crossover (extr.)"; 400 crossover.GetVariableInfo("Operator").ActualName = "Crossover"; 401 UniformSequentialSubScopesProcessor individualProc = new UniformSequentialSubScopesProcessor(); 402 SequentialProcessor individualSeqProc = new SequentialProcessor(); 403 StochasticBranch cond = new StochasticBranch(); 404 cond.GetVariableInfo("Probability").ActualName = "MutationRate"; 405 OperatorExtractor manipulator = new OperatorExtractor(); 406 manipulator.Name = "Manipulator (extr.)"; 407 manipulator.GetVariableInfo("Operator").ActualName = "Manipulator"; 408 OperatorExtractor evaluator = new OperatorExtractor(); 409 evaluator.Name = "Evaluator (extr.)"; 410 evaluator.GetVariableInfo("Operator").ActualName = "Evaluator"; 411 MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator(); 412 validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality"; 413 validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart"; 414 validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd"; 415 Counter evalCounter = new Counter(); 416 evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions"; 417 418 Sorter sorter = new Sorter(); 419 sorter.GetVariableInfo("Descending").ActualName = "Maximization"; 420 sorter.GetVariableInfo("Value").ActualName = "Quality"; 421 422 423 seq.AddSubOperator(selector); 424 seq.AddSubOperator(seqScopesProc); 425 seqScopesProc.AddSubOperator(emptyOpt); 426 seqScopesProc.AddSubOperator(selectedProc); 427 selectedProc.AddSubOperator(crossover); 428 selectedProc.AddSubOperator(individualProc); 429 individualProc.AddSubOperator(individualSeqProc); 430 individualSeqProc.AddSubOperator(cond); 431 cond.AddSubOperator(manipulator); 432 individualSeqProc.AddSubOperator(evaluator); 433 individualSeqProc.AddSubOperator(validationEvaluator); 434 individualSeqProc.AddSubOperator(evalCounter); 435 selectedProc.AddSubOperator(sorter); 436 437 childCreater.OperatorGraph.AddOperator(seq); 438 childCreater.OperatorGraph.InitialOperator = seq; 439 return childCreater; 440 } 441 442 public IEditor CreateEditor() { 283 284 loggingOperator.OperatorGraph.AddOperator(seq); 285 loggingOperator.OperatorGraph.InitialOperator = seq; 286 return loggingOperator; 287 } 288 289 public virtual IEditor CreateEditor() { 443 290 return new StandardGpEditor(this); 444 291 } … … 447 294 return new StandardGpEditor(this); 448 295 } 449 450 public override object Clone(IDictionary<Guid, object> clonedObjects) {451 StandardGP clone = new StandardGP();452 clonedObjects.Add(Guid, clone);453 clone.engine = (SequentialEngine.SequentialEngine)Auxiliary.Clone(Engine, clonedObjects);454 return clone;455 }456 #region SetReferences Method457 private void SetReferences() {458 // SGA459 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;460 // SequentialProcessor in SGA461 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;462 // RandomInjector463 RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];464 setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();465 seed = ri.GetVariable("Seed").GetValue<IntData>();466 // VariableInjector467 VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];468 populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();469 parents = vi.GetVariable("Parents").GetValue<IntData>();470 maxGenerations = vi.GetVariable("MaxGenerations").GetValue<IntData>();471 mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();472 elites = vi.GetVariable("Elites").GetValue<IntData>();473 }474 #endregion475 476 #region Persistence Methods477 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {478 XmlNode node = base.GetXmlNode(name, document, persistedObjects);479 node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));480 return node;481 }482 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {483 base.Populate(node, restoredObjects);484 engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);485 SetReferences();486 }487 #endregion488 296 } 489 297 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGpEditor.Designer.cs
r1053 r1287 165 165 this.setRandomSeedRandomlyCheckBox.TabIndex = 1; 166 166 this.setRandomSeedRandomlyCheckBox.UseVisualStyleBackColor = true; 167 this.setRandomSeedRandomlyCheckBox.CheckedChanged += new System.EventHandler(this.setRandomSeedRandomlyCheckBox_CheckedChanged); 167 168 // 168 169 // elitesTextBox … … 353 354 354 355 private System.Windows.Forms.Button executeButton; 355 pr ivateSystem.Windows.Forms.TabControl tabControl;356 pr ivateSystem.Windows.Forms.TabPage parametersTabPage;356 protected System.Windows.Forms.TabControl tabControl; 357 protected System.Windows.Forms.TabPage parametersTabPage; 357 358 private System.Windows.Forms.Button abortButton; 358 359 private System.Windows.Forms.Button resetButton; -
trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGpEditor.cs
r1053 r1287 71 71 } 72 72 73 pr ivatevoid SetDataBinding() {73 protected virtual void SetDataBinding() { 74 74 setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", StandardGP, "SetSeedRandomly"); 75 75 randomSeedTextBox.DataBindings.Add("Text", StandardGP, "Seed"); … … 97 97 executeButton.Enabled = false; 98 98 abortButton.Enabled = true; 99 resetButton.Enabled = false; 99 100 StandardGP.Engine.Execute(); 100 101 } … … 127 128 executeButton.Enabled = true; 128 129 abortButton.Enabled = false; 130 resetButton.Enabled = true; 129 131 } 130 132 } 131 133 #endregion 132 134 133 135 private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) { 136 randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked; 137 randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked; 138 } 134 139 } 135 140 }
Note: See TracChangeset
for help on using the changeset viewer.