Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2351 for trunk


Ignore:
Timestamp:
09/14/09 17:30:02 (15 years ago)
Author:
gkronber
Message:

Worked on SVM classification engine. #625

Location:
trunk/sources
Files:
1 deleted
6 edited
1 copied
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/DefaultClassificationAlgorithmOperators.cs

    r2344 r2351  
    3737      subScopesProc.AddSubOperator(individualProc);
    3838      seq.AddSubOperator(subScopesProc);
    39       AccuracyEvaluator trainingAccuracy = new AccuracyEvaluator();
     39      SimpleAccuracyEvaluator trainingAccuracy = new SimpleAccuracyEvaluator();
    4040      trainingAccuracy.Name = "TrainingAccuracyEvaluator";
    4141      trainingAccuracy.GetVariableInfo("Accuracy").ActualName = "TrainingAccuracy";
    42       trainingAccuracy.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    43       trainingAccuracy.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     42      trainingAccuracy.GetVariableInfo("Values").ActualName = "TrainingValues";
    4443
    45       AccuracyEvaluator validationAccuracy = new AccuracyEvaluator();
     44      SimpleAccuracyEvaluator validationAccuracy = new SimpleAccuracyEvaluator();
    4645      validationAccuracy.Name = "ValidationAccuracyEvaluator";
    4746      validationAccuracy.GetVariableInfo("Accuracy").ActualName = "ValidationAccuracy";
    48       validationAccuracy.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    49       validationAccuracy.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     47      validationAccuracy.GetVariableInfo("Values").ActualName = "ValidationValues";
    5048
    51       AccuracyEvaluator testAccuracy = new AccuracyEvaluator();
     49      SimpleAccuracyEvaluator testAccuracy = new SimpleAccuracyEvaluator();
    5250      testAccuracy.Name = "TestAccuracyEvaluator";
    5351      testAccuracy.GetVariableInfo("Accuracy").ActualName = "TestAccuracy";
    54       testAccuracy.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    55       testAccuracy.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     52      testAccuracy.GetVariableInfo("Values").ActualName = "TestValues";
    5653
    5754      individualProc.AddSubOperator(trainingAccuracy);
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/HeuristicLab.GP.StructureIdentification.Classification-3.3.csproj

    r2341 r2351  
    8080  </ItemGroup>
    8181  <ItemGroup>
    82     <Compile Include="AccuracyEvaluator.cs" />
    8382    <Compile Include="ClassificationMeanSquaredErrorEvaluator.cs" />
    84     <Compile Include="ConfusionMatrixEvaluator.cs" />
    85     <Compile Include="TargetClassesCalculator.cs" />
    8683    <Compile Include="DefaultClassificationAlgorithmOperators.cs" />
    8784    <Compile Include="GPClassificationEvaluatorBase.cs" />
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs

    r2344 r2351  
    126126      evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    127127
     128      #region simple evaluators
     129      SimpleEvaluator trainingEvaluator = new SimpleEvaluator();
     130      trainingEvaluator.Name = "TrainingEvaluator";
     131      trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
     132      trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     133      trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     134      trainingEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     135      SimpleEvaluator validationEvaluator = new SimpleEvaluator();
     136      validationEvaluator.Name = "ValidationEvaluator";
     137      validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
     138      validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     139      validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     140      validationEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     141      SimpleEvaluator testEvaluator = new SimpleEvaluator();
     142      testEvaluator.Name = "TestEvaluator";
     143      testEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
     144      testEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     145      testEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
     146      testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     147      #endregion
    128148      #region MSE
    129       MeanSquaredErrorEvaluator trainingMseEvaluator = new MeanSquaredErrorEvaluator();
     149      SimpleMSEEvaluator trainingMseEvaluator = new SimpleMSEEvaluator();
    130150      trainingMseEvaluator.Name = "TrainingMseEvaluator";
    131       trainingMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    132151      trainingMseEvaluator.GetVariableInfo("MSE").ActualName = "TrainingMSE";
    133       trainingMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    134       trainingMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    135       MeanSquaredErrorEvaluator validationMseEvaluator = new MeanSquaredErrorEvaluator();
     152      trainingMseEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     153      SimpleMSEEvaluator validationMseEvaluator = new SimpleMSEEvaluator();
    136154      validationMseEvaluator.Name = "ValidationMseEvaluator";
    137       validationMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    138155      validationMseEvaluator.GetVariableInfo("MSE").ActualName = "ValidationMSE";
    139       validationMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    140       validationMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    141       MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator();
    142       testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator";
    143       testMseEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     156      validationMseEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     157      SimpleMSEEvaluator testMseEvaluator = new SimpleMSEEvaluator();
     158      testMseEvaluator.Name = "TestMseEvaluator";
    144159      testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestMSE";
    145       testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    146       testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     160      testMseEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    147161      #endregion
    148162      #region MAPE
    149       MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
     163      SimpleMeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    150164      trainingMapeEvaluator.Name = "TrainingMapeEvaluator";
    151       trainingMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
    152165      trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
    153       trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    154       trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    155       MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    156       validationMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     166      trainingMapeEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     167      SimpleMeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    157168      validationMapeEvaluator.Name = "ValidationMapeEvaluator";
    158169      validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    159       validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    160       validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    161       MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    162       testMapeEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     170      validationMapeEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     171      SimpleMeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
    163172      testMapeEvaluator.Name = "TestMapeEvaluator";
    164173      testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE";
    165       testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    166       testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     174      testMapeEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    167175      #endregion
    168176      #region MAPRE
    169       MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    170       trainingMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     177      SimpleMeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    171178      trainingMapreEvaluator.Name = "TrainingMapreEvaluator";
    172179      trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";
    173       trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    174       trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    175       MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    176       validationMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     180      trainingMapreEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     181      SimpleMeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    177182      validationMapreEvaluator.Name = "ValidationMapreEvaluator";
    178183      validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";
    179       validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    180       validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    181       MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    182       testMapreEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     184      validationMapreEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     185      SimpleMeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
    183186      testMapreEvaluator.Name = "TestMapreEvaluator";
    184187      testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";
    185       testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    186       testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     188      testMapreEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    187189      #endregion MAPRE
    188190      #region R2
    189       CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator();
    190       trainingR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     191      SimpleR2Evaluator trainingR2Evaluator = new SimpleR2Evaluator();
    191192      trainingR2Evaluator.Name = "TrainingR2Evaluator";
    192193      trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2";
    193       trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    194       trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    195       CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator();
    196       validationR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     194      trainingR2Evaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     195      SimpleR2Evaluator validationR2Evaluator = new SimpleR2Evaluator();
    197196      validationR2Evaluator.Name = "ValidationR2Evaluator";
    198197      validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";
    199       validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    200       validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    201       CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator();
    202       testR2Evaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     198      validationR2Evaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     199      SimpleR2Evaluator testR2Evaluator = new SimpleR2Evaluator();
    203200      testR2Evaluator.Name = "TestR2Evaluator";
    204201      testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2";
    205       testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    206       testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     202      testR2Evaluator.GetVariableInfo("Values").ActualName = "TestValues";
    207203      #endregion
    208204      #region VAF
    209       VarianceAccountedForEvaluator trainingVAFEvaluator = new VarianceAccountedForEvaluator();
    210       trainingVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     205      SimpleVarianceAccountedForEvaluator trainingVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    211206      trainingVAFEvaluator.Name = "TrainingVAFEvaluator";
    212207      trainingVAFEvaluator.GetVariableInfo("VAF").ActualName = "TrainingVAF";
    213       trainingVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    214       trainingVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    215       VarianceAccountedForEvaluator validationVAFEvaluator = new VarianceAccountedForEvaluator();
    216       validationVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     208      trainingVAFEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     209      SimpleVarianceAccountedForEvaluator validationVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    217210      validationVAFEvaluator.Name = "ValidationVAFEvaluator";
    218211      validationVAFEvaluator.GetVariableInfo("VAF").ActualName = "ValidationVAF";
    219       validationVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    220       validationVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    221       VarianceAccountedForEvaluator testVAFEvaluator = new VarianceAccountedForEvaluator();
    222       testVAFEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
     212      validationVAFEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     213      SimpleVarianceAccountedForEvaluator testVAFEvaluator = new SimpleVarianceAccountedForEvaluator();
    223214      testVAFEvaluator.Name = "TestVAFEvaluator";
    224215      testVAFEvaluator.GetVariableInfo("VAF").ActualName = "TestVAF";
    225       testVAFEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    226       testVAFEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     216      testVAFEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
    227217      #endregion
    228218
    229219      solutionProc.AddSubOperator(evaluatorInjector);
     220      solutionProc.AddSubOperator(trainingEvaluator);
     221      solutionProc.AddSubOperator(validationEvaluator);
     222      solutionProc.AddSubOperator(testEvaluator);
    230223      solutionProc.AddSubOperator(trainingMseEvaluator);
    231224      solutionProc.AddSubOperator(validationMseEvaluator);
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r2349 r2351  
    8484    <Compile Include="AnalyzerModel.cs" />
    8585    <Compile Include="BestSolutionStorer.cs" />
    86     <Compile Include="ClassificationProblemInjector.cs" />
     86    <Compile Include="SimpleAccuracyEvaluator.cs" />
     87    <Compile Include="SimpleConfusionMatrixEvaluator.cs" />
    8788    <Compile Include="SimpleTheilInequalityCoefficientEvaluator.cs" />
    8889    <Compile Include="SolutionExtractor.cs" />
     
    9091    <Compile Include="IAnalyzerModel.cs" />
    9192    <Compile Include="MatrixCreator.cs" />
     93    <Compile Include="TargetClassesCalculator.cs" />
    9294    <Compile Include="VariableEvaluationImpactCalculator.cs" />
    9395    <Compile Include="IPredictor.cs" />
  • trunk/sources/HeuristicLab.Modeling/3.2/SimpleAccuracyEvaluator.cs

    r2348 r2351  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.DataAnalysis;
     26using System.Linq;
     27using HeuristicLab.Common;
    2628
    27 namespace HeuristicLab.GP.StructureIdentification.Classification {
    28   public class AccuracyEvaluator : GPClassificationEvaluatorBase {
    29     private const double EPSILON = 1.0E-6;
     29namespace HeuristicLab.Modeling {
     30  public class SimpleAccuracyEvaluator : SimpleEvaluatorBase {
     31    public override string OutputVariableName {
     32      get {
     33        return "Accuracy";
     34      }
     35    }
    3036    public override string Description {
    3137      get {
     
    3440    }
    3541
    36     public AccuracyEvaluator()
    37       : base() {
    38       AddVariableInfo(new VariableInfo("Accuracy", "The total accuracy of the model (ratio of correctly classified instances to total number of instances)", typeof(DoubleData), VariableKind.New));
     42    public override double Evaluate(double[,] values) {
     43      return Calculate(values);
    3944    }
    4045
    41     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    42       DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false);
    43       if (accuracy == null) {
    44         accuracy = new DoubleData();
    45         scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Accuracy"), accuracy));
    46       }
     46    public static double Calculate(double[,] values) {
     47      int nSamples = values.GetLength(0);
     48      int nCorrect = 0;
     49      double[] classes = CalculateTargetClasses(values);
     50      double[] thresholds = CalculateThresholds(classes);
    4751
    48       int nSamples = end - start;
    49       int nCorrect = 0;
    50       for (int sample = start; sample < end; sample++) {
    51         double est = evaluator.Evaluate(sample);
    52         double origClass = dataset.GetValue(sample, targetVariable);
     52      for (int sample = 0; sample < nSamples; sample++) {
     53        double est = values[sample, 0];
     54        double origClass = values[sample, 1];
    5355        double estClass = double.NaN;
    5456        // if estimation is lower than the smallest threshold value -> estimated class is the lower class
     
    6567          }
    6668        }
    67         if (Math.Abs(estClass - origClass) < EPSILON) nCorrect++;
     69        if (estClass.IsAlmost(origClass)) nCorrect++;
    6870      }
    69       accuracy.Data = nCorrect / (double)nSamples;
     71      return nCorrect / (double)nSamples;
     72    }
     73
     74    public static double[] CalculateTargetClasses(double[,] values) {
     75      int n = values.GetLength(0);
     76      double[] original = new double[n];
     77      for (int i = 0; i < n; i++) original[i] = values[i, 1];
     78      return original.OrderBy(x => x).Distinct().ToArray();
     79    }
     80
     81    public static double[] CalculateThresholds(double[] targetClasses) {
     82      double[] thresholds = new double[targetClasses.Length - 1];
     83      for (int i = 1; i < targetClasses.Length; i++) {
     84        thresholds[i - 1] = (targetClasses[i - 1] + targetClasses[i]) / 2.0;
     85      }
     86      return thresholds;
    7087    }
    7188  }
  • trunk/sources/HeuristicLab.Modeling/3.2/SimpleConfusionMatrixEvaluator.cs

    r2348 r2351  
    2323using HeuristicLab.Data;
    2424
    25 namespace HeuristicLab.GP.StructureIdentification.Classification {
    26   public class ConfusionMatrixEvaluator : GPClassificationEvaluatorBase {
     25namespace HeuristicLab.Modeling {
     26  public class SimpleConfusionMatrixEvaluator : OperatorBase {
    2727    public override string Description {
    2828      get {
     
    3131    }
    3232
    33     public ConfusionMatrixEvaluator()
     33    public SimpleConfusionMatrixEvaluator()
    3434      : base() {
     35      AddVariableInfo(new VariableInfo("Values", "Original and predicted target values generated by a model", typeof(DoubleMatrixData), VariableKind.In));
    3536      AddVariableInfo(new VariableInfo("ConfusionMatrix", "The confusion matrix of the model", typeof(IntMatrixData), VariableKind.New));
    3637    }
    3738
    38     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     39    public override IOperation Apply(IScope scope) {
     40      double[,] values = GetVariableValue<DoubleMatrixData>("Values", scope, true).Data;
     41      int[,] confusionMatrix = Calculate(values);
    3942      IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false);
    4043      if (matrix == null) {
    41         matrix = new IntMatrixData(new int[classes.Length, classes.Length]);
     44        matrix = new IntMatrixData(confusionMatrix);
    4245        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("ConfusionMatrix"), matrix));
    4346      }
    4447
    45       int nSamples = end - start;
    46       for (int sample = start; sample < end; sample++) {
    47         double est = evaluator.Evaluate(sample);
    48         double origClass = dataset.GetValue(sample, targetVariable);
     48      return null;
     49    }
     50
     51    public static int[,] Calculate(double[,] values) {
     52      double[] classes = SimpleAccuracyEvaluator.CalculateTargetClasses(values);
     53      double[] thresholds = SimpleAccuracyEvaluator.CalculateThresholds(classes);
     54      int nSamples = values.GetLength(0);
     55      int[,] confusionMatrix = new int[classes.Length, classes.Length];
     56      for (int sample = 0; sample < nSamples; sample++) {
     57        double est = values[sample, 0];
     58        double origClass = values[sample, 1];
    4959        int estClassIndex = -1;
    5060        // if estimation is lower than the smallest threshold value -> estimated class is the lower class
     
    7080          }
    7181        }
    72         matrix.Data[origClassIndex, estClassIndex]++;
     82        confusionMatrix[origClassIndex, estClassIndex]++;
    7383      }
     84      return confusionMatrix;
    7485    }
    7586  }
  • trunk/sources/HeuristicLab.Modeling/3.2/TargetClassesCalculator.cs

    r2348 r2351  
    2626using System.Linq;
    2727
    28 namespace HeuristicLab.GP.StructureIdentification.Classification {
     28namespace HeuristicLab.Modeling {
    2929  public class TargetClassesCalculator : OperatorBase {
    3030
     
    4141
    4242      ItemList<DoubleData> classes = new ItemList<DoubleData>();
    43       foreach(double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v=>v)) {
     43      foreach (double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v => v)) {
    4444        classes.Add(new DoubleData(x));
    4545      }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj

    r2349 r2351  
    8383  </ItemGroup>
    8484  <ItemGroup>
     85    <Compile Include="SupportVectorClassification.cs" />
    8586    <Compile Include="TimeSeriesSupportVectorRegression.cs" />
    8687    <Compile Include="PredictorView.cs">
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorClassification.cs

    r2349 r2351  
    3737
    3838namespace HeuristicLab.SupportVectorMachines {
    39   public class TimeSeriesSupportVectorRegression : SupportVectorRegression {
     39  public class SupportVectorClassification : SupportVectorRegression {
    4040
    41     public override string Name { get { return "SupportVectorRegression - Time Series Prognosis"; } }
     41    public override string Name { get { return "SupportVectorClassification"; } }
    4242
    43     public int MaxTimeOffset {
    44       get { return GetVariableInjector().GetVariable("MaxTimeOffset").GetValue<IntData>().Data; }
    45       set { GetVariableInjector().GetVariable("MaxTimeOffset").GetValue<IntData>().Data = value; }
    46     }
    47 
    48     public int MinTimeOffset {
    49       get { return GetVariableInjector().GetVariable("MinTimeOffset").GetValue<IntData>().Data; }
    50       set { GetVariableInjector().GetVariable("MinTimeOffset").GetValue<IntData>().Data = value; }
    51     }
    52 
    53     public TimeSeriesSupportVectorRegression()
     43    public SupportVectorClassification()
    5444      : base() {
    55       MaxTimeOffset = 0;
    56       MinTimeOffset = 0;
    57     }
    58 
    59     protected override IOperator CreateInitialization() {
    60       SequentialProcessor seq = new SequentialProcessor();
    61       seq.Name = "Initialization";
    62       seq.AddSubOperator(CreateGlobalInjector());
    63       ProblemInjector probInjector = new ProblemInjector();
    64       seq.AddSubOperator(probInjector);
    65       seq.AddSubOperator(new RandomInjector());
    66 
    67       return seq;
    68     }
    69 
    70     protected override VariableInjector CreateGlobalInjector() {
    71       VariableInjector injector = base.CreateGlobalInjector();
    72       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTimeOffset", new IntData()));
    73       injector.AddVariable(new HeuristicLab.Core.Variable("MinTimeOffset", new IntData()));
    74       return injector;
     45      SvmType = "NU_SVC";
     46      CostList = new DoubleArrayData(new double[] { 1.0 });
     47      MaxCostIndex = 1;
    7548    }
    7649
     
    8356      SequentialProcessor seqProc = new SequentialProcessor();
    8457
    85       SimpleTheilInequalityCoefficientEvaluator trainingTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator();
    86       trainingTheilUCalculator.GetVariableInfo("Values").ActualName = "TrainingValues";
    87       trainingTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TrainingTheilInequalityCoefficient";
    88       SimpleTheilInequalityCoefficientEvaluator validationTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator();
    89       validationTheilUCalculator.GetVariableInfo("Values").ActualName = "ValidationValues";
    90       validationTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "ValidationTheilInequalityCoefficient";
    91       SimpleTheilInequalityCoefficientEvaluator testTheilUCalculator = new SimpleTheilInequalityCoefficientEvaluator();
    92       testTheilUCalculator.GetVariableInfo("Values").ActualName = "TestValues";
    93       testTheilUCalculator.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TestTheilInequalityCoefficient";
     58      SupportVectorEvaluator trainingEvaluator = new SupportVectorEvaluator();
     59      trainingEvaluator.Name = "TrainingSimpleEvaluator";
     60      trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
     61      trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     62      trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
    9463
    95       seqProc.AddSubOperator(trainingTheilUCalculator);
    96       seqProc.AddSubOperator(validationTheilUCalculator);
    97       seqProc.AddSubOperator(testTheilUCalculator);
     64      SimpleAccuracyEvaluator trainingAccuracyEvaluator = new SimpleAccuracyEvaluator();
     65      trainingAccuracyEvaluator.Name = "TrainingAccuracyEvaluator";
     66      trainingAccuracyEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     67      trainingAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "TrainingAccuracy";
     68      SimpleAccuracyEvaluator validationAccuracyEvaluator = new SimpleAccuracyEvaluator();
     69      validationAccuracyEvaluator.Name = "ValidationAccuracyEvaluator";
     70      validationAccuracyEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     71      validationAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "ValidationAccuracy";
     72      SimpleAccuracyEvaluator testAccuracyEvaluator = new SimpleAccuracyEvaluator();
     73      testAccuracyEvaluator.Name = "TestAccuracyEvaluator";
     74      testAccuracyEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
     75      testAccuracyEvaluator.GetVariableInfo("Accuracy").ActualName = "TestAccuracy";
     76
     77      SimpleConfusionMatrixEvaluator trainingConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator();
     78      trainingConfusionMatrixEvaluator.Name = "TrainingConfusionMatrixEvaluator";
     79      trainingConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
     80      trainingConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "TrainingConfusionMatrix";
     81      SimpleConfusionMatrixEvaluator validationConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator();
     82      validationConfusionMatrixEvaluator.Name = "ValidationConfusionMatrixEvaluator";
     83      validationConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
     84      validationConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "ValidationConfusionMatrix";
     85      SimpleConfusionMatrixEvaluator testConfusionMatrixEvaluator = new SimpleConfusionMatrixEvaluator();
     86      testConfusionMatrixEvaluator.Name = "TestConfusionMatrixEvaluator";
     87      testConfusionMatrixEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
     88      testConfusionMatrixEvaluator.GetVariableInfo("ConfusionMatrix").ActualName = "TestConfusionMatrix";
     89
     90      seqProc.AddSubOperator(trainingEvaluator);
     91      seqProc.AddSubOperator(trainingAccuracyEvaluator);
     92      seqProc.AddSubOperator(validationAccuracyEvaluator);
     93      seqProc.AddSubOperator(testAccuracyEvaluator);
     94      seqProc.AddSubOperator(trainingConfusionMatrixEvaluator);
     95      seqProc.AddSubOperator(validationConfusionMatrixEvaluator);
     96      seqProc.AddSubOperator(testConfusionMatrixEvaluator);
    9897
    9998      seq.AddSubOperator(seqSubScopeProc);
     
    109108      IAnalyzerModel model = base.CreateSVMModel(bestModelScope);
    110109
    111       model.SetResult("TrainingTheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("TrainingTheilInequalityCoefficient", false).Data);
    112       model.SetResult("ValidationTheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("ValidationTheilInequalityCoefficient", false).Data);
    113       model.SetResult("TestTheilInequalityCoefficient", bestModelScope.GetVariableValue<DoubleData>("TestTheilInequalityCoefficient", false).Data);
     110      model.SetResult("TrainingAccuracy", bestModelScope.GetVariableValue<DoubleData>("TrainingAccuracy", false).Data);
     111      model.SetResult("ValidationAccuracy", bestModelScope.GetVariableValue<DoubleData>("ValidationAccuracy", false).Data);
     112      model.SetResult("TestAccuracy", bestModelScope.GetVariableValue<DoubleData>("TestAccuracy", false).Data);
    114113
    115114      return model;
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r2349 r2351  
    105105      get { return GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data; }
    106106      set { GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data = value; }
     107    }
     108
     109    public string SvmType {
     110      get { return GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data; }
     111      set { GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data = value; }
    107112    }
    108113
Note: See TracChangeset for help on using the changeset viewer.