Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8623


Ignore:
Timestamp:
09/10/12 17:13:46 (12 years ago)
Author:
gkronber
Message:

#1902 implemented LS Gaussian Process classification

Location:
trunk/sources
Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r8612 r8623  
    228228    #endregion
    229229
     230
    230231    private IEnumerable<double> GetEstimatedValuesHelper(Dataset dataset, IEnumerable<int> rows) {
    231232      var newX = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, inputScaling);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r8620 r8623  
    120120    </Compile>
    121121    <Compile Include="FixedDataAnalysisAlgorithm.cs" />
     122    <Compile Include="GaussianProcess\GaussianProcessDiscriminantFunctionClassificationSolution.cs" />
     123    <Compile Include="GaussianProcess\GaussianProcessDiscriminantFunctionClassificationModel.cs" />
     124    <Compile Include="GaussianProcess\GaussianProcessClassificationSolutionCreator.cs" />
     125    <Compile Include="GaussianProcess\GaussianProcessClassificationModelCreator.cs" />
     126    <Compile Include="GaussianProcess\GaussianProcessClassification.cs" />
    122127    <Compile Include="GaussianProcess\CovarianceProduct.cs" />
    123128    <Compile Include="GaussianProcess\CovarianceScale.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModel.cs

    r8594 r8623  
    2222namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2323  public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicClassificationModel {
    24     IDiscriminantFunctionThresholdCalculator ThresholdCalculator { get; }
     24
    2525  }
    2626}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs

    r8594 r8623  
    3232  [StorableClass]
    3333  [Item(Name = "SymbolicClassificationModel", Description = "Represents a symbolic classification model.")]
    34   public abstract class SymbolicClassificationModel : SymbolicDataAnalysisModel, ISymbolicClassificationModel {
     34  public abstract class
     35    SymbolicClassificationModel : SymbolicDataAnalysisModel, ISymbolicClassificationModel {
    3536    [Storable]
    3637    private double lowerEstimationLimit;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r7259 r8623  
    5151    }
    5252
     53    private IDiscriminantFunctionThresholdCalculator thresholdCalculator;
     54    [Storable]
     55    public IDiscriminantFunctionThresholdCalculator ThresholdCalculator {
     56      get { return thresholdCalculator; }
     57      private set { thresholdCalculator = value; }
     58    }
     59
    5360
    5461    [StorableConstructor]
     
    6168    }
    6269
    63     public DiscriminantFunctionClassificationModel(IRegressionModel model)
     70    public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator)
    6471      : base() {
    6572      this.name = ItemName;
    6673      this.description = ItemDescription;
    6774      this.model = model;
    68       this.classValues = new double[] { 0.0 };
    69       this.thresholds = new double[] { double.NegativeInfinity };
     75      this.classValues = new double[0];
     76      this.thresholds = new double[0];
     77      this.thresholdCalculator = thresholdCalculator;
     78    }
     79
     80    [StorableHook(HookType.AfterDeserialization)]
     81    private void AfterDeserialization() {
     82      if (ThresholdCalculator == null) ThresholdCalculator = new AccuracyMaximizationThresholdCalculator();
    7083    }
    7184
     
    8093    }
    8194
     95    public virtual void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows) {
     96      double[] classValues;
     97      double[] thresholds;
     98      var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     99      var estimatedTrainingValues = GetEstimatedValues(problemData.Dataset, rows);
     100      thresholdCalculator.Calculate(problemData, estimatedTrainingValues, targetClassValues, out classValues, out thresholds);
     101      SetThresholdsAndClassValues(thresholds, classValues);
     102    }
     103
     104
    82105    public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
    83106      return model.GetEstimatedValues(dataset, rows);
     
    85108
    86109    public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) {
     110      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    87111      foreach (var x in GetEstimatedValues(dataset, rows)) {
    88112        int classIndex = 0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs

    r7259 r8623  
    107107        double maxDensityClassValue = -1;
    108108        foreach (var classValue in originalClasses) {
    109           double density = NormalDensity(m, classMean[classValue], classStdDev[classValue]);
     109          double density = LogNormalDensity(m, classMean[classValue], classStdDev[classValue]);
    110110          if (density > maxDensity) {
    111111            maxDensity = density;
     
    139139    }
    140140
    141     private static double NormalDensity(double x, double mu, double sigma) {
    142       if (sigma.IsAlmost(0.0)) {
    143         if (x.IsAlmost(mu)) return 1.0; else return 0.0;
    144       } else {
    145         return (1.0 / Math.Sqrt(2.0 * Math.PI * sigma * sigma)) * Math.Exp(-((x - mu) * (x - mu)) / (2.0 * sigma * sigma));
    146       }
     141    private static double LogNormalDensity(double x, double mu, double sigma) {
     142      return -0.5 * Math.Log(2.0 * Math.PI * sigma * sigma) - ((x - mu) * (x - mu)) / (2.0 * sigma * sigma);
    147143    }
    148144
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r7259 r8623  
    2626    IEnumerable<double> Thresholds { get; }
    2727    IEnumerable<double> ClassValues { get; }
     28    IDiscriminantFunctionThresholdCalculator ThresholdCalculator { get; }
     29    void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows);
    2830    // class values and thresholds can only be assigned simultanously
    2931    void SetThresholdsAndClassValues(IEnumerable<double> thresholds, IEnumerable<double> classValues);
Note: See TracChangeset for help on using the changeset viewer.