Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2288: Added sliders functionality, dialog box for setting the number of repetitions for each batch + modified node importance weighting

File size: 3.4 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
29        public CreateTargetVariationExperimentDialog() : this(null) { }
30        public CreateTargetVariationExperimentDialog(IAlgorithm alg)
31        {
32            InitializeComponent();
33            repetitions = (int)repetitionsNumericUpDown.Value;
34
35            Experiment = null;
36            okButton.Enabled = alg != null;
37        }
38
39        private void repetitionsNumericUpDown_Validated(object sender, EventArgs e)
40        {
41            if (repetitionsNumericUpDown.Text == string.Empty)
42                repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
43            repetitions = (int)repetitionsNumericUpDown.Value;
44        }
45
46        public Experiment CreateVariableCombinations(IAlgorithm algorithm)
47        {
48            var experiment = new Experiment("Target Variation Experiment");
49
50            if (algorithm == null)
51                throw new InvalidOperationException("Null algorithm!");
52
53            var problem = algorithm.Problem;
54            var regressionProblem = problem as IRegressionProblem;
55            if (regressionProblem == null)
56                throw new Exception();
57
58            var problemData = regressionProblem.ProblemData;
59            var variables = problemData.InputVariables.ToList();
60
61            for (int i = 0; i < variables.Count; i++)
62            {
63                var alg = (IAlgorithm)algorithm.Clone();
64                var pd = ((IRegressionProblem)alg.Problem).ProblemData;
65
66                // set target to false
67                pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
68
69                pd.TargetVariable = pd.InputVariables[i].Value;
70                alg.Name += "{Target variable=" + pd.TargetVariable + "}";
71
72                var batchrun = new BatchRun("Batchrun" + i)
73                {
74                    Repetitions = repetitions,
75                    Optimizer = alg
76                };
77
78                experiment.Optimizers.Add(batchrun);
79            }
80            return experiment;
81        }
82
83        private void okButton_Click(object sender, EventArgs e)
84        {
85            IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
86            if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked)
87            {
88                Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
89                DialogResult = System.Windows.Forms.DialogResult.OK;
90                Close();
91            }
92        }
93    }
94}
Note: See TracBrowser for help on using the repository browser.