Changeset 6439 for trunk/sources/HeuristicLab/3.3/Tests
- Timestamp:
- 06/17/11 15:22:27 (14 years ago)
- Location:
- trunk/sources/HeuristicLab/3.3/Tests
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.