Changeset 1266


Ignore:
Timestamp:
03/05/09 20:08:00 (10 years ago)
Author:
gkronber
Message:
  • Added support for classification and time series forecasting algorithms in the CEDMA dispatcher.
  • Deleted obsolete class ProblemInjector.

#419 (Refactor CEDMA plugins)

Location:
branches/CEDMA-Refactoring-Ticket419
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r1109 r1266  
    107107    </Compile>
    108108    <Compile Include="Properties\AssemblyInfo.cs" />
    109     <Compile Include="ProblemInjector.cs" />
    110109    <Compile Include="Results.cs" />
    111110  </ItemGroup>
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Problem.cs

    r1215 r1266  
    104104      get { return autoRegressive; }
    105105      set { autoRegressive = value; }
     106    }
     107
     108    private int minTimeOffset;
     109    public int MinTimeOffset {
     110      get { return minTimeOffset; }
     111      set { minTimeOffset = value; }
     112    }
     113
     114    private int maxTimeOffset;
     115    public int MaxTimeOffset {
     116      get { return maxTimeOffset; }
     117      set { maxTimeOffset = value; }
    106118    }
    107119
     
    147159      XmlAttribute autoRegressiveAttr = document.CreateAttribute("AutoRegressive");
    148160      autoRegressiveAttr.Value = AutoRegressive.ToString();
     161      XmlAttribute minTimeOffsetAttr = document.CreateAttribute("MinTimeOffset");
     162      minTimeOffsetAttr.Value = MinTimeOffset.ToString();
     163      XmlAttribute maxTimeOffsetAttr = document.CreateAttribute("MaxTimeOffset");
     164      maxTimeOffsetAttr.Value = MaxTimeOffset.ToString();
    149165
    150166      node.Attributes.Append(trainingSamplesStartAttr);
     
    156172      node.Attributes.Append(learningTaskAttr);
    157173      node.Attributes.Append(autoRegressiveAttr);
     174      node.Attributes.Append(minTimeOffsetAttr);
     175      node.Attributes.Append(maxTimeOffsetAttr);
    158176
    159177      XmlElement targetVariablesElement = document.CreateElement("AllowedTargetVariables");
     
    177195      LearningTask = (LearningTask)Enum.Parse(typeof(LearningTask), node.Attributes["LearningTask"].Value);
    178196      AutoRegressive = bool.Parse(node.Attributes["AutoRegressive"].Value);
     197      if (node.Attributes["MinTimeOffset"] != null)
     198        MinTimeOffset = XmlConvert.ToInt32(node.Attributes["MinTimeOffset"].Value);
     199      else MinTimeOffset = 0;
     200      if (node.Attributes["MaxTimeOffset"] != null)
     201        MaxTimeOffset = XmlConvert.ToInt32(node.Attributes["MaxTimeOffset"].Value);
     202      else MaxTimeOffset = 0;
     203
    179204      allowedTargetVariables.Clear();
    180205      foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/DispatcherBase.cs

    r1252 r1266  
    3737
    3838namespace HeuristicLab.CEDMA.Server {
    39   public abstract class DispatcherBase :IDispatcher {
     39  public abstract class DispatcherBase : IDispatcher {
    4040    public enum ModelComplexity { Low, Medium, High };
    41     public enum Algorithm { StandardGP };
     41    public enum Algorithm { StandardGpRegression, OffspringGpRegression, StandardGpClassification, OffspringGpClassification, StandardGpForecasting, OffspringGpForecasting };
    4242
    4343    private IStore store;
    4444    private ModelComplexity[] possibleComplexities = new ModelComplexity[] { ModelComplexity.Low, ModelComplexity.Medium, ModelComplexity.High };
    4545    private Dictionary<LearningTask, Algorithm[]> possibleAlgorithms = new Dictionary<LearningTask, Algorithm[]>() {
    46       {LearningTask.Classification, new Algorithm[] {}},
    47       {LearningTask.Regression, new Algorithm[] { Algorithm.StandardGP }},
    48       {LearningTask.TimeSeries, new 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 }}
    4949    };
    5050
     
    9090    private Execution CreateExecution(Problem problem, int targetVariable, Algorithm algorithm, ModelComplexity complexity) {
    9191      switch (algorithm) {
    92         case Algorithm.StandardGP: {
    93             return CreateStandardGpExecution(problem, targetVariable, complexity);
     92        case Algorithm.StandardGpRegression: {
     93            var algo = new HeuristicLab.GP.StructureIdentification.StandardGP();
     94            SetGpParameters(algo, complexity);
     95            SetProblemParameters(algo, problem, targetVariable);
     96            algo.MaxGenerations = 2;
     97            Execution exec = new Execution(algo.Engine);
     98            exec.Description = "StandardGP - Complexity: " + complexity;
     99            return exec;
     100          }
     101        case Algorithm.OffspringGpRegression: {
     102            var algo = new HeuristicLab.GP.StructureIdentification.OffspringSelectionGP();
     103            SetGpParameters(algo, complexity);
     104            SetProblemParameters(algo, problem, targetVariable);
     105            algo.MaxEvaluatedSolutions = 10000;
     106            Execution exec = new Execution(algo.Engine);
     107            exec.Description = "OffspringGP - Complexity: " + complexity;
     108            return exec;
     109          }
     110        case Algorithm.StandardGpClassification: {
     111            var algo = new HeuristicLab.GP.StructureIdentification.Classification.StandardGP();
     112            SetGpParameters(algo, complexity);
     113            SetProblemParameters(algo, problem, targetVariable);
     114            algo.MaxGenerations = 2;
     115            Execution exec = new Execution(algo.Engine);
     116            exec.Description = "StandardGP - Complexity: " + complexity;
     117            return exec;
     118          }
     119        case Algorithm.OffspringGpClassification: {
     120            var algo = new HeuristicLab.GP.StructureIdentification.Classification.OffspringSelectionGP();
     121            SetGpParameters(algo, complexity);
     122            SetProblemParameters(algo, problem, targetVariable);
     123            algo.MaxEvaluatedSolutions = 10000;
     124            Execution exec = new Execution(algo.Engine);
     125            exec.Description = "OffspringGP - Complexity: " + complexity;
     126            return exec;
     127          }
     128        case Algorithm.StandardGpForecasting: {
     129            var algo = new HeuristicLab.GP.StructureIdentification.TimeSeries.StandardGP();
     130            SetGpParameters(algo, complexity);
     131            SetProblemParameters(algo, problem, targetVariable);
     132            algo.MaxGenerations = 2;
     133            Execution exec = new Execution(algo.Engine);
     134            exec.Description = "StandardGP - Complexity: " + complexity;
     135            return exec;
     136          }
     137        case Algorithm.OffspringGpForecasting: {
     138            var algo = new HeuristicLab.GP.StructureIdentification.TimeSeries.OffspringSelectionGP();
     139            SetGpParameters(algo, complexity);
     140            SetProblemParameters(algo, problem, targetVariable);
     141            algo.MaxEvaluatedSolutions = 10000;
     142            Execution exec = new Execution(algo.Engine);
     143            exec.Description = "OffspringGP - Complexity: " + complexity;
     144            return exec;
    94145          }
    95146        default: {
     
    99150    }
    100151
    101     private Execution CreateStandardGpExecution(Problem problem, int targetVariable, ModelComplexity complexity) {
    102       HeuristicLab.CEDMA.Core.ProblemInjector probInjector = new HeuristicLab.CEDMA.Core.ProblemInjector(problem);
    103       probInjector.TargetVariable = targetVariable;
    104       StandardGP sgp = new StandardGP();
    105       sgp.SetSeedRandomly = true;
    106       sgp.MaxGenerations = 2;
    107       sgp.PopulationSize = 100;
    108       sgp.Elites = 1;
    109       sgp.ProblemInjector = probInjector;
    110 
    111       int maxTreeHeight = 10;
    112       int maxTreeSize = 100;
     152    private void SetGpParameters(AlgorithmBase algo, ModelComplexity complexity) {
     153      algo.SetSeedRandomly = true;
     154      algo.PopulationSize = 1000;
     155      algo.Elites = 1;
    113156      switch (complexity) {
    114157        case ModelComplexity.Low: {
    115             maxTreeHeight = 5;
    116             maxTreeSize = 20;
     158            algo.MaxTreeHeight = 5;
     159            algo.MaxTreeSize = 20;
    117160            break;
    118161          }
    119162        case ModelComplexity.Medium: {
    120             maxTreeHeight = 10;
    121             maxTreeSize = 100;
     163            algo.MaxTreeHeight = 10;
     164            algo.MaxTreeSize = 100;
    122165            break;
    123166          }
    124167        case ModelComplexity.High: {
    125             maxTreeHeight = 12;
    126             maxTreeSize = 200;
     168            algo.MaxTreeHeight = 12;
     169            algo.MaxTreeSize = 200;
    127170            break;
    128171          }
    129172      }
    130 
    131       sgp.MaxTreeHeight = maxTreeHeight;
    132       sgp.MaxTreeSize = maxTreeSize;
    133       Execution exec = new Execution(sgp.Engine);
    134       exec.Description = "StandardGP - Complexity: " + complexity;
    135       return exec;
     173    }
     174
     175    private void SetProblemParameters(AlgorithmBase algo, Problem problem, int targetVariable) {
     176      algo.ProblemInjector.GetVariable("Dataset").Value = problem.DataSet;
     177      algo.ProblemInjector.GetVariable("TargetVariable").GetValue<IntData>().Data = targetVariable;
     178      algo.ProblemInjector.GetVariable("TrainingSamplesStart").GetValue<IntData>().Data = problem.TrainingSamplesStart;
     179      algo.ProblemInjector.GetVariable("TrainingSamplesEnd").GetValue<IntData>().Data = problem.TrainingSamplesEnd;
     180      algo.ProblemInjector.GetVariable("ValidationSamplesStart").GetValue<IntData>().Data = problem.ValidationSamplesStart;
     181      algo.ProblemInjector.GetVariable("ValidationSamplesEnd").GetValue<IntData>().Data = problem.ValidationSamplesEnd;
     182      algo.ProblemInjector.GetVariable("TestSamplesStart").GetValue<IntData>().Data = problem.TestSamplesStart;
     183      algo.ProblemInjector.GetVariable("TestSamplesEnd").GetValue<IntData>().Data = problem.TestSamplesEnd;
     184      ItemList<IntData> allowedFeatures = algo.ProblemInjector.GetVariable("AllowedFeatures").GetValue<ItemList<IntData>>();
     185      foreach (int allowedFeature in problem.AllowedInputVariables) allowedFeatures.Add(new IntData(allowedFeature));
     186
     187      if (problem.LearningTask == LearningTask.TimeSeries) {
     188        algo.ProblemInjector.GetVariable("Autoregressive").GetValue<BoolData>().Data = problem.AutoRegressive;
     189        algo.ProblemInjector.GetVariable("MinTimeOffset").GetValue<IntData>().Data = problem.MinTimeOffset;
     190        algo.ProblemInjector.GetVariable("MaxTimeOffset").GetValue<IntData>().Data = problem.MaxTimeOffset;
     191      } else if (problem.LearningTask == LearningTask.Classification) {
     192        ItemList<DoubleData> classValues = algo.ProblemInjector.GetVariable("TargetClassValues").GetValue<ItemList<DoubleData>>();
     193        foreach (double classValue in GetDifferentClassValues(problem.DataSet, targetVariable)) classValues.Add(new DoubleData(classValue));
     194      }
     195    }
     196
     197    private IEnumerable<double> GetDifferentClassValues(HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable) {
     198      throw new NotImplementedException();
    136199    }
    137200  }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj

    r1217 r1266  
    108108      <Name>HeuristicLab.Core</Name>
    109109    </ProjectReference>
     110    <ProjectReference Include="..\HeuristicLab.DataAnalysis\HeuristicLab.DataAnalysis.csproj">
     111      <Project>{7DD3A97A-56E9-462F-90E2-A351FE7AF5C2}</Project>
     112      <Name>HeuristicLab.DataAnalysis</Name>
     113    </ProjectReference>
    110114    <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj">
    111115      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    112116      <Name>HeuristicLab.Data</Name>
     117    </ProjectReference>
     118    <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification.Classification\HeuristicLab.GP.StructureIdentification.Classification.csproj">
     119      <Project>{7C20D100-8BEB-433A-9499-F075E2CB9297}</Project>
     120      <Name>HeuristicLab.GP.StructureIdentification.Classification</Name>
     121    </ProjectReference>
     122    <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification.TimeSeries\HeuristicLab.GP.StructureIdentification.TimeSeries.csproj">
     123      <Project>{6084CFB5-733F-449D-9F92-2E40D13F0514}</Project>
     124      <Name>HeuristicLab.GP.StructureIdentification.TimeSeries</Name>
    113125    </ProjectReference>
    114126    <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification\HeuristicLab.GP.StructureIdentification.csproj">
Note: See TracChangeset for help on using the changeset viewer.