Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2288: VariableInteractionNetworkView - calculates adjacency matrix from the mean impacts

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 pd = ((IRegressionProblem)alg.Problem).ProblemData;
38               
39                // check all input variables
40                foreach(var v in pd.InputVariables)
41                    pd.InputVariables.SetItemCheckedState(v, true);
42             
43                // set target to false
44                pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
45
46                pd.TargetVariable = pd.InputVariables[i].Value;
47                alg.Name += "{Target variable=" + pd.TargetVariable + "}";
48                 
49                var batchrun = new BatchRun("Batchrun" + i)
50                {
51                    Repetitions = 10,
52                    Optimizer = alg
53                };
54
55                experiment.Optimizers.Add(batchrun);
56            }
57            return experiment;
58        }
59    }
60  }
Note: See TracBrowser for help on using the repository browser.