Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysisService/HeuristicLab.ExperimentGeneration.DataAnalysis.ExperimentWizard/3.3/MediumAnalysisPage.cs @ 7939

Last change on this file since 7939 was 7939, checked in by spimming, 12 years ago

#1807:

  • wizard page to view generated experiments
  • generate experiments according to example
  • plugin frame adapted
  • new version of problem view dialog included
File size: 8.3 KB
Line 
1
2using System.ComponentModel;
3using System.Linq;
4using HeuristicLab.Algorithms.DataAnalysis;
5using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
6using HeuristicLab.Common;
7using HeuristicLab.Data;
8using HeuristicLab.Encodings.ParameterConfigurationTreeEncoding;
9using HeuristicLab.Optimization;
10using HeuristicLab.Problems.DataAnalysis;
11using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
12namespace HeuristicLab.ExperimentGeneration.DataAnalysis.ExperimentWizard {
13  public partial class MediumAnalysisPage : HeuristicLab.ExperimentGeneration.DataAnalysis.Wizard.WizardPage {
14    private const int nrOfRepetitions = 10;
15    private const string gaCrossover = "SubtreeSwappingCrossover";
16    private const string gaMutator = "MultiSymbolicExpressionTreeManipulator";
17    private const string gaSelector = "GenderSpecificSelection";
18
19    private BackgroundWorker worker;
20
21    private DataAnalysisWizardContext context;
22    public DataAnalysisWizardContext Context {
23      get { return context; }
24    }
25
26    public MediumAnalysisPage(DataAnalysisWizardContext context) {
27      InitializeComponent();
28      this.context = context;
29      worker = new BackgroundWorker();
30      worker.DoWork += new DoWorkEventHandler(GenerateExperimentsTask);
31      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
32      worker.WorkerReportsProgress = true;
33      worker.ProgressChanged += new ProgressChangedEventHandler(WorkerProgressChanged);
34
35    }
36
37    private void GenerateExperimentsTask(object sender, DoWorkEventArgs e) {
38      DataAnalysisWizardContext c = e.Argument as DataAnalysisWizardContext;
39      IProblem problem = c.Problem;
40
41      // SVR Experiment -------------------------------------------------------
42      SupportVectorRegression svr = new SupportVectorRegression();
43      svr.Problem = (IRegressionProblem)problem;
44      ParameterConfigurationTree vc = new ParameterConfigurationTree(svr, problem);
45
46      var nuRange = new DoubleValueRange(new DoubleValue(0.1), new DoubleValue(0.9), new DoubleValue(0.1));
47      SetParameterRangeContraint(vc, "Nu", nuRange);
48
49      var costRange = new DoubleValueFactorRange(new DoubleValue(0.03125), new DoubleValue(32768), new DoubleValue(4));
50      SetParameterRangeContraint(vc, "Cost", costRange);
51
52      var gammaRange = new DoubleValueFactorRange(new DoubleValue(6.10352E-05), new DoubleValue(64), new DoubleValue(4));
53      SetParameterRangeContraint(vc, "Gamma", gammaRange);
54      worker.ReportProgress(5);
55      Experiment svrExperiment = vc.GenerateExperiment(svr);
56      // ======================================================================
57      worker.ReportProgress(20);
58
59      // RF Experiment --------------------------------------------------------
60      RandomForestRegression rfr = new RandomForestRegression();
61      rfr.Problem = (IRegressionProblem)problem;
62      ParameterConfigurationTree rfConfig = new ParameterConfigurationTree(rfr, problem);
63      var rRange = new DoubleValueRange(new DoubleValue(0.1), new DoubleValue(0.7), new DoubleValue(0.1));
64      SetParameterRangeContraint(rfConfig, "R", rRange);
65      var treeRange = new IntValueRange(new IntValue(250), new IntValue(250), new IntValue(250));
66      SetParameterRangeContraint(rfConfig, "Number of trees", treeRange);
67      Experiment rfrExperiment = rfConfig.GenerateExperiment(rfr);
68      // ======================================================================
69      worker.ReportProgress(40);
70      // NN Experiment --------------------------------------------------------
71      NeuralNetworkRegression nnr = new NeuralNetworkRegression();
72      nnr.Problem = (IRegressionProblem)problem;
73      ParameterConfigurationTree nnrConfig = new ParameterConfigurationTree(nnr, problem);
74      var decayRange = new DoubleValueFactorRange(new DoubleValue(0.001), new DoubleValue(100), new DoubleValue(10));
75      SetParameterRangeContraint(nnrConfig, "Decay", decayRange);
76      var nodesRange = new IntValueFactorRange(new IntValue(1), new IntValue(100), new IntValue(3));
77      SetParameterRangeContraint(nnrConfig, "NodesInFirstHiddenLayer", nodesRange);
78      Experiment nnrExperiment = nnrConfig.GenerateExperiment(nnr);
79      // ======================================================================
80      worker.ReportProgress(60);
81      // GP Experiment --------------------------------------------------------
82      OffspringSelectionGeneticAlgorithm osga = new OffspringSelectionGeneticAlgorithm();
83      var prob = new SymbolicRegressionSingleObjectiveProblem();
84      prob.ProblemData = ((IRegressionProblem)problem).ProblemData;
85      //prob.SolutionCreator = new MultiSymbolicDataAnalysisExpressionCreator();
86      osga.Problem = prob;
87      osga.ComparisonFactorLowerBound.Value = 1;
88      osga.Crossover = osga.Problem.Operators.OfType<ICrossover>().FirstOrDefault(x => x.Name == gaCrossover);
89      osga.MaximumEvaluatedSolutions.Value = 500000;
90      osga.MaximumGenerations.Value = 100;
91      osga.MutationProbability = new PercentValue(0.15);
92      osga.Mutator = osga.Problem.Operators.OfType<IManipulator>().FirstOrDefault(x => x.Name == gaMutator);
93      osga.PopulationSize.Value = 500;
94      osga.Selector = osga.SelectorParameter.ValidValues.FirstOrDefault(x => x.Name == gaSelector);
95
96      CrossValidation crossSmall = new CrossValidation();
97      crossSmall.Algorithm = osga;
98      BatchRun batchSmall = new BatchRun("small");
99      batchSmall.Repetitions = nrOfRepetitions;
100      batchSmall.Optimizer = crossSmall;
101
102      CrossValidation crossMedium = (CrossValidation)crossSmall.Clone(new Cloner());
103      var probMedium = (SymbolicRegressionSingleObjectiveProblem)prob.Clone(new Cloner());
104      probMedium.MaximumSymbolicExpressionTreeDepth.Value = 12;
105      probMedium.MaximumSymbolicExpressionTreeLength.Value = 125;
106      crossMedium.Algorithm.Problem = probMedium;
107      BatchRun batchMedium = new BatchRun("medium");
108      batchMedium.Repetitions = nrOfRepetitions;
109      batchMedium.Optimizer = crossMedium;
110
111      CrossValidation crossLarge = (CrossValidation)crossSmall.Clone(new Cloner());
112      var probLarge = (SymbolicRegressionSingleObjectiveProblem)prob.Clone(new Cloner());
113      probLarge.MaximumSymbolicExpressionTreeDepth.Value = 17;
114      probLarge.MaximumSymbolicExpressionTreeLength.Value = 250;
115      crossLarge.Algorithm.Problem = probLarge;
116      BatchRun batchLarge = new BatchRun("large");
117      batchLarge.Repetitions = nrOfRepetitions;
118      batchLarge.Optimizer = crossLarge;
119
120      Experiment gpExperiment = new Experiment();
121      gpExperiment.Optimizers.Add(batchSmall);
122      gpExperiment.Optimizers.Add(batchMedium);
123      gpExperiment.Optimizers.Add(batchLarge);
124      // ======================================================================
125      worker.ReportProgress(80);
126
127      Experiment experiment = new Experiment("Data Analysis Experiment");
128      experiment.Optimizers.Add(svrExperiment);
129      experiment.Optimizers.Add(rfrExperiment);
130      experiment.Optimizers.Add(nnrExperiment);
131      experiment.Optimizers.Add(gpExperiment);
132
133      worker.ReportProgress(100);
134
135      e.Result = experiment;
136    }
137
138    private void SetParameterRangeContraint(ParameterConfigurationTree pct, string parameterName, IRange rangeContraint) {
139      var pc = pct.AlgorithmConfiguration.ParameterConfigurations.Where(x => x.ParameterName == parameterName).SingleOrDefault();
140      pc.Optimize = true;
141      var vc = (RangeValueConfiguration)pc.ValueConfigurations.First();
142      vc.Optimize = true;
143      vc.RangeConstraint = rangeContraint;
144
145    }
146
147    private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) {
148      progressBar1.Value = e.ProgressPercentage;
149    }
150
151    private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
152      SetWizardButton(Wizard.WizardButtons.Next);
153      Experiment experiment = (Experiment)e.Result;
154      context.Experiment = experiment;
155    }
156
157    private void MediumAnalysisPage_WizardBack(object sender, Wizard.WizardPageEventArgs e) {
158      e.NewPage = "SelectAnalysisPage";
159    }
160
161    private void MediumAnalysisPage_SetActive(object sender, System.ComponentModel.CancelEventArgs e) {
162      SetWizardButton(Wizard.WizardButtons.None);
163      worker.RunWorkerAsync(context);
164    }
165  }
166}
Note: See TracBrowser for help on using the repository browser.