Changeset 8024 for branches/DataAnalysisService/HeuristicLab.ExperimentGeneration.DataAnalysis.ExperimentWizard/3.3/MediumAnalysisPage.cs
- Timestamp:
- 06/18/12 10:10:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysisService/HeuristicLab.ExperimentGeneration.DataAnalysis.ExperimentWizard/3.3/MediumAnalysisPage.cs
r7944 r8024 1 1 2 using System; 2 3 using System.ComponentModel; 3 4 using System.Linq; 5 using System.Windows.Forms; 4 6 using HeuristicLab.Algorithms.DataAnalysis; 5 7 using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm; … … 32 34 worker.WorkerReportsProgress = true; 33 35 worker.ProgressChanged += new ProgressChangedEventHandler(WorkerProgressChanged); 34 36 worker.WorkerSupportsCancellation = true; 35 37 } 36 38 … … 38 40 DataAnalysisWizardContext c = e.Argument as DataAnalysisWizardContext; 39 41 IProblem problem = c.Problem; 42 if (worker.CancellationPending) { 43 e.Cancel = true; 44 } else { 45 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Generating Support Vector Regression Experiment ..."; })); 46 } 40 47 41 48 // 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); 49 //Experiment svrExperiment = null; 50 //if (!e.Cancel) { 51 // SupportVectorRegression svr = new SupportVectorRegression(); 52 // svr.Problem = (IRegressionProblem)problem; 53 // ParameterConfigurationTree vc = new ParameterConfigurationTree(svr, problem); 54 55 // var nuRange = new DoubleValueRange(new DoubleValue(0.1), new DoubleValue(0.9), new DoubleValue(0.1)); 56 // SetParameterRangeContraint(vc, "Nu", nuRange); 57 58 // var costRange = new DoubleValueFactorRange(new DoubleValue(0.03125), new DoubleValue(32768), new DoubleValue(4)); 59 // SetParameterRangeContraint(vc, "Cost", costRange); 60 61 // var gammaRange = new DoubleValueFactorRange(new DoubleValue(6.10352E-05), new DoubleValue(64), new DoubleValue(4)); 62 // SetParameterRangeContraint(vc, "Gamma", gammaRange); 63 // worker.ReportProgress(5); 64 // svrExperiment = vc.GenerateExperiment(svr); 65 //} 66 // ====================================================================== 67 68 if (worker.CancellationPending) { 69 e.Cancel = true; 70 } else { 71 worker.ReportProgress(20); 72 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Generating Random Forest Regression Experiment ..."; })); 73 } 74 58 75 59 76 // 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); 77 //Experiment rfrExperiment = null; 78 //if (!e.Cancel) { 79 // RandomForestRegression rfr = new RandomForestRegression(); 80 // rfr.Problem = (IRegressionProblem)problem; 81 // ParameterConfigurationTree rfConfig = new ParameterConfigurationTree(rfr, problem); 82 // var rRange = new DoubleValueRange(new DoubleValue(0.1), new DoubleValue(0.7), new DoubleValue(0.1)); 83 // SetParameterRangeContraint(rfConfig, "R", rRange); 84 // var treeRange = new IntValueRange(new IntValue(250), new IntValue(250), new IntValue(250)); 85 // SetParameterRangeContraint(rfConfig, "Number of trees", treeRange); 86 // rfrExperiment = rfConfig.GenerateExperiment(rfr); 87 //} 88 // ====================================================================== 89 90 if (worker.CancellationPending) { 91 e.Cancel = true; 92 } else { 93 worker.ReportProgress(40); 94 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Generating Neural Network Regression Experiment ..."; })); 95 } 96 97 70 98 // 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); 99 //Experiment nnrExperiment = null; 100 //if (!e.Cancel) { 101 // NeuralNetworkRegression nnr = new NeuralNetworkRegression(); 102 // nnr.Problem = (IRegressionProblem)problem; 103 // ParameterConfigurationTree nnrConfig = new ParameterConfigurationTree(nnr, problem); 104 // var decayRange = new DoubleValueFactorRange(new DoubleValue(0.001), new DoubleValue(100), new DoubleValue(10)); 105 // SetParameterRangeContraint(nnrConfig, "Decay", decayRange); 106 // var nodesRange = new IntValueFactorRange(new IntValue(1), new IntValue(100), new IntValue(3)); 107 // SetParameterRangeContraint(nnrConfig, "NodesInFirstHiddenLayer", nodesRange); 108 // nnrExperiment = nnrConfig.GenerateExperiment(nnr); 109 //} 110 // ====================================================================== 111 112 if (worker.CancellationPending) { 113 e.Cancel = true; 114 } else { 115 worker.ReportProgress(60); 116 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Generating Offspring Selection Genetic Algorithm Experiment ..."; })); 117 } 118 81 119 // 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 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); 121 if (!e.Cancel) { 122 OffspringSelectionGeneticAlgorithm osga = new OffspringSelectionGeneticAlgorithm(); 123 var prob = new SymbolicRegressionSingleObjectiveProblem(); 124 prob.ProblemData = ((IRegressionProblem)problem).ProblemData; 125 //prob.SolutionCreator = new MultiSymbolicDataAnalysisExpressionCreator(); 126 osga.Problem = prob; 127 osga.ComparisonFactorLowerBound.Value = 1; 128 osga.Crossover = osga.Problem.Operators.OfType<ICrossover>().FirstOrDefault(x => x.Name == gaCrossover); 129 osga.MaximumEvaluatedSolutions.Value = 500000; 130 osga.MaximumGenerations.Value = 100; 131 osga.MutationProbability = new PercentValue(0.15); 132 osga.Mutator = osga.Problem.Operators.OfType<IManipulator>().FirstOrDefault(x => x.Name == gaMutator); 133 osga.PopulationSize.Value = 500; 134 osga.Selector = osga.SelectorParameter.ValidValues.FirstOrDefault(x => x.Name == gaSelector); 135 136 CrossValidation crossSmall = new CrossValidation(); 137 crossSmall.Algorithm = osga; 138 BatchRun batchSmall = new BatchRun("small"); 139 batchSmall.Repetitions = nrOfRepetitions; 140 batchSmall.Optimizer = crossSmall; 141 142 CrossValidation crossMedium = (CrossValidation)crossSmall.Clone(new Cloner()); 143 var probMedium = (SymbolicRegressionSingleObjectiveProblem)prob.Clone(new Cloner()); 144 probMedium.MaximumSymbolicExpressionTreeDepth.Value = 12; 145 probMedium.MaximumSymbolicExpressionTreeLength.Value = 125; 146 crossMedium.Algorithm.Problem = probMedium; 147 BatchRun batchMedium = new BatchRun("medium"); 148 batchMedium.Repetitions = nrOfRepetitions; 149 batchMedium.Optimizer = crossMedium; 150 151 CrossValidation crossLarge = (CrossValidation)crossSmall.Clone(new Cloner()); 152 var probLarge = (SymbolicRegressionSingleObjectiveProblem)prob.Clone(new Cloner()); 153 probLarge.MaximumSymbolicExpressionTreeDepth.Value = 17; 154 probLarge.MaximumSymbolicExpressionTreeLength.Value = 250; 155 crossLarge.Algorithm.Problem = probLarge; 156 BatchRun batchLarge = new BatchRun("large"); 157 batchLarge.Repetitions = nrOfRepetitions; 158 batchLarge.Optimizer = crossLarge; 159 160 //Experiment gpExperiment = new Experiment(); 161 gpExperiment.Optimizers.Add(batchSmall); 162 gpExperiment.Optimizers.Add(batchMedium); 163 gpExperiment.Optimizers.Add(batchLarge); 164 } 165 // ====================================================================== 166 if (worker.CancellationPending) { 167 e.Cancel = true; 168 } else { 169 worker.ReportProgress(80); 170 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Packing Data Analysis Experiment ..."; })); 171 } 126 172 127 173 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); 174 if (!e.Cancel) { 175 //Experiment experiment = new Experiment("Data Analysis Experiment"); 176 //experiment.Optimizers.Add(svrExperiment); 177 //experiment.Optimizers.Add(rfrExperiment); 178 //experiment.Optimizers.Add(nnrExperiment); 179 experiment.Optimizers.Add(gpExperiment); 180 } 181 182 if (worker.CancellationPending) { 183 e.Cancel = true; 184 } else { 185 worker.ReportProgress(100); 186 lblProgress.Invoke(new Action(() => { lblProgress.Text = "Experiment generation completed"; })); 187 } 134 188 135 189 e.Result = experiment; … … 150 204 151 205 private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 152 SetWizardButton(Wizard.WizardButtons.Next); 153 Experiment experiment = (Experiment)e.Result; 154 context.Experiment = experiment; 206 if (e.Error != null) { 207 SetWizardButton(Wizard.WizardButtons.Back); 208 MessageBox.Show(e.Error.Message, "Error occurred while generating experiments", MessageBoxButtons.OK, MessageBoxIcon.Error); 209 } else if (e.Cancelled) { 210 // nothing to do here ... 211 } else { 212 SetWizardButton(Wizard.WizardButtons.Next); 213 Experiment experiment = (Experiment)e.Result; 214 context.Experiment = experiment; 215 } 155 216 } 156 217 … … 163 224 worker.RunWorkerAsync(context); 164 225 } 226 227 private void MediumAnalysisPage_WizardCancel(object sender, CancelEventArgs e) { 228 worker.CancelAsync(); 229 } 165 230 } 166 231 }
Note: See TracChangeset
for help on using the changeset viewer.