Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1857


Ignore:
Timestamp:
05/20/09 10:50:18 (15 years ago)
Author:
gkronber
Message:

Worked on lose coupling of CEDMA and GP/SVR with plugin HeuristicLab.Modeling as common bridge. #635

Location:
trunk/sources
Files:
4 added
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs

    r1529 r1857  
    3535using HeuristicLab.Data;
    3636using HeuristicLab.Core;
     37using HeuristicLab.Modeling;
    3738
    3839namespace HeuristicLab.CEDMA.Server {
    3940  public abstract class DispatcherBase : IDispatcher {
    40     public enum ModelComplexity { Low, Medium, High };
    41     public enum Algorithm { StandardGpRegression, OffspringGpRegression, StandardGpClassification, OffspringGpClassification, StandardGpForecasting, OffspringGpForecasting };
    42 
    4341    private IStore store;
    44     private ModelComplexity[] possibleComplexities = new ModelComplexity[] { ModelComplexity.Low, ModelComplexity.Medium, ModelComplexity.High };
    45     private Dictionary<LearningTask, Algorithm[]> possibleAlgorithms = new Dictionary<LearningTask, Algorithm[]>() {
    46       {LearningTask.Classification, new Algorithm[] { Algorithm.StandardGpClassification, Algorithm.OffspringGpClassification }},
    47       {LearningTask.Regression, new Algorithm[] { Algorithm.StandardGpRegression, Algorithm.OffspringGpRegression }},
    48       {LearningTask.TimeSeries, new Algorithm[] { Algorithm.StandardGpForecasting, Algorithm.OffspringGpForecasting }}
    49     };
    5042
    5143    private static int MaxGenerations {
     
    7971
    8072      int targetVariable = SelectTargetVariable(dataSet, dataSet.Problem.AllowedTargetVariables.ToArray());
    81       Algorithm selectedAlgorithm = SelectAlgorithm(dataSet, targetVariable, possibleAlgorithms[dataSet.Problem.LearningTask]);
     73      IAlgorithm selectedAlgorithm = SelectAlgorithm(dataSet, targetVariable, dataSet.Problem.LearningTask);
    8274      string targetVariableName = dataSet.Problem.GetVariableName(targetVariable);
    83       ModelComplexity selectedComplexity = SelectComplexity(dataSet, targetVariable, selectedAlgorithm, possibleComplexities);
    8475
    85       Execution exec = CreateExecution(dataSet.Problem, targetVariable, selectedAlgorithm, selectedComplexity);
    86       if (exec != null) {
     76
     77      if (selectedAlgorithm != null) {
     78        Execution exec = CreateExecution(dataSet.Problem, targetVariable, selectedAlgorithm);
    8779        exec.DataSetEntity = dataSetEntity;
    8880        exec.TargetVariable = targetVariableName;
    89       }
    90       return exec;
     81        return exec;
     82      } else return null;
    9183    }
    9284
    9385    public abstract Entity SelectDataSet(Entity[] datasets);
    9486    public abstract int SelectTargetVariable(DataSet dataSet, int[] targetVariables);
    95     public abstract Algorithm SelectAlgorithm(DataSet dataSet, int targetVariable, Algorithm[] possibleAlgorithms);
    96     public abstract ModelComplexity SelectComplexity(DataSet dataSet, int targetVariable, Algorithm algorithm, ModelComplexity[] possibleComplexities);
     87    public abstract IAlgorithm SelectAlgorithm(DataSet dataSet, int targetVariable, LearningTask learningTask);
    9788
    98     private Execution CreateExecution(Problem problem, int targetVariable, Algorithm algorithm, ModelComplexity complexity) {
    99       switch (algorithm) {
    100         case Algorithm.StandardGpRegression: {
    101             var algo = new HeuristicLab.GP.StructureIdentification.StandardGP();
    102             SetComplexityParameters(algo, complexity);
    103             SetProblemParameters(algo, problem, targetVariable);
    104             algo.PopulationSize = 10000;
    105             algo.MaxGenerations = MaxGenerations;
    106             Execution exec = new Execution(algo.Engine);
    107             exec.Description = "StandardGP - Complexity: " + complexity;
    108             return exec;
    109           }
    110         case Algorithm.OffspringGpRegression: {
    111             var algo = new HeuristicLab.GP.StructureIdentification.OffspringSelectionGP();
    112             SetComplexityParameters(algo, complexity);
    113             SetProblemParameters(algo, problem, targetVariable);
    114             algo.MaxEvaluatedSolutions = MaxEvaluatedSolutions;
    115             Execution exec = new Execution(algo.Engine);
    116             exec.Description = "OffspringGP - Complexity: " + complexity;
    117             return exec;
    118           }
    119         case Algorithm.StandardGpClassification: {
    120             var algo = new HeuristicLab.GP.StructureIdentification.Classification.StandardGP();
    121             SetComplexityParameters(algo, complexity);
    122             SetProblemParameters(algo, problem, targetVariable);
    123             algo.PopulationSize = 10000;
    124             algo.MaxGenerations = MaxGenerations;
    125             Execution exec = new Execution(algo.Engine);
    126             exec.Description = "StandardGP - Complexity: " + complexity;
    127             return exec;
    128           }
    129         case Algorithm.OffspringGpClassification: {
    130             var algo = new HeuristicLab.GP.StructureIdentification.Classification.OffspringSelectionGP();
    131             SetComplexityParameters(algo, complexity);
    132             SetProblemParameters(algo, problem, targetVariable);
    133             algo.MaxEvaluatedSolutions = MaxEvaluatedSolutions;
    134             Execution exec = new Execution(algo.Engine);
    135             exec.Description = "OffspringGP - Complexity: " + complexity;
    136             return exec;
    137           }
    138         case Algorithm.StandardGpForecasting: {
    139             var algo = new HeuristicLab.GP.StructureIdentification.TimeSeries.StandardGP();
    140             SetComplexityParameters(algo, complexity);
    141             SetProblemParameters(algo, problem, targetVariable);
    142             algo.PopulationSize = 10000;
    143             algo.MaxGenerations = MaxGenerations;
    144             Execution exec = new Execution(algo.Engine);
    145             exec.Description = "StandardGP - Complexity: " + complexity;
    146             return exec;
    147           }
    148         case Algorithm.OffspringGpForecasting: {
    149             var algo = new HeuristicLab.GP.StructureIdentification.TimeSeries.OffspringSelectionGP();
    150             SetComplexityParameters(algo, complexity);
    151             SetProblemParameters(algo, problem, targetVariable);
    152             algo.MaxEvaluatedSolutions = MaxEvaluatedSolutions;
    153             Execution exec = new Execution(algo.Engine);
    154             exec.Description = "OffspringGP - Complexity: " + complexity;
    155             return exec;
    156           }
    157         default: {
    158             return null;
    159           }
    160       }
     89    private Execution CreateExecution(Problem problem, int targetVariable, IAlgorithm algorithm) {
     90      //switch (algorithm) {
     91      //  case Algorithm.StandardGpRegression: {
     92      //      var algo = new HeuristicLab.GP.StructureIdentification.StandardGP();
     93      //      SetComplexityParameters(algo, complexity);
     94      //      SetProblemParameters(algo, problem, targetVariable);
     95      //      algo.PopulationSize = 10000;
     96      //      algo.MaxGenerations = MaxGenerations;
     97      //      Execution exec = new Execution(algo.Engine);
     98      //      exec.Description = "StandardGP - Complexity: " + complexity;
     99      //      return exec;
     100      //    }
     101      SetProblemParameters(algorithm, problem, targetVariable);
     102      Execution exec = new Execution(algorithm.Engine);
     103      exec.Description = algorithm.Name;
     104      return exec;
    161105    }
    162106
    163     private void SetComplexityParameters(AlgorithmBase algo, ModelComplexity complexity) {
    164       switch (complexity) {
    165         case ModelComplexity.Low: {
    166             algo.MaxTreeHeight = 5;
    167             algo.MaxTreeSize = 20;
    168             break;
    169           }
    170         case ModelComplexity.Medium: {
    171             algo.MaxTreeHeight = 10;
    172             algo.MaxTreeSize = 100;
    173             break;
    174           }
    175         case ModelComplexity.High: {
    176             algo.MaxTreeHeight = 12;
    177             algo.MaxTreeSize = 200;
    178             break;
    179           }
    180       }
    181     }
    182 
    183     private void SetProblemParameters(AlgorithmBase algo, Problem problem, int targetVariable) {
     107    private void SetProblemParameters(IAlgorithm algo, Problem problem, int targetVariable) {
    184108      algo.ProblemInjector.GetVariable("Dataset").Value = problem.DataSet;
    185109      algo.ProblemInjector.GetVariable("TargetVariable").GetValue<IntData>().Data = targetVariable;
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLab.CEDMA.Server-3.3.csproj

    r1534 r1857  
    132132      <Name>HeuristicLab.Data-3.2</Name>
    133133    </ProjectReference>
    134     <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification.Classification\3.3\HeuristicLab.GP.StructureIdentification.Classification-3.3.csproj">
    135       <Project>{7C20D100-8BEB-433A-9499-F075E2CB9297}</Project>
    136       <Name>HeuristicLab.GP.StructureIdentification.Classification-3.3</Name>
    137     </ProjectReference>
    138     <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification.TimeSeries\3.3\HeuristicLab.GP.StructureIdentification.TimeSeries-3.3.csproj">
    139       <Project>{6084CFB5-733F-449D-9F92-2E40D13F0514}</Project>
    140       <Name>HeuristicLab.GP.StructureIdentification.TimeSeries-3.3</Name>
    141     </ProjectReference>
    142     <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification\3.3\HeuristicLab.GP.StructureIdentification-3.3.csproj">
    143       <Project>{74223A32-C726-4978-BE78-37113A18373C}</Project>
    144       <Name>HeuristicLab.GP.StructureIdentification-3.3</Name>
    145     </ProjectReference>
    146134    <ProjectReference Include="..\..\HeuristicLab.Grid\3.2\HeuristicLab.Grid-3.2.csproj">
    147135      <Project>{545CE756-98D8-423B-AC2E-6E7D70926E5C}</Project>
    148136      <Name>HeuristicLab.Grid-3.2</Name>
     137    </ProjectReference>
     138    <ProjectReference Include="..\..\HeuristicLab.Modeling\3.2\HeuristicLab.Modeling-3.2.csproj">
     139      <Project>{80F7FADA-549D-4151-8856-79B620A50DBA}</Project>
     140      <Name>HeuristicLab.Modeling-3.2</Name>
    149141    </ProjectReference>
    150142    <ProjectReference Include="..\..\HeuristicLab.Operators\3.2\HeuristicLab.Operators-3.2.csproj">
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLabCedmaServerPlugin.cs

    r1529 r1857  
    3434  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
    3535  [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")]
    36   [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification-3.3")]
    37   [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification.Classification-3.3")]
    38   [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification.TimeSeries-3.3")]
     36  [Dependency(Dependency = "HeuristicLab.Modeling-3.2")]
    3937  public class HeuristicLabCedmaServerPlugin : PluginBase {
    4038  }
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/RandomDispatcher.cs

    r1529 r1857  
    3535using HeuristicLab.Data;
    3636using HeuristicLab.Core;
     37using HeuristicLab.Modeling;
    3738
    3839namespace HeuristicLab.CEDMA.Server {
     
    4445    }
    4546
    46     public override Algorithm SelectAlgorithm(DataSet dataSet, int targetVariable, Algorithm[] possibleAlgorithms) {
    47       return possibleAlgorithms[random.Next(possibleAlgorithms.Length)];
    48     }
    49 
    50     public override ModelComplexity SelectComplexity(DataSet dataSet, int targetVariable, Algorithm algorithm, ModelComplexity[] possibleComplexities) {
    51       return possibleComplexities[random.Next(possibleComplexities.Length)];
     47    public override IAlgorithm SelectAlgorithm(DataSet dataSet, int targetVariable, LearningTask learningTask) {
     48      DiscoveryService ds = new DiscoveryService();
     49      IAlgorithm[] algos = ds.GetInstances<IAlgorithm>();
     50      switch (learningTask) {
     51        case LearningTask.Regression: {
     52            var regressionAlgos = algos.Where(a => (a as IClassificationAlgorithm) == null && (a as ITimeSeriesAlgorithm) == null);
     53            if (regressionAlgos.Count() == 0) return null;
     54            return regressionAlgos.ElementAt(random.Next(regressionAlgos.Count()));
     55          }
     56        case LearningTask.Classification: {
     57            var classificationAlgos = algos.Where(a => (a as IClassificationAlgorithm) != null);
     58            if (classificationAlgos.Count() == 0) return null;
     59            return classificationAlgos.ElementAt(random.Next(classificationAlgos.Count()));
     60          }
     61        case LearningTask.TimeSeries: {
     62            var timeSeriesAlgos = algos.Where(a => (a as ITimeSeriesAlgorithm) != null);
     63            if (timeSeriesAlgos.Count() == 0) return null;
     64            return timeSeriesAlgos.ElementAt(random.Next(timeSeriesAlgos.Count()));
     65          }
     66      }
     67      return null;
    5268    }
    5369
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/OffspringSelectionGP.cs

    r1856 r1857  
    3333
    3434namespace HeuristicLab.GP.StructureIdentification.Classification {
    35   public class OffspringSelectionGP : HeuristicLab.GP.StructureIdentification.OffspringSelectionGP {
     35  public class OffspringSelectionGP : HeuristicLab.GP.StructureIdentification.OffspringSelectionGP, IClassificationAlgorithm {
    3636    protected override IOperator CreateProblemInjector() {
    3737      return new ProblemInjector();
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/StandardGP.cs

    r1856 r1857  
    3434
    3535namespace HeuristicLab.GP.StructureIdentification.Classification {
    36   public class StandardGP : HeuristicLab.GP.StructureIdentification.StandardGP {
    37 
     36  public class StandardGP : HeuristicLab.GP.StructureIdentification.StandardGP, IClassificationAlgorithm {
    3837    protected override IOperator CreateProblemInjector() {
    3938      return new ProblemInjector();
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/OffspringSelectionGP.cs

    r1856 r1857  
    3434
    3535namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
    36   public class OffspringSelectionGP : HeuristicLab.GP.StructureIdentification.OffspringSelectionGP {
     36  public class OffspringSelectionGP : HeuristicLab.GP.StructureIdentification.OffspringSelectionGP, ITimeSeriesAlgorithm {
    3737    public virtual bool Autoregressive {
    3838      get { return ProblemInjector.GetVariable("Autoregressive").GetValue<BoolData>().Data; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/StandardGP.cs

    r1856 r1857  
    3434
    3535namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
    36   public class StandardGP : HeuristicLab.GP.StructureIdentification.StandardGP {
     36  public class StandardGP : HeuristicLab.GP.StructureIdentification.StandardGP, ITimeSeriesAlgorithm {
    3737    public bool Autoregressive {
    3838      get { return ProblemInjector.GetVariable("Autoregressive").GetValue<BoolData>().Data; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/AlgorithmBase.cs

    r1529 r1857  
    3535using HeuristicLab.Operators.Programmable;
    3636using HeuristicLab.Evolutionary;
     37using HeuristicLab.Modeling;
    3738
    3839namespace HeuristicLab.GP.StructureIdentification {
    39   public abstract class AlgorithmBase : ItemBase {
     40  public abstract class AlgorithmBase : ItemBase, IAlgorithm, IStochasticAlgorithm {
     41    public virtual string Name { get { return "GP"; } }
     42    public virtual string Description { get { return "TODO"; } }
     43
    4044    public virtual double MutationRate {
    4145      get { return GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data; }
     
    5256    }
    5357
    54     public virtual int Seed {
     58    public virtual int RandomSeed {
    5559      get { return GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data; }
    5660      set { GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data = value; }
     
    430434    }
    431435    #endregion
     436
    432437  }
    433438}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffspringSelectionGP.cs

    r1529 r1857  
    3939namespace HeuristicLab.GP.StructureIdentification {
    4040  public class OffspringSelectionGP : StandardGP {
     41    public override string Name { get { return "OffspringSelectionGP"; } }
    4142
    4243    public virtual int MaxEvaluatedSolutions {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs

    r1856 r1857  
    3838namespace HeuristicLab.GP.StructureIdentification {
    3939  public class StandardGP : AlgorithmBase, IEditable {
     40
     41    public override string Name { get { return "StandardGP"; } }
    4042
    4143    public virtual int MaxGenerations {
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r1856 r1857  
    8383  <ItemGroup>
    8484    <Compile Include="ClassificationProblemInjector.cs" />
     85    <Compile Include="ITimeSeriesAlgorithm.cs" />
     86    <Compile Include="IClassificationAlgorithm.cs" />
     87    <Compile Include="IStochasticAlgorithm.cs" />
    8588    <Compile Include="HeuristicLabModelingPlugin.cs" />
     89    <Compile Include="IAlgorithm.cs" />
    8690    <Compile Include="ProblemInjector.cs" />
    8791    <Compile Include="ProblemInjectorView.cs">
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj

    r1854 r1857  
    109109      <Name>HeuristicLab.Data-3.2</Name>
    110110    </ProjectReference>
    111     <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification\3.3\HeuristicLab.GP.StructureIdentification-3.3.csproj">
    112       <Project>{74223A32-C726-4978-BE78-37113A18373C}</Project>
    113       <Name>HeuristicLab.GP.StructureIdentification-3.3</Name>
    114     </ProjectReference>
    115111    <ProjectReference Include="..\..\HeuristicLab.Logging\3.2\HeuristicLab.Logging-3.2.csproj">
    116112      <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project>
    117113      <Name>HeuristicLab.Logging-3.2</Name>
     114    </ProjectReference>
     115    <ProjectReference Include="..\..\HeuristicLab.Modeling\3.2\HeuristicLab.Modeling-3.2.csproj">
     116      <Project>{80F7FADA-549D-4151-8856-79B620A50DBA}</Project>
     117      <Name>HeuristicLab.Modeling-3.2</Name>
    118118    </ProjectReference>
    119119    <ProjectReference Include="..\..\HeuristicLab.Operators.Programmable\3.2\HeuristicLab.Operators.Programmable-3.2.csproj">
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLabSupportVectorMachinesPlugin.cs

    r1854 r1857  
    3333  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
    3434  [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")]
    35   [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification-3.3")]
     35  [Dependency(Dependency = "HeuristicLab.Modeling-3.2")]
    3636  [Dependency(Dependency = "HeuristicLab.SequentialEngine-3.2")]
    3737  [Dependency(Dependency = "HeuristicLab.Logging-3.2")]
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r1854 r1857  
    3333using HeuristicLab.Logging;
    3434using HeuristicLab.Operators.Programmable;
     35using HeuristicLab.Modeling;
    3536
    3637namespace HeuristicLab.SupportVectorMachines {
    37   public class SupportVectorRegression : ItemBase, IEditable {
     38  public class SupportVectorRegression : ItemBase, IEditable, IAlgorithm {
     39
     40    public string Name { get { return "SupportVectorRegression"; } }
     41    public string Description { get { return "TODO"; } }
     42
    3843    private SequentialEngine.SequentialEngine engine;
    3944    public IEngine Engine {
Note: See TracChangeset for help on using the changeset viewer.