Changeset 6439
- Timestamp:
- 06/17/11 15:22:27 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r6436 r6439 65 65 get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; } 66 66 } 67 p rivateConstrainedValueParameter<ISelector> SelectorParameter {67 public ConstrainedValueParameter<ISelector> SelectorParameter { 68 68 get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; } 69 69 } 70 p rivateConstrainedValueParameter<ICrossover> CrossoverParameter {70 public ConstrainedValueParameter<ICrossover> CrossoverParameter { 71 71 get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; } 72 72 } … … 74 74 get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; } 75 75 } 76 p rivateOptionalConstrainedValueParameter<IManipulator> MutatorParameter {76 public OptionalConstrainedValueParameter<IManipulator> MutatorParameter { 77 77 get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 78 78 } … … 105 105 set { SelectorParameter.Value = value; } 106 106 } 107 public IEnumerable<ISelector> ValidSelectors {108 get { return SelectorParameter.ValidValues; }109 }110 107 public ICrossover Crossover { 111 108 get { return CrossoverParameter.Value; } … … 119 116 get { return MutatorParameter.Value; } 120 117 set { MutatorParameter.Value = value; } 121 }122 public IEnumerable<IManipulator> ValidMutators {123 get { return MutatorParameter.ValidValues; }124 118 } 125 119 public IntValue Elites { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/FullTreeShaker.cs
r5809 r6439 32 32 private const string ShakingFactorParameterName = "ShakingFactor"; 33 33 #region parameter properties 34 public IValue LookupParameter<DoubleValue> ShakingFactorParameter {35 get { return (IValue LookupParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; }34 public IValueParameter<DoubleValue> ShakingFactorParameter { 35 get { return (IValueParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; } 36 36 } 37 37 #endregion 38 38 #region properties 39 public DoubleValue ShakingFactor { 40 get { return ShakingFactorParameter.ActualValue; } 39 public double ShakingFactor { 40 get { return ShakingFactorParameter.Value.Value; } 41 set { ShakingFactorParameter.Value.Value = value; } 41 42 } 42 43 #endregion 43 44 44 [StorableConstructor] 45 45 private FullTreeShaker(bool deserializing) : base(deserializing) { } … … 47 47 public FullTreeShaker() 48 48 : base() { 49 Parameters.Add(new ValueLookupParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0)));49 Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0))); 50 50 } 51 51 … … 57 57 tree.Root.ForEachNodePostfix(node => { 58 58 if (node.HasLocalParameters) { 59 node.ShakeLocalParameters(random, ShakingFactor .Value);59 node.ShakeLocalParameters(random, ShakingFactor); 60 60 } 61 61 }); -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs
r5809 r6439 34 34 private const string ShakingFactorParameterName = "ShakingFactor"; 35 35 #region parameter properties 36 public IValue LookupParameter<DoubleValue> ShakingFactorParameter {37 get { return (IValue LookupParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; }36 public IValueParameter<DoubleValue> ShakingFactorParameter { 37 get { return (IValueParameter<DoubleValue>)Parameters[ShakingFactorParameterName]; } 38 38 } 39 39 #endregion 40 40 #region properties 41 public DoubleValue ShakingFactor { 42 get { return ShakingFactorParameter.ActualValue; } 41 public double ShakingFactor { 42 get { return ShakingFactorParameter.Value.Value; } 43 set { ShakingFactorParameter.Value.Value = value; } 43 44 } 44 45 #endregion … … 48 49 public OnePointShaker() 49 50 : base() { 50 Parameters.Add(new ValueLookupParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0)));51 Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0))); 51 52 } 52 53 … … 62 63 if (parametricNodes.Count > 0) { 63 64 var selectedPoint = parametricNodes.SelectRandom(random); 64 selectedPoint.ShakeLocalParameters(random, ShakingFactor .Value);65 selectedPoint.ShakeLocalParameters(random, ShakingFactor); 65 66 } 66 67 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r6238 r6439 77 77 #endregion 78 78 79 public IValueParameter<StringValue> TargetVariableParameter {80 get { return ( IValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }79 public ConstrainedValueParameter<StringValue> TargetVariableParameter { 80 get { return (ConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 81 81 } 82 82 public string TargetVariable { -
trunk/sources/HeuristicLab/3.3/Tests/GeneticProgrammingSamplesTest.cs
r6436 r6439 13 13 using System.Threading; 14 14 using HeuristicLab.ParallelEngine; 15 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 16 using HeuristicLab.Problems.DataAnalysis; 17 using HeuristicLab.Problems.DataAnalysis.Symbolic; 18 using System.IO; 15 19 16 20 namespace HeuristicLab_33.Tests { … … 18 22 public class GeneticProgrammingSamplesTest { 19 23 [TestMethod] 20 public void ArtificialAntProblemTest() {24 public void CreateArtificialAntSample() { 21 25 GeneticAlgorithm ga = new GeneticAlgorithm(); 22 #region algorithm configuration 23 ga.Name = "Genetic Programming - Artificial Ant"; 24 ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (Santa-Fe trail)"; 26 #region problem configuration 25 27 ArtificialAntProblem antProblem = new ArtificialAntProblem(); 26 ga.Problem = antProblem;27 ga.PopulationSize.Value = 1000;28 ga.MaximumGenerations.Value = 100;29 ga.MutationProbability.Value = 0.15;30 ga.Elites.Value = 1;31 var tSelector = (TournamentSelector)ga.ValidSelectors32 .Single(s => s.Name == "TournamentSelector");33 tSelector.GroupSizeParameter.Value = new IntValue(5);34 ga.Selector = tSelector;35 var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.ValidMutators36 .Single(m => m.Name == "MultiSymbolicExpressionTreeArchitectureManipulator");37 mutator.Operators.SetItemCheckedState(mutator.Operators.Single(x => x.Name == "FullTreeShaker"), false);38 mutator.Operators.SetItemCheckedState(mutator.Operators.Single(x => x.Name == "OnePointShaker"), false);39 ga.Mutator = mutator;40 41 ga.SetSeedRandomly.Value = false;42 ga.Seed.Value = 0;43 ga.Engine = new ParallelEngine();44 #endregion45 #region problem configuration46 28 antProblem.BestKnownQuality.Value = 89; 47 29 antProblem.MaxExpressionDepth.Value = 10; … … 51 33 antProblem.MaxTimeSteps.Value = 600; 52 34 #endregion 35 #region algorithm configuration 36 ga.Name = "Genetic Programming - Artificial Ant"; 37 ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (Santa-Fe trail)"; 38 ga.Problem = antProblem; 39 ga.PopulationSize.Value = 1000; 40 ga.MaximumGenerations.Value = 100; 41 ga.MutationProbability.Value = 0.15; 42 ga.Elites.Value = 1; 43 var tSelector = ga.SelectorParameter.ValidValues 44 .OfType<TournamentSelector>() 45 .Single(); 46 tSelector.GroupSizeParameter.Value = new IntValue(5); 47 ga.Selector = tSelector; 48 var mutator = ga.MutatorParameter.ValidValues 49 .OfType<MultiSymbolicExpressionTreeArchitectureManipulator>() 50 .Single(); 51 mutator.Operators.SetItemCheckedState(mutator.Operators 52 .OfType<FullTreeShaker>() 53 .Single(), false); 54 mutator.Operators.SetItemCheckedState(mutator.Operators 55 .OfType<OnePointShaker>() 56 .Single(), false); 57 ga.Mutator = mutator; 58 59 ga.SetSeedRandomly.Value = false; 60 ga.Seed.Value = 0; 61 ga.Engine = new ParallelEngine(); 62 #endregion 53 63 54 64 XmlGenerator.Serialize(ga, "../../SGP_SantaFe.hl"); … … 56 66 RunAlgorithm(ga); 57 67 } 68 69 [TestMethod] 70 public void CreateSymbolicRegressionSample() { 71 GeneticAlgorithm ga = new GeneticAlgorithm(); 72 #region problem configuration 73 SymbolicRegressionSingleObjectiveProblem symbRegProblem = new SymbolicRegressionSingleObjectiveProblem(); 74 // import and configure problem data 75 string filename = Path.GetTempFileName(); 76 using (var writer = File.CreateText(filename)) { 77 writer.Write(HeuristicLab_33.Tests.Properties.Resources.TowerData); 78 } 79 var towerProblemData = RegressionProblemData.ImportFromFile(filename); 80 towerProblemData.TargetVariableParameter.Value = towerProblemData.TargetVariableParameter.ValidValues 81 .First(v => v.Value == "towerResponse"); 82 towerProblemData.InputVariables.SetItemCheckedState( 83 towerProblemData.InputVariables.Single(x => x.Value == "x1"), true); 84 towerProblemData.InputVariables.SetItemCheckedState( 85 towerProblemData.InputVariables.Single(x => x.Value == "x7"), false); 86 towerProblemData.InputVariables.SetItemCheckedState( 87 towerProblemData.InputVariables.Single(x => x.Value == "x11"), false); 88 towerProblemData.InputVariables.SetItemCheckedState( 89 towerProblemData.InputVariables.Single(x => x.Value == "x16"), false); 90 towerProblemData.InputVariables.SetItemCheckedState( 91 towerProblemData.InputVariables.Single(x => x.Value == "x21"), false); 92 towerProblemData.InputVariables.SetItemCheckedState( 93 towerProblemData.InputVariables.Single(x => x.Value == "x25"), false); 94 towerProblemData.InputVariables.SetItemCheckedState( 95 towerProblemData.InputVariables.Single(x => x.Value == "towerResponse"), false); 96 towerProblemData.TrainingPartition.Start = 0; 97 towerProblemData.TrainingPartition.End = 4000; 98 towerProblemData.TestPartition.Start = 4000; 99 towerProblemData.TestPartition.End = 4999; 100 towerProblemData.Name = "Data imported from towerData.txt"; 101 towerProblemData.Description = "Chemical concentration at top of distillation tower, dataset downloaded from: http://vanillamodeling.com/realproblems.html, best R² achieved with nu-SVR = 0.97"; 102 symbRegProblem.ProblemData = towerProblemData; 103 104 // configure grammar 105 var grammar = new TypeCoherentExpressionGrammar(); 106 grammar.Symbols.OfType<Sine>().Single().InitialFrequency = 0.0; 107 grammar.Symbols.OfType<Cosine>().Single().InitialFrequency = 0.0; 108 grammar.Symbols.OfType<Tangent>().Single().InitialFrequency = 0.0; 109 grammar.Symbols.OfType<IfThenElse>().Single().InitialFrequency = 0.0; 110 grammar.Symbols.OfType<GreaterThan>().Single().InitialFrequency = 0.0; 111 grammar.Symbols.OfType<LessThan>().Single().InitialFrequency = 0.0; 112 grammar.Symbols.OfType<And>().Single().InitialFrequency = 0.0; 113 grammar.Symbols.OfType<Or>().Single().InitialFrequency = 0.0; 114 grammar.Symbols.OfType<Not>().Single().InitialFrequency = 0.0; 115 grammar.Symbols.OfType<TimeLag>().Single().InitialFrequency = 0.0; 116 grammar.Symbols.OfType<Integral>().Single().InitialFrequency = 0.0; 117 grammar.Symbols.OfType<Derivative>().Single().InitialFrequency = 0.0; 118 grammar.Symbols.OfType<LaggedVariable>().Single().InitialFrequency = 0.0; 119 grammar.Symbols.OfType<VariableCondition>().Single().InitialFrequency = 0.0; 120 var varSymbol = grammar.Symbols.OfType<Variable>().Where(x => !(x is LaggedVariable)).Single(); 121 varSymbol.WeightMu = 1.0; 122 varSymbol.WeightSigma = 1.0; 123 varSymbol.WeightManipulatorMu = 0.0; 124 varSymbol.WeightManipulatorSigma = 0.05; 125 varSymbol.MultiplicativeWeightManipulatorSigma = 0.03; 126 var constSymbol = grammar.Symbols.OfType<Constant>().Single(); 127 constSymbol.MaxValue = 20; 128 constSymbol.MinValue = -20; 129 constSymbol.ManipulatorMu = 0.0; 130 constSymbol.ManipulatorSigma = 1; 131 constSymbol.MultiplicativeManipulatorSigma = 0.03; 132 symbRegProblem.SymbolicExpressionTreeGrammar = grammar; 133 134 // configure remaining problem parameters 135 symbRegProblem.BestKnownQuality.Value = 0.97; 136 symbRegProblem.FitnessCalculationPartition.Start = 0; 137 symbRegProblem.FitnessCalculationPartition.End = 2800; 138 symbRegProblem.ValidationPartition.Start = 2800; 139 symbRegProblem.ValidationPartition.End = 4000; 140 symbRegProblem.RelativeNumberOfEvaluatedSamples.Value = 0.3; 141 symbRegProblem.EvaluatorParameter.Value = new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(); 142 #endregion 143 #region algorithm configuration 144 ga.Problem = symbRegProblem; 145 ga.Name = "Genetic Programming - Symbolic Regression"; 146 ga.Description = "A standard genetic programming algorithm to solve a symbolic regression problem (tower dataset)"; 147 ga.Elites.Value = 1; 148 ga.MaximumGenerations.Value = 100; 149 ga.MutationProbability.Value = 0.15; 150 ga.PopulationSize.Value = 1000; 151 ga.Seed.Value = 0; 152 ga.SetSeedRandomly.Value = false; 153 var tSelector = ga.SelectorParameter.ValidValues 154 .OfType<TournamentSelector>() 155 .Single(); 156 tSelector.GroupSizeParameter.Value.Value = 5; 157 ga.Selector = tSelector; 158 var mutator = ga.MutatorParameter.ValidValues 159 .OfType<MultiSymbolicExpressionTreeManipulator>() 160 .Single(); 161 mutator.Operators.OfType<FullTreeShaker>().Single().ShakingFactor = 0.1; 162 mutator.Operators.OfType<OnePointShaker>().Single().ShakingFactor = 1.0; 163 ga.Mutator = mutator; 164 165 ga.Analyzer.Operators.SetItemCheckedState( 166 ga.Analyzer.Operators 167 .OfType<SymbolicRegressionSingleObjectiveOverfittingAnalyzer>() 168 .Single(), false); 169 ga.Engine = new ParallelEngine(); 170 #endregion 171 172 XmlGenerator.Serialize(ga, "../../SGP_SymbReg.hl"); 173 174 RunAlgorithm(ga); 175 } 176 58 177 59 178 private void RunAlgorithm(IAlgorithm a) { -
trunk/sources/HeuristicLab/3.3/Tests/HeuristicLab-3.3.Tests.csproj
r6436 r6439 127 127 <Compile Include="ContentViewTests.cs" /> 128 128 <Compile Include="GeneticProgrammingSamplesTest.cs" /> 129 <Compile Include="Properties\Resources.Designer.cs"> 130 <AutoGen>True</AutoGen> 131 <DesignTime>True</DesignTime> 132 <DependentUpon>Resources.resx</DependentUpon> 133 </Compile> 129 134 <Compile Include="SymbolicRegressionTest.cs" /> 130 135 <Compile Include="PluginDependenciesTest.cs" /> … … 442 447 <Project>{3E9E8944-44FF-40BB-A622-3A4A7DD0F198}</Project> 443 448 <Name>HeuristicLab.Problems.DataAnalysis.Views-3.4</Name> 444 </ProjectReference>445 <ProjectReference Include="..\..\..\HeuristicLab.Problems.DataAnalysis\3.3\HeuristicLab.Problems.DataAnalysis-3.3.csproj">446 <Project>{70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC}</Project>447 <Name>HeuristicLab.Problems.DataAnalysis-3.3</Name>448 449 </ProjectReference> 449 450 <ProjectReference Include="..\..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> … … 554 555 </None> 555 556 </ItemGroup> 557 <ItemGroup> 558 <Content Include="towerData.txt"> 559 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 560 </Content> 561 </ItemGroup> 562 <ItemGroup> 563 <EmbeddedResource Include="Properties\Resources.resx"> 564 <Generator>ResXFileCodeGenerator</Generator> 565 <LastGenOutput>Resources.Designer.cs</LastGenOutput> 566 </EmbeddedResource> 567 </ItemGroup> 556 568 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 557 569 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.