Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs @ 12321

Last change on this file since 12321 was 12321, checked in by arapeanu, 9 years ago

#2288: Modified CreateTargetVariationExperimentDialog.cs to exclude unchecked inputs from the target variables

File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Globalization;
5using System.Linq;
6using System.Text;
7using System.Threading;
8using System.Windows.Forms;
9using HeuristicLab.Core;
10using HeuristicLab.Data;
11using HeuristicLab.MainForm.WindowsForms;
12using HeuristicLab.Optimization;
13using HeuristicLab.Parameters;
14using HeuristicLab.Problems.Instances;
15using HeuristicLab.Problems.DataAnalysis;
16using HeuristicLab.Problems.DataAnalysis.Symbolic;
17using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
18using HeuristicLab.Optimizer;
19using HeuristicLab.MainForm;
20
21namespace 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;
33
34            Experiment = null;
35            okButton.Enabled = alg != null;
36        }
37
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        }
44
45        public Experiment CreateVariableCombinations(IAlgorithm algorithm)
46        {
47            var experiment = new Experiment("Target Variation Experiment");
48
49            if (algorithm == null)
50                throw new InvalidOperationException("Null algorithm!");
51
52            var regressionProblem = algorithm.Problem as IRegressionProblem;
53            if (regressionProblem == null)
54                throw new InvalidOperationException("Null regression problem!!");
55
56            var problemData = regressionProblem.ProblemData;
57            var variables = problemData.InputVariables.ToList();
58            int checksNo = 0;
59
60            for (int i = 0; i < variables.Count; i++)
61            {
62                if (!problemData.InputVariables.ItemChecked(problemData.InputVariables[i]))
63                    continue;
64
65                var alg = (IAlgorithm)algorithm.Clone();
66                var pd = ((IRegressionProblem)alg.Problem).ProblemData;
67                checksNo++;
68
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 + "}";
75
76                var batchrun = new BatchRun("Batchrun" + checksNo)
77                {
78                    Repetitions = repetitions,
79                    Optimizer = alg
80                };
81
82                experiment.Optimizers.Add(batchrun);
83            }
84            return experiment;
85        }
86
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        }
97    }
98}
Note: See TracBrowser for help on using the repository browser.