Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/SymbolicVectorRegressionSolution.cs @ 6274

Last change on this file since 6274 was 4056, checked in by gkronber, 14 years ago

Added new plugins for multi-variate regression. #1089

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using System.Collections.Generic;
29using System.Linq;
30using System.Drawing;
31using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
32using HeuristicLab.Problems.DataAnalysis.Symbolic;
33
34namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic {
35  /// <summary>
36  /// Represents a solution for a symbolic vector regression problem which can be visualized in the GUI.
37  /// </summary>
38  [Item("SymbolicVectorRegressionSolution", "Represents a solution for a symbolic vector regression problems which can be visualized in the GUI.")]
39  [StorableClass]
40  public sealed class SymbolicVectorRegressionSolution : NamedItem, IMultiVariateDataAnalysisSolution {
41    [Storable]
42    private Dictionary<string, SymbolicRegressionSolution> regressionSolutions;
43
44    public IEnumerable<string> TargetVariables {
45      get { return regressionSolutions.Keys; }
46    }
47
48    public SymbolicVectorRegressionSolution() : base() { }
49    public SymbolicVectorRegressionSolution(MultiVariateDataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter)
50      : base() {
51      var selectedTargetVariables = (from targetVariable in problemData.TargetVariables
52                                     where problemData.TargetVariables.ItemChecked(targetVariable)
53                                     select targetVariable.Value).ToArray();
54
55
56      regressionSolutions = new Dictionary<string, SymbolicRegressionSolution>();
57      for (int i = 0; i < selectedTargetVariables.Length; i++) {
58        SymbolicExpressionTree componentTree = (SymbolicExpressionTree)tree.Clone();
59        List<SymbolicExpressionTreeNode> componentBranches = new List<SymbolicExpressionTreeNode>(componentTree.Root.SubTrees[0].SubTrees);
60        // use only the i-th vector component
61        while (componentTree.Root.SubTrees[0].SubTrees.Count > 0) componentTree.Root.SubTrees[0].RemoveSubTree(0);
62        componentTree.Root.SubTrees[0].AddSubTree(componentBranches[i]);
63        var componentSolution = CreateSymbolicRegressionSolution(problemData, componentTree, selectedTargetVariables[i], interpreter);
64        regressionSolutions.Add(selectedTargetVariables[i], componentSolution);
65      }
66
67    }
68
69    private static SymbolicRegressionSolution CreateSymbolicRegressionSolution(
70      MultiVariateDataAnalysisProblemData problemData,
71      SymbolicExpressionTree symbolicExpressionTree,
72      string targetVariable,
73      ISymbolicExpressionTreeInterpreter interpreter) {
74      return new SymbolicRegressionSolution(problemData.ConvertToDataAnalysisProblemData(targetVariable), new SymbolicRegressionModel(interpreter, symbolicExpressionTree), double.NegativeInfinity, double.PositiveInfinity);
75    }
76
77    public override Image ItemImage {
78      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; }
79    }
80
81    public SymbolicRegressionSolution GetModelFor(string targetVariable) {
82      return regressionSolutions[targetVariable];
83    }
84
85    public override IDeepCloneable Clone(Cloner cloner) {
86      SymbolicVectorRegressionSolution clone = (SymbolicVectorRegressionSolution)base.Clone(cloner);
87      clone.regressionSolutions = new Dictionary<string, SymbolicRegressionSolution>(regressionSolutions.Count);
88      foreach (var pair in regressionSolutions)
89        clone.regressionSolutions.Add(pair.Key, (SymbolicRegressionSolution)cloner.Clone(pair.Value));
90      return clone;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.