Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/TargetVariation.cs @ 12198

Last change on this file since 12198 was 12198, checked in by arapeanu, 8 years ago

#2288: Implemented Create Target Variation Experiment and added view skeleton for the variable interaction network

File size: 2.1 KB
Line 
1using System;
2using System.CodeDom;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8using HeuristicLab.Data;
9using HeuristicLab.Optimization;
10using HeuristicLab.Persistence;
11using HeuristicLab.Persistence.Default.Xml;
12using HeuristicLab.Problems.DataAnalysis;
13using HeuristicLab.Problems.DataAnalysis.Symbolic;
14using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
15
16namespace HeuristicLab.VariableInteractionNetworks {
17    class TargetVariation
18    {
19        public static Experiment CreateVariableCombinations(IAlgorithm algorithm)
20        {
21            var experiment = new Experiment("Target Variation Experiment");
22
23            if (algorithm == null)
24                throw new InvalidOperationException("Null algorithm!");
25
26            var problem = algorithm.Problem;
27            var regressionProblem = problem as IRegressionProblem;
28            if (regressionProblem == null)
29                throw new Exception();
30
31            var problemData = regressionProblem.ProblemData;
32            var variables = problemData.InputVariables.ToList();
33
34            for (int i = 0; i < variables.Count; i++)
35            {
36                var alg = (IAlgorithm)algorithm.Clone();           
37                var rp = (IRegressionProblem) alg.Problem;
38                var pd = rp.ProblemData;
39               
40                // check all input variables
41                foreach(var v in pd.InputVariables)
42                    pd.InputVariables.SetItemCheckedState(v, true);
43             
44                // set target to false
45                pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
46
47                pd.TargetVariable = pd.InputVariables[i].Value;
48                alg.Name += "{Target variable=" + pd.TargetVariable + "}";
49
50 
51                var batchrun = new BatchRun("Batchrun" + i)
52                {
53                    Repetitions = 10,
54                    Optimizer = alg
55                };
56
57                experiment.Optimizers.Add(batchrun);
58            }
59            return experiment;
60        }
61    }
62  }
Note: See TracBrowser for help on using the repository browser.