Changeset 6489
- Timestamp:
- 06/27/11 23:56:35 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r6473 r6489 24 24 using HeuristicLab.Problems.MetaOptimization; 25 25 using HeuristicLab.Problems.TestFunctions; 26 using HeuristicLab.Problems.TravelingSalesman;27 26 using HeuristicLab.Random; 28 27 using HeuristicLab.Selection; … … 49 48 //private static double mutationProbability = 0.10; 50 49 51 private static int metaAlgorithmPopulationSize = 3 0;50 private static int metaAlgorithmPopulationSize = 3; 52 51 private static int metaAlgorithmMaxGenerations = 10; 53 52 private static double metaAlgorithmMutationProbability = 0.10; 54 private static int metaProblemRepetitions = 3;55 private static int baseAlgorithmMaxGenerations = 20;56 private static int baseAlgorithmPopulationSize = 100;53 private static int metaProblemRepetitions = 2; 54 private static int baseAlgorithmMaxGenerations = 1; 55 private static int baseAlgorithmPopulationSize = 5; 57 56 58 57 public override void Run() { … … 87 86 88 87 //TestSymbolicDataAnalysisGrammar(); return; 89 TestObjectGraphObjectsTraversal(); return;88 //TestObjectGraphObjectsTraversal(); return; 90 89 //TestParameterizedItem(); return; 91 90 … … 93 92 //var algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; 94 93 95 var metaOptimizationProblem = new MetaOptimizationProblem(); 96 var algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem); 94 //var metaOptimizationProblem = new MetaOptimizationProblem(); 95 //var algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem); 96 97 // import classification 4 problems 98 var metaOptimizationProblem = ((MetaOptimizationProblem)ContentManager.Load("MetaOpt GA,OSGA,Classification (melanoma,respiratory,wisconsin,prostata),MSE-Evaluator_test.hl")); 99 metaOptimizationProblem.QualityMeasureNameParameter.Value.Value = "Best training solution.Mean squared error (test)"; 97 100 98 101 metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions); 99 //GeneticAlgorithm metaLevelAlgorithm = GetSequentialMetaGA(metaOptimizationProblem);100 GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);102 GeneticAlgorithm metaLevelAlgorithm = GetSequentialMetaGA(metaOptimizationProblem); 103 //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem); 101 104 //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem); 102 105 //EvolutionStrategy metaLevelAlgorithm = GetMetaES(metaOptimizationProblem); … … 105 108 //TestConfiguration(algorithmVc, typeof(GeneticAlgorithm), metaOptimizationProblem.Problems.First()); 106 109 107 Console.WriteLine("Press enter to start"); Console.ReadLine();110 //Console.WriteLine("Press enter to start"); Console.ReadLine(); 108 111 TestOptimization(metaLevelAlgorithm); 109 112 … … 809 812 810 813 // tsp 811 metaOptimizationProblem.ProblemType.Value = typeof(TravelingSalesmanProblem);814 //metaOptimizationProblem.ProblemType.Value = typeof(TravelingSalesmanProblem); 812 815 813 816 ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; … … 815 818 ((IntValue)algorithmVc.AlgorithmConfiguration.ParameterConfigurations.Single(x => x.Name == "PopulationSize").ActualValue.Value).Value = baseAlgorithmPopulationSize; 816 819 817 ConfigurePopulationSize(algorithmVc, 10, 100, 1);818 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);819 ConfigureMutationOperator(algorithmVc);820 ConfigureElites(algorithmVc, 0, 10, 1);821 ConfigureSelectionOperator(algorithmVc, true);820 //ConfigurePopulationSize(algorithmVc, 10, 100, 1); 821 //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01); 822 //ConfigureMutationOperator(algorithmVc); 823 //ConfigureElites(algorithmVc, 0, 5, 1); 824 //ConfigureSelectionOperator(algorithmVc, true); 822 825 823 826 //ConfigureSymbolicExpressionGrammar(algorithmVc); … … 1052 1055 1053 1056 StringBuilder sb1 = new StringBuilder(); 1054 sb1.AppendFormat("Meta .PopulationSize: {0}\n", metaAlgorithmPopulationSize);1055 sb1.AppendFormat("Meta .MaxGenerations: {0}\n", metaAlgorithmMaxGenerations);1056 sb1.AppendFormat("Meta .Repetitions : {0}\n", metaProblemRepetitions);1057 sb1.AppendFormat("Meta .MutProb : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).MutationProbability.Value);1058 sb1.AppendFormat("Meta .Seed : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).Seed.Value);1059 sb1.AppendFormat("Base .MaxGenerations: {0}\n", baseAlgorithmMaxGenerations);1057 sb1.AppendFormat("Meta-PopulationSize: {0}\n", metaAlgorithmPopulationSize); 1058 sb1.AppendFormat("Meta-MaxGenerations: {0}\n", metaAlgorithmMaxGenerations); 1059 sb1.AppendFormat("Meta-Repetitions : {0}\n", metaProblemRepetitions); 1060 sb1.AppendFormat("Meta-MutProb : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).MutationProbability.Value); 1061 sb1.AppendFormat("Meta-Seed : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).Seed.Value); 1062 sb1.AppendFormat("Base-MaxGenerations: {0}\n", baseAlgorithmMaxGenerations); 1060 1063 1061 1064 sb1.AppendLine("Problems:"); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj
r5655 r6489 153 153 <DependentUpon>ItemDictionaryView.cs</DependentUpon> 154 154 </Compile> 155 <Compile Include="MessageItem.cs" /> 155 156 <Compile Include="MetaOptimizationProblemView.cs"> 156 157 <SubType>UserControl</SubType> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs
r5927 r6489 79 79 } else { 80 80 this.viewHost.ViewsLabelVisible = false; 81 this.viewHost.Content = Content.ActualValue; 81 if (Content.ValuesReadOnly) { 82 this.viewHost.Content = new MessageItem("Cannot modify value directly. Please modify the value in the list of problems."); 83 } else { 84 this.viewHost.Content = Content.ActualValue; 85 } 82 86 } 83 87 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOBestSolutionHistoryAnalyzer.cs
r6197 r6489 75 75 bestSolutionHistory = results[key].Value as RunCollection; 76 76 } 77 if (bestSolutionHistory.Count == 0 || best.ParameterInfoString != ((StringValue)bestSolutionHistory.Last().Results["Meta .ParameterInfoString"]).Value) {77 if (bestSolutionHistory.Count == 0 || best.ParameterInfoString != ((StringValue)bestSolutionHistory.Last().Results["Meta-ParameterInfoString"]).Value) { 78 78 IRun run = best.ToRun(string.Format("{0}: {1}", currentGeneration, best.ParameterInfoString), false); 79 run.Results.Add("Meta .Generation", new IntValue(currentGeneration));80 run.Results.Add("Meta .ParameterInfoString", new StringValue(best.ParameterInfoString));79 run.Results.Add("Meta-Generation", new IntValue(currentGeneration)); 80 run.Results.Add("Meta-ParameterInfoString", new StringValue(best.ParameterInfoString)); 81 81 bestSolutionHistory.Add(run); 82 82 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs
r6090 r6489 74 74 var runCollection = allRuns.Single(x => x.Key.Value == key).Value; 75 75 foreach (var run in solution.Runs) { 76 if (!((BoolValue)run.Results["Meta .FromCache"]).Value || first) {77 run.Results["Meta .FromCache"] = new BoolValue(true);76 if (!((BoolValue)run.Results["Meta-FromCache"]).Value || first) { 77 run.Results["Meta-FromCache"] = new BoolValue(true); 78 78 runCollection.Add(run); 79 79 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs
r5653 r6489 22 22 get { 23 23 if (!initialized) 24 throw new SystemException("Enumeration not started. Call MoveNext!");24 throw new InvalidOperationException("Enumeration not started. Call MoveNext!"); 25 25 return Current; 26 26 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r6421 r6489 161 161 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Algorithm", algproblemitem.AlgorithmParameter)); 162 162 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Problem", algproblemitem.ProblemParameter)); 163 164 // problems can be modified in the list of problem instances, so the parameters which are not Optimize=true, 165 // must not be modifiable in the parameter configuration tree. otherwise the parameter values would be ambiguous 166 ProblemConfiguration.ValuesReadOnly = true; 163 167 } 164 168 public ParameterConfigurationTree() { } … … 190 194 [StorableHook(HookType.AfterDeserialization)] 191 195 private void AfterDeserialization() { 196 if(ProblemConfiguration != null) ProblemConfiguration.ValuesReadOnly = true; 192 197 } 193 198 #endregion -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r6486 r6489 146 146 } 147 147 148 [Storable] 149 protected bool valuesReadOnly = false; 150 public virtual bool ValuesReadOnly { 151 get { return valuesReadOnly; } 152 set { 153 if (value != this.valuesReadOnly) { 154 this.valuesReadOnly = value; 155 foreach (var vc in this.valueConfigurations) { 156 vc.ValuesReadOnly = value; 157 } 158 } 159 } 160 } 148 161 149 162 #region Constructors and Cloning … … 220 233 this.discoverValidValues = original.discoverValidValues; 221 234 this.AutoPopulateValueConfigurations = original.AutoPopulateValueConfigurations; 235 this.valuesReadOnly = original.valuesReadOnly; 222 236 } 223 237 … … 485 499 486 500 public void Parameterize(IValueParameter parameter) { 501 if (!Optimize && ValuesReadOnly) 502 return; 503 487 504 if (Optimize) { 488 505 if (this.ActualValue.Value is IParameterizedItem) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ParameterizedValueConfiguration.cs
r5927 r6489 46 46 get { return discoverValidValues; } 47 47 set { discoverValidValues = value; } 48 } 49 50 public override bool ValuesReadOnly { 51 set { 52 if (value != this.valuesReadOnly) { 53 this.valuesReadOnly = value; 54 foreach (var pc in this.parameterConfigurations) { 55 pc.ValuesReadOnly = value; 56 } 57 } 58 } 48 59 } 49 60 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5927 r6489 73 73 } 74 74 75 [Storable] 76 protected bool valuesReadOnly = false; 77 public virtual bool ValuesReadOnly { 78 get { return valuesReadOnly; } 79 set { 80 if (value != this.valuesReadOnly) { 81 this.valuesReadOnly = value; 82 } 83 } 84 } 85 75 86 #region Constructors and Cloning 76 87 public ValueConfiguration(IItem value, Type valueDataType) { … … 88 99 this.optimize = original.optimize; 89 100 this.number = original.number; 101 this.valuesReadOnly = original.valuesReadOnly; 90 102 RegisterActualValueEvents(); 91 103 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmRunsAnalyzer.cs
r6473 r6489 69 69 public IScope CurrentScope { 70 70 get { return CurrentScopeParameter.ActualValue; } 71 } 72 public LookupParameter<StringValue> QualityMeasureNameParameter { 73 get { return (LookupParameter<StringValue>)Parameters[MetaOptimizationProblem.QualityMeasureNameName]; } 71 74 } 72 75 #endregion … … 93 96 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName)); 94 97 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName)); 98 Parameters.Add(new LookupParameter<StringValue>(MetaOptimizationProblem.QualityMeasureNameName)); 95 99 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents.")); 96 100 } … … 104 108 private void AfterDeserialization() { 105 109 if (!Parameters.ContainsKey("CurrentScope")) Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents.")); // backwards compatibility 110 if (!Parameters.ContainsKey(MetaOptimizationProblem.QualityMeasureNameName)) Parameters.Add(new LookupParameter<StringValue>(MetaOptimizationProblem.QualityMeasureNameName)); // backwards compatibility 106 111 } 107 112 … … 118 123 double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value; 119 124 double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value; 120 var resultNames = new List<string> { "BestQuality", "Execution Time", "EvaluatedSolutions" }; 125 string qualityMeasureName = QualityMeasureNameParameter.ActualValue.Value; 126 var resultNames = new List<string> { qualityMeasureName, "Execution Time", "EvaluatedSolutions" }; 121 127 int currentGeneration = GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0; 122 128 double[] referenceQualityAverages; … … 146 152 MetaOptimizationUtil.ClearResults(run, resultNames); 147 153 MetaOptimizationUtil.ClearParameters(run, parameterNames); 148 run.Results.Add("Meta .FromCache", new BoolValue(false));149 run.Results.Add("Meta .Generation", new IntValue(currentGeneration));150 run.Results.Add("Meta .ProblemIndex", new IntValue(problemIndex));154 run.Results.Add("Meta-FromCache", new BoolValue(false)); 155 run.Results.Add("Meta-Generation", new IntValue(currentGeneration)); 156 run.Results.Add("Meta-ProblemIndex", new IntValue(problemIndex)); 151 157 run.Name = string.Format("{0} Problem {1} Run {2}", parameterConfiguration.ParameterInfoString, problemIndex, repetitionIndex); 152 qualities[problemIndex][repetitionIndex] = (((DoubleValue)run.Results["BestQuality"]).Value); 158 159 qualities[problemIndex][repetitionIndex] = GetResultValue<DoubleValue>(run.Results, qualityMeasureName).Value; 153 160 executionTimes[problemIndex][repetitionIndex] = (((TimeSpanValue)run.Results["Execution Time"]).Value); 154 161 evaluatedSolutions[problemIndex][repetitionIndex] = (((IntValue)run.Results["EvaluatedSolutions"]).Value); … … 203 210 204 211 return base.Apply(); 212 } 213 214 private T1 GetResultValue<T1>(IDictionary<string, IItem> results, string resultName) { 215 return (T1)results[resultName]; 216 217 //string separator = "."; 218 //string[] tokens = resultName.Split(separator.ToCharArray()); 219 220 //IDictionary<string, IItem> currentResults = results; 221 //IItem currentResult = null; 222 //for (int i = 0; i < tokens.Length; i++) { 223 // if(currentResults == null) 224 // throw new KeyNotFoundException("Result value " + resultName + " was not found"); 225 // if (currentResults.ContainsKey(tokens[i])) { 226 // currentResult = currentResults[tokens[i]]; 227 // currentResults = currentResult as IDictionary<string, IItem>; 228 // } else { 229 // throw new KeyNotFoundException("Result value " + resultName + " was not found"); 230 // } 231 //} 232 //return (T1)currentResult; 205 233 } 206 234 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5653 r6489 26 26 event EventHandler IsOptimizableChanged; 27 27 event EventHandler OptimizeChanged; 28 29 /// <summary> 30 /// indicates if the actualvalues are modifiable 31 /// </summary> 32 bool ValuesReadOnly { get; set; } 28 33 } 29 34 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r6090 r6489 40 40 public sealed class MetaOptimizationProblem : SingleObjectiveHeuristicOptimizationProblem<IParameterConfigurationEvaluator, IParameterConfigurationCreator>, IStorableContent { 41 41 public string Filename { get; set; } 42 42 43 43 public const string AlgorithmTypeParameterName = "AlgorithmType"; 44 44 public const string ProblemTypeParameterName = "ProblemType"; … … 46 46 public const string ParameterConfigurationTreeParameterName = "ParameterConfiguration"; 47 47 public const string RepetitionsParameterName = "Repetitions"; 48 public const string QualityMeasureNameName = "QualityMeasureName"; 48 49 49 50 public const string IntValueManipulatorParameterName = "IntValueManipulator"; … … 67 68 } 68 69 public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { 69 get { return ( ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; }70 get { return (OptionalValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; } 70 71 } 71 72 public IValueParameter<IntValue> RepetitionsParameter { … … 79 80 public IValueParameter<IDoubleValueManipulator> DoubleValueManipulatorParameter { 80 81 get { return (ValueParameter<IDoubleValueManipulator>)Parameters[DoubleValueManipulatorParameterName]; } 82 } 83 public IValueParameter<StringValue> QualityMeasureNameParameter { 84 get { return (ValueParameter<StringValue>)Parameters[QualityMeasureNameName]; } 81 85 } 82 86 #endregion … … 131 135 Parameters.Add(new ValueParameter<ConstrainedTypeValue<IProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<IProblem>())); 132 136 Parameters.Add(new ValueParameter<ConstrainedItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<IProblem>())); 133 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized."));137 Parameters.Add(new OptionalValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized.")); // needs to be optional, when last problem is removed from list, it must be set null 134 138 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); 139 Parameters.Add(new ValueParameter<StringValue>(QualityMeasureNameName, "The name of the quality result of the base-level algorithm. Subresults can be accessed by dot separator.", new StringValue("BestQuality"))); 135 140 136 141 var validIntManipulators = new ItemSet<IIntValueManipulator>(ApplicationManager.Manager.GetInstances<IIntValueManipulator>()); … … 174 179 [StorableHook(HookType.AfterDeserialization)] 175 180 private void AfterDeserializationHook() { 181 if(!Parameters.ContainsKey(QualityMeasureNameName)) Parameters.Add(new ValueParameter<StringValue>(QualityMeasureNameName, "The name of the quality result of the base-level algorithm. Subresults can be accessed by dot separator.", new StringValue("BestQuality"))); // backwards compatibility 176 182 RegisterParameterEvents(); 177 183 } … … 211 217 if (RunsAnalyzer != null) { 212 218 RunsAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 213 } 219 } 214 220 if (PMOPopulationDiversityAnalyzer != null) { 215 221 PMOPopulationDiversityAnalyzer.SolutionParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; … … 260 266 IAlgorithm instance = (IAlgorithm)Activator.CreateInstance(AlgorithmType.Value); 261 267 this.ProblemType.ValidTypes = ApplicationManager.Manager.GetTypes(instance.ProblemType, true).ToList(); 262 this.ProblemType.Value = this.ProblemType.ValidTypes.SingleOrDefault(t => t == typeof(SingleObjectiveTestFunctionProblem)) ?? this.ProblemType.ValidTypes.Where(t => t != typeof(MetaOptimizationProblem)).FirstOrDefault(); 263 // ProblemType_ValueChanged will add one problem and create ParameterConfigurationTree 268 var newProblemType = this.ProblemType.ValidTypes.SingleOrDefault(t => t == typeof(SingleObjectiveTestFunctionProblem)) ?? this.ProblemType.ValidTypes.Where(t => t != typeof(MetaOptimizationProblem)).FirstOrDefault(); 269 if (this.ProblemType.Value != newProblemType) 270 this.ProblemType.Value = newProblemType; // ProblemType_ValueChanged will add one problem and create ParameterConfigurationTree 271 else 272 ProblemType_ValueChanged(this, EventArgs.Empty); // call explicitly 264 273 } 265 274 … … 274 283 } 275 284 276 private void Problems_ItemsAdded(object sender, Collection s.CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) {285 private void Problems_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) { 277 286 // the first problem in the list is always the instance for the algorithm - this way some basic wiring between problem and algorithm can be sustained 278 287 if (e.Items.Single().Index == 0) { … … 287 296 } 288 297 289 private void Problems_ItemsRemoved(object sender, Collection s.CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) {298 private void Problems_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) { 290 299 if (e.Items.Single().Index == 0) { 291 300 ParameterConfigurationTreeParameter.ActualValue = null;
Note: See TracChangeset
for help on using the changeset viewer.