Changeset 11851


Ignore:
Timestamp:
02/01/15 20:30:44 (8 years ago)
Author:
gkronber
Message:

#2283: solution reorganization

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/GrammaticalOptimization.sln

    r11850 r11851  
    33# Visual Studio 2012
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.GrammaticalOptimization", "HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.csproj", "{CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}"
    5 EndProject
    6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.GrammaticalOptimization.Test", "HeuristicLab.Problems.GrammaticalOptimization.Test\HeuristicLab.Problems.GrammaticalOptimization.Test.csproj", "{3FB49880-7127-40D4-A9D3-A6C30BDDE885}"
    75EndProject
    86Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.GrammaticalOptimization", "HeuristicLab.Algorithms.GrammaticalOptimization\HeuristicLab.Algorithms.GrammaticalOptimization.csproj", "{EEA07488-1A51-412A-A52C-53B754A628B3}"
     
    3432    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.ActiveCfg = Release|Any CPU
    3533    {CB9DCCF6-667E-4A13-B82D-DBD6B45A045E}.Release|Any CPU.Build.0 = Release|Any CPU
    36     {3FB49880-7127-40D4-A9D3-A6C30BDDE885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    37     {3FB49880-7127-40D4-A9D3-A6C30BDDE885}.Debug|Any CPU.Build.0 = Debug|Any CPU
    38     {3FB49880-7127-40D4-A9D3-A6C30BDDE885}.Release|Any CPU.ActiveCfg = Release|Any CPU
    39     {3FB49880-7127-40D4-A9D3-A6C30BDDE885}.Release|Any CPU.Build.0 = Release|Any CPU
    4034    {EEA07488-1A51-412A-A52C-53B754A628B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    4135    {EEA07488-1A51-412A-A52C-53B754A628B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/ActionInfos/ModelPolicyActionInfo.cs

    r11849 r11851  
    1212    public double Value {
    1313      get {
    14         return model.SampleExpectedReward(new Random());
     14        return model.Sample(new Random());
    1515      }
    1616    }
     
    2727
    2828    public double SampleExpectedReward(Random random) {
    29       return model.SampleExpectedReward(random);
     29      return model.Sample(random);
    3030    }
    3131
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/HeuristicLab.Algorithms.Bandits.csproj

    r11850 r11851  
    3131  </PropertyGroup>
    3232  <ItemGroup>
    33     <Reference Include="ALGLIB-3.7.0">
    34       <HintPath>..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    35     </Reference>
    3633    <Reference Include="System" />
    3734    <Reference Include="System.Core" />
     
    6966      <Name>HeuristicLab.Distributions</Name>
    7067    </ProjectReference>
    71     <ProjectReference Include="..\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.csproj">
    72       <Project>{cb9dccf6-667e-4a13-b82d-dbd6b45a045e}</Project>
    73       <Name>HeuristicLab.Problems.GrammaticalOptimization</Name>
    74     </ProjectReference>
    7568  </ItemGroup>
    7669  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GeneticProgramming/HeuristicLab.Algorithms.GeneticProgramming.csproj

    r11847 r11851  
    6767      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Selection-3.3.dll</HintPath>
    6868    </Reference>
    69     <Reference Include="HeuristicLab.SequentialEngine-3.3">
    70       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
    71     </Reference>
    7269    <Reference Include="System" />
    7370    <Reference Include="System.Core" />
    74     <Reference Include="System.Xml.Linq" />
    75     <Reference Include="System.Data.DataSetExtensions" />
    76     <Reference Include="Microsoft.CSharp" />
    77     <Reference Include="System.Data" />
    78     <Reference Include="System.Xml" />
    7971  </ItemGroup>
    8072  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GeneticProgramming/OffspringSelectionGP.cs

    r11847 r11851  
    88using HeuristicLab.Problems.GrammaticalOptimization;
    99using HeuristicLab.Selection;
    10 using HeuristicLab.SequentialEngine;
    1110using HeuristicLab.Algorithms.GeneticAlgorithm;
    1211
     
    3332    public override void Run(int maxEvaluations) {
    3433      var hlProblem = new GenericSymbExprProblem(problem);
    35       hlProblem.Evaluator.SolutionEvaluated += OnSolutionEvaluated; // raise solution evaluated event for each GP solution, don't scale quality to 0..1
     34      var onEvalLocker = new object();
     35      hlProblem.Evaluator.SolutionEvaluated += (sentence, quality) => {
     36        // raise solution evaluated event for each GP solution, don't scale quality to 0..1
     37        // need to synchronize in case we are using a parallel engine
     38        lock (onEvalLocker) {
     39          OnSolutionEvaluated(sentence, quality);
     40        }
     41      };
    3642      hlProblem.MaximumSymbolicExpressionTreeLength.Value = MaxSolutionSize;
    3743      hlProblem.MaximumSymbolicExpressionTreeDepth.Value = MaxSolutionDepth;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GeneticProgramming/StandardGP.cs

    r11847 r11851  
    88using HeuristicLab.Problems.GrammaticalOptimization;
    99using HeuristicLab.Selection;
    10 using HeuristicLab.SequentialEngine;
    1110using HeuristicLab.Algorithms.GeneticAlgorithm;
    1211
     
    3534    public override void Run(int maxEvaluations) {
    3635      var hlProblem = new GenericSymbExprProblem(problem);
    37       hlProblem.Evaluator.SolutionEvaluated += OnSolutionEvaluated; // raise solution evaluated event for each GP solution, don't scale quality to 0..1
     36      var onEvalLocker = new object();
     37      hlProblem.Evaluator.SolutionEvaluated += (sentence, quality) => {
     38        // raise solution evaluated event for each GP solution, don't scale quality to 0..1
     39        // need to synchronize in case we are using a parallel engine
     40        lock (onEvalLocker) {
     41          OnSolutionEvaluated(sentence, quality);
     42        }
     43      };
    3844      hlProblem.MaximumSymbolicExpressionTreeLength.Value = MaxSolutionSize;
    3945      hlProblem.MaximumSymbolicExpressionTreeDepth.Value = MaxSolutionDepth;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions

    • Property svn:ignore set to
      bin
      *.user
      obj
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/BernoulliModel.cs

    r11849 r11851  
    2222    }
    2323
    24     public double SampleExpectedReward(Random random) {
     24    public double Sample(Random random) {
    2525      // sample bernoulli mean from beta prior
    2626      return Rand.BetaRand(random, success + alpha, failure + beta);
     
    4141    }
    4242
    43     public void PrintStats() {
    44       Console.Write("{0:F2} ", success / (double)failure);
    45     }
    46 
    4743    public object Clone() {
    4844      return new BernoulliModel() { failure = this.failure, success = this.success };
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/GaussianMixtureModel.cs

    r11849 r11851  
    2323
    2424
    25     public double SampleExpectedReward(Random random) {
     25    public double Sample(Random random) {
    2626      var k = Enumerable.Range(0, numComponents).SampleProportional(random, componentProbs);
    2727      return alglib.invnormaldistribution(random.NextDouble()) * Math.Sqrt(componentVars[k]) + componentMeans[k];
     
    9696      this.componentVars = Enumerable.Range(0, numComponents).Select((_) => 0.01).ToArray();
    9797    }
    98 
    99     public void PrintStats() {
    100       throw new NotImplementedException();
    101     }
    10298  }
    10399}
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/GaussianModel.cs

    r11849 r11851  
    4545
    4646
    47     public double SampleExpectedReward(Random random) {
     47    public double Sample(Random random) {
    4848      if (knownVariance) {
    4949        return SampleExpectedRewardKnownVariance(random);
     
    113113    }
    114114
    115     public void PrintStats() {
    116       Console.Write("{0:F2} ", estimator.Avg);
    117     }
    118 
    119115    public object Clone() {
    120116      if (knownVariance)
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/HeuristicLab.Distributions.csproj

    r11849 r11851  
    3636    <Reference Include="System" />
    3737    <Reference Include="System.Core" />
    38     <Reference Include="System.Xml.Linq" />
    39     <Reference Include="System.Data.DataSetExtensions" />
    40     <Reference Include="Microsoft.CSharp" />
    41     <Reference Include="System.Data" />
    42     <Reference Include="System.Xml" />
    4338  </ItemGroup>
    4439  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/IModel.cs

    r11849 r11851  
    88  // represents a model for the reward distribution (of an action given a state)
    99  public interface IModel : ICloneable {
    10     double SampleExpectedReward(Random random);
     10    double Sample(Random random);
    1111    void Update(double reward);
    1212    void Reset();
    13     void PrintStats();
    1413  }
    1514}
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Distributions/LogitNormalModel.cs

    r11849 r11851  
    1313
    1414
    15     public double SampleExpectedReward(Random random) {
    16       return 1.0 / (1 + Math.Exp(-gaussian.SampleExpectedReward(random)));
     15    public double Sample(Random random) {
     16      return 1.0 / (1 + Math.Exp(-gaussian.Sample(random)));
    1717    }
    1818
     
    2323    public void Reset() {
    2424      gaussian.Reset();
    25     }
    26 
    27     public void PrintStats() {
    2825    }
    2926
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.Bandits

    • Property svn:ignore set to
      bin
      *.user
      obj
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.Bandits/HeuristicLab.Problems.Bandits.csproj

    r11849 r11851  
    3636    <Reference Include="System" />
    3737    <Reference Include="System.Core" />
    38     <Reference Include="System.Xml.Linq" />
    39     <Reference Include="System.Data.DataSetExtensions" />
    40     <Reference Include="Microsoft.CSharp" />
    41     <Reference Include="System.Data" />
    42     <Reference Include="System.Xml" />
    4338  </ItemGroup>
    4439  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg/HeuristicLab.Problems.GrammaticalOptimization.SymbReg.csproj

    r11832 r11851  
    3131  </PropertyGroup>
    3232  <ItemGroup>
    33     <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    34       <SpecificVersion>False</SpecificVersion>
    35       <HintPath>..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    36     </Reference>
    37     <Reference Include="AutoDiff-1.0">
    38       <HintPath>..\..\..\trunk\sources\bin\AutoDiff-1.0.dll</HintPath>
    39     </Reference>
    4033    <Reference Include="HeuristicLab.Common-3.3">
    4134      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     
    4740      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
    4841    </Reference>
    49     <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    50       <SpecificVersion>False</SpecificVersion>
    51       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    52     </Reference>
    5342    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4">
    5443      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
    55     </Reference>
    56     <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4">
    57       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath>
    5844    </Reference>
    5945    <Reference Include="HeuristicLab.Problems.Instances-3.3">
     
    6551    <Reference Include="System" />
    6652    <Reference Include="System.Core" />
    67     <Reference Include="System.Xml.Linq" />
    68     <Reference Include="System.Data.DataSetExtensions" />
    69     <Reference Include="Microsoft.CSharp" />
    70     <Reference Include="System.Data" />
    71     <Reference Include="System.Xml" />
    7253  </ItemGroup>
    7354  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg/SymbolicRegressionProblem.cs

    r11832 r11851  
    55using System.Security.AccessControl;
    66using System.Text;
    7 using AutoDiff;
    87using HeuristicLab.Common;
    98using HeuristicLab.Problems.DataAnalysis;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs

    r11799 r11851  
    11using System;
    22using System.Collections.Generic;
    3 using System.Data;
    43using System.Diagnostics;
    54using System.IO;
     
    76using System.Text;
    87using System.Text.RegularExpressions;
    9 using System.Xml.Linq;
    108using HeuristicLab.Common;
    119
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.csproj

    r11848 r11851  
    7272    <Reference Include="System.Core" />
    7373    <Reference Include="System.Drawing" />
    74     <Reference Include="System.Xml.Linq" />
    75     <Reference Include="System.Data.DataSetExtensions" />
    76     <Reference Include="System.Data" />
    77     <Reference Include="System.Xml" />
    7874  </ItemGroup>
    7975  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/FindPhrasesProblem.cs

    r11832 r11851  
    11using System;
    22using System.Collections.Generic;
    3 using System.Data.Odbc;
    43using System.Diagnostics;
    54using System.Linq;
    6 using System.Text;
    7 using System.Text.RegularExpressions;
    85using HeuristicLab.Common;
    96
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Test/Test.csproj

    r11850 r11851  
    4747      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
    4848    </Reference>
    49     <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     49    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    5050      <SpecificVersion>False</SpecificVersion>
    51       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
    52     </Reference>
    53     <Reference Include="HeuristicLab.Problems.Instances-3.3">
    54       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
    55     </Reference>
    56     <Reference Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3">
    57       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath>
     51      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    5852    </Reference>
    5953    <Reference Include="System" />
     
    8680      <Project>{24408f7d-ee0f-4886-a08b-ec324d662e47}</Project>
    8781      <Name>HeuristicLab.Algorithms.Bandits</Name>
     82    </ProjectReference>
     83    <ProjectReference Include="..\HeuristicLab.Algorithms.GeneticProgramming\HeuristicLab.Algorithms.GeneticProgramming.csproj">
     84      <Project>{14BEC23F-63FD-4954-B8AE-E2F4962E9B57}</Project>
     85      <Name>HeuristicLab.Algorithms.GeneticProgramming</Name>
    8886    </ProjectReference>
    8987    <ProjectReference Include="..\HeuristicLab.Algorithms.GrammaticalOptimization\HeuristicLab.Algorithms.GrammaticalOptimization.csproj">
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Test/TestSolvers.cs

    r11730 r11851  
    11using System;
     2using HeuristicLab.Algorithms.GeneticProgramming;
    23using HeuristicLab.Algorithms.GrammaticalOptimization;
    34using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    128129    }
    129130
     131    [TestMethod]
     132    public void TestStandardGP() {
     133      var prob = new SymbolicRegressionPoly10Problem();
     134      var rand = new Random(31415);
     135      var sgp = new StandardGP(prob, rand);
     136      sgp.PopulationSize = 10000;
     137      sgp.MaxSolutionSize = 50;
     138      sgp.MaxSolutionDepth = 20;
     139
     140      string bestSentence = string.Empty;
     141      double bestQuality = double.NegativeInfinity;
     142
     143      sgp.FoundNewBestSolution += (sentence, quality) => {
     144        Assert.Inconclusive(string.Format("{0:N3} {1}", quality, sentence));
     145        bestSentence = sentence;
     146        bestQuality = quality;
     147      };
     148
     149      sgp.Run(100000);
     150
     151      Assert.AreEqual(1.0, bestQuality, 1E-6);
     152      Assert.AreEqual("", bestSentence);
     153    }
     154
     155    [TestMethod]
     156    public void TestOSGP() {
     157      var prob = new SymbolicRegressionPoly10Problem();
     158      var rand = new Random(31415);
     159      var osgp = new OffspringSelectionGP(prob, rand);
     160      osgp.PopulationSize = 1000;
     161      osgp.MaxSolutionSize = 50;
     162      osgp.MaxSolutionDepth = 20;
     163
     164      string bestSentence = string.Empty;
     165      double bestQuality = double.NegativeInfinity;
     166
     167      osgp.FoundNewBestSolution += (sentence, quality) => {
     168        Assert.Inconclusive(string.Format("{0:N3} {1}", quality, sentence));
     169        bestSentence = sentence;
     170        bestQuality = quality;
     171      };
     172
     173      osgp.Run(100000);
     174
     175      Assert.AreEqual(1.0, bestQuality, 1E-6);
     176      Assert.AreEqual("", bestSentence);
     177    }
    130178  }
    131179}
Note: See TracChangeset for help on using the changeset viewer.