Changeset 13728
- Timestamp:
- 03/24/16 14:05:07 (9 years ago)
- Location:
- branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperiment.cs
r12320 r13728 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Windows.Forms; … … 6 27 using HeuristicLab.Optimizer; 7 28 8 namespace HeuristicLab.VariableInteractionNetworks 9 { 10 internal class CreateTargetVariationExperiment : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider 11 { 12 public override string Name 13 { 14 get { return "Create Target Variation &Experiment"; } 29 namespace HeuristicLab.VariableInteractionNetworks { 30 internal class CreateTargetVariationExperiment : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider { 31 public override string Name { 32 get { return "Create Target Variation &Experiment"; } 33 } 34 public override IEnumerable<string> Structure { 35 get { return new string[] { "&Edit" }; } 36 } 37 public override int Position { 38 get { return 2300; } 39 } 40 public override string ToolTipText { 41 get { return "Create an experiment for varying the target variable"; } 42 } 43 44 protected override void OnToolStripItemSet(EventArgs e) { 45 ToolStripItem.Enabled = false; 46 } 47 protected override void OnActiveViewChanged(object sender, EventArgs e) { 48 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 49 ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked; 50 } 51 52 public override void Execute() { 53 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 54 if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) { 55 using (CreateTargetVariationExperimentDialog dialog = new CreateTargetVariationExperimentDialog((IAlgorithm)activeView.Content)) { 56 if (dialog.ShowDialog() == DialogResult.OK) MainFormManager.MainForm.ShowContent(dialog.Experiment); 15 57 } 16 public override IEnumerable<string> Structure 17 { 18 get { return new string[] { "&Edit" }; } 19 } 20 public override int Position 21 { 22 get { return 2300; } 23 } 24 public override string ToolTipText 25 { 26 get { return "Create an experiment for varying the target variable"; } 27 } 28 29 protected override void OnToolStripItemSet(EventArgs e) 30 { 31 ToolStripItem.Enabled = false; 32 } 33 protected override void OnActiveViewChanged(object sender, EventArgs e) 34 { 35 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 36 ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked; 37 } 38 39 public override void Execute() 40 { 41 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 42 if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) 43 { 44 using (CreateTargetVariationExperimentDialog dialog = new CreateTargetVariationExperimentDialog((IAlgorithm)activeView.Content)) 45 { 46 if (dialog.ShowDialog() == DialogResult.OK) MainFormManager.MainForm.ShowContent(dialog.Experiment); 47 } 48 } 49 } 58 } 50 59 } 60 } 51 61 } -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj
r12460 r13728 166 166 <Compile Include="Properties\AssemblyInfo.cs" /> 167 167 <Compile Include="SymbolicDataAnalysisVariableImpactsAnalyzer.cs" /> 168 <Compile Include="VariableInteractionNetwork.cs" /> 168 169 </ItemGroup> 169 170 <ItemGroup> -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/SymbolicDataAnalysisVariableImpactsAnalyzer.cs
r13665 r13728 38 38 [StorableClass] 39 39 public class SymbolicRegressionVariableImpactsAnalyzer : SymbolicDataAnalysisAnalyzer { 40 #region parameter names 40 41 private const string UpdateCounterParameterName = "UpdateCounter"; 41 42 private const string UpdateIntervalParameterName = "UpdateInterval"; … … 47 48 private const string EstimationLimitsParameterName = "EstimationLimits"; 48 49 private const string EvaluatorParameterName = "Evaluator"; 49 private const string VariableImpactsParameterName = "AverageVariableImpacts";50 50 private const string PercentageBestParameterName = "PercentageBest"; 51 51 private const string LastGenerationsParameterName = "LastGenerations"; … … 53 53 private const string OptimizeConstantsParameterName = "OptimizeConstants"; 54 54 private const string PruneTreesParameterName = "PruneTrees"; 55 private const string AverageVariableImpactsResultName = "Average variable impacts"; 56 private const string AverageVariableImpactsHistoryResultName = "Average variable impacts history"; 57 #endregion 55 58 56 59 private SymbolicDataAnalysisExpressionTreeSimplifier simplifier; … … 84 87 public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter { 85 88 get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; } 86 }87 public ILookupParameter<DataTable> VariableImpactsParameter {88 get { return (ILookupParameter<DataTable>)Parameters[VariableImpactsParameterName]; }89 89 } 90 90 public IFixedValueParameter<PercentValue> PercentageBestParameter { … … 126 126 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 127 127 Parameters.Add(new FixedValueParameter<IntValue>(MaxCOIterationsParameterName, new IntValue(3))); 128 Parameters.Add(new LookupParameter<DataTable>(VariableImpactsParameterName, "The relative variable relevance calculated as the average relative variable frequency over the whole run.")); 129 Parameters.Add(new FixedValueParameter<PercentValue>(PercentageBestParameterName, new PercentValue(100))); 128 Parameters.Add(new FixedValueParameter<PercentValue>(PercentageBestParameterName, new PercentValue(1))); 130 129 Parameters.Add(new FixedValueParameter<IntValue>(LastGenerationsParameterName, new IntValue(10))); 131 130 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeConstantsParameterName, new BoolValue(false))); … … 171 170 var results = ResultCollectionParameter.ActualValue; 172 171 int maxGen = MaximumGenerationsParameter.ActualValue.Value; 173 int gen = ((IntValue)results["Generations"].Value).Value;172 int gen = results.ContainsKey("Generations") ? ((IntValue)results["Generations"].Value).Value : 0; 174 173 int lastGen = LastGenerationsParameter.Value.Value; 175 174 … … 195 194 var allowedInputVariables = problemData.AllowedInputVariables.ToList(); 196 195 DataTable dataTable; 197 if ( VariableImpactsParameter.ActualValue == null) {196 if (!results.ContainsKey(AverageVariableImpactsHistoryResultName)) { 198 197 dataTable = new DataTable("Variable impacts", "Average impact of variables over the population"); 199 198 dataTable.VisualProperties.XAxisTitle = "Generation"; 200 199 dataTable.VisualProperties.YAxisTitle = "Average variable impact"; 201 VariableImpactsParameter.ActualValue = dataTable; 202 results.Add(new Result("Average variable impacts", "The relative variable relevance calculated as the average relative variable frequency over the whole run.", new DataTable())); 200 results.Add(new Result(AverageVariableImpactsHistoryResultName, dataTable)); 203 201 204 202 foreach (var v in allowedInputVariables) { 205 203 dataTable.Rows.Add(new DataRow(v) { VisualProperties = { StartIndexZero = true } }); 206 204 } 207 VariableImpactsParameter.ActualValue = dataTable;208 }209 dataTable = VariableImpactsParameter.ActualValue; 205 } 206 dataTable = (DataTable)results[AverageVariableImpactsHistoryResultName].Value; 207 210 208 int nTrees = (int)Math.Round(trees.Length * percentageBest); 211 209 var bestTrees = trees.Take(nTrees).Select(x => (ISymbolicExpressionTree)x.Clone()).ToList(); … … 215 213 if (optimizeConstants) { 216 214 for (int i = 0; i < simplifiedTrees.Count; ++i) { 217 qualities[i].Value = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, simplifiedTrees[i], problemData, problemData.TrainingIndices, applyLinearScaling, constantOptimizationIterations, estimationLimits.Upper, estimationLimits.Lower);215 qualities[i].Value = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, simplifiedTrees[i], problemData, problemData.TrainingIndices, applyLinearScaling, constantOptimizationIterations, true, estimationLimits.Upper, estimationLimits.Lower); 218 216 } 219 217 } … … 243 241 var averageImpact = 0d; 244 242 for (int i = 0; i < indices.Count; ++i) { 243 var tree = simplifiedTrees[i]; 245 244 var originalQuality = qualities[i].Value; 246 245 double newQuality; 247 246 if (optimizeConstants) { 248 newQuality = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, simplifiedTrees[i], pd, problemData.TrainingIndices, applyLinearScaling, constantOptimizationIterations, estimationLimits.Upper, estimationLimits.Lower);247 newQuality = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, pd, problemData.TrainingIndices, applyLinearScaling, constantOptimizationIterations, true, estimationLimits.Upper, estimationLimits.Lower); 249 248 } else { 250 249 var evaluator = EvaluatorParameter.ActualValue; 251 newQuality = evaluator.Evaluate(this.ExecutionContext, simplifiedTrees[i], pd, pd.TrainingIndices);250 newQuality = evaluator.Evaluate(this.ExecutionContext, tree, pd, pd.TrainingIndices); 252 251 } 253 252 averageImpact += originalQuality - newQuality; // impact calculated this way may be negative … … 257 256 } 258 257 259 results["Average variable impacts"].Value = dataTable; 258 var averageVariableImpacts = new DoubleMatrix(dataTable.Rows.Count, 1); 259 var rowNames = dataTable.Rows.Select(x => x.Name).ToList(); 260 averageVariableImpacts.RowNames = rowNames; 261 for (int i = 0; i < rowNames.Count; ++i) { 262 averageVariableImpacts[i, 0] = dataTable.Rows[rowNames[i]].Values.Last(); 263 } 264 if (!results.ContainsKey(AverageVariableImpactsResultName)) { 265 results.Add(new Result(AverageVariableImpactsResultName, averageVariableImpacts)); 266 } else { 267 results[AverageVariableImpactsResultName].Value = averageVariableImpacts; 268 } 260 269 return base.Apply(); 261 270 }
Note: See TracChangeset
for help on using the changeset viewer.