Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/24/16 20:30:20 (8 years ago)
Author:
bburlacu
Message:

#2288: Improve the CreateTargetVariationExperimentDialog to produce combinations of inputs and target according to a user-provided binomial coefficient.

File:
1 edited

Legend:

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

    r13664 r13788  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    3132    public Experiment Experiment { get; private set; }
    3233    private int repetitions;
     34    private int binomialCoefficient;
    3335
    3436    public CreateTargetVariationExperimentDialog() : this(null) { }
     
    4749    }
    4850
     51    private void binomialCoefficientNumericUpDown_Validated(object sender, EventArgs e) {
     52      if (binomialCoeffNumericUpDown.Text == string.Empty)
     53        binomialCoeffNumericUpDown.Text = binomialCoeffNumericUpDown.Value.ToString();
     54      binomialCoefficient = (int)binomialCoeffNumericUpDown.Value;
     55    }
     56
    4957    public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
    5058      var experiment = new Experiment("Target Variation Experiment");
     
    6169
    6270      for (int i = 0; i < variables.Count; i++) {
    63         var alg = (IAlgorithm)algorithm.Clone();
    64         var pd = ((IRegressionProblem)alg.Problem).ProblemData;
     71        var target = variables[i];
     72        var inputs = variables.Where(x => x != target).ToList();
     73        var combinations = Util.Combinations(inputs, binomialCoefficient);
    6574
    66         for (int j = 0; j < variables.Count; ++j)
    67           pd.InputVariables.SetItemCheckedState(pd.InputVariables[j], true);
     75        foreach (var combination in combinations) {
     76          var h = new HashSet<string>(combination);
     77          var alg = (IAlgorithm)algorithm.Clone();
     78          var pd = ((IRegressionProblem)alg.Problem).ProblemData;
     79          pd.TargetVariable = target;
     80          alg.Name += "{Target = " + target + ", Inputs = (" + combination.Aggregate((a, b) => a + "," + b) + ")}";
    6881
    69         pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
    70         pd.TargetVariable = pd.InputVariables[i].Value;
     82          foreach (var item in pd.InputVariables) {
     83            pd.InputVariables.SetItemCheckedState(item, h.Contains(item.Value));
     84          }
    7185
    72         alg.Name += "{Target = " + pd.TargetVariable + "}";
     86          var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
     87            Repetitions = repetitions,
     88            Optimizer = alg
     89          };
    7390
    74         var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
    75           Repetitions = repetitions,
    76           Optimizer = alg
    77         };
    78 
    79         experiment.Optimizers.Add(batchrun);
     91          experiment.Optimizers.Add(batchrun);
     92        }
    8093      }
    8194      return experiment;
Note: See TracChangeset for help on using the changeset viewer.