Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/08/16 11:24:33 (8 years ago)
Author:
bburlacu
Message:

#2288: Change the CreateTargetVariationExperimentDialog so that it creates combinations of all variables in the dataset.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs

    r12321 r13664  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Globalization;
     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
     22using System;
    523using System.Linq;
    6 using System.Text;
    7 using System.Threading;
    824using System.Windows.Forms;
    9 using HeuristicLab.Core;
    10 using HeuristicLab.Data;
    11 using HeuristicLab.MainForm.WindowsForms;
     25using HeuristicLab.MainForm;
    1226using HeuristicLab.Optimization;
    13 using HeuristicLab.Parameters;
    14 using HeuristicLab.Problems.Instances;
    1527using HeuristicLab.Problems.DataAnalysis;
    16 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    17 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    18 using HeuristicLab.Optimizer;
    19 using HeuristicLab.MainForm;
    2028
    21 namespace HeuristicLab.VariableInteractionNetworks
    22 {
    23     public partial class CreateTargetVariationExperimentDialog : Form
    24     {
    25         public Experiment Experiment { get; private set; }
    26         private int repetitions;
    27        
    28         public CreateTargetVariationExperimentDialog() : this(null) { }
    29         public CreateTargetVariationExperimentDialog(IAlgorithm alg)
    30         {
    31             InitializeComponent();
    32             repetitions = (int)repetitionsNumericUpDown.Value;
     29namespace HeuristicLab.VariableInteractionNetworks {
     30  public partial class CreateTargetVariationExperimentDialog : Form {
     31    public Experiment Experiment { get; private set; }
     32    private int repetitions;
    3333
    34             Experiment = null;
    35             okButton.Enabled = alg != null;
    36         }
     34    public CreateTargetVariationExperimentDialog() : this(null) { }
     35    public CreateTargetVariationExperimentDialog(IAlgorithm alg) {
     36      InitializeComponent();
     37      repetitions = (int)repetitionsNumericUpDown.Value;
    3738
    38         private void repetitionsNumericUpDown_Validated(object sender, EventArgs e)
    39         {
    40             if (repetitionsNumericUpDown.Text == string.Empty)
    41                 repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
    42             repetitions = (int)repetitionsNumericUpDown.Value;
    43         }
     39      Experiment = null;
     40      okButton.Enabled = alg != null;
     41    }
    4442
    45         public Experiment CreateVariableCombinations(IAlgorithm algorithm)
    46         {
    47             var experiment = new Experiment("Target Variation Experiment");
     43    private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
     44      if (repetitionsNumericUpDown.Text == string.Empty)
     45        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
     46      repetitions = (int)repetitionsNumericUpDown.Value;
     47    }
    4848
    49             if (algorithm == null)
    50                 throw new InvalidOperationException("Null algorithm!");
     49    public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
     50      var experiment = new Experiment("Target Variation Experiment");
    5151
    52             var regressionProblem = algorithm.Problem as IRegressionProblem;
    53             if (regressionProblem == null)
    54                 throw new InvalidOperationException("Null regression problem!!");
     52      if (algorithm == null)
     53        throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance.");
    5554
    56             var problemData = regressionProblem.ProblemData;
    57             var variables = problemData.InputVariables.ToList();
    58             int checksNo = 0;
     55      var regressionProblem = algorithm.Problem as IRegressionProblem;
     56      if (regressionProblem == null)
     57        throw new ArgumentNullException("The algorithm does not contain a valid problem instance.");
    5958
    60             for (int i = 0; i < variables.Count; i++)
    61             {
    62                 if (!problemData.InputVariables.ItemChecked(problemData.InputVariables[i]))
    63                     continue;
     59      var problemData = regressionProblem.ProblemData;
     60      var variables = problemData.Dataset.DoubleVariables.ToList();
    6461
    65                 var alg = (IAlgorithm)algorithm.Clone();
    66                 var pd = ((IRegressionProblem)alg.Problem).ProblemData;
    67                 checksNo++;
     62      for (int i = 0; i < variables.Count; i++) {
     63        var alg = (IAlgorithm)algorithm.Clone();
     64        var pd = ((IRegressionProblem)alg.Problem).ProblemData;
    6865
    69                 // set target to false
    70                 pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
    71                    
    72                 pd.TargetVariable = pd.InputVariables[i].Value;
    73                    
    74                 alg.Name += "{Target variable=" + pd.TargetVariable + "}";
     66        for (int j = 0; j < variables.Count; ++j)
     67          pd.InputVariables.SetItemCheckedState(pd.InputVariables[j], true);
    7568
    76                 var batchrun = new BatchRun("Batchrun" + checksNo)
    77                 {
    78                     Repetitions = repetitions,
    79                     Optimizer = alg
    80                 };
     69        pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
     70        pd.TargetVariable = pd.InputVariables[i].Value;
    8171
    82                 experiment.Optimizers.Add(batchrun);
    83             }
    84             return experiment;
    85         }
     72        alg.Name += "{Target = " + pd.TargetVariable + "}";
    8673
    87         private void okButton_Click(object sender, EventArgs e)
    88         {
    89             IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    90             if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked)
    91             {
    92                 Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
    93                 DialogResult = System.Windows.Forms.DialogResult.OK;
    94                 Close();
    95             }
    96         }
     74        var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
     75          Repetitions = repetitions,
     76          Optimizer = alg
     77        };
     78
     79        experiment.Optimizers.Add(batchrun);
     80      }
     81      return experiment;
    9782    }
     83
     84    private void okButton_Click(object sender, EventArgs e) {
     85      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     86      if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
     87        Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
     88        DialogResult = DialogResult.OK;
     89        Close();
     90      }
     91    }
     92  }
    9893}
Note: See TracChangeset for help on using the changeset viewer.