Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/06/12 09:52:52 (12 years ago)
Author:
ascheibe
Message:

#1861 merged changes from trunk into branch

Location:
branches/HeuristicLab.Mono
Files:
15 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Mono

  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis

  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r8440 r8585  
    9393  </PropertyGroup>
    9494  <ItemGroup>
     95    <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <HintPath>..\..\bin\ALGLIB-3.6.0.dll</HintPath>
     97      <Private>False</Private>
     98    </Reference>
     99    <Reference Include="HeuristicLab.ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     100      <HintPath>..\..\bin\HeuristicLab.ALGLIB-3.6.0.dll</HintPath>
     101      <Private>False</Private>
     102    </Reference>
    95103    <Reference Include="System" />
    96104    <Reference Include="System.Core">
     
    122130    <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" />
    123131    <Compile Include="Implementation\Clustering\ClusteringSolution.cs" />
     132    <Compile Include="Implementation\FeatureCorrelation\FeatureCorrelationCalculator.cs" />
     133    <Compile Include="Implementation\FeatureCorrelation\FeatureCorrelationEnums.cs" />
    124134    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    125135    <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" />
     
    180190    <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" />
    181191    <Compile Include="Implementation\Regression\RegressionSolution.cs" />
     192    <Compile Include="OnlineCalculators\SpearmansRankCorrelationCoefficientCalculator.cs" />
    182193    <Compile Include="Plugin.cs" />
    183194    <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" />
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r7259 r8585  
    9595
    9696    IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    97       return new ClassificationEnsembleSolution(models, problemData);
     97      return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData));
    9898    }
    9999    #endregion
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r8174 r8585  
    104104    }
    105105
     106    public ClassificationEnsembleSolution(IClassificationProblemData problemData) :
     107      this(Enumerable.Empty<IClassificationModel>(), problemData) { }
     108
    106109    public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData)
    107110      : this(models, problemData,
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r8121 r8585  
    223223    }
    224224
    225     private List<double> classValues;
    226     public List<double> ClassValues {
     225    private List<double> classValuesCache;
     226    private List<double> ClassValuesCache {
    227227      get {
    228         if (classValues == null) {
    229           classValues = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().ToList();
    230           classValues.Sort();
     228        if (classValuesCache == null) {
     229          classValuesCache = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().OrderBy(x => x).ToList();
    231230        }
    232         return classValues;
     231        return classValuesCache;
    233232      }
    234233    }
    235     IEnumerable<double> IClassificationProblemData.ClassValues {
    236       get { return ClassValues; }
    237     }
    238 
     234    public IEnumerable<double> ClassValues {
     235      get { return ClassValuesCache; }
     236    }
    239237    public int Classes {
    240       get { return ClassValues.Count; }
    241     }
    242 
    243     private List<string> classNames;
    244     public List<string> ClassNames {
     238      get { return ClassValuesCache.Count; }
     239    }
     240
     241    private List<string> classNamesCache;
     242    private List<string> ClassNamesCache {
    245243      get {
    246         if (classNames == null) {
    247           classNames = new List<string>();
     244        if (classNamesCache == null) {
     245          classNamesCache = new List<string>();
    248246          for (int i = 0; i < ClassNamesParameter.Value.Rows; i++)
    249             classNames.Add(ClassNamesParameter.Value[i, 0]);
     247            classNamesCache.Add(ClassNamesParameter.Value[i, 0]);
    250248        }
    251         return classNames;
     249        return classNamesCache;
    252250      }
    253251    }
    254     IEnumerable<string> IClassificationProblemData.ClassNames {
    255       get { return ClassNames; }
    256     }
    257 
    258     private Dictionary<Tuple<double, double>, double> classificationPenaltiesCache = new Dictionary<Tuple<double, double>, double>();
     252    public IEnumerable<string> ClassNames {
     253      get { return ClassNamesCache; }
     254    }
    259255    #endregion
    260256
     
    277273
    278274    public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { }
     275
     276    public ClassificationProblemData(IClassificationProblemData classificationProblemData)
     277      : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
     278      TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
     279      TrainingPartition.End = classificationProblemData.TrainingPartition.End;
     280      TestPartition.Start = classificationProblemData.TestPartition.Start;
     281      TestPartition.End = classificationProblemData.TestPartition.End;
     282    }
     283
    279284    public ClassificationProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
    280285      : base(dataset, allowedInputVariables) {
     
    310315      DeregisterParameterEvents();
    311316
    312       classNames = null;
    313317      ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1;
    314       ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValues.Count;
     318      ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValuesCache.Count;
    315319      for (int i = 0; i < Classes; i++)
    316         ClassNamesParameter.Value[i, 0] = "Class " + ClassValues[i];
     320        ClassNamesParameter.Value[i, 0] = "Class " + ClassValuesCache[i];
    317321      ClassNamesParameter.Value.ColumnNames = new List<string>() { "ClassNames" };
    318322      ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s);
    319323
    320       classificationPenaltiesCache.Clear();
    321       ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
    322324      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes;
    323325      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes;
     
    330332        }
    331333      }
    332       ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = true;
    333334      RegisterParameterEvents();
    334335    }
    335336
    336337    public string GetClassName(double classValue) {
    337       if (!ClassValues.Contains(classValue)) throw new ArgumentException();
    338       int index = ClassValues.IndexOf(classValue);
    339       return ClassNames[index];
     338      if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException();
     339      int index = ClassValuesCache.IndexOf(classValue);
     340      return ClassNamesCache[index];
    340341    }
    341342    public double GetClassValue(string className) {
    342       if (!ClassNames.Contains(className)) throw new ArgumentException();
    343       int index = ClassNames.IndexOf(className);
    344       return ClassValues[index];
     343      if (!ClassNamesCache.Contains(className)) throw new ArgumentException();
     344      int index = ClassNamesCache.IndexOf(className);
     345      return ClassValuesCache[index];
    345346    }
    346347    public void SetClassName(double classValue, string className) {
    347       if (!classValues.Contains(classValue)) throw new ArgumentException();
    348       int index = ClassValues.IndexOf(classValue);
    349       ClassNames[index] = className;
     348      if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException();
     349      int index = ClassValuesCache.IndexOf(classValue);
    350350      ClassNamesParameter.Value[index, 0] = className;
     351      // updating of class names cache is not necessary here as the parameter value fires a changed event which updates the cache
    351352    }
    352353
     
    355356    }
    356357    public double GetClassificationPenalty(double correctClassValue, double estimatedClassValue) {
    357       var key = Tuple.Create(correctClassValue, estimatedClassValue);
    358       if (!classificationPenaltiesCache.ContainsKey(key)) {
    359         int correctClassIndex = ClassValues.IndexOf(correctClassValue);
    360         int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue);
    361         classificationPenaltiesCache[key] = ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex];
    362       }
    363       return classificationPenaltiesCache[key];
     358      int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue);
     359      int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue);
     360      return ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex];
    364361    }
    365362    public void SetClassificationPenalty(string correctClassName, string estimatedClassName, double penalty) {
     
    367364    }
    368365    public void SetClassificationPenalty(double correctClassValue, double estimatedClassValue, double penalty) {
    369       var key = Tuple.Create(correctClassValue, estimatedClassValue);
    370       int correctClassIndex = ClassValues.IndexOf(correctClassValue);
    371       int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue);
     366      int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue);
     367      int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue);
    372368
    373369      ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex] = penalty;
     
    379375      ClassNamesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged);
    380376      ClassNamesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    381       ClassificationPenaltiesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged);
    382       ClassificationPenaltiesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    383377    }
    384378    private void DeregisterParameterEvents() {
     
    386380      ClassNamesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged);
    387381      ClassNamesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    388       ClassificationPenaltiesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged);
    389       ClassificationPenaltiesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    390382    }
    391383
    392384    private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
    393       classValues = null;
     385      classValuesCache = null;
     386      classNamesCache = null;
    394387      ResetTargetVariableDependentMembers();
    395388      OnChanged();
    396389    }
    397390    private void Parameter_ValueChanged(object sender, EventArgs e) {
     391      classNamesCache = null;
    398392      OnChanged();
    399393    }
    400394    private void MatrixParameter_ItemChanged(object sender, EventArgs<int, int> e) {
     395      classNamesCache = null;
    401396      OnChanged();
    402397    }
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs

    r8139 r8585  
    5151      valueEvaluationCache = new Dictionary<int, double>();
    5252      classValueEvaluationCache = new Dictionary<int, double>();
    53 
    54       SetAccuracyMaximizingThresholds();
    5553    }
    5654
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r8139 r8585  
    9494    }
    9595
    96     protected override void OnModelChanged() {
    97       DeregisterEventHandler();
    98       SetAccuracyMaximizingThresholds();
    99       RegisterEventHandler();
    100       base.OnModelChanged();
    101     }
    102 
    10396    protected void CalculateRegressionResults() {
    10497      double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
     
    137130    }
    138131
    139     public void SetAccuracyMaximizingThresholds() {
    140       double[] classValues;
    141       double[] thresholds;
    142       var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);
    143       AccuracyMaximizationThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);
    144 
    145       Model.SetThresholdsAndClassValues(thresholds, classValues);
    146     }
    147 
    148     public void SetClassDistibutionCutPointThresholds() {
    149       double[] classValues;
    150       double[] thresholds;
    151       var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);
    152       NormalDistributionCutPointsThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);
    153 
    154       Model.SetThresholdsAndClassValues(thresholds, classValues);
    155     }
    156 
    157132    protected virtual void OnModelThresholdsChanged(EventArgs e) {
    158       CalculateResults();
    159       CalculateRegressionResults();
     133      OnModelChanged();
    160134    }
    161135
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs

    r8126 r8585  
    8585            //all positives
    8686            if (pair.TargetClassValue.IsAlmost(classValues[i - 1])) {
    87               if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)
     87              if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold)
    8888                //true positive
    89                 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i - 1]);
     89                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue);
    9090              else
    9191                //false negative
    92                 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i - 1]);
     92                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]);
    9393            }
    9494              //all negatives
    9595            else {
    96               if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)
    97                 //false positive
    98                 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i]);
    99               else
    100                 //true negative, consider only upper class
    101                 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i]);
     96              //false positive
     97              if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold)
     98                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 1]);
     99              else if (pair.EstimatedValue <= lowerThreshold)
     100                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 2]);
     101              else if (pair.EstimatedValue > actualThreshold) {
     102                if (pair.TargetClassValue < classValues[i - 1]) //negative in wrong class, consider upper class
     103                  classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]);
     104                else //true negative, must be optimized by the other thresholds
     105                  classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue);
     106              }
    102107            }
    103108          }
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r8139 r8585  
    107107    [StorableConstructor]
    108108    protected DataAnalysisProblemData(bool deserializing) : base(deserializing) { }
     109
    109110    [StorableHook(HookType.AfterDeserialization)]
    110111    private void AfterDeserialization() {
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r7259 r8585  
    5555
    5656    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    57       return new ConstantRegressionSolution(this, problemData);
     57      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
    5858    }
    5959  }
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r7259 r8585  
    102102
    103103    public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    104       return new RegressionEnsembleSolution(this.Models, problemData);
     104      return new RegressionEnsembleSolution(this.Models, new RegressionEnsembleProblemData(problemData));
    105105    }
    106106    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r8121 r8585  
    121121      : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) {
    122122    }
     123    public RegressionProblemData(IRegressionProblemData regressionProblemData)
     124      : this(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) {
     125      TrainingPartition.Start = regressionProblemData.TrainingPartition.Start;
     126      TrainingPartition.End = regressionProblemData.TrainingPartition.End;
     127      TestPartition.Start = regressionProblemData.TestPartition.Start;
     128      TestPartition.End = regressionProblemData.TestPartition.End;
     129    }
    123130
    124131    public RegressionProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/HoeffdingsDependenceCalculator.cs

    r8355 r8585  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Common;
    2625
    2726namespace HeuristicLab.Problems.DataAnalysis {
  • branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r8246 r8585  
    2828  [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.3.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.ALGLIB","3.6")]
    3031  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3132  [PluginDependency("HeuristicLab.Common", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.