Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5522


Ignore:
Timestamp:
02/21/11 00:46:33 (14 years ago)
Author:
cneumuel
Message:

#1215

  • implemented population diversity analysis
Location:
branches/HeuristicLab.MetaOptimization
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/HeuristicLab.MetaOptimization.Test.csproj

    r5267 r5522  
    4444  </PropertyGroup>
    4545  <ItemGroup>
    46     <Reference Include="ALGLIB-2.5.0">
    47       <HintPath>C:\Program Files\HeuristicLab 3.3\ALGLIB-2.5.0.dll</HintPath>
    48     </Reference>
    4946    <Reference Include="ALGLIB-3.1.0">
    5047      <HintPath>C:\Program Files\HeuristicLab 3.3\ALGLIB-3.1.0.dll</HintPath>
     
    5249    <Reference Include="Google.ProtocolBuffers-0.9.1">
    5350      <HintPath>C:\Program Files\HeuristicLab 3.3\Google.ProtocolBuffers-0.9.1.dll</HintPath>
    54     </Reference>
    55     <Reference Include="HeuristicLab.ALGLIB-2.5.0">
    56       <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.ALGLIB-2.5.0.dll</HintPath>
    5751    </Reference>
    5852    <Reference Include="HeuristicLab.ALGLIB-3.1.0">
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5361 r5522  
    2323using HeuristicLab.Hive.ExperimentManager;
    2424using System.Threading.Tasks;
     25using HeuristicLab.PluginInfrastructure.Manager;
     26using System.Reflection;
    2527
    2628namespace HeuristicLab.MetaOptimization.Test {
    2729  class Program {
     30    static void Main(string[] args) {
     31      //PluginLoader.pluginAssemblies.Any();
     32      PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
     33      pm.DiscoverAndCheckPlugins();
     34
     35      pm.Run(pm.Applications.Where(x => x.Name == "TestApp").SingleOrDefault());
     36    }
     37  }
     38
     39  [Plugin("TestPlugin", "1.0.0.0")]
     40  [PluginFile("HeuristicLab.MetaOptimization.Test.exe", PluginFileType.Assembly)]
     41  public class TestPlugin : PluginBase { }
     42
     43  [Application("TestApp")]
     44  public class TestApp : ApplicationBase {
    2845    //private static int metaAlgorithmPopulationSize = 50;
    2946    //private static int metaAlgorithmMaxGenerations = 30;
     
    3148    //private static int baseAlgorithmMaxGenerations = 1000;
    3249
    33     private static int metaAlgorithmPopulationSize = 10;
    34     private static int metaAlgorithmMaxGenerations = 10;
     50    private static int metaAlgorithmPopulationSize = 20;
     51    private static int metaAlgorithmMaxGenerations = 20;
    3552    private static int metaProblemRepetitions = 2;
    36     private static int baseAlgorithmMaxGenerations = 20;
     53    private static int baseAlgorithmMaxGenerations = 10;
    3754    private static double mutationProbability = 0.10;
    3855
    39     static void Main(string[] args) {
     56    public override void Run() {
    4057      ContentManager.Initialize(new PersistenceContentManager());
    41      
     58
    4259      //TestTableBuilder();
    4360      //TestShorten();
    4461
     62      //TestSimilarities(); return;
    4563      //TestIntSampling();
    4664      //TestDoubleSampling(); return;
     
    5169      //TestCombinations3();
    5270      //TestEnumeratorCollectionEnumerator();
    53       TestCombinations4(); return;
     71      //TestCombinations4(); return;
    5472      //TestAlgorithmPerformanceIssue();
    5573      //TestWaitAny();
     
    5977      //TestItemDictionary();
    6078
    61      
     79
    6280
    6381      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
     
    87105    }
    88106
     107    private static void TestSimilarities() {
     108      Console.WriteLine("\nDoubleRange:");
     109      var doubleRange = new DoubleValueRange(new DoubleValue(0), new DoubleValue(10), new DoubleValue(1));
     110      var a = new DoubleValue(5.0);
     111
     112      for (double d = 0; d < 10; d += 0.1) {
     113        var similarity = doubleRange.CalculateSimilarity(a, new DoubleValue(d));
     114        Console.WriteLine("{0}: {1}", d, similarity);
     115      }
     116
     117      Console.WriteLine("\nPecentRange:");
     118      var percentRange = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(1));
     119      var b = new PercentValue(0.05);
     120
     121      for (double d = 0; d < 1; d += 0.01) {
     122        var similarity = percentRange.CalculateSimilarity(b, new PercentValue(d));
     123        Console.WriteLine("{0}: {1}", d, similarity);
     124      }
     125
     126      Console.WriteLine("\nIntRange:");
     127      var intRange = new IntValueRange(new IntValue(50), new IntValue(100), new IntValue(1));
     128      var c = new IntValue(90);
     129
     130      for (int i = 0; i < 100; i++) {
     131        var similarity = intRange.CalculateSimilarity(c, new IntValue(i));
     132        Console.WriteLine("{0}: {1}", i, similarity);
     133      }
     134
     135      Console.WriteLine("\nValueConfigurations:");
     136      var vc1 = SetupGAAlgorithm(typeof(GeneticAlgorithm), new MetaOptimizationProblem());
     137      vc1.ParameterConfigurations.Single(x => x.Name == "Elites").Optimize = true;
     138      vc1.ParameterConfigurations.Single(x => x.Name == "PopulationSize").Optimize = true;
     139      vc1.ParameterConfigurations.Single(x => x.Name == "MutationProbability").Optimize = true;
     140      vc1.ParameterConfigurations.Single(x => x.Name == "Selector").Optimize = true;
     141
     142      var vc2 = (IValueConfiguration)vc1.Clone();
     143      Console.WriteLine("Assert(1): {0}", vc1.CalculateSimilarity(vc2));
     144
     145      ((IntValue)vc2.ParameterConfigurations.Single(x => x.Name == "PopulationSize").ValueConfigurations[0].ActualValue.Value).Value = 75;
     146      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     147
     148      ((PercentValue)vc2.ParameterConfigurations.Single(x => x.Name == "MutationProbability").ValueConfigurations[0].ActualValue.Value).Value = 0.15;
     149      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     150
     151      ((PercentValue)vc2.ParameterConfigurations.Single(x => x.Name == "MutationProbability").ValueConfigurations[0].ActualValue.Value).Value = 0.25;
     152      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     153      ((PercentValue)vc2.ParameterConfigurations.Single(x => x.Name == "MutationProbability").ValueConfigurations[0].ActualValue.Value).Value = 0.35;
     154      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     155      ((PercentValue)vc2.ParameterConfigurations.Single(x => x.Name == "MutationProbability").ValueConfigurations[0].ActualValue.Value).Value = 0.45;
     156      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     157      ((PercentValue)vc2.ParameterConfigurations.Single(x => x.Name == "MutationProbability").ValueConfigurations[0].ActualValue.Value).Value = 0.55;
     158      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     159
     160      vc2.ParameterConfigurations.Single(x => x.Name == "Selector").ActualValueConfigurationIndex = 3;
     161      Console.WriteLine("{0}", vc1.CalculateSimilarity(vc2));
     162
     163      var random = new Random.MersenneTwister(0);
     164      for (int i = 0; i < 10; i++) {
     165        vc2.Randomize(random);
     166        Console.WriteLine("Randomized: {0}", vc1.CalculateSimilarity(vc2));
     167      }
     168    }
     169
    89170    private static void TestItemDictionary() {
    90171      var dict = new ItemDictionary<StringValue, RunCollection>();
     
    116197      using (var sw = new StreamWriter("normalCrossover-IntValue.txt")) {
    117198        for (int i = 0; i < 10000; i++) {
    118          sw.WriteLine(NormalIntValueCrossover.ApplyStatic(random, new IntValue(i1), new IntValue(i2), intRange));
     199          sw.WriteLine(NormalIntValueCrossover.ApplyStatic(random, new IntValue(i1), new IntValue(i2), intRange));
    119200        }
    120201      }
     
    557638        ProblemSize = new IntValue(2)
    558639      });
    559       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    560         Evaluator = new GriewankEvaluator(),
    561         ProblemSize = new IntValue(20)
    562       });
    563       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    564         Evaluator = new GriewankEvaluator(),
    565         ProblemSize = new IntValue(500)
    566       });
     640      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     641      //  Evaluator = new GriewankEvaluator(),
     642      //  ProblemSize = new IntValue(20)
     643      //});
     644      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     645      //  Evaluator = new GriewankEvaluator(),
     646      //  ProblemSize = new IntValue(500)
     647      //});
    567648
    568649      ConfigurePopulationSize(algorithmVc, 0, 20, 1);
    569       //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    570       //ConfigureMutationOperator(algorithmVc);
     650      ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
     651      ConfigureMutationOperator(algorithmVc);
    571652      ConfigureElites(algorithmVc, 0, 30, 1);
    572       //ConfigureSelectionOperator(algorithmVc, true);
     653      ConfigureSelectionOperator(algorithmVc, true);
    573654      return algorithmVc;
    574655    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.sln

    r5207 r5522  
    1010Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F96C8DD1-9B68-4F2D-AD4F-1A174F596041}"
    1111  ProjectSection(SolutionItems) = preProject
    12     HeuristicLab.MetaOptimization.vsmdi = HeuristicLab.MetaOptimization.vsmdi
    13     Local.testsettings = Local.testsettings
    1412    Performance1.psess = Performance1.psess
    1513    PreBuildEvent.cmd = PreBuildEvent.cmd
    16     TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
    1714  EndProjectSection
    1815EndProject
    1916Global
    20   GlobalSection(TestCaseManagementSettings) = postSolution
    21     CategoryFile = HeuristicLab.MetaOptimization.vsmdi
    22   EndGlobalSection
    2317  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2418    Debug|Any CPU = Debug|Any CPU
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5361 r5522  
    493493      }
    494494    }
     495
     496    public double CalculateSimilarity(IOptimizable optimizable) {
     497      var other = (IParameterConfiguration)optimizable;
     498      if (this.ActualValueConfigurationIndex == other.ActualValueConfigurationIndex) {
     499        return this.ValueConfigurations[this.ActualValueConfigurationIndex].CalculateSimilarity(other.ValueConfigurations[other.ActualValueConfigurationIndex]);
     500      } else {
     501        return 0.0;
     502      }
     503    }
    495504  }
    496505}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/ConstrainedValue.cs

    r5231 r5522  
    8686    #endregion
    8787
    88     void value_ToStringChanged(object sender, EventArgs e) {
     88    private void value_ToStringChanged(object sender, EventArgs e) {
    8989      OnToStringChanged();
    9090    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs

    r5337 r5522  
    4848      return solutions;
    4949    }
     50
     51    protected override double CalculateSimilarityValue(DoubleValue a, DoubleValue b) {
     52      double range = UpperBound.Value - LowerBound.Value;
     53      double diff = Math.Abs(a.Value - b.Value);
     54      return Math.Max(0, (range - (diff*2)) / range);
     55    }
    5056  }
    5157}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs

    r5337 r5522  
    4747      return solutions;
    4848    }
     49
     50    protected override double CalculateSimilarityValue(IntValue a, IntValue b) {
     51      double range = UpperBound.Value - LowerBound.Value;
     52      double diff = Math.Abs(a.Value - b.Value);
     53      return Math.Max(0, (range - (diff * 2)) / range);
     54    }
    4955  }
    5056}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs

    r5337 r5522  
    5252      return solutions;
    5353    }
     54
     55    protected override double CalculateSimilarityValue(PercentValue a, PercentValue b) {
     56      double range = UpperBound.Value - LowerBound.Value;
     57      double diff = Math.Abs(a.Value - b.Value);
     58      return Math.Max(0, (range - (diff * 2)) / range);
     59    }
    5460  }
    5561}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs

    r5144 r5522  
    208208
    209209    protected abstract T GetRandomSample(IRandom random);
     210
    210211    IItem IRange.GetRandomValue(IRandom random) {
    211212      return GetRandomValue(random);
     
    216217      return GetCombinations().Cast<IItem>().ToArray();
    217218    }
     219
     220    public virtual double CalculateSimilarity(IItem a, IItem b) {
     221      return CalculateSimilarityValue((T)a, (T)b);
     222    }
     223
     224    protected abstract double CalculateSimilarityValue(T a, T b);
    218225  }
    219226}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5361 r5522  
    326326      return list;
    327327    }
     328
     329    public double CalculateSimilarity(IOptimizable optimizable) {
     330      var other = (IValueConfiguration)optimizable;
     331      if (rangeConstraint != null) {
     332        return this.RangeConstraint.CalculateSimilarity(this.ActualValue.Value, other.ActualValue.Value);
     333      } else {
     334        double sum = 0;
     335        int count = 0;
     336        for (int i = 0; i < ParameterConfigurations.Count; i++) {
     337          if (this.ParameterConfigurations.ElementAt(i).Optimize) {
     338            sum += this.ParameterConfigurations.ElementAt(i).CalculateSimilarity(other.ParameterConfigurations.ElementAt(i));
     339            count++;
     340          }
     341        }
     342        return count == 0 ? 1.0 : sum / (double)count;
     343      }
     344    }
    328345  }
    329346}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5359 r5522  
    7575      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>
    7676    </Reference>
     77    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     78      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Analysis-3.3.dll</HintPath>
     79    </Reference>
    7780    <Reference Include="HeuristicLab.Collections-3.3">
    7881      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath>
     
    119122    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    120123      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath>
     124    </Reference>
     125    <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     126      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Selection-3.3.dll</HintPath>
    121127    </Reference>
    122128    <Reference Include="HeuristicLab.SequentialEngine-3.3">
     
    133139  <ItemGroup>
    134140    <Compile Include="Analyzers\BestParameterConfigurationAnalyzer.cs" />
     141    <Compile Include="Analyzers\PMOPopulationDiversityAnalyzer.cs" />
    135142    <Compile Include="ConstrainedTypeValue.cs" />
    136143    <Compile Include="MetaOptimizationUtil.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r5340 r5522  
    2020    string ParameterInfoString { get; }
    2121    void CollectOptimizedParameterNames(List<string> parameterNames, string prefix);
     22    double CalculateSimilarity(IOptimizable optimizable);
    2223
    2324    /// <summary>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs

    r5144 r5522  
    1818
    1919    IEnumerable<IItem> GetCombinations();
     20
     21    double CalculateSimilarity(IItem a, IItem b);
    2022  }
    2123
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5359 r5522  
    107107      get { return Operators.OfType<SolutionCacheAnalyzer>().FirstOrDefault(); }
    108108    }
     109    private PMOPopulationDiversityAnalyzer PMOPopulationDiversityAnalyzer {
     110      get { return Operators.OfType<PMOPopulationDiversityAnalyzer>().FirstOrDefault(); }
     111    }   
    109112    #endregion
    110113
     
    170173      Operators.Add(new ReferenceQualityAnalyzer());
    171174      Operators.Add(new SolutionCacheAnalyzer());
     175      Operators.Add(new PMOPopulationDiversityAnalyzer());
    172176    }
    173177    private void ParameterizeSolutionCreator() {
     
    185189      if (RunsAnalyzer != null) {
    186190        RunsAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     191      }
     192      if (PMOPopulationDiversityAnalyzer != null) {
     193        PMOPopulationDiversityAnalyzer.SolutionParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     194        PMOPopulationDiversityAnalyzer.StoreHistoryParameter.Value.Value = true;
    187195      }
    188196    }
Note: See TracChangeset for help on using the changeset viewer.