Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5717


Ignore:
Timestamp:
03/16/11 16:34:31 (13 years ago)
Author:
gkronber
Message:

#1418 Implemented interactive simplifier views for symbolic classification and regression.

Location:
branches/DataAnalysis Refactoring
Files:
4 added
29 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj

    r5694 r5717  
    128128      <DependentUpon>SupportVectorMachineModelView.cs</DependentUpon>
    129129    </Compile>
    130     <Compile Include="SupportVectorRegressionSolutionView.cs" />
     130    <Compile Include="SupportVectorRegressionSolutionView.cs">
     131      <SubType>UserControl</SubType>
     132    </Compile>
    131133    <Compile Include="SupportVectorRegressionSolutionView.Designer.cs">
    132134      <DependentUpon>SupportVectorRegressionSolutionView.cs</DependentUpon>
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/ISupportVectorMachineModel.cs

    r5694 r5717  
    2929  /// Interface to represent a support vector machine model
    3030  /// </summary>
    31   public interface ISupportVectorMachineModel : IDataAnalysisModel {
     31  public interface ISupportVectorMachineModel : IDataAnalysisModel, IRegressionModel, IClassificationModel {
    3232    SVM.Model Model { get; }
    3333    SVM.RangeTransform RangeTransform { get; }
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/ISupportVectorMachineSolution.cs

    r5694 r5717  
    2929  /// </summary>
    3030  public interface ISupportVectorMachineSolution : IDataAnalysisSolution {
    31     ISupportVectorMachineModel Model { get; }
     31    new ISupportVectorMachineModel Model { get; }
    3232  }
    3333}
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassificationSolution.cs

    r5694 r5717  
    3939    public new ISupportVectorMachineModel Model {
    4040      get { return (ISupportVectorMachineModel)base.Model; }
     41      set { base.Model = value; }
    4142    }
    4243
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs

    r5694 r5717  
    3838  [StorableClass]
    3939  [Item("SupportVectorMachineModel", "Represents a support vector machine model.")]
    40   public sealed class SupportVectorMachineModel : NamedItem, ISupportVectorMachineModel, IRegressionModel, IClassificationModel {
     40  public sealed class SupportVectorMachineModel : NamedItem, ISupportVectorMachineModel {
    4141
    4242    private SVM.Model model;
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegressionSolution.cs

    r5694 r5717  
    3939    public new ISupportVectorMachineModel Model {
    4040      get { return (ISupportVectorMachineModel)base.Model; }
     41      set { base.Model = value; }
    4142    }
    4243
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringSolution.cs

    r5651 r5717  
    4242    public new KMeansClusteringModel Model {
    4343      get { return (KMeansClusteringModel)base.Model; }
     44      set { base.Model = value; }
    4445    }
    4546
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.csproj

    r5699 r5717  
    110110  </ItemGroup>
    111111  <ItemGroup>
     112    <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionView.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionView.Designer.cs">
     116      <DependentUpon>SymbolicDiscriminantFunctionClassificationSolutionView.cs</DependentUpon>
     117    </Compile>
    112118    <None Include="HeuristicLab.snk" />
    113119    <None Include="HeuristicLabProblemsDataAnalysisSymbolicClassificationViewsPlugin.cs.frame" />
    114120    <None Include="Properties\AssemblyInfo.frame" />
    115121    <Compile Include="HeuristicLabProblemsDataAnalysisSymbolicClassificationViewsPlugin.cs" />
     122    <Compile Include="InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs">
     123      <SubType>UserControl</SubType>
     124    </Compile>
     125    <Compile Include="InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.Designer.cs">
     126      <DependentUpon>InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs</DependentUpon>
     127    </Compile>
    116128    <Compile Include="Properties\AssemblyInfo.cs" />
    117129  </ItemGroup>
     
    141153      <Name>HeuristicLab.Data-3.3</Name>
    142154    </ProjectReference>
     155    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
     156      <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
     157      <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
     158    </ProjectReference>
    143159    <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.ALGLIB\3.1.0\ALGLIB-3.1.0\ALGLIB-3.1.0.csproj">
    144160      <Project>{FC841674-62A7-4055-BE91-E41944B6C606}</Project>
     
    176192      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    177193      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
     194    </ProjectReference>
     195    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj">
     196      <Project>{05BAE4E1-A9FA-4644-AA77-42558720159E}</Project>
     197      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4</Name>
     198    </ProjectReference>
     199    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Views\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj">
     200      <Project>{7A2531CE-3F7C-4F13-BCCA-ED6DC27A7086}</Project>
     201      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4</Name>
     202    </ProjectReference>
     203    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
     204      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
     205      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
     206    </ProjectReference>
     207    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Views\3.4\HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj">
     208      <Project>{3E9E8944-44FF-40BB-A622-3A4A7DD0F198}</Project>
     209      <Name>HeuristicLab.Problems.DataAnalysis.Views-3.4</Name>
    178210    </ProjectReference>
    179211    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj

    r5685 r5717  
    112112    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs" />
    113113    <Compile Include="SymbolicDiscriminantFunctionClassificationModel.cs" />
    114     <Compile Include="SymbolicDiscriminantFunctionClassificationSolution.cs" />
    115114    <Compile Include="Interfaces\ISymbolicClassificationModel.cs" />
    116115    <Compile Include="Interfaces\ISymbolicClassificationSolution.cs" />
     
    130129    </Compile>
    131130    <Compile Include="SymbolicClassificationSolution.cs" />
     131    <Compile Include="SymbolicDiscriminantFunctionClassificationSolution.cs">
     132      <SubType>Code</SubType>
     133    </Compile>
    132134    <None Include="HeuristicLab.snk" />
    133135    <None Include="HeuristicLabProblemsDataAnalysisSymbolicClassificationPlugin.cs.frame" />
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModel.cs

    r5649 r5717  
    2222using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2323namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    24   public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicDataAnalysisModel {
     24  public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicClassificationModel {
    2525  }
    2626}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolution.cs

    r5624 r5717  
    3838  [StorableClass]
    3939  [Item(Name = "SymbolicClassificationSolution", Description = "Represents a symbolic classification solution (model + data) and attributes of the solution like accuracy and complexity.")]
    40   public class SymbolicClassificationSolution : ClassificationSolution, ISymbolicClassificationSolution {
     40  public sealed class SymbolicClassificationSolution : ClassificationSolution, ISymbolicClassificationSolution {
    4141    #region ISymbolicClassificationSolution Members
    4242
    4343    public new ISymbolicClassificationModel Model {
    4444      get { return (ISymbolicClassificationModel)base.Model; }
     45      set { base.Model = value; }
    4546    }
    4647
     
    5152    #endregion
    5253    [StorableConstructor]
    53     protected SymbolicClassificationSolution(bool deserializing) : base(deserializing) { }
    54     protected SymbolicClassificationSolution(SymbolicClassificationSolution original, Cloner cloner)
     54    private SymbolicClassificationSolution(bool deserializing) : base(deserializing) { }
     55    private SymbolicClassificationSolution(SymbolicClassificationSolution original, Cloner cloner)
    5556      : base(original, cloner) {
    5657    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolution.cs

    r5678 r5717  
    3838  [StorableClass]
    3939  [Item(Name = "SymbolicDiscriminantFunctionClassificationSolution", Description = "Represents a symbolic classification solution (model + data) and attributes of the solution like accuracy and complexity.")]
    40   public class SymbolicDiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolution, ISymbolicClassificationSolution {
    41     #region ISymbolicClassificationSolution Members
     40  public sealed class SymbolicDiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolution, ISymbolicClassificationSolution {
    4241
    43     public new IDiscriminantFunctionClassificationModel Model {
    44       get { return (IDiscriminantFunctionClassificationModel)base.Model; }
     42    public new ISymbolicDiscriminantFunctionClassificationModel Model {
     43      get { return (ISymbolicDiscriminantFunctionClassificationModel)base.Model; }
     44      set { base.Model = value; }
    4545    }
    4646
    4747    ISymbolicClassificationModel ISymbolicClassificationSolution.Model {
    48       get { return (ISymbolicClassificationModel)Model; }
     48      get { return Model; }
    4949    }
    5050
    5151    ISymbolicDataAnalysisModel ISymbolicDataAnalysisSolution.Model {
    52       get { return (ISymbolicDataAnalysisModel)Model; }
     52      get { return Model; }
    5353    }
    5454
    55     #endregion
    5655    [StorableConstructor]
    57     protected SymbolicDiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { }
    58     protected SymbolicDiscriminantFunctionClassificationSolution(SymbolicDiscriminantFunctionClassificationSolution original, Cloner cloner)
     56    private SymbolicDiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { }
     57    private SymbolicDiscriminantFunctionClassificationSolution(SymbolicDiscriminantFunctionClassificationSolution original, Cloner cloner)
    5958      : base(original, cloner) {
    6059    }
    61     public SymbolicDiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
     60    public SymbolicDiscriminantFunctionClassificationSolution(ISymbolicDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
    6261      : base(model, problemData) {
    6362    }
     
    6564    public override IDeepCloneable Clone(Cloner cloner) {
    6665      return new SymbolicDiscriminantFunctionClassificationSolution(this, cloner);
    67     } 
     66    }
    6867  }
    6968}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r5699 r5717  
    3434    private readonly ConstantTreeNode constantNode;
    3535    private readonly SymbolicExpressionTree tempTree;
     36
     37    public new SymbolicRegressionSolution Content {
     38      get { return (SymbolicRegressionSolution)base.Content; }
     39      set { base.Content = value; }
     40    }
     41
    3642    public InteractiveSymbolicRegressionSolutionSimplifierView()
    3743      : base() {
     
    4652    }
    4753
    48     public new ISymbolicRegressionSolution Content {
    49       get { return (ISymbolicRegressionSolution)base.Content; }
    50       set { base.Content = value; }
     54    protected override void UpdateModel(ISymbolicExpressionTree tree) {
     55      Content.Model = new SymbolicRegressionModel(tree, Content.Model.Interpreter);
    5156    }
    5257
    53     protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     58    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    5459      Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    5560      foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    5661        if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
    57           replacementValues[node] = CalculateReplacementValue(node, interpreter, dataset, rows);
     62          replacementValues[node] = CalculateReplacementValue(node);
    5863        }
    5964      }
     
    6166    }
    6267
    63     protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     68    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
     69      var interpreter = Content.Model.Interpreter;
     70      var dataset = Content.ProblemData.Dataset;
     71      var rows = Content.ProblemData.TrainingIndizes;
     72      string targetVariable = Content.ProblemData.TargetVariable;
    6473      Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    6574      List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubTree(0).GetSubTree(0).IterateNodesPostfix().ToList();
    6675      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
    6776        .ToArray();
     77      var targetValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
     78
     79      double originalR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, originalOutput);
    6880
    6981      foreach (ISymbolicExpressionTreeNode node in nodes) {
    7082        var parent = node.Parent;
    71         constantNode.Value = CalculateReplacementValue(node, interpreter, dataset, rows);
     83        constantNode.Value = CalculateReplacementValue(node);
    7284        ISymbolicExpressionTreeNode replacementNode = constantNode;
    7385        SwitchNode(parent, node, replacementNode);
    74         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();
     86        var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
     87        double newR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, newOutput);
    7588
    76         impactValues[node] = 1 - OnlinePearsonsRSquaredEvaluator.Calculate(originalOutput, newOutput);
     89        // impact = 0 if no change
     90        // impact < 0 if new solution is better
     91        // impact > 0 if new solution is worse
     92        impactValues[node] = originalR2 - newR2;
    7793        SwitchNode(parent, replacementNode, node);
    7894      }
     
    8096    }
    8197
    82     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset dataset, IEnumerable<int> rows) {
     98    private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) {
    8399      var start = tempTree.Root.GetSubTree(0);
    84100      while (start.SubTrees.Count() > 0) start.RemoveSubTree(0);
    85101      start.AddSubTree((ISymbolicExpressionTreeNode)node.Clone());
     102      var interpreter = Content.Model.Interpreter;
     103      var rows = Content.ProblemData.TrainingIndizes;
    86104      return interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows).Median();
    87105    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs

    r5699 r5717  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    28   [Content(typeof(ISymbolicRegressionSolution))]
     28  [Content(typeof(SymbolicRegressionSolution))]
    2929  [View("Symbolic Regression Solution View")]
    3030  public partial class SymbolicRegressionSolutionView : DataAnalysisSolutionView {
     
    3333    }
    3434
    35     protected new ISymbolicRegressionSolution Content {
    36       get { return (ISymbolicRegressionSolution)base.Content; }
     35    protected new SymbolicRegressionSolution Content {
     36      get { return (SymbolicRegressionSolution)base.Content; }
    3737      set { base.Content = value; }
    3838    }
     
    4040    private void btn_SimplifyModel_Click(object sender, EventArgs e) {
    4141      InteractiveSymbolicRegressionSolutionSimplifierView view = new InteractiveSymbolicRegressionSolutionSimplifierView();
    42       view.Content = (ISymbolicRegressionSolution)this.Content.Clone();
     42      view.Content = (SymbolicRegressionSolution)this.Content.Clone();
    4343      view.Show();
    4444    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r5624 r5717  
    3838  [StorableClass]
    3939  [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")]
    40   public class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution {
     40  public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution {
    4141    #region ISymbolicRegressionSolution Members
    4242
    4343    public new ISymbolicRegressionModel Model {
    4444      get { return (ISymbolicRegressionModel)base.Model; }
     45      set { base.Model = value; }
    4546    }
    4647    ISymbolicDataAnalysisModel ISymbolicDataAnalysisSolution.Model {
     
    5152
    5253    [StorableConstructor]
    53     protected SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
    54     protected SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner)
     54    private SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
     55    private SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner)
    5556      : base(original, cloner) {
    5657    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r5699 r5717  
    8888        simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    8989
    90         var replacementValues = CalculateReplacementValues(Content.Model.Interpreter, simplifiedExpressionTree, Content.ProblemData.Dataset, Content.ProblemData.TrainingIndizes);
     90        var replacementValues = CalculateReplacementValues(simplifiedExpressionTree);
    9191        foreach (var pair in replacementValues) {
    9292          replacementNodes.Add(pair.Key, MakeConstantTreeNode(pair.Value));
    9393        }
    94         nodeImpacts = CalculateImpactValues(Content.Model.Interpreter, simplifiedExpressionTree, Content.ProblemData.Dataset, Content.ProblemData.TrainingIndizes);
     94        nodeImpacts = CalculateImpactValues(simplifiedExpressionTree);
    9595
    9696        // automatically fold all branches with impact = 1
     
    110110    }
    111111
    112     protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);
    113     protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);
     112    protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree);
     113    protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree);
     114    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
    114115
    115116    private ConstantTreeNode MakeConstantTreeNode(double value) {
     
    137138
    138139      SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone();
    139 
    140       //this.Content.ModelChanged -= new EventHandler(Content_ModelChanged);
    141       //this.Content.Model = new SymbolicRegressionModel(Content.Model.Interpreter, tree);
    142       //this.Content.ModelChanged += new EventHandler(Content_ModelChanged);
    143 
     140      UpdateModel(tree);
    144141      this.PaintNodeImpacts();
    145142    }
     
    166163          VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
    167164         
    168           //if (impact < 1.0) {
    169           //  visualTree.FillColor = Color.FromArgb((int)((1.0 - impact) * 255), Color.Red);
    170           //} else {
    171           visualTree.FillColor = Color.FromArgb((int)((impact - 1.0) / max * 255), Color.Green);
    172           //}
     165          // impact = 0 if no change
     166          // impact < 0 if new solution is better
     167          // impact > 0 if new solution is worse
     168          if (impact < 0.0) {
     169            visualTree.FillColor = Color.FromArgb((int)(impact / min * 255), Color.Red);
     170          } else {
     171            visualTree.FillColor = Color.FromArgb((int)(impact / max * 255), Color.Green);
     172          }
    173173          visualTree.ToolTip += Environment.NewLine + "Node impact: " + impact;
    174174          visualTree.ToolTip += Environment.NewLine + "Replacement value: " + replacementValue;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r5649 r5717  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3636  /// <summary>
    37   /// Abstract base class symbolic data analysis models
     37  /// Abstract base class for symbolic data analysis models
    3838  /// </summary>
    3939  [StorableClass]
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionView.cs

    r5664 r5717  
    8787      Content.ModelChanged += new EventHandler(Content_ModelChanged);
    8888      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    89       Content.ThresholdsChanged += new EventHandler(Content_ThresholdsChanged);
    9089    }
    9190    protected override void DeregisterContentEvents() {
     
    9392      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
    9493      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    95       Content.ThresholdsChanged -= new EventHandler(Content_ThresholdsChanged);
    9694    }
    9795
     
    168166      chart.Annotations.Clear();
    169167      int classIndex = 1;
    170       foreach (double threshold in Content.Thresholds) {
     168      foreach (double threshold in Content.Model.Thresholds) {
    171169        if (!double.IsInfinity(threshold)) {
    172170          HorizontalLineAnnotation annotation = new HorizontalLineAnnotation();
     
    235233    private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) {
    236234      int classIndex = (int)e.Annotation.Tag;
    237       double[] thresholds = Content.Thresholds.ToArray();
     235      double[] thresholds = Content.Model.Thresholds.ToArray();
    238236      double max = thresholds[classIndex + 1];
    239237      double min = thresholds[classIndex - 1];
     
    246244
    247245      thresholds[classIndex] = e.NewLocationY;
    248       Content.Thresholds = thresholds;
     246      Content.Model.Thresholds = thresholds;
    249247    }
    250248
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationEnsembleModel.cs

    r5662 r5717  
    5454      this.name = ItemName;
    5555      this.description = ItemDescription;
    56       this.models = new List<IClassificationModel>(models);
     56      this.models = new List<IClassificationModel>(models);     
    5757    }
    5858
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationSolution.cs

    r5649 r5717  
    3939    private const string TrainingAccuracyResultName = "Accuracy (training)";
    4040    private const string TestAccuracyResultName = "Accuracy (test)";
     41
     42    public new IClassificationModel Model {
     43      get { return (IClassificationModel)base.Model; }
     44      protected set { base.Model = value; }
     45    }
     46
     47    public new IClassificationProblemData ProblemData {
     48      get { return (IClassificationProblemData)base.ProblemData; }
     49      protected set { base.ProblemData = value; }
     50    }
     51
     52    public double TrainingAccuracy {
     53      get { return ((DoubleValue)this[TrainingAccuracyResultName].Value).Value; }
     54      private set { ((DoubleValue)this[TrainingAccuracyResultName].Value).Value = value; }
     55    }
     56
     57    public double TestAccuracy {
     58      get { return ((DoubleValue)this[TestAccuracyResultName].Value).Value; }
     59      private set { ((DoubleValue)this[TestAccuracyResultName].Value).Value = value; }
     60    }
     61
    4162    [StorableConstructor]
    4263    protected ClassificationSolution(bool deserializing) : base(deserializing) { }
     
    4667    public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData)
    4768      : base(model, problemData) {
     69      Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue()));
     70      Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue()));
     71      RecalculateResults();
     72    }
     73
     74    protected override void OnProblemDataChanged(EventArgs e) {
     75      base.OnProblemDataChanged(e);
     76      RecalculateResults();
     77    }
     78
     79    protected override void OnModelChanged(EventArgs e) {
     80      base.OnModelChanged(e);
     81      RecalculateResults();
     82    }
     83
     84    private void RecalculateResults() {
    4885      double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values
    4986      IEnumerable<double> originalTrainingClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     
    5491      double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues);
    5592
    56       Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue(trainingAccuracy)));
    57       Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue(testAccuracy)));
    58     }
    59 
    60     #region IClassificationSolution Members
    61 
    62     public new IClassificationModel Model {
    63       get { return (IClassificationModel)base.Model; }
    64     }
    65 
    66     public new IClassificationProblemData ProblemData {
    67       get { return (IClassificationProblemData)base.ProblemData; }
     93      TrainingAccuracy = trainingAccuracy;
     94      TestAccuracy = testAccuracy;
    6895    }
    6996
     
    89116      return Model.GetEstimatedClassValues(ProblemData.Dataset, rows);
    90117    }
    91     #endregion
    92118  }
    93119}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClusteringSolution.cs

    r5649 r5717  
    5151    public new IClusteringModel Model {
    5252      get { return (IClusteringModel)base.Model; }
     53      set { base.Model = value; }
    5354    }
    5455
    5556    public new IClusteringProblemData ProblemData {
    5657      get { return (IClusteringProblemData)base.ProblemData; }
     58      set { base.ProblemData = value; }
    5759    }
    5860
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisSolution.cs

    r5649 r5717  
    4848    public IDataAnalysisModel Model {
    4949      get { return (IDataAnalysisModel)this[ModelResultName].Value; }
    50       //set {
    51       //  if (this[ModelResultName].Value != value) {
    52       //    if (value != null) {
    53       //      this[ModelResultName].Value = value;
    54       //      OnModelChanged(EventArgs.Empty);
    55       //    }
    56       //  }
    57       //}
     50      protected set {
     51        if (this[ModelResultName].Value != value) {
     52          if (value != null) {
     53            this[ModelResultName].Value = value;
     54            OnModelChanged(EventArgs.Empty);
     55          }
     56        }
     57      }
    5858    }
    5959
    6060    public IDataAnalysisProblemData ProblemData {
    6161      get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
    62       //set {
    63       //  if (this[ProblemDataResultName].Value != value) {
    64       //    if (value != null) {
    65       //      ProblemData.Changed -= new EventHandler(ProblemData_Changed);
    66       //      this[ProblemDataResultName].Value = value;
    67       //      ProblemData.Changed += new EventHandler(ProblemData_Changed);
    68       //      OnProblemDataChanged(EventArgs.Empty);
    69       //    }
    70       //  }
    71       //}
     62      protected set {
     63        if (this[ProblemDataResultName].Value != value) {
     64          if (value != null) {
     65            ProblemData.Changed -= new EventHandler(ProblemData_Changed);
     66            this[ProblemDataResultName].Value = value;
     67            ProblemData.Changed += new EventHandler(ProblemData_Changed);
     68            OnProblemDataChanged(EventArgs.Empty);
     69          }
     70        }
     71      }
    7272    }
    7373    #endregion
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DiscriminantFunctionClassificationSolution.cs

    r5681 r5717  
    3838  [Item("DiscriminantFunctionClassificationSolution", "Represents a classification solution that uses a discriminant function and classification thresholds.")]
    3939  public class DiscriminantFunctionClassificationSolution : ClassificationSolution, IDiscriminantFunctionClassificationSolution {
     40    public new IDiscriminantFunctionClassificationModel Model {
     41      get { return (IDiscriminantFunctionClassificationModel)base.Model; }
     42      protected set { base.Model = value; }
     43    }
     44
    4045    [StorableConstructor]
    4146    protected DiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { }
     
    4853    public DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
    4954      : base(model, problemData) {
    50       Model.ThresholdsChanged += new EventHandler(Model_ThresholdsChanged);
    51     }
    52 
    53     #region IDiscriminantFunctionClassificationSolution Members
    54 
    55     public new IDiscriminantFunctionClassificationModel Model {
    56       get { return (IDiscriminantFunctionClassificationModel)base.Model; }
    5755    }
    5856
     
    7270      return Model.GetEstimatedValues(ProblemData.Dataset, rows);
    7371    }
    74 
    75     public IEnumerable<double> Thresholds {
    76       get {
    77         return Model.Thresholds;
    78       }
    79       set { Model.Thresholds = new List<double>(value); }
    80     }
    81 
    82     public event EventHandler ThresholdsChanged;
    83 
    84     private void Model_ThresholdsChanged(object sender, EventArgs e) {
    85       OnThresholdsChanged(e);
    86     }
    87 
    88     protected virtual void OnThresholdsChanged(EventArgs e) {
    89       var listener = ThresholdsChanged;
    90       if (listener != null) listener(this, e);
    91     }
    92     #endregion
    9372  }
    9473}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationSolution.cs

    r5649 r5717  
    3131    IEnumerable<double> EstimatedTestClassValues { get; }
    3232    IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows);
     33
     34    double TrainingAccuracy { get; }
     35    double TestAccuracy { get; }
    3336  }
    3437}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r5678 r5717  
    2626    IEnumerable<double> Thresholds { get; set; }
    2727    IEnumerable<double> ClassValues { get; set; }
     28    IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);
     29
    2830    event EventHandler ThresholdsChanged;
    29     IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);
    3031  }
    3132}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationSolution.cs

    r5664 r5717  
    3030    IEnumerable<double> EstimatedTestValues { get; }
    3131    IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);
    32 
    33     IEnumerable<double> Thresholds { get; set; }
    34 
    35     event EventHandler ThresholdsChanged;
    3632  }
    3733}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionSolution.cs

    r5530 r5717  
    3030    IEnumerable<double> EstimatedTestValues { get; }
    3131    IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);
     32
     33    double TrainingMeanSquaredError { get; }
     34    double TestMeanSquaredError { get; }
     35    double TrainingRSquared { get; }
     36    double TestRSquared { get; }
    3237  }
    3338}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/RegressionSolution.cs

    r5649 r5717  
    4444    private const string TestRelativeErrorResultName = "Average relative error (test)";
    4545
     46    public new IRegressionModel Model {
     47      get { return (IRegressionModel)base.Model; }
     48      protected set { base.Model = value; }
     49    }
     50
     51    public new IRegressionProblemData ProblemData {
     52      get { return (IRegressionProblemData)base.ProblemData; }
     53      protected set { base.ProblemData = value; }
     54    }
     55
     56    public double TrainingMeanSquaredError {
     57      get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; }
     58      private set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }
     59    }
     60
     61    public double TestMeanSquaredError {
     62      get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; }
     63      private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }
     64    }
     65
     66    public double TrainingRSquared {
     67      get { return ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value; }
     68      private set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }
     69    }
     70
     71    public double TestRSquared {
     72      get { return ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value; }
     73      private set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }
     74    }
     75
     76    public double TrainingRelativeError {
     77      get { return ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value; }
     78      private set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }
     79    }
     80
     81    public double TestRelativeError {
     82      get { return ((DoubleValue)this[TestRelativeErrorResultName].Value).Value; }
     83      private set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }
     84    }
     85
     86
    4687    [StorableConstructor]
    4788    protected RegressionSolution(bool deserializing) : base(deserializing) { }
     
    5192    public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData)
    5293      : base(model, problemData) {
     94      Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
     95      Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
     96      Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
     97      Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     98      Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));
     99      Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));
     100
     101      RecalculateResults();
     102    }
     103
     104    protected override void OnProblemDataChanged(EventArgs e) {
     105      base.OnProblemDataChanged(e);
     106      RecalculateResults();
     107    }
     108    protected override void OnModelChanged(EventArgs e) {
     109      base.OnModelChanged(e);
     110      RecalculateResults();
     111    }
     112
     113    private void RecalculateResults() {
    53114      double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
    54115      IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     
    63124      double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues);
    64125
    65       Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue(trainingMSE)));
    66       Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue(testMSE)));
    67       Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue(trainingR2)));
    68       Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue(testR2)));
    69       Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue(trainingRelError)));
    70       Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue(testRelError)));
    71     }
    72 
    73     protected override void OnProblemDataChanged(EventArgs e) {
    74       base.OnProblemDataChanged(e);
    75       throw new NotImplementedException(); // need to recalculate results
    76     }
    77     protected override void OnModelChanged(EventArgs e) {
    78       base.OnModelChanged(e);
    79       throw new NotImplementedException(); // need to recalculate results
    80     }
    81     #region IRegressionSolution Members
    82 
    83     public new IRegressionModel Model {
    84       get { return (IRegressionModel)base.Model; }
    85     }
    86 
    87     public new IRegressionProblemData ProblemData {
    88       get { return (IRegressionProblemData)base.ProblemData; }
     126      TrainingMeanSquaredError = trainingMSE;
     127      TestMeanSquaredError = testMSE;
     128      TrainingRSquared = trainingR2;
     129      TestRSquared = testR2;
     130      TrainingRelativeError = trainingRelError;
     131      TestRelativeError = testRelError;
    89132    }
    90133
     
    110153      return Model.GetEstimatedValues(ProblemData.Dataset, rows);
    111154    }
    112     #endregion
    113155  }
    114156}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs

    r5681 r5717  
    7676      int[,] confusionMatrix = new int[nClasses, nClasses];
    7777
    78       // one threshold is always treated as binary separation of the remaining classes
    7978      for (int i = 1; i < thresholds.Length - 1; i++) {
    8079        double lowerThreshold = thresholds[i - 1];
Note: See TracChangeset for help on using the changeset viewer.