Changeset 4417


Ignore:
Timestamp:
09/16/10 17:17:51 (9 years ago)
Author:
mkommend
Message:

adapted classification analyzer and readded views project (ticket #939)

Location:
branches/HeuristicLab.Classification
Files:
15 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Classification/HeuristicLab.Classification.sln

    r4391 r4417  
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Classification", "HeuristicLab.Classification\HeuristicLab.Classification.csproj", "{3AB5A7E5-9F0C-4920-B18D-E06B9577618C}"
    55  ProjectSection(ProjectDependencies) = postProject
     6    {7F038E9A-B91E-4F49-8C27-D47BC86F1220} = {7F038E9A-B91E-4F49-8C27-D47BC86F1220}
    67    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E} = {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}
    78  EndProjectSection
     
    3536    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|Any CPU.ActiveCfg = Release|Any CPU
    3637    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|Any CPU.Build.0 = Release|Any CPU
    37     {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|x64.ActiveCfg = Release|Any CPU
     38    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|x64.ActiveCfg = Release|x64
     39    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|x64.Build.0 = Release|x64
    3840    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|x86.ActiveCfg = Release|x86
    3941    {3AB5A7E5-9F0C-4920-B18D-E06B9577618C}.Release|x86.Build.0 = Release|x86
     
    4648    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|Any CPU.ActiveCfg = Release|Any CPU
    4749    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|Any CPU.Build.0 = Release|Any CPU
    48     {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|x64.ActiveCfg = Release|Any CPU
     50    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|x64.ActiveCfg = Release|x64
     51    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|x64.Build.0 = Release|x64
    4952    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|x86.ActiveCfg = Release|x86
    5053    {D35FD6DB-D704-4BEA-BDAE-C40ABFB5B13E}.Release|x86.Build.0 = Release|x86
     
    5760    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|Any CPU.ActiveCfg = Release|Any CPU
    5861    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|Any CPU.Build.0 = Release|Any CPU
    59     {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|x64.ActiveCfg = Release|Any CPU
     62    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|x64.ActiveCfg = Release|x64
     63    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|x64.Build.0 = Release|x64
    6064    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|x86.ActiveCfg = Release|x86
    6165    {7F038E9A-B91E-4F49-8C27-D47BC86F1220}.Release|x86.Build.0 = Release|x86
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/HeuristicLab.Problems.DataAnalysis.Classification-3.3.csproj

    r4391 r4417  
    140140    <Reference Include="System.Core" />
    141141    <Reference Include="System.Drawing" />
    142     <Reference Include="System.Xml.Linq" />
    143     <Reference Include="System.Data.DataSetExtensions" />
    144142    <Reference Include="System.Data" />
    145     <Reference Include="System.Xml" />
    146143  </ItemGroup>
    147144  <ItemGroup>
     
    156153    <Compile Include="Interfaces\ISymbolicClassificationAnalyzer.cs" />
    157154    <Compile Include="Symbolic\Analyzer\ValidationBestSymbolicClassificationSolutionAnalyzer.cs" />
     155    <Compile Include="Symbolic\Evaluators\OnlineAccuracyEvaluator.cs" />
    158156    <Compile Include="Symbolic\Evaluators\SymbolicClassificationPearsonRSquaredEvaluator.cs" />
    159157    <Compile Include="Symbolic\SymbolicClassificationSolution.cs" />
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic/Analyzer/ValidationBestSymbolicClassificationSolutionAnalyzer.cs

    r4391 r4417  
    5555    private const string BestValidationQualityParameterName = "Best validation quality";
    5656    private const string BestValidationSolutionParameterName = "Best validation solution";
    57     private const string BestSolutionGenerationParameterName = "Best solution generation";
    58     private const string BestSolutionInputvariableCountParameterName = "Variables used by best solution";
     57    private const string BestSolutionAccuracyTrainingParameterName = "Best solution accuracy (training)";
     58    private const string BestSolutionAccuracyTestParameterName = "Best solution accuracy (test)";
    5959    private const string VariableFrequenciesParameterName = "VariableFrequencies";
    60     private const string VariableImpactsParameterName = "Variable Impacts";
    6160
    6261    #region parameter properties
     
    111110      get { return (ILookupParameter<SymbolicClassificationSolution>)Parameters[BestValidationSolutionParameterName]; }
    112111    }
    113     public ILookupParameter<IntValue> BestSolutionGenerationParameter {
    114       get { return (ILookupParameter<IntValue>)Parameters[BestSolutionGenerationParameterName]; }
    115     }
    116     public ILookupParameter<DoubleMatrix> VariableImpactsParameter {
    117       get { return (ILookupParameter<DoubleMatrix>)Parameters[VariableImpactsParameterName]; }
    118     }
    119     public ILookupParameter<IntValue> BestSolutionInputvariableCountParameter {
    120       get { return (ILookupParameter<IntValue>)Parameters[BestSolutionInputvariableCountParameterName]; }
     112    public ILookupParameter<DoubleValue> BestSolutionAccuracyTrainingParameter {
     113      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionAccuracyTrainingParameterName]; }
     114    }
     115    public ILookupParameter<DoubleValue> BestSolutionAccuracyTestParameter {
     116      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionAccuracyTestParameterName]; }
    121117    }
    122118    #endregion
     
    174170      protected set { BestValidationSolutionParameter.ActualValue = value; }
    175171    }
    176     public IntValue BestSolutionGeneration {
    177       get { return BestSolutionGenerationParameter.ActualValue; }
    178       protected set { BestSolutionGenerationParameter.ActualValue = value; }
    179     }
    180     public IntValue BestSolutionInputvariableCount {
    181       get { return BestSolutionInputvariableCountParameter.ActualValue; }
    182       protected set { BestSolutionInputvariableCountParameter.ActualValue = value; }
    183     }
    184     public DoubleMatrix VariableImpacts {
    185       get { return VariableImpactsParameter.ActualValue; }
    186       protected set { VariableImpactsParameter.ActualValue = value; }
     172    public DoubleValue BestSolutionAccuracyTraining {
     173      get { return BestSolutionAccuracyTrainingParameter.ActualValue; }
     174      protected set { BestSolutionAccuracyTrainingParameter.ActualValue = value; }
     175    }
     176    public DoubleValue BestSolutionAccuracyTest {
     177      get { return BestSolutionAccuracyTestParameter.ActualValue; }
     178      protected set { BestSolutionAccuracyTestParameter.ActualValue = value; }
    187179    }
    188180    #endregion
     
    208200      Parameters.Add(new LookupParameter<DoubleValue>(BestValidationQualityParameterName, "The validation quality of the best solution in the current run."));
    209201      Parameters.Add(new LookupParameter<SymbolicClassificationSolution>(BestValidationSolutionParameterName, "The best solution on the validation data found in the current run."));
    210       Parameters.Add(new LookupParameter<IntValue>(BestSolutionGenerationParameterName, "The generation in which the best solution was found."));
    211       Parameters.Add(new LookupParameter<DoubleMatrix>(VariableImpactsParameterName, "The impacts of the input variables calculated during the run."));
    212       Parameters.Add(new LookupParameter<IntValue>(BestSolutionInputvariableCountParameterName, "The number of input variables used by the best solution."));
    213 
     202      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTrainingParameterName, "The training accuracy of the best solution."));
     203      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTestParameterName, "The test accuracy of the best solution."));
    214204    }
    215205
     
    272262          BestValidationSolution.Description = "Best solution on validation partition found over the whole run.";
    273263          BestValidationQuality = new DoubleValue(bestQuality);
    274           BestSolutionGeneration = (IntValue)Generations.Clone();
    275           BestSolutionInputvariableCount = new IntValue(BestValidationSolution.Model.InputVariables.Count());
    276 
    277           Results.Add(new Result(BestValidationSolutionParameterName, BestValidationSolution));
    278           Results.Add(new Result(BestValidationQualityParameterName, BestValidationQuality));
    279           Results.Add(new Result(BestSolutionGenerationParameterName, BestSolutionGeneration));
    280 
    281           Results.Add(new Result(BestSolutionInputvariableCountParameterName, BestSolutionInputvariableCount));
    282 
    283           if (VariableFrequencies != null) {
    284             VariableImpacts = CalculateVariableImpacts(VariableFrequencies);
    285             Results.Add(new Result(VariableImpactsParameterName, VariableImpacts));
    286           }
    287 
    288264        } else {
    289265          BestValidationSolution.Model = model;
    290           BestValidationQuality.Value = bestQuality;
    291           BestSolutionGeneration.Value = Generations.Value;
    292           BestSolutionInputvariableCount.Value = BestValidationSolution.Model.InputVariables.Count();
    293 
    294           if (VariableFrequencies != null) {
    295             VariableImpacts = CalculateVariableImpacts(VariableFrequencies);
    296             Results[VariableImpactsParameterName].Value = VariableImpacts;
    297           }
    298266        }
     267
     268        UpdateBestSolutionResults();
    299269      }
    300270      return base.Apply();
    301271    }
    302272
    303     private static DoubleMatrix CalculateVariableImpacts(DataTable variableFrequencies) {
    304       if (variableFrequencies != null) {
    305         var impacts = new DoubleMatrix(variableFrequencies.Rows.Count, 1, new string[] { "Impact" }, variableFrequencies.Rows.Select(x => x.Name));
    306         impacts.SortableView = true;
    307         int rowIndex = 0;
    308         foreach (var dataRow in variableFrequencies.Rows) {
    309           string variableName = dataRow.Name;
    310           impacts[rowIndex++, 0] = dataRow.Values.Average();
    311         }
    312         return impacts;
    313       } else return new DoubleMatrix(1, 1);
    314     }
     273    private void UpdateBestSolutionResults() {
     274      BestSymbolicRegressionSolutionAnalyzer.UpdateBestSolutionResults(BestValidationSolution, ClassificationProblemData, Results, Generations, VariableFrequencies);
     275
     276      IEnumerable<double> trainingValues = ClassificationProblemData.Dataset.GetEnumeratedVariableValues(
     277        ClassificationProblemData.TargetVariable.Value,
     278        ClassificationProblemData.TrainingSamplesStart.Value,
     279        ClassificationProblemData.TrainingSamplesEnd.Value);
     280      IEnumerable<double> testValues = ClassificationProblemData.Dataset.GetEnumeratedVariableValues(
     281        ClassificationProblemData.TargetVariable.Value,
     282        ClassificationProblemData.TestSamplesStart.Value,
     283        ClassificationProblemData.TestSamplesEnd.Value);
     284
     285      OnlineAccuracyEvaluator accuracyEvaluator = new OnlineAccuracyEvaluator();
     286      var originalEnumerator = trainingValues.GetEnumerator();
     287      var estimatedEnumerator = BestValidationSolution.EstimatedTrainingClassValues.GetEnumerator();
     288      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     289        accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     290      }
     291      double trainingAccuracy = accuracyEvaluator.Accuracy;
     292
     293      accuracyEvaluator.Reset();
     294      originalEnumerator = testValues.GetEnumerator();
     295      estimatedEnumerator = BestValidationSolution.EstimatedTestClassValues.GetEnumerator();
     296      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     297        accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
     298      }
     299      double testAccuracy = accuracyEvaluator.Accuracy;
     300
     301      if (!Results.ContainsKey(BestSolutionAccuracyTrainingParameterName)) {
     302        BestSolutionAccuracyTraining = new DoubleValue(trainingAccuracy);
     303        BestSolutionAccuracyTest = new DoubleValue(testAccuracy);
     304
     305        Results.Add(new Result(BestSolutionAccuracyTrainingParameterName, BestSolutionAccuracyTraining));
     306        Results.Add(new Result(BestSolutionAccuracyTestParameterName, BestSolutionAccuracyTest));
     307      } else {
     308        BestSolutionAccuracyTraining.Value = trainingAccuracy;
     309        BestSolutionAccuracyTest.Value = testAccuracy;
     310      }
     311    }
     312
    315313  }
    316314}
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic/SymbolicClassificationSolution.cs

    r4391 r4417  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using HeuristicLab.Common;
     
    3534  [Item("SymbolicClassificationSolution", "Represents a solution for a symbolic classification problem which can be visualized in the GUI.")]
    3635  [StorableClass]
    37   public class SymbolicClassificationSolution : DataAnalysisSolution, IClassificationSolution {
     36  public class SymbolicClassificationSolution : SymbolicRegressionSolution, IClassificationSolution {
    3837    private SymbolicClassificationSolution() : base() { }
    3938    public SymbolicClassificationSolution(ClassificationProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit)
    40       : base(problemData, lowerEstimationLimit, upperEstimationLimit) {
    41       this.Model = model;
    42     }
    43 
    44     public override Image ItemImage {
    45       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; }
    46     }
    47 
    48     public new SymbolicRegressionModel Model {
    49       get { return (SymbolicRegressionModel)base.Model; }
    50       set { base.Model = value; }
     39      : base(problemData, model, lowerEstimationLimit, upperEstimationLimit) {
    5140    }
    5241
     
    6352      RecalculateClassIntermediates();
    6453      OnEstimatedValuesChanged();
    65     }
    66 
    67     protected List<double> estimatedValues;
    68     public override IEnumerable<double> EstimatedValues {
    69       get {
    70         if (estimatedValues == null) RecalculateEstimatedValues();
    71         return estimatedValues.AsEnumerable();
    72       }
    73     }
    74 
    75     public override IEnumerable<double> EstimatedTrainingValues {
    76       get {
    77         if (estimatedValues == null) RecalculateEstimatedValues();
    78         int start = ProblemData.TrainingSamplesStart.Value;
    79         int n = ProblemData.TrainingSamplesEnd.Value - start;
    80         return estimatedValues.Skip(start).Take(n).ToList();
    81       }
    82     }
    83 
    84     public override IEnumerable<double> EstimatedTestValues {
    85       get {
    86         if (estimatedValues == null) RecalculateEstimatedValues();
    87         int start = ProblemData.TestSamplesStart.Value;
    88         int n = ProblemData.TestSamplesEnd.Value - start;
    89         return estimatedValues.Skip(start).Take(n).ToList();
    90       }
    9154    }
    9255
Note: See TracChangeset for help on using the changeset viewer.