using System; using System.CodeDom; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Persistence; using HeuristicLab.Persistence.Default.Xml; using HeuristicLab.Problems.DataAnalysis; using HeuristicLab.Problems.DataAnalysis.Symbolic; using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; namespace HeuristicLab.VariableInteractionNetworks { class TargetVariation { public static Experiment CreateVariableCombinations(IAlgorithm algorithm) { var experiment = new Experiment("Target Variation Experiment"); if (algorithm == null) throw new InvalidOperationException("Null algorithm!"); var problem = algorithm.Problem; var regressionProblem = problem as IRegressionProblem; if (regressionProblem == null) throw new Exception(); var problemData = regressionProblem.ProblemData; var variables = problemData.InputVariables.ToList(); for (int i = 0; i < variables.Count; i++) { var alg = (IAlgorithm)algorithm.Clone(); var rp = (IRegressionProblem) alg.Problem; var pd = rp.ProblemData; // check all input variables foreach(var v in pd.InputVariables) pd.InputVariables.SetItemCheckedState(v, true); // set target to false pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false); pd.TargetVariable = pd.InputVariables[i].Value; alg.Name += "{Target variable=" + pd.TargetVariable + "}"; var batchrun = new BatchRun("Batchrun" + i) { Repetitions = 10, Optimizer = alg }; experiment.Optimizers.Add(batchrun); } return experiment; } } }