Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10553


Ignore:
Timestamp:
03/05/14 17:30:38 (10 years ago)
Author:
mkommend
Message:

#1998: Updated classification model comparision branch with trunk changes.

Location:
branches/ClassificationModelComparison
Files:
1 deleted
94 edited
13 copied

Legend:

Unmodified
Added
Removed
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r8970 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    266266    }
    267267
    268     private bool startPending;
    269268    public void Start() {
    270269      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    271270        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
    272271
    273       if (Algorithm != null && !startPending) {
    274         startPending = true;
     272      if (Algorithm != null) {
    275273        //create cloned algorithms
    276274        if (clonedAlgorithms.Count == 0) {
     
    335333      if (!pausePending) {
    336334        pausePending = true;
    337         if (!startPending) PauseAllClonedAlgorithms();
     335        PauseAllClonedAlgorithms();
    338336      }
    339337    }
     
    352350      if (!stopPending) {
    353351        stopPending = true;
    354         if (!startPending) StopAllClonedAlgorithms();
     352        StopAllClonedAlgorithms();
    355353      }
    356354    }
     
    389387
    390388    private void AggregateResultValues(IDictionary<string, IItem> results) {
    391       Dictionary<string, List<double>> resultValues = new Dictionary<string, List<double>>();
    392389      IEnumerable<IRun> runs = clonedAlgorithms.Select(alg => alg.Runs.FirstOrDefault()).Where(run => run != null);
    393390      IEnumerable<KeyValuePair<string, IItem>> resultCollections = runs.Where(x => x != null).SelectMany(x => x.Results).ToList();
     
    552549      }
    553550      if (problem != null) problem.Reset -= new EventHandler(Problem_Reset);
    554       if (Problem != null) Problem.Reset += new EventHandler(Problem_Reset);
    555551      problem = (IDataAnalysisProblem)algorithm.Problem;
     552      if (problem != null) problem.Reset += new EventHandler(Problem_Reset);
    556553      OnProblemChanged();
    557554    }
     
    653650
    654651    private readonly object locker = new object();
     652    private readonly object resultLocker = new object();
    655653    private void ClonedAlgorithm_Started(object sender, EventArgs e) {
    656       lock (locker) {
    657         IAlgorithm algorithm = sender as IAlgorithm;
     654      IAlgorithm algorithm = sender as IAlgorithm;
     655      lock (resultLocker) {
    658656        if (algorithm != null && !results.ContainsKey(algorithm.Name))
    659657          results.Add(new Result(algorithm.Name, "Contains results for the specific fold.", algorithm.Results));
    660 
    661         if (startPending) {
    662           int startedAlgorithms = clonedAlgorithms.Count(alg => alg.ExecutionState == ExecutionState.Started);
    663           if (startedAlgorithms == NumberOfWorkers.Value ||
    664              clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Prepared))
    665             startPending = false;
    666 
    667           if (pausePending) PauseAllClonedAlgorithms();
    668           if (stopPending) StopAllClonedAlgorithms();
    669         }
    670658      }
    671659    }
     
    718706    public event EventHandler Started;
    719707    private void OnStarted() {
    720       startPending = false;
    721708      ExecutionState = ExecutionState.Started;
    722709      EventHandler handler = Started;
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    9696    private void Run(object state) {
    9797      CancellationToken cancellationToken = (CancellationToken)state;
    98       lastUpdateTime = DateTime.Now;
     98      lastUpdateTime = DateTime.UtcNow;
    9999      System.Timers.Timer timer = new System.Timers.Timer(250);
    100100      timer.AutoReset = true;
     
    107107        timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed);
    108108        timer.Stop();
    109         ExecutionTime += DateTime.Now - lastUpdateTime;
     109        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
    110110      }
    111111
     
    121121      System.Timers.Timer timer = (System.Timers.Timer)sender;
    122122      timer.Enabled = false;
    123       DateTime now = DateTime.Now;
     123      DateTime now = DateTime.UtcNow;
    124124      ExecutionTime += now - lastUpdateTime;
    125125      lastUpdateTime = now;
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceConst.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3637      get { return (IValueParameter<DoubleValue>)Parameters["Scale"]; }
    3738    }
    38 
     39    private bool HasFixedScaleParameter {
     40      get { return ScaleParameter.Value != null; }
     41    }
    3942    [StorableConstructor]
    4043    private CovarianceConst(bool deserializing)
     
    5962
    6063    public int GetNumberOfParameters(int numberOfVariables) {
    61       return ScaleParameter.Value != null ? 0 : 1;
     64      return HasFixedScaleParameter ? 0 : 1;
    6265    }
    6366
     
    7174      int c = 0;
    7275      // gather parameter values
    73       if (ScaleParameter.Value != null) {
     76      if (HasFixedScaleParameter) {
    7477        scale = ScaleParameter.Value.Value;
    7578      } else {
     
    8790      cov.Covariance = (x, i, j) => scale;
    8891      cov.CrossCovariance = (x, xt, i, j) => scale;
    89       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, columnIndices);
     92      if (HasFixedScaleParameter) {
     93        cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     94      } else {
     95        cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, columnIndices);
     96      }
    9097      return cov;
    9198    }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinear.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3737      get { return (IValueParameter<DoubleArray>)Parameters["InverseLength"]; }
    3838    }
     39    private bool HasFixedInverseLengthParameter {
     40      get { return InverseLengthParameter.Value != null; }
     41    }
    3942
    4043    [StorableConstructor]
     
    5760
    5861    public int GetNumberOfParameters(int numberOfVariables) {
    59       if (InverseLengthParameter.Value == null)
     62      if (HasFixedInverseLengthParameter)
     63        return 0;
     64      else
    6065        return numberOfVariables;
    61       else
    62         return 0;
    6366    }
    6467
     
    7174    private void GetParameterValues(double[] p, out double[] inverseLength) {
    7275      // gather parameter values
    73       if (InverseLengthParameter.Value != null) {
     76      if (HasFixedInverseLengthParameter) {
    7477        inverseLength = InverseLengthParameter.Value.ToArray();
    7578      } else {
     
    8184      double[] inverseLength;
    8285      GetParameterValues(p, out inverseLength);
     86      var fixedInverseLength = HasFixedInverseLengthParameter;
    8387      // create functions
    8488      var cov = new ParameterizedCovarianceFunction();
    8589      cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, inverseLength, columnIndices);
    8690      cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, inverseLength, columnIndices);
    87       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, inverseLength, columnIndices);
     91      if (fixedInverseLength)
     92        cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     93      else
     94        cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, inverseLength, columnIndices);
    8895      return cov;
    8996    }
    9097
    9198    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, IEnumerable<int> columnIndices) {
    92       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    93 
    9499      int k = 0;
    95100      foreach (int columnIndex in columnIndices) {
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMask.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    7474
    7575    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
    76       if (columnIndices != null)
    77         throw new InvalidOperationException("Stacking of masking covariance functions is not supported.");
    7876      var cov = CovarianceFunctionParameter.Value;
    7977      var selectedDimensions = SelectedDimensionsParameter.Value;
    8078
    81       return cov.GetParameterizedCovarianceFunction(p, selectedDimensions);
     79      return cov.GetParameterizedCovarianceFunction(p, selectedDimensions.Intersect(columnIndices));
    8280    }
    8381  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMaternIso.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4545      get { return (IConstrainedValueParameter<IntValue>)Parameters["D"]; }
    4646    }
    47 
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50    private bool HasFixedInverseLengthParameter {
     51      get { return InverseLengthParameter.Value != null; }
     52    }
    4853
    4954    [StorableConstructor]
     
    7681    public int GetNumberOfParameters(int numberOfVariables) {
    7782      return
    78         (InverseLengthParameter.Value != null ? 0 : 1) +
    79         (ScaleParameter.Value != null ? 0 : 1);
     83        (HasFixedInverseLengthParameter ? 0 : 1) +
     84        (HasFixedScaleParameter ? 0 : 1);
    8085    }
    8186
     
    9095      // gather parameter values
    9196      int c = 0;
    92       if (InverseLengthParameter.Value != null) {
     97      if (HasFixedInverseLengthParameter) {
    9398        inverseLength = InverseLengthParameter.Value.Value;
    9499      } else {
     
    97102      }
    98103
    99       if (ScaleParameter.Value != null) {
     104      if (HasFixedScaleParameter) {
    100105        scale = ScaleParameter.Value.Value;
    101106      } else {
     
    110115      int d = DParameter.Value.Value;
    111116      GetParameterValues(p, out scale, out inverseLength);
     117      var fixedInverseLength = HasFixedInverseLengthParameter;
     118      var fixedScale = HasFixedScaleParameter;
    112119      // create functions
    113120      var cov = new ParameterizedCovarianceFunction();
     
    122129        return scale * m(d, dist);
    123130      };
    124       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, d, scale, inverseLength, columnIndices);
     131      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, d, scale, inverseLength, columnIndices, fixedInverseLength, fixedScale);
    125132      return cov;
    126133    }
     
    149156
    150157
    151     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, IEnumerable<int> columnIndices) {
     158    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, IEnumerable<int> columnIndices,
     159      bool fixedInverseLength, bool fixedScale) {
    152160      double dist = i == j
    153161                   ? 0.0
    154162                   : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
    155163
    156       yield return scale * dm(d, dist);
    157       yield return 2 * scale * m(d, dist);
     164      if (!fixedInverseLength) yield return scale * dm(d, dist);
     165      if (!fixedScale) yield return 2 * scale * m(d, dist);
    158166    }
    159167  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNoise.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3737      get { return (IValueParameter<DoubleValue>)Parameters["Scale"]; }
    3838    }
     39    private bool HasFixedScaleParameter {
     40      get { return ScaleParameter.Value != null; }
     41    }
    3942
    4043    [StorableConstructor]
     
    6063
    6164    public int GetNumberOfParameters(int numberOfVariables) {
    62       return ScaleParameter.Value != null ? 0 : 1;
     65      return HasFixedScaleParameter ? 0 : 1;
    6366    }
    6467
     
    7275      int c = 0;
    7376      // gather parameter values
    74       if (ScaleParameter.Value != null) {
     77      if (HasFixedScaleParameter) {
    7578        scale = ScaleParameter.Value.Value;
    7679      } else {
     
    8487      double scale;
    8588      GetParameterValues(p, out scale);
     89      var fixedScale = HasFixedScaleParameter;
    8690      // create functions
    8791      var cov = new ParameterizedCovarianceFunction();
    8892      cov.Covariance = (x, i, j) => i == j ? scale : 0.0;
    89       cov.CrossCovariance = (x, xt, i, j) => 0.0;
    90       cov.CovarianceGradient = (x, i, j) => Enumerable.Repeat(i == j ? 2.0 * scale : 0.0, 1);
     93      cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, 1.0, columnIndices) < 1e-9 ? scale : 0.0;
     94      if (fixedScale)
     95        cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     96      else
     97        cov.CovarianceGradient = (x, i, j) => Enumerable.Repeat(i == j ? 2.0 * scale : 0.0, 1);
    9198      return cov;
    9299    }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4646    }
    4747
     48    private bool HasFixedScaleParameter {
     49      get { return ScaleParameter.Value != null; }
     50    }
     51    private bool HasFixedInverseLengthParameter {
     52      get { return InverseLengthParameter.Value != null; }
     53    }
     54    private bool HasFixedPeriodParameter {
     55      get { return PeriodParameter.Value != null; }
     56    }
     57
    4858
    4959    [StorableConstructor]
     
    6878
    6979    public int GetNumberOfParameters(int numberOfVariables) {
    70       return (ScaleParameter.Value != null ? 0 : 1) +
    71        (PeriodParameter.Value != null ? 0 : 1) +
    72        (InverseLengthParameter.Value != null ? 0 : 1);
     80      return (HasFixedScaleParameter ? 0 : 1) +
     81       (HasFixedPeriodParameter ? 0 : 1) +
     82       (HasFixedInverseLengthParameter ? 0 : 1);
    7383    }
    7484
     
    8292
    8393
    84     private void GetParameterValues(double[] p, out double scale, out double period, out double inverseLength) {
     94    private void GetParameterValues(double[]
     95      p, out double scale, out double period, out double inverseLength) {
    8596      // gather parameter values
    8697      int c = 0;
    87       if (InverseLengthParameter.Value != null) {
     98      if (HasFixedInverseLengthParameter) {
    8899        inverseLength = InverseLengthParameter.Value.Value;
    89100      } else {
     
    91102        c++;
    92103      }
    93       if (PeriodParameter.Value != null) {
     104      if (HasFixedPeriodParameter) {
    94105        period = PeriodParameter.Value.Value;
    95106      } else {
     
    97108        c++;
    98109      }
    99       if (ScaleParameter.Value != null) {
     110      if (HasFixedScaleParameter) {
    100111        scale = ScaleParameter.Value.Value;
    101112      } else {
     
    109120      double inverseLength, period, scale;
    110121      GetParameterValues(p, out scale, out period, out inverseLength);
     122      var fixedInverseLength = HasFixedInverseLengthParameter;
     123      var fixedPeriod = HasFixedPeriodParameter;
     124      var fixedScale = HasFixedScaleParameter;
    111125      // create functions
    112126      var cov = new ParameterizedCovarianceFunction();
     
    127141        return scale * Math.Exp(-2.0 * k);
    128142      };
    129       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, period, inverseLength);
     143      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, period, inverseLength, fixedInverseLength, fixedPeriod, fixedScale);
    130144      return cov;
    131145    }
    132146
    133147
    134     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double period, double inverseLength) {
    135       double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period;
    136       double gradient = Math.Sin(v) * inverseLength;
     148    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double period, double inverseLength,
     149      bool fixedInverseLength, bool fixedPeriod, bool fixedScale) {
     150      double k = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period;
     151      double gradient = Math.Sin(k) * inverseLength;
    137152      gradient *= gradient;
    138       yield return 4.0 * scale * Math.Exp(-2.0 * gradient) * gradient;
    139       double r = Math.Sin(v) * inverseLength;
    140       yield return 4.0 * scale * inverseLength * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v;
    141       yield return 2.0 * scale * Math.Exp(-2 * gradient);
     153      if (!fixedInverseLength) yield return 4.0 * scale * Math.Exp(-2.0 * gradient) * gradient;
     154      if (!fixedPeriod) {
     155        double r = Math.Sin(k) * inverseLength;
     156        yield return 2.0 * k * scale * Math.Exp(-2 * r * r) * Math.Sin(2 * k) * inverseLength * inverseLength;
     157      }
     158      if (!fixedScale)
     159        yield return 2.0 * scale * Math.Exp(-2 * gradient);
     160
    142161    }
    143162
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceProduct.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4545      get { return (IValueParameter<DoubleValue>)Parameters["Shape"]; }
    4646    }
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50    private bool HasFixedInverseLengthParameter {
     51      get { return InverseLengthParameter.Value != null; }
     52    }
     53    private bool HasFixedShapeParameter {
     54      get { return ShapeParameter.Value != null; }
     55    }
    4756
    4857    [StorableConstructor]
     
    7180    public int GetNumberOfParameters(int numberOfVariables) {
    7281      return
    73         (ScaleParameter.Value != null ? 0 : 1) +
    74         (ShapeParameter.Value != null ? 0 : 1) +
    75         (InverseLengthParameter.Value != null ? 0 : numberOfVariables);
     82        (HasFixedScaleParameter ? 0 : 1) +
     83        (HasFixedShapeParameter ? 0 : 1) +
     84        (HasFixedInverseLengthParameter ? 0 : numberOfVariables);
    7685    }
    7786
     
    8897      int c = 0;
    8998      // gather parameter values
    90       if (ScaleParameter.Value != null) {
     99      if (HasFixedInverseLengthParameter) {
     100        inverseLength = InverseLengthParameter.Value.ToArray();
     101      } else {
     102        int length = p.Length;
     103        if (!HasFixedScaleParameter) length--;
     104        if (!HasFixedShapeParameter) length--;
     105        inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray();
     106        c += inverseLength.Length;
     107      }
     108      if (HasFixedScaleParameter) {
    91109        scale = ScaleParameter.Value.Value;
    92110      } else {
     
    94112        c++;
    95113      }
    96       if (ShapeParameter.Value != null) {
     114      if (HasFixedShapeParameter) {
    97115        shape = ShapeParameter.Value.Value;
    98116      } else {
    99117        shape = Math.Exp(p[c]);
    100118        c++;
    101       }
    102       if (InverseLengthParameter.Value != null) {
    103         inverseLength = InverseLengthParameter.Value.ToArray();
    104       } else {
    105         inverseLength = p.Skip(2).Select(e => 1.0 / Math.Exp(e)).ToArray();
    106         c += inverseLength.Length;
    107119      }
    108120      if (p.Length != c) throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for CovarianceRationalQuadraticArd", "p");
     
    113125      double[] inverseLength;
    114126      GetParameterValues(p, out scale, out shape, out inverseLength);
     127      var fixedInverseLength = HasFixedInverseLengthParameter;
     128      var fixedScale = HasFixedScaleParameter;
     129      var fixedShape = HasFixedShapeParameter;
    115130      // create functions
    116131      var cov = new ParameterizedCovarianceFunction();
     
    125140        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    126141      };
    127       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength);
     142      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength, fixedInverseLength, fixedScale, fixedShape);
    128143      return cov;
    129144    }
    130145
    131     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double[] inverseLength) {
    132       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     146    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double[] inverseLength,
     147      bool fixedInverseLength, bool fixedScale, bool fixedShape) {
    133148      double d = i == j
    134149                   ? 0.0
     
    136151      double b = 1 + 0.5 * d / shape;
    137152      int k = 0;
    138       foreach (var columnIndex in columnIndices) {
    139         yield return scale * Math.Pow(b, -shape - 1) * Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
    140         k++;
     153      if (!fixedInverseLength) {
     154        foreach (var columnIndex in columnIndices) {
     155          yield return
     156            scale * Math.Pow(b, -shape - 1) *
     157            Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
     158          k++;
     159        }
    141160      }
    142       yield return 2 * scale * Math.Pow(b, -shape);
    143       yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
     161      if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape);
     162      if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
    144163    }
    145164  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4444      get { return (IValueParameter<DoubleValue>)Parameters["Shape"]; }
    4545    }
     46
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50    private bool HasFixedInverseLengthParameter {
     51      get { return InverseLengthParameter.Value != null; }
     52    }
     53    private bool HasFixedShapeParameter {
     54      get { return ShapeParameter.Value != null; }
     55    }
     56
     57
    4658    [StorableConstructor]
    4759    private CovarianceRationalQuadraticIso(bool deserializing)
     
    6880
    6981    public int GetNumberOfParameters(int numberOfVariables) {
    70       return (ScaleParameter.Value != null ? 0 : 1) +
    71         (ShapeParameter.Value != null ? 0 : 1) +
    72         (InverseLengthParameter.Value != null ? 0 : 1);
     82      return (HasFixedScaleParameter ? 0 : 1) +
     83        (HasFixedShapeParameter ? 0 : 1) +
     84        (HasFixedInverseLengthParameter ? 0 : 1);
    7385    }
    7486
     
    8496      int c = 0;
    8597      // gather parameter values
    86       if (ScaleParameter.Value != null) {
     98      if (HasFixedInverseLengthParameter) {
     99        inverseLength = InverseLengthParameter.Value.Value;
     100      } else {
     101        inverseLength = 1.0 / Math.Exp(p[c]);
     102        c++;
     103      }
     104      if (HasFixedScaleParameter) {
    87105        scale = ScaleParameter.Value.Value;
    88106      } else {
     
    90108        c++;
    91109      }
    92       if (ShapeParameter.Value != null) {
     110      if (HasFixedShapeParameter) {
    93111        shape = ShapeParameter.Value.Value;
    94112      } else {
    95113        shape = Math.Exp(p[c]);
    96         c++;
    97       }
    98       if (InverseLengthParameter.Value != null) {
    99         inverseLength = InverseLengthParameter.Value.Value;
    100       } else {
    101         inverseLength = 1.0 / Math.Exp(p[c]);
    102114        c++;
    103115      }
     
    108120      double scale, shape, inverseLength;
    109121      GetParameterValues(p, out scale, out shape, out inverseLength);
     122      var fixedInverseLength = HasFixedInverseLengthParameter;
     123      var fixedScale = HasFixedScaleParameter;
     124      var fixedShape = HasFixedShapeParameter;
    110125      // create functions
    111126      var cov = new ParameterizedCovarianceFunction();
     
    114129                    ? 0.0
    115130                    : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    116         return shape * Math.Pow(1 + 0.5 * d / shape, -shape);
     131        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    117132      };
    118133      cov.CrossCovariance = (x, xt, i, j) => {
     
    120135        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    121136      };
    122       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength);
     137      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength, fixedInverseLength, fixedScale, fixedShape);
    123138      return cov;
    124139    }
    125140
    126     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double inverseLength) {
     141    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double inverseLength,
     142      bool fixedInverseLength, bool fixedScale, bool fixedShape) {
    127143      double d = i == j
    128144                   ? 0.0
     
    130146
    131147      double b = 1 + 0.5 * d / shape;
    132       yield return scale * Math.Pow(b, -shape - 1) * d;
    133       yield return 2 * scale * Math.Pow(b, -shape);
    134       yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
     148      if (!fixedInverseLength) yield return scale * Math.Pow(b, -shape - 1) * d;
     149      if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape);
     150      if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
    135151    }
    136152  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceScale.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3737      get { return (IValueParameter<DoubleValue>)Parameters["Scale"]; }
    3838    }
     39    private bool HasFixedScaleParameter {
     40      get { return ScaleParameter.Value != null; }
     41    }
    3942
    4043    public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
     
    6568
    6669    public int GetNumberOfParameters(int numberOfVariables) {
    67       return (ScaleParameter.Value != null ? 0 : 1) + CovarianceFunctionParameter.Value.GetNumberOfParameters(numberOfVariables);
     70      return (HasFixedScaleParameter ? 0 : 1) + CovarianceFunctionParameter.Value.GetNumberOfParameters(numberOfVariables);
    6871    }
    6972
     
    7780    private void GetParameterValues(double[] p, out double scale) {
    7881      // gather parameter values
    79       if (ScaleParameter.Value != null) {
     82      if (HasFixedScaleParameter) {
    8083        scale = ScaleParameter.Value.Value;
    8184      } else {
     
    8790      double scale;
    8891      GetParameterValues(p, out scale);
     92      var fixedScale = HasFixedScaleParameter;
    8993      var subCov = CovarianceFunctionParameter.Value.GetParameterizedCovarianceFunction(p.Skip(1).ToArray(), columnIndices);
    9094      // create functions
     
    9296      cov.Covariance = (x, i, j) => scale * subCov.Covariance(x, i, j);
    9397      cov.CrossCovariance = (x, xt, i, j) => scale * subCov.CrossCovariance(x, xt, i, j);
    94       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, subCov);
     98      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, subCov, fixedScale);
    9599      return cov;
    96100    }
    97101
    98     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, ParameterizedCovarianceFunction cov) {
    99       yield return 2 * scale * cov.Covariance(x, i, j);
     102    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, ParameterizedCovarianceFunction cov,
     103      bool fixedScale) {
     104      if (!fixedScale) {
     105        yield return 2 * scale * cov.Covariance(x, i, j);
     106      }
    100107      foreach (var g in cov.CovarianceGradient(x, i, j))
    101108        yield return scale * g;
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4040      get { return (IValueParameter<DoubleArray>)Parameters["InverseLength"]; }
    4141    }
     42    private bool HasFixedInverseLengthParameter {
     43      get { return InverseLengthParameter.Value != null; }
     44    }
     45    private bool HasFixedScaleParameter {
     46      get { return ScaleParameter.Value != null; }
     47    }
    4248
    4349    [StorableConstructor]
     
    6167    public int GetNumberOfParameters(int numberOfVariables) {
    6268      return
    63         (ScaleParameter.Value != null ? 0 : 1) +
    64         (InverseLengthParameter.Value != null ? 0 : numberOfVariables);
     69        (HasFixedScaleParameter ? 0 : 1) +
     70        (HasFixedInverseLengthParameter ? 0 : numberOfVariables);
    6571    }
    6672
     
    7682      int c = 0;
    7783      // gather parameter values
    78       if (ScaleParameter.Value != null) {
     84      if (HasFixedInverseLengthParameter) {
     85        inverseLength = InverseLengthParameter.Value.ToArray();
     86      } else {
     87        int length = p.Length;
     88        if (!HasFixedScaleParameter) length--;
     89        inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray();
     90        c += inverseLength.Length;
     91      }
     92      if (HasFixedScaleParameter) {
    7993        scale = ScaleParameter.Value.Value;
    8094      } else {
    8195        scale = Math.Exp(2 * p[c]);
    8296        c++;
    83       }
    84       if (InverseLengthParameter.Value != null) {
    85         inverseLength = InverseLengthParameter.Value.ToArray();
    86       } else {
    87         inverseLength = p.Skip(1).Select(e => 1.0 / Math.Exp(e)).ToArray();
    88         c += inverseLength.Length;
    8997      }
    9098      if (p.Length != c) throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for CovarianceSquaredExponentialArd", "p");
     
    95103      double[] inverseLength;
    96104      GetParameterValues(p, out scale, out inverseLength);
     105      var fixedInverseLength = HasFixedInverseLengthParameter;
     106      var fixedScale = HasFixedScaleParameter;
    97107      // create functions
    98108      var cov = new ParameterizedCovarianceFunction();
     
    107117        return scale * Math.Exp(-d / 2.0);
    108118      };
    109       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, inverseLength);
     119      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, inverseLength, fixedInverseLength, fixedScale);
    110120      return cov;
    111121    }
    112122
    113 
    114     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double[] inverseLength) {
    115       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     123    // order of returned gradients must match the order in GetParameterValues!
     124    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double[] inverseLength,
     125      bool fixedInverseLength, bool fixedScale) {
    116126      double d = i == j
    117127                   ? 0.0
    118128                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
     129
    119130      int k = 0;
    120       foreach (var columnIndex in columnIndices) {
    121         double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
    122         yield return scale * Math.Exp(-d / 2.0) * sqrDist;
    123         k++;
     131      if (!fixedInverseLength) {
     132        foreach (var columnIndex in columnIndices) {
     133          double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
     134          yield return scale * Math.Exp(-d / 2.0) * sqrDist;
     135          k++;
     136        }
    124137      }
    125 
    126       yield return 2.0 * scale * Math.Exp(-d / 2.0);
     138      if (!fixedScale) yield return 2.0 * scale * Math.Exp(-d / 2.0);
    127139    }
    128140  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4242    }
    4343
     44    private bool HasFixedInverseLengthParameter {
     45      get { return InverseLengthParameter.Value != null; }
     46    }
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50
    4451    [StorableConstructor]
    4552    private CovarianceSquaredExponentialIso(bool deserializing)
     
    6673    public int GetNumberOfParameters(int numberOfVariables) {
    6774      return
    68         (ScaleParameter.Value != null ? 0 : 1) +
    69         (InverseLengthParameter.Value != null ? 0 : 1);
     75        (HasFixedScaleParameter ? 0 : 1) +
     76        (HasFixedInverseLengthParameter ? 0 : 1);
    7077    }
    7178
     
    8188      // gather parameter values
    8289      int c = 0;
    83       if (InverseLengthParameter.Value != null) {
     90      if (HasFixedInverseLengthParameter) {
    8491        inverseLength = InverseLengthParameter.Value.Value;
    8592      } else {
     
    8895      }
    8996
    90       if (ScaleParameter.Value != null) {
     97      if (HasFixedScaleParameter) {
    9198        scale = ScaleParameter.Value.Value;
    9299      } else {
     
    100107      double inverseLength, scale;
    101108      GetParameterValues(p, out scale, out inverseLength);
     109      var fixedInverseLength = HasFixedInverseLengthParameter;
     110      var fixedScale = HasFixedScaleParameter;
    102111      // create functions
    103112      var cov = new ParameterizedCovarianceFunction();
     
    112121        return scale * Math.Exp(-d / 2.0);
    113122      };
    114       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices);
     123      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices,
     124        fixedInverseLength, fixedScale);
    115125      return cov;
    116126    }
    117127
    118     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices) {
     128    // order of returned gradients must match the order in GetParameterValues!
     129    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices,
     130      bool fixedInverseLength, bool fixedScale) {
    119131      double d = i == j
    120132                   ? 0.0
    121133                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    122134      double g = Math.Exp(-d / 2.0);
    123       yield return sf2 * g * d;
    124       yield return 2.0 * sf2 * g;
     135      if (!fixedInverseLength) yield return sf2 * g * d;
     136      if (!fixedScale) yield return 2.0 * sf2 * g;
    125137    }
    126138  }
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSum.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessClassification.cs

    r8623 r10553  
    22#region License Information
    33/* HeuristicLab
    4  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    2222
    2323using System;
     24using System.Linq;
    2425using HeuristicLab.Algorithms.GradientDescent;
    2526using HeuristicLab.Common;
     
    3031using HeuristicLab.Parameters;
    3132using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using HeuristicLab.PluginInfrastructure;
    3234using HeuristicLab.Problems.DataAnalysis;
    3335
     
    3941  [Creatable("Data Analysis")]
    4042  [StorableClass]
    41   public sealed class GaussianProcessClassification : EngineAlgorithm, IStorableContent {
     43  public sealed class GaussianProcessClassification : GaussianProcessBase, IStorableContent {
    4244    public string Filename { get; set; }
    4345
     
    4850    }
    4951
    50     private const string MeanFunctionParameterName = "MeanFunction";
    51     private const string CovarianceFunctionParameterName = "CovarianceFunction";
    52     private const string MinimizationIterationsParameterName = "Iterations";
    53     private const string ApproximateGradientsParameterName = "ApproximateGradients";
    54     private const string SeedParameterName = "Seed";
    55     private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
     52    private const string ModelParameterName = "Model";
    5653
    5754    #region parameter properties
    58     public IValueParameter<IMeanFunction> MeanFunctionParameter {
    59       get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
     55    public IConstrainedValueParameter<IGaussianProcessClassificationModelCreator> GaussianProcessModelCreatorParameter {
     56      get { return (IConstrainedValueParameter<IGaussianProcessClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
    6057    }
    61     public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
    62       get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
     58    public IFixedValueParameter<GaussianProcessClassificationSolutionCreator> GaussianProcessSolutionCreatorParameter {
     59      get { return (IFixedValueParameter<GaussianProcessClassificationSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
    6360    }
    64     public IValueParameter<IntValue> MinimizationIterationsParameter {
    65       get { return (IValueParameter<IntValue>)Parameters[MinimizationIterationsParameterName]; }
    66     }
    67     public IValueParameter<IntValue> SeedParameter {
    68       get { return (IValueParameter<IntValue>)Parameters[SeedParameterName]; }
    69     }
    70     public IValueParameter<BoolValue> SetSeedRandomlyParameter {
    71       get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
    72     }
    73     #endregion
    74     #region properties
    75     public IMeanFunction MeanFunction {
    76       set { MeanFunctionParameter.Value = value; }
    77       get { return MeanFunctionParameter.Value; }
    78     }
    79     public ICovarianceFunction CovarianceFunction {
    80       set { CovarianceFunctionParameter.Value = value; }
    81       get { return CovarianceFunctionParameter.Value; }
    82     }
    83     public int MinimizationIterations {
    84       set { MinimizationIterationsParameter.Value.Value = value; }
    85       get { return MinimizationIterationsParameter.Value.Value; }
    86     }
    87     public int Seed { get { return SeedParameter.Value.Value; } set { SeedParameter.Value.Value = value; } }
    88     public bool SetSeedRandomly { get { return SetSeedRandomlyParameter.Value.Value; } set { SetSeedRandomlyParameter.Value.Value = value; } }
    8961    #endregion
    9062
     
    9365    private GaussianProcessClassification(GaussianProcessClassification original, Cloner cloner)
    9466      : base(original, cloner) {
     67      RegisterEventHandlers();
    9568    }
    9669    public GaussianProcessClassification()
    97       : base() {
     70      : base(new ClassificationProblem()) {
    9871      this.name = ItemName;
    9972      this.description = ItemDescription;
    10073
    101       Problem = new ClassificationProblem();
     74      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessClassificationModelCreator>();
     75      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessClassificationModelCreator);
    10276
    103       Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
    104       Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSquaredExponentialIso()));
    105       Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
    106       Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    107       Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     77      // GP regression and classification algorithms only differ in the model and solution creators,
     78      // thus we use a common base class and use operator parameters to implement the specific versions.
     79      // Different model creators can be implemented,
     80      // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
     81      Parameters.Add(new ConstrainedValueParameter<IGaussianProcessClassificationModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
     82        new ItemSet<IGaussianProcessClassificationModelCreator>(modelCreators), defaultModelCreator));
     83      // this parameter is not intended to be changed,
     84      Parameters.Add(new FixedValueParameter<GaussianProcessClassificationSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
     85        new GaussianProcessClassificationSolutionCreator()));
     86      Parameters[SolutionCreatorParameterName].Hidden = true;
    10887
    109       Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false)));
    110       Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed
    111 
    112       var randomCreator = new HeuristicLab.Random.RandomCreator();
    113       var gpInitializer = new GaussianProcessHyperparameterInitializer();
    114       var bfgsInitializer = new LbfgsInitializer();
    115       var makeStep = new LbfgsMakeStep();
    116       var branch = new ConditionalBranch();
    117       var modelCreator = new GaussianProcessClassificationModelCreator();
    118       var updateResults = new LbfgsUpdateResults();
    119       var analyzer = new LbfgsAnalyzer();
    120       var finalModelCreator = new GaussianProcessClassificationModelCreator();
    121       var finalAnalyzer = new LbfgsAnalyzer();
    122       var solutionCreator = new GaussianProcessClassificationSolutionCreator();
    123 
    124       OperatorGraph.InitialOperator = randomCreator;
    125       randomCreator.SeedParameter.ActualName = SeedParameterName;
    126       randomCreator.SeedParameter.Value = null;
    127       randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameterName;
    128       randomCreator.SetSeedRandomlyParameter.Value = null;
    129       randomCreator.Successor = gpInitializer;
    130 
    131       gpInitializer.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    132       gpInitializer.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    133       gpInitializer.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    134       gpInitializer.HyperparameterParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    135       gpInitializer.RandomParameter.ActualName = randomCreator.RandomParameter.Name;
    136       gpInitializer.Successor = bfgsInitializer;
    137 
    138       bfgsInitializer.IterationsParameter.ActualName = MinimizationIterationsParameterName;
    139       bfgsInitializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    140       bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    141       bfgsInitializer.Successor = makeStep;
    142 
    143       makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    144       makeStep.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    145       makeStep.Successor = branch;
    146 
    147       branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
    148       branch.FalseBranch = modelCreator;
    149       branch.TrueBranch = finalModelCreator;
    150 
    151       modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    152       modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    153       modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    154       modelCreator.Successor = updateResults;
    155 
    156       updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    157       updateResults.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    158       updateResults.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    159       updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    160       updateResults.Successor = analyzer;
    161 
    162       analyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    163       analyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    164       analyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    165       analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    166       analyzer.PointsTableParameter.ActualName = "Hyperparameter table";
    167       analyzer.QualityGradientsTableParameter.ActualName = "Gradients table";
    168       analyzer.QualitiesTableParameter.ActualName = "Negative log likelihood table";
    169       analyzer.Successor = makeStep;
    170 
    171       finalModelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    172       finalModelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    173       finalModelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    174       finalModelCreator.HyperparameterParameter.ActualName = bfgsInitializer.PointParameter.ActualName;
    175       finalModelCreator.Successor = finalAnalyzer;
    176 
    177       finalAnalyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    178       finalAnalyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    179       finalAnalyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    180       finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
    181       finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
    182       finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
    183       finalAnalyzer.Successor = solutionCreator;
    184 
    185       solutionCreator.ModelParameter.ActualName = finalModelCreator.ModelParameter.Name;
    186       solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     88      ParameterizedModelCreators();
     89      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
     90      RegisterEventHandlers();
    18791    }
    18892
     93
    18994    [StorableHook(HookType.AfterDeserialization)]
    190     private void AfterDeserialization() { }
     95    private void AfterDeserialization() {
     96      RegisterEventHandlers();
     97    }
    19198
    19299    public override IDeepCloneable Clone(Cloner cloner) {
    193100      return new GaussianProcessClassification(this, cloner);
    194101    }
     102
     103    #region events
     104    private void RegisterEventHandlers() {
     105      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
     106    }
     107
     108    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
     109      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
     110    }
     111    #endregion
     112
     113    private void ParameterizedModelCreators() {
     114      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
     115        ParameterizedModelCreator(creator);
     116      }
     117    }
     118
     119    private void ParameterizedModelCreator(IGaussianProcessClassificationModelCreator modelCreator) {
     120      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     121      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
     122      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
     123
     124      // parameter names fixed by the algorithm
     125      modelCreator.ModelParameter.ActualName = ModelParameterName;
     126      modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
     127      modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
     128      modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
     129    }
     130
     131    private void ParameterizeSolutionCreator(GaussianProcessClassificationSolutionCreator solutionCreator) {
     132      solutionCreator.ModelParameter.ActualName = ModelParameterName;
     133      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     134    }
    195135  }
    196136}
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessClassificationModelCreator.cs

    r8623 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434  [Item(Name = "GaussianProcessClassificationModelCreator",
    3535    Description = "Creates a Gaussian process model for least-squares classification given the data, the hyperparameters, a mean function, and a covariance function.")]
    36   public sealed class GaussianProcessClassificationModelCreator : GaussianProcessModelCreator {
     36  public sealed class GaussianProcessClassificationModelCreator : GaussianProcessModelCreator, IGaussianProcessClassificationModelCreator {
    3737    private const string ProblemDataParameterName = "ProblemData";
    3838
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessClassificationSolutionCreator.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessHyperparameterInitializer.cs

    r8732 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    284284      var kss = new double[newN];
    285285      double[,] sWKs = new double[n, newN];
    286       var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, newX.GetLength(1)));
     286      var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
    287287
    288288      // for stddev
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs

    r8401 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegression.cs

    r8615 r10553  
    22#region License Information
    33/* HeuristicLab
    4  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    2222
    2323using System;
     24using System.Linq;
    2425using HeuristicLab.Algorithms.GradientDescent;
    2526using HeuristicLab.Common;
     
    3031using HeuristicLab.Parameters;
    3132using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using HeuristicLab.PluginInfrastructure;
    3234using HeuristicLab.Problems.DataAnalysis;
    3335
     
    3941  [Creatable("Data Analysis")]
    4042  [StorableClass]
    41   public sealed class GaussianProcessRegression : EngineAlgorithm, IStorableContent {
     43  public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
    4244    public string Filename { get; set; }
    4345
     
    4850    }
    4951
    50     private const string MeanFunctionParameterName = "MeanFunction";
    51     private const string CovarianceFunctionParameterName = "CovarianceFunction";
    52     private const string MinimizationIterationsParameterName = "Iterations";
    53     private const string ApproximateGradientsParameterName = "ApproximateGradients";
    54     private const string SeedParameterName = "Seed";
    55     private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
     52    private const string ModelParameterName = "Model";
    5653
    5754    #region parameter properties
    58     public IValueParameter<IMeanFunction> MeanFunctionParameter {
    59       get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
     55    public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
     56      get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
    6057    }
    61     public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
    62       get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
     58    public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
     59      get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
    6360    }
    64     public IValueParameter<IntValue> MinimizationIterationsParameter {
    65       get { return (IValueParameter<IntValue>)Parameters[MinimizationIterationsParameterName]; }
    66     }
    67     public IValueParameter<IntValue> SeedParameter {
    68       get { return (IValueParameter<IntValue>)Parameters[SeedParameterName]; }
    69     }
    70     public IValueParameter<BoolValue> SetSeedRandomlyParameter {
    71       get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
    72     }
    73     #endregion
    74     #region properties
    75     public IMeanFunction MeanFunction {
    76       set { MeanFunctionParameter.Value = value; }
    77       get { return MeanFunctionParameter.Value; }
    78     }
    79     public ICovarianceFunction CovarianceFunction {
    80       set { CovarianceFunctionParameter.Value = value; }
    81       get { return CovarianceFunctionParameter.Value; }
    82     }
    83     public int MinimizationIterations {
    84       set { MinimizationIterationsParameter.Value.Value = value; }
    85       get { return MinimizationIterationsParameter.Value.Value; }
    86     }
    87     public int Seed { get { return SeedParameter.Value.Value; } set { SeedParameter.Value.Value = value; } }
    88     public bool SetSeedRandomly { get { return SetSeedRandomlyParameter.Value.Value; } set { SetSeedRandomlyParameter.Value.Value = value; } }
    8961    #endregion
    9062
     
    9365    private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
    9466      : base(original, cloner) {
     67      RegisterEventHandlers();
    9568    }
    9669    public GaussianProcessRegression()
    97       : base() {
     70      : base(new RegressionProblem()) {
    9871      this.name = ItemName;
    9972      this.description = ItemDescription;
    10073
    101       Problem = new RegressionProblem();
     74      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
     75      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
    10276
    103       Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
    104       Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSquaredExponentialIso()));
    105       Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
    106       Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    107       Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     77      // GP regression and classification algorithms only differ in the model and solution creators,
     78      // thus we use a common base class and use operator parameters to implement the specific versions.
     79      // Different model creators can be implemented,
     80      // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
     81      Parameters.Add(new ConstrainedValueParameter<IGaussianProcessRegressionModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
     82        new ItemSet<IGaussianProcessRegressionModelCreator>(modelCreators), defaultModelCreator));
     83      // this parameter is not intended to be changed,
     84      Parameters.Add(new FixedValueParameter<GaussianProcessRegressionSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
     85        new GaussianProcessRegressionSolutionCreator()));
     86      Parameters[SolutionCreatorParameterName].Hidden = true;
    10887
    109       Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false)));
    110       Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed
    111 
    112       var randomCreator = new HeuristicLab.Random.RandomCreator();
    113       var gpInitializer = new GaussianProcessHyperparameterInitializer();
    114       var bfgsInitializer = new LbfgsInitializer();
    115       var makeStep = new LbfgsMakeStep();
    116       var branch = new ConditionalBranch();
    117       var modelCreator = new GaussianProcessRegressionModelCreator();
    118       var updateResults = new LbfgsUpdateResults();
    119       var analyzer = new LbfgsAnalyzer();
    120       var finalModelCreator = new GaussianProcessRegressionModelCreator();
    121       var finalAnalyzer = new LbfgsAnalyzer();
    122       var solutionCreator = new GaussianProcessRegressionSolutionCreator();
    123 
    124       OperatorGraph.InitialOperator = randomCreator;
    125       randomCreator.SeedParameter.ActualName = SeedParameterName;
    126       randomCreator.SeedParameter.Value = null;
    127       randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameterName;
    128       randomCreator.SetSeedRandomlyParameter.Value = null;
    129       randomCreator.Successor = gpInitializer;
    130 
    131       gpInitializer.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    132       gpInitializer.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    133       gpInitializer.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    134       gpInitializer.HyperparameterParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    135       gpInitializer.RandomParameter.ActualName = randomCreator.RandomParameter.Name;
    136       gpInitializer.Successor = bfgsInitializer;
    137 
    138       bfgsInitializer.IterationsParameter.ActualName = MinimizationIterationsParameterName;
    139       bfgsInitializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    140       bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    141       bfgsInitializer.Successor = makeStep;
    142 
    143       makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    144       makeStep.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    145       makeStep.Successor = branch;
    146 
    147       branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
    148       branch.FalseBranch = modelCreator;
    149       branch.TrueBranch = finalModelCreator;
    150 
    151       modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    152       modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    153       modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    154       modelCreator.Successor = updateResults;
    155 
    156       updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    157       updateResults.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    158       updateResults.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    159       updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    160       updateResults.Successor = analyzer;
    161 
    162       analyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    163       analyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    164       analyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    165       analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    166       analyzer.PointsTableParameter.ActualName = "Hyperparameter table";
    167       analyzer.QualityGradientsTableParameter.ActualName = "Gradients table";
    168       analyzer.QualitiesTableParameter.ActualName = "Negative log likelihood table";
    169       analyzer.Successor = makeStep;
    170 
    171       finalModelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
    172       finalModelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
    173       finalModelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
    174       finalModelCreator.HyperparameterParameter.ActualName = bfgsInitializer.PointParameter.ActualName;
    175       finalModelCreator.Successor = finalAnalyzer;
    176 
    177       finalAnalyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
    178       finalAnalyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
    179       finalAnalyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
    180       finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
    181       finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
    182       finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
    183       finalAnalyzer.Successor = solutionCreator;
    184 
    185       solutionCreator.ModelParameter.ActualName = finalModelCreator.ModelParameter.Name;
    186       solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     88      ParameterizedModelCreators();
     89      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
     90      RegisterEventHandlers();
    18791    }
    18892
     93
    18994    [StorableHook(HookType.AfterDeserialization)]
    190     private void AfterDeserialization() { }
     95    private void AfterDeserialization() {
     96      RegisterEventHandlers();
     97    }
    19198
    19299    public override IDeepCloneable Clone(Cloner cloner) {
    193100      return new GaussianProcessRegression(this, cloner);
    194101    }
     102
     103    #region events
     104    private void RegisterEventHandlers() {
     105      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
     106    }
     107
     108    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
     109      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
     110    }
     111    #endregion
     112
     113    private void ParameterizedModelCreators() {
     114      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
     115        ParameterizedModelCreator(creator);
     116      }
     117    }
     118
     119    private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
     120      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     121      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
     122      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
     123
     124      // parameter names fixed by the algorithm
     125      modelCreator.ModelParameter.ActualName = ModelParameterName;
     126      modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
     127      modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
     128      modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
     129    }
     130
     131    private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
     132      solutionCreator.ModelParameter.ActualName = ModelParameterName;
     133      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
     134    }
    195135  }
    196136}
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs

    r8484 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434  [Item(Name = "GaussianProcessRegressionModelCreator",
    3535    Description = "Creates a Gaussian process model for regression given the data, the hyperparameters, a mean function, and a covariance function.")]
    36   public sealed class GaussianProcessRegressionModelCreator : GaussianProcessModelCreator {
     36  public sealed class GaussianProcessRegressionModelCreator : GaussianProcessModelCreator, IGaussianProcessRegressionModelCreator {
    3737    private const string ProblemDataParameterName = "ProblemData";
    3838
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionSolution.cs

    r8837 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionSolutionCreator.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/ICovarianceFunction.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/IMeanFunction.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r9074 r10553  
    101101  </PropertyGroup>
    102102  <ItemGroup>
    103     <Reference Include="ALGLIB-3.6.0">
    104       <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.6.0.dll</HintPath>
     103    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     104      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    105105      <Private>False</Private>
    106106    </Reference>
     
    200200    </Compile>
    201201    <Compile Include="FixedDataAnalysisAlgorithm.cs" />
     202    <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" />
     203    <Compile Include="GaussianProcess\CovarianceFunctions\CovariancePiecewisePolynomial.cs" />
     204    <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceNeuralNetwork.cs" />
     205    <Compile Include="GaussianProcess\CovarianceFunctions\CovariancePolynomial.cs" />
     206    <Compile Include="GaussianProcess\GaussianProcessBase.cs" />
    202207    <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceConst.cs">
    203208      <SubType>Code</SubType>
     
    264269    <Compile Include="GaussianProcess\GaussianProcessRegressionSolution.cs" />
    265270    <Compile Include="GaussianProcess\ICovarianceFunction.cs" />
     271    <Compile Include="Interfaces\IGaussianProcessClassificationModelCreator.cs" />
     272    <Compile Include="Interfaces\IGaussianProcessRegressionModelCreator.cs" />
     273    <Compile Include="Interfaces\IGaussianProcessModelCreator.cs" />
    266274    <Compile Include="Interfaces\IGaussianProcessModel.cs" />
    267275    <Compile Include="Interfaces\IGaussianProcessSolution.cs" />
     
    304312    <Compile Include="Nca\Initialization\INcaInitializer.cs" />
    305313    <Compile Include="Nca\Initialization\LdaInitializer.cs" />
     314    <Compile Include="Nca\Initialization\NcaInitializer.cs" />
    306315    <Compile Include="Nca\Initialization\PcaInitializer.cs" />
    307316    <Compile Include="Nca\Initialization\RandomInitializer.cs" />
    308317    <Compile Include="Nca\Matrix.cs" />
     318    <Compile Include="Nca\ModelCreation\INcaModelCreator.cs" />
     319    <Compile Include="Nca\ModelCreation\NcaModelCreator.cs" />
    309320    <Compile Include="Nca\NcaAlgorithm.cs" />
    310321    <Compile Include="Nca\NcaClassificationSolution.cs" />
     322    <Compile Include="Nca\NcaGradientCalculator.cs" />
    311323    <Compile Include="Nca\NcaModel.cs" />
     324    <Compile Include="Nca\SolutionCreation\INcaSolutionCreator.cs" />
     325    <Compile Include="Nca\SolutionCreation\NcaSolutionCreator.cs" />
    312326    <Compile Include="NearestNeighbour\NearestNeighbourClassification.cs" />
    313327    <Compile Include="NearestNeighbour\NearestNeighbourClassificationSolution.cs" />
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IDataAnalysisAlgorithm.cs

    r8137 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModel.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessSolution.cs

    r8371 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INcaClassificationSolution.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INcaModel.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INearestNeighbourClassificationSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INearestNeighbourModel.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INearestNeighbourRegressionSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkClassificationSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkEnsembleClassificationSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkEnsembleModel.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkEnsembleRegressionSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkModel.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/INeuralNetworkRegressionSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IRandomForestClassificationSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IRandomForestModel.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IRandomForestRegressionSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/ISupportVectorMachineModel.cs

    r8609 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/ISupportVectorMachineSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/INcaInitializer.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424
    2525namespace HeuristicLab.Algorithms.DataAnalysis {
    26   public interface INCAInitializer : IItem {
     26  public interface INcaInitializer : IOperator {
    2727    /// <summary>
    2828    /// Calculates an initial projection for the NCA to start from.
     
    3030    /// <param name="data">The problem data that contains the AllowedInputVariables and TrainingIndices.</param>
    3131    /// <param name="dimensions">The amount of columns in the matrix</param>
    32     /// <returns>A flat representation of a matrix that is read row-wise and contains AllowedInputVariables * TrainingIndices numbers.</returns>
    33     double[] Initialize(IClassificationProblemData data, int dimensions);
     32    /// <returns>The matrix that projects the input variables into a lower dimensional space.</returns>
     33    double[,] Initialize(IClassificationProblemData data, int dimensions);
    3434  }
    3535}
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/LdaInitializer.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Linq;
    2423using HeuristicLab.Common;
     
    3029  [Item("LDA", "Initializes the matrix by performing a linear discriminant analysis.")]
    3130  [StorableClass]
    32   public class LDAInitializer : Item, INCAInitializer {
     31  public class LdaInitializer : NcaInitializer {
    3332
    3433    [StorableConstructor]
    35     protected LDAInitializer(bool deserializing) : base(deserializing) { }
    36     protected LDAInitializer(LDAInitializer original, Cloner cloner) : base(original, cloner) { }
    37     public LDAInitializer() : base() { }
     34    protected LdaInitializer(bool deserializing) : base(deserializing) { }
     35    protected LdaInitializer(LdaInitializer original, Cloner cloner) : base(original, cloner) { }
     36    public LdaInitializer() : base() { }
    3837
    3938    public override IDeepCloneable Clone(Cloner cloner) {
    40       return new LDAInitializer(this, cloner);
     39      return new LdaInitializer(this, cloner);
    4140    }
    4241
    43     public double[] Initialize(IClassificationProblemData data, int dimensions) {
     42    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    4443      var instances = data.TrainingIndices.Count();
    4544      var attributes = data.AllowedInputVariables.Count();
    4645
    47       var ldaDs = new double[instances, attributes + 1];
    48       int row, col = 0;
    49       foreach (var variable in data.AllowedInputVariables) {
    50         row = 0;
    51         foreach (var value in data.Dataset.GetDoubleValues(variable, data.TrainingIndices)) {
    52           ldaDs[row, col] = value;
    53           row++;
    54         }
    55         col++;
    56       }
    57       row = 0;
    58       var uniqueClasses = new Dictionary<double, int>();
    59       foreach (var label in data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices)) {
    60         if (!uniqueClasses.ContainsKey(label))
    61           uniqueClasses[label] = uniqueClasses.Count;
    62         ldaDs[row++, attributes] = label;
    63       }
    64       for (row = 0; row < instances; row++)
     46      var ldaDs = AlglibUtil.PrepareInputMatrix(data.Dataset,
     47                                                data.AllowedInputVariables.Concat(data.TargetVariable.ToEnumerable()),
     48                                                data.TrainingIndices);
     49
     50      // map class values to sequential natural numbers (required by alglib)
     51      var uniqueClasses = data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices)
     52                                        .Distinct()
     53                                        .Select((v, i) => new { v, i })
     54                                        .ToDictionary(x => x.v, x => x.i);
     55
     56      for (int row = 0; row < instances; row++)
    6557        ldaDs[row, attributes] = uniqueClasses[ldaDs[row, attributes]];
    6658
     
    6961      alglib.fisherldan(ldaDs, instances, attributes, uniqueClasses.Count, out info, out matrix);
    7062
    71       var result = new double[attributes * dimensions];
    72       for (int i = 0; i < attributes; i++)
    73         for (int j = 0; j < dimensions; j++)
    74           result[i * dimensions + j] = matrix[i, j];
    75 
    76       return result;
     63      return matrix;
    7764    }
    7865
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2929  [Item("PCA", "Initializes the matrix by performing a principal components analysis.")]
    3030  [StorableClass]
    31   public sealed class PCAInitializer : Item, INCAInitializer {
     31  public sealed class PcaInitializer : NcaInitializer {
    3232
    3333    [StorableConstructor]
    34     private PCAInitializer(bool deserializing) : base(deserializing) { }
    35     private PCAInitializer(PCAInitializer original, Cloner cloner) : base(original, cloner) { }
    36     public PCAInitializer() : base() { }
     34    private PcaInitializer(bool deserializing) : base(deserializing) { }
     35    private PcaInitializer(PcaInitializer original, Cloner cloner) : base(original, cloner) { }
     36    public PcaInitializer() : base() { }
    3737
    3838    public override IDeepCloneable Clone(Cloner cloner) {
    39       return new PCAInitializer(this, cloner);
     39      return new PcaInitializer(this, cloner);
    4040    }
    4141
    42     public double[] Initialize(IClassificationProblemData data, int dimensions) {
     42    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    4343      var instances = data.TrainingIndices.Count();
    4444      var attributes = data.AllowedInputVariables.Count();
    4545
    46       var pcaDs = new double[instances, attributes];
    47       int col = 0;
    48       foreach (var variable in data.AllowedInputVariables) {
    49         int row = 0;
    50         foreach (var value in data.Dataset.GetDoubleValues(variable, data.TrainingIndices)) {
    51           pcaDs[row, col] = value;
    52           row++;
    53         }
    54         col++;
    55       }
     46      var pcaDs = AlglibUtil.PrepareInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices);
    5647
    5748      int info;
     
    6051      alglib.pcabuildbasis(pcaDs, instances, attributes, out info, out varianceValues, out matrix);
    6152
    62       var result = new double[attributes * dimensions];
    63       for (int i = 0; i < attributes; i++)
    64         for (int j = 0; j < dimensions; j++)
    65           result[i * dimensions + j] = matrix[i, j];
    66 
    67       return result;
     53      return matrix;
    6854    }
    6955
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/RandomInitializer.cs

    r8471 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
     25using HeuristicLab.Optimization;
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using HeuristicLab.Problems.DataAnalysis;
    29 using HeuristicLab.Random;
    3029
    3130namespace HeuristicLab.Algorithms.DataAnalysis {
    3231  [Item("Random", "Initializes the matrix randomly.")]
    3332  [StorableClass]
    34   public class RandomInitializer : ParameterizedNamedItem, INCAInitializer {
    35     private IValueParameter<IntValue> RandomParameter {
    36       get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
    37     }
    38     private IValueParameter<BoolValue> SetSeedRandomlyParameter {
    39       get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    40     }
    41 
    42     public int Seed {
    43       get { return RandomParameter.Value.Value; }
    44       set { RandomParameter.Value.Value = value; }
    45     }
    46 
    47     public bool SetSeedRandomly {
    48       get { return SetSeedRandomlyParameter.Value.Value; }
    49       set { SetSeedRandomlyParameter.Value.Value = value; }
     33  public sealed class RandomInitializer : NcaInitializer, IStochasticOperator {
     34    public ILookupParameter<IRandom> RandomParameter {
     35      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    5036    }
    5137
    5238    [StorableConstructor]
    53     protected RandomInitializer(bool deserializing) : base(deserializing) { }
    54     protected RandomInitializer(RandomInitializer original, Cloner cloner) : base(original, cloner) { }
     39    private RandomInitializer(bool deserializing) : base(deserializing) { }
     40    private RandomInitializer(RandomInitializer original, Cloner cloner) : base(original, cloner) { }
    5541    public RandomInitializer()
    5642      : base() {
    57       Parameters.Add(new ValueParameter<IntValue>("Seed", "The seed for the random number generator.", new IntValue(0)));
    58       Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "Whether the seed should be randomized for each call.", new BoolValue(true)));
     43      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    5944    }
    6045
     
    6348    }
    6449
    65     public double[] Initialize(IClassificationProblemData data, int dimensions) {
    66       var instances = data.TrainingIndices.Count();
     50    public override double[,] Initialize(IClassificationProblemData data, int dimensions) {
    6751      var attributes = data.AllowedInputVariables.Count();
    6852
    69       var random = new MersenneTwister();
    70       if (SetSeedRandomly) Seed = random.Next();
    71       random.Reset(Seed);
    72 
    73       var range = data.AllowedInputVariables.Select(x => data.Dataset.GetDoubleValues(x).Max() - data.Dataset.GetDoubleValues(x).Min()).ToArray();
    74       var matrix = new double[attributes * dimensions];
    75       for (int i = 0; i < matrix.Length; i++)
    76         matrix[i] = random.NextDouble() / range[i / dimensions];
     53      var random = RandomParameter.ActualValue;
     54      var matrix = new double[attributes, dimensions];
     55      for (int i = 0; i < attributes; i++)
     56        for (int j = 0; j < dimensions; j++)
     57          matrix[i, j] = random.NextDouble();
    7758
    7859      return matrix;
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Matrix.cs

    r8681 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaAlgorithm.cs

    r8681 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Threading;
    26 using HeuristicLab.Analysis;
     24using HeuristicLab.Algorithms.GradientDescent;
    2725using HeuristicLab.Common;
    2826using HeuristicLab.Core;
    2927using HeuristicLab.Data;
     28using HeuristicLab.Operators;
    3029using HeuristicLab.Optimization;
    3130using HeuristicLab.Parameters;
     
    3332using HeuristicLab.PluginInfrastructure;
    3433using HeuristicLab.Problems.DataAnalysis;
     34using HeuristicLab.Random;
    3535
    3636namespace HeuristicLab.Algorithms.DataAnalysis {
    37   internal delegate void Reporter(double quality, double[] coefficients, double[] gradients);
    3837  /// <summary>
    3938  /// Neighborhood Components Analysis
     
    4645  [Creatable("Data Analysis")]
    4746  [StorableClass]
    48   public sealed class NcaAlgorithm : FixedDataAnalysisAlgorithm<IClassificationProblem> {
     47  public sealed class NcaAlgorithm : EngineAlgorithm {
     48    #region Parameter Names
     49    private const string SeedParameterName = "Seed";
     50    private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
     51    private const string KParameterName = "K";
     52    private const string DimensionsParameterName = "Dimensions";
     53    private const string InitializationParameterName = "Initialization";
     54    private const string NeighborSamplesParameterName = "NeighborSamples";
     55    private const string IterationsParameterName = "Iterations";
     56    private const string RegularizationParameterName = "Regularization";
     57    private const string NcaModelCreatorParameterName = "NcaModelCreator";
     58    private const string NcaSolutionCreatorParameterName = "NcaSolutionCreator";
     59    private const string ApproximateGradientsParameterName = "ApproximateGradients";
     60    private const string NcaMatrixParameterName = "NcaMatrix";
     61    private const string NcaMatrixGradientsParameterName = "NcaMatrixGradients";
     62    private const string QualityParameterName = "Quality";
     63    #endregion
     64
     65    public override Type ProblemType { get { return typeof(IClassificationProblem); } }
     66    public new IClassificationProblem Problem {
     67      get { return (IClassificationProblem)base.Problem; }
     68      set { base.Problem = value; }
     69    }
     70
    4971    #region Parameter Properties
     72    public IValueParameter<IntValue> SeedParameter {
     73      get { return (IValueParameter<IntValue>)Parameters[SeedParameterName]; }
     74    }
     75    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
     76      get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
     77    }
    5078    public IFixedValueParameter<IntValue> KParameter {
    51       get { return (IFixedValueParameter<IntValue>)Parameters["K"]; }
     79      get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; }
    5280    }
    5381    public IFixedValueParameter<IntValue> DimensionsParameter {
    54       get { return (IFixedValueParameter<IntValue>)Parameters["Dimensions"]; }
    55     }
    56     public IConstrainedValueParameter<INCAInitializer> InitializationParameter {
    57       get { return (IConstrainedValueParameter<INCAInitializer>)Parameters["Initialization"]; }
     82      get { return (IFixedValueParameter<IntValue>)Parameters[DimensionsParameterName]; }
     83    }
     84    public IConstrainedValueParameter<INcaInitializer> InitializationParameter {
     85      get { return (IConstrainedValueParameter<INcaInitializer>)Parameters[InitializationParameterName]; }
    5886    }
    5987    public IFixedValueParameter<IntValue> NeighborSamplesParameter {
    60       get { return (IFixedValueParameter<IntValue>)Parameters["NeighborSamples"]; }
     88      get { return (IFixedValueParameter<IntValue>)Parameters[NeighborSamplesParameterName]; }
    6189    }
    6290    public IFixedValueParameter<IntValue> IterationsParameter {
    63       get { return (IFixedValueParameter<IntValue>)Parameters["Iterations"]; }
     91      get { return (IFixedValueParameter<IntValue>)Parameters[IterationsParameterName]; }
    6492    }
    6593    public IFixedValueParameter<DoubleValue> RegularizationParameter {
    66       get { return (IFixedValueParameter<DoubleValue>)Parameters["Regularization"]; }
     94      get { return (IFixedValueParameter<DoubleValue>)Parameters[RegularizationParameterName]; }
     95    }
     96    public IValueParameter<BoolValue> ApproximateGradientsParameter {
     97      get { return (IValueParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; }
     98    }
     99    public IValueParameter<INcaModelCreator> NcaModelCreatorParameter {
     100      get { return (IValueParameter<INcaModelCreator>)Parameters[NcaModelCreatorParameterName]; }
     101    }
     102    public IValueParameter<INcaSolutionCreator> NcaSolutionCreatorParameter {
     103      get { return (IValueParameter<INcaSolutionCreator>)Parameters[NcaSolutionCreatorParameterName]; }
    67104    }
    68105    #endregion
    69106
    70107    #region Properties
     108    public int Seed {
     109      get { return SeedParameter.Value.Value; }
     110      set { SeedParameter.Value.Value = value; }
     111    }
     112    public bool SetSeedRandomly {
     113      get { return SetSeedRandomlyParameter.Value.Value; }
     114      set { SetSeedRandomlyParameter.Value.Value = value; }
     115    }
    71116    public int K {
    72117      get { return KParameter.Value.Value; }
     
    88133      get { return RegularizationParameter.Value.Value; }
    89134      set { RegularizationParameter.Value.Value = value; }
     135    }
     136    public INcaModelCreator NcaModelCreator {
     137      get { return NcaModelCreatorParameter.Value; }
     138      set { NcaModelCreatorParameter.Value = value; }
     139    }
     140    public INcaSolutionCreator NcaSolutionCreator {
     141      get { return NcaSolutionCreatorParameter.Value; }
     142      set { NcaSolutionCreatorParameter.Value = value; }
    90143    }
    91144    #endregion
     
    96149    public NcaAlgorithm()
    97150      : base() {
    98       Parameters.Add(new FixedValueParameter<IntValue>("K", "The K for the nearest neighbor.", new IntValue(3)));
    99       Parameters.Add(new FixedValueParameter<IntValue>("Dimensions", "The number of dimensions that NCA should reduce the data to.", new IntValue(2)));
    100       Parameters.Add(new ConstrainedValueParameter<INCAInitializer>("Initialization", "Which method should be used to initialize the matrix. Typically LDA (linear discriminant analysis) should provide a good estimate."));
    101       Parameters.Add(new FixedValueParameter<IntValue>("NeighborSamples", "How many of the neighbors should be sampled in order to speed up the calculation. This should be at least the value of k and at most the number of training instances minus one.", new IntValue(60)));
    102       Parameters.Add(new FixedValueParameter<IntValue>("Iterations", "How many iterations the conjugate gradient (CG) method should be allowed to perform. The method might still terminate earlier if a local optima has already been reached.", new IntValue(50)));
    103       Parameters.Add(new FixedValueParameter<DoubleValue>("Regularization", "A non-negative paramter which can be set to increase generalization and avoid overfitting. If set to 0 the algorithm is similar to NCA as proposed by Goldberger et al.", new DoubleValue(0)));
    104 
    105       INCAInitializer defaultInitializer = null;
    106       foreach (var initializer in ApplicationManager.Manager.GetInstances<INCAInitializer>().OrderBy(x => x.ItemName)) {
    107         if (initializer is LDAInitializer) defaultInitializer = initializer;
     151      Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The seed of the random number generator.", new IntValue(0)));
     152      Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "A boolean flag that indicates whether the seed should be randomly reset each time the algorithm is run.", new BoolValue(true)));
     153      Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The K for the nearest neighbor.", new IntValue(3)));
     154      Parameters.Add(new FixedValueParameter<IntValue>(DimensionsParameterName, "The number of dimensions that NCA should reduce the data to.", new IntValue(2)));
     155      Parameters.Add(new ConstrainedValueParameter<INcaInitializer>(InitializationParameterName, "Which method should be used to initialize the matrix. Typically LDA (linear discriminant analysis) should provide a good estimate."));
     156      Parameters.Add(new FixedValueParameter<IntValue>(NeighborSamplesParameterName, "How many of the neighbors should be sampled in order to speed up the calculation. This should be at least the value of k and at most the number of training instances minus one will be used.", new IntValue(60)));
     157      Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "How many iterations the conjugate gradient (CG) method should be allowed to perform. The method might still terminate earlier if a local optima has already been reached.", new IntValue(50)));
     158      Parameters.Add(new FixedValueParameter<DoubleValue>(RegularizationParameterName, "A non-negative paramter which can be set to increase generalization and avoid overfitting. If set to 0 the algorithm is similar to NCA as proposed by Goldberger et al.", new DoubleValue(0)));
     159      Parameters.Add(new ValueParameter<INcaModelCreator>(NcaModelCreatorParameterName, "Creates an NCA model out of the matrix.", new NcaModelCreator()));
     160      Parameters.Add(new ValueParameter<INcaSolutionCreator>(NcaSolutionCreatorParameterName, "Creates an NCA solution given a model and some data.", new NcaSolutionCreator()));
     161      Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "True if the gradient should be approximated otherwise they are computed exactly.", new BoolValue()));
     162
     163      NcaSolutionCreatorParameter.Hidden = true;
     164      ApproximateGradientsParameter.Hidden = true;
     165
     166      INcaInitializer defaultInitializer = null;
     167      foreach (var initializer in ApplicationManager.Manager.GetInstances<INcaInitializer>().OrderBy(x => x.ItemName)) {
     168        if (initializer is LdaInitializer) defaultInitializer = initializer;
    108169        InitializationParameter.ValidValues.Add(initializer);
    109170      }
    110171      if (defaultInitializer != null) InitializationParameter.Value = defaultInitializer;
    111172
     173      var randomCreator = new RandomCreator();
     174      var ncaInitializer = new Placeholder();
     175      var bfgsInitializer = new LbfgsInitializer();
     176      var makeStep = new LbfgsMakeStep();
     177      var branch = new ConditionalBranch();
     178      var gradientCalculator = new NcaGradientCalculator();
     179      var modelCreator = new Placeholder();
     180      var updateResults = new LbfgsUpdateResults();
     181      var analyzer = new LbfgsAnalyzer();
     182      var finalModelCreator = new Placeholder();
     183      var finalAnalyzer = new LbfgsAnalyzer();
     184      var solutionCreator = new Placeholder();
     185
     186      OperatorGraph.InitialOperator = randomCreator;
     187      randomCreator.SeedParameter.ActualName = SeedParameterName;
     188      randomCreator.SeedParameter.Value = null;
     189      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameterName;
     190      randomCreator.SetSeedRandomlyParameter.Value = null;
     191      randomCreator.Successor = ncaInitializer;
     192
     193      ncaInitializer.Name = "(NcaInitializer)";
     194      ncaInitializer.OperatorParameter.ActualName = InitializationParameterName;
     195      ncaInitializer.Successor = bfgsInitializer;
     196
     197      bfgsInitializer.IterationsParameter.ActualName = IterationsParameterName;
     198      bfgsInitializer.PointParameter.ActualName = NcaMatrixParameterName;
     199      bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
     200      bfgsInitializer.Successor = makeStep;
     201
     202      makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
     203      makeStep.PointParameter.ActualName = NcaMatrixParameterName;
     204      makeStep.Successor = branch;
     205
     206      branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
     207      branch.FalseBranch = gradientCalculator;
     208      branch.TrueBranch = finalModelCreator;
     209
     210      gradientCalculator.Successor = modelCreator;
     211
     212      modelCreator.OperatorParameter.ActualName = NcaModelCreatorParameterName;
     213      modelCreator.Successor = updateResults;
     214
     215      updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
     216      updateResults.QualityParameter.ActualName = QualityParameterName;
     217      updateResults.QualityGradientsParameter.ActualName = NcaMatrixGradientsParameterName;
     218      updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
     219      updateResults.Successor = analyzer;
     220
     221      analyzer.QualityParameter.ActualName = QualityParameterName;
     222      analyzer.PointParameter.ActualName = NcaMatrixParameterName;
     223      analyzer.QualityGradientsParameter.ActualName = NcaMatrixGradientsParameterName;
     224      analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
     225      analyzer.PointsTableParameter.ActualName = "Matrix table";
     226      analyzer.QualityGradientsTableParameter.ActualName = "Gradients table";
     227      analyzer.QualitiesTableParameter.ActualName = "Qualities";
     228      analyzer.Successor = makeStep;
     229
     230      finalModelCreator.OperatorParameter.ActualName = NcaModelCreatorParameterName;
     231      finalModelCreator.Successor = finalAnalyzer;
     232
     233      finalAnalyzer.QualityParameter.ActualName = QualityParameterName;
     234      finalAnalyzer.PointParameter.ActualName = NcaMatrixParameterName;
     235      finalAnalyzer.QualityGradientsParameter.ActualName = NcaMatrixGradientsParameterName;
     236      finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
     237      finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
     238      finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
     239      finalAnalyzer.Successor = solutionCreator;
     240
     241      solutionCreator.OperatorParameter.ActualName = NcaSolutionCreatorParameterName;
     242
    112243      Problem = new ClassificationProblem();
    113244    }
     
    117248    }
    118249
    119     [StorableHook(HookType.AfterDeserialization)]
    120     private void AfterDeserialization() {
    121       if (!Parameters.ContainsKey("Regularization")) {
    122         Parameters.Add(new FixedValueParameter<DoubleValue>("Regularization", "A non-negative paramter which can be set to increase generalization and avoid overfitting. If set to 0 the algorithm is similar to NCA as proposed by Goldberger et al.", new DoubleValue(0)));
    123       }
    124     }
    125 
    126250    public override void Prepare() {
    127251      if (Problem != null) base.Prepare();
    128252    }
    129 
    130     protected override void Run() {
    131       var initializer = InitializationParameter.Value;
    132 
    133       var clonedProblem = (IClassificationProblemData)Problem.ProblemData.Clone();
    134       var model = Train(clonedProblem, K, Dimensions, NeighborSamples, Regularization, Iterations, initializer.Initialize(clonedProblem, Dimensions), ReportQuality, CancellationToken.None);
    135       var solution = model.CreateClassificationSolution(clonedProblem);
    136       if (!Results.ContainsKey("ClassificationSolution"))
    137         Results.Add(new Result("ClassificationSolution", "The classification solution.", solution));
    138       else Results["ClassificationSolution"].Value = solution;
    139     }
    140 
    141     public static INcaClassificationSolution CreateClassificationSolution(IClassificationProblemData data, int k, int dimensions, int neighborSamples, double regularization, int iterations, INCAInitializer initializer) {
    142       var clonedProblem = (IClassificationProblemData)data.Clone();
    143       var model = Train(clonedProblem, k, dimensions, neighborSamples, regularization, iterations, initializer);
    144       return model.CreateClassificationSolution(clonedProblem);
    145     }
    146 
    147     public static INcaModel Train(IClassificationProblemData problemData, int k, int dimensions, int neighborSamples, double regularization, int iterations, INCAInitializer initializer) {
    148       return Train(problemData, k, dimensions, neighborSamples, regularization, iterations, initializer.Initialize(problemData, dimensions), null, CancellationToken.None);
    149     }
    150 
    151     public static INcaModel Train(IClassificationProblemData problemData, int k, int neighborSamples, double regularization, int iterations, double[,] initalMatrix) {
    152       var matrix = new double[initalMatrix.Length];
    153       for (int i = 0; i < initalMatrix.GetLength(0); i++)
    154         for (int j = 0; j < initalMatrix.GetLength(1); j++)
    155           matrix[i * initalMatrix.GetLength(1) + j] = initalMatrix[i, j];
    156       return Train(problemData, k, initalMatrix.GetLength(1), neighborSamples, regularization, iterations, matrix, null, CancellationToken.None);
    157     }
    158 
    159     private static INcaModel Train(IClassificationProblemData data, int k, int dimensions, int neighborSamples, double regularization, int iterations, double[] matrix, Reporter reporter, CancellationToken cancellation) {
    160       var scaling = new Scaling(data.Dataset, data.AllowedInputVariables, data.TrainingIndices);
    161       var scaledData = AlglibUtil.PrepareAndScaleInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices, scaling);
    162       var classes = data.Dataset.GetDoubleValues(data.TargetVariable, data.TrainingIndices).ToArray();
    163       var attributes = scaledData.GetLength(1);
    164 
    165       alglib.mincgstate state;
    166       alglib.mincgreport rep;
    167       alglib.mincgcreate(matrix, out state);
    168       alglib.mincgsetcond(state, 0, 0, 0, iterations);
    169       alglib.mincgsetxrep(state, true);
    170       //alglib.mincgsetgradientcheck(state, 0.01);
    171       int neighborSampleSize = neighborSamples;
    172       Optimize(state, scaledData, classes, dimensions, neighborSampleSize, regularization, cancellation, reporter);
    173       alglib.mincgresults(state, out matrix, out rep);
    174       if (rep.terminationtype == -7) throw new InvalidOperationException("Gradient verification failed.");
    175 
    176       var transformationMatrix = new double[attributes, dimensions];
    177       var counter = 0;
    178       for (var i = 0; i < attributes; i++)
    179         for (var j = 0; j < dimensions; j++)
    180           transformationMatrix[i, j] = matrix[counter++];
    181 
    182       return new NcaModel(k, transformationMatrix, data.Dataset, data.TrainingIndices, data.TargetVariable, data.AllowedInputVariables, scaling, data.ClassValues.ToArray());
    183     }
    184 
    185     private static void Optimize(alglib.mincgstate state, double[,] data, double[] classes, int dimensions, int neighborSampleSize, double lambda, CancellationToken cancellation, Reporter reporter) {
    186       while (alglib.mincgiteration(state)) {
    187         if (cancellation.IsCancellationRequested) break;
    188         if (state.needfg) {
    189           Gradient(state.x, ref state.innerobj.f, state.innerobj.g, data, classes, dimensions, neighborSampleSize, lambda);
    190           continue;
    191         }
    192         if (state.innerobj.xupdated) {
    193           if (reporter != null)
    194             reporter(state.innerobj.f, state.innerobj.x, state.innerobj.g);
    195           continue;
    196         }
    197         throw new InvalidOperationException("Neighborhood Components Analysis: Error in Optimize() (some derivatives were not provided?)");
    198       }
    199     }
    200 
    201     private static void Gradient(double[] A, ref double func, double[] grad, double[,] data, double[] classes, int dimensions, int neighborSampleSize, double lambda) {
    202       var instances = data.GetLength(0);
    203       var attributes = data.GetLength(1);
    204 
    205       var AMatrix = new Matrix(A, A.Length / dimensions, dimensions);
    206 
    207       alglib.sparsematrix probabilities;
    208       alglib.sparsecreate(instances, instances, out probabilities);
    209       var transformedDistances = new Dictionary<int, double>(instances);
    210       for (int i = 0; i < instances; i++) {
    211         var iVector = new Matrix(GetRow(data, i), data.GetLength(1));
    212         for (int k = 0; k < instances; k++) {
    213           if (k == i) {
    214             transformedDistances.Remove(k);
    215             continue;
    216           }
    217           var kVector = new Matrix(GetRow(data, k));
    218           transformedDistances[k] = Math.Exp(-iVector.Multiply(AMatrix).Subtract(kVector.Multiply(AMatrix)).SumOfSquares());
    219         }
    220         var normalization = transformedDistances.Sum(x => x.Value);
    221         if (normalization <= 0) continue;
    222         foreach (var s in transformedDistances.Where(x => x.Value > 0).OrderByDescending(x => x.Value).Take(neighborSampleSize)) {
    223           alglib.sparseset(probabilities, i, s.Key, s.Value / normalization);
    224         }
    225       }
    226       alglib.sparseconverttocrs(probabilities); // needed to enumerate in order (top-down and left-right)
    227 
    228       int t0 = 0, t1 = 0, r, c;
    229       double val;
    230       var pi = new double[instances];
    231       while (alglib.sparseenumerate(probabilities, ref t0, ref t1, out r, out c, out val)) {
    232         if (classes[r].IsAlmost(classes[c])) {
    233           pi[r] += val;
    234         }
    235       }
    236 
    237       var innerSum = new double[attributes, attributes];
    238       while (alglib.sparseenumerate(probabilities, ref t0, ref t1, out r, out c, out val)) {
    239         var vector = new Matrix(GetRow(data, r)).Subtract(new Matrix(GetRow(data, c)));
    240         vector.OuterProduct(vector).Multiply(val * pi[r]).AddTo(innerSum);
    241 
    242         if (classes[r].IsAlmost(classes[c])) {
    243           vector.OuterProduct(vector).Multiply(-val).AddTo(innerSum);
    244         }
    245       }
    246 
    247       func = -pi.Sum() + lambda * AMatrix.SumOfSquares();
    248 
    249       r = 0;
    250       var newGrad = AMatrix.Multiply(-2.0).Transpose().Multiply(new Matrix(innerSum)).Transpose();
    251       foreach (var g in newGrad) {
    252         grad[r] = g + lambda * 2 * A[r];
    253         r++;
    254       }
    255     }
    256 
    257     private void ReportQuality(double func, double[] coefficients, double[] gradients) {
    258       var instances = Problem.ProblemData.TrainingIndices.Count();
    259       DataTable qualities;
    260       if (!Results.ContainsKey("Optimization")) {
    261         qualities = new DataTable("Optimization");
    262         qualities.Rows.Add(new DataRow("Quality", string.Empty));
    263         Results.Add(new Result("Optimization", qualities));
    264       } else qualities = (DataTable)Results["Optimization"].Value;
    265       qualities.Rows["Quality"].Values.Add(-func / instances);
    266 
    267       string[] attributNames = Problem.ProblemData.AllowedInputVariables.ToArray();
    268       if (gradients != null) {
    269         DataTable grads;
    270         if (!Results.ContainsKey("Gradients")) {
    271           grads = new DataTable("Gradients");
    272           for (int i = 0; i < gradients.Length; i++)
    273             grads.Rows.Add(new DataRow(attributNames[i / Dimensions] + "-" + (i % Dimensions), string.Empty));
    274           Results.Add(new Result("Gradients", grads));
    275         } else grads = (DataTable)Results["Gradients"].Value;
    276         for (int i = 0; i < gradients.Length; i++)
    277           grads.Rows[attributNames[i / Dimensions] + "-" + (i % Dimensions)].Values.Add(gradients[i]);
    278       }
    279 
    280       if (!Results.ContainsKey("Quality")) {
    281         Results.Add(new Result("Quality", new DoubleValue(-func / instances)));
    282       } else ((DoubleValue)Results["Quality"].Value).Value = -func / instances;
    283 
    284       var attributes = attributNames.Length;
    285       var transformationMatrix = new double[attributes, Dimensions];
    286       var counter = 0;
    287       for (var i = 0; i < attributes; i++)
    288         for (var j = 0; j < Dimensions; j++)
    289           transformationMatrix[i, j] = coefficients[counter++];
    290 
    291       var scaling = new Scaling(Problem.ProblemData.Dataset, attributNames, Problem.ProblemData.TrainingIndices);
    292       var model = new NcaModel(K, transformationMatrix, Problem.ProblemData.Dataset, Problem.ProblemData.TrainingIndices, Problem.ProblemData.TargetVariable, attributNames, scaling, Problem.ProblemData.ClassValues.ToArray());
    293 
    294       IClassificationSolution solution = model.CreateClassificationSolution(Problem.ProblemData);
    295       if (!Results.ContainsKey("ClassificationSolution")) {
    296         Results.Add(new Result("ClassificationSolution", solution));
    297       } else {
    298         Results["ClassificationSolution"].Value = solution;
    299       }
    300     }
    301 
    302     private static IEnumerable<double> GetRow(double[,] data, int row) {
    303       for (int i = 0; i < data.GetLength(1); i++)
    304         yield return data[row, i];
    305     }
    306 
    307253  }
    308254}
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaClassificationSolution.cs

    r8723 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r8528 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3333
    3434    [Storable]
    35     private Scaling scaling;
    36     [Storable]
    3735    private double[,] transformationMatrix;
    3836    public double[,] TransformationMatrix {
     
    5250    protected NcaModel(NcaModel original, Cloner cloner)
    5351      : base(original, cloner) {
    54       this.scaling = cloner.Clone(original.scaling);
    5552      this.transformationMatrix = (double[,])original.transformationMatrix.Clone();
    5653      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
     
    5956      this.classValues = (double[])original.classValues.Clone();
    6057    }
    61     public NcaModel(int k, double[,] transformationMatrix, Dataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, Scaling scaling, double[] classValues) {
     58    public NcaModel(int k, double[,] transformationMatrix, Dataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues) {
    6259      Name = ItemName;
    6360      Description = ItemDescription;
    64       this.scaling = scaling;
    6561      this.transformationMatrix = (double[,])transformationMatrix.Clone();
    6662      this.allowedInputVariables = allowedInputVariables.ToArray();
     
    9086
    9187    public double[,] Reduce(Dataset dataset, IEnumerable<int> rows) {
    92       var scaledData = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, scaling);
     88      var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     89
    9390      var targets = dataset.GetDoubleValues(targetVariable, rows).ToArray();
    94       var result = new double[scaledData.GetLength(0), transformationMatrix.GetLength(1) + 1];
    95       for (int i = 0; i < scaledData.GetLength(0); i++)
    96         for (int j = 0; j < scaledData.GetLength(1); j++) {
     91      var result = new double[data.GetLength(0), transformationMatrix.GetLength(1) + 1];
     92      for (int i = 0; i < data.GetLength(0); i++)
     93        for (int j = 0; j < data.GetLength(1); j++) {
    9794          for (int x = 0; x < transformationMatrix.GetLength(1); x++) {
    98             result[i, x] += scaledData[i, j] * transformationMatrix[j, x];
     95            result[i, x] += data[i, j] * transformationMatrix[j, x];
    9996          }
    10097          result[i, transformationMatrix.GetLength(1)] = targets[i];
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Plugin.cs.frame

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626  /// Plugin class for HeuristicLab.Algorithms.DataAnalysis plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Algorithms.DataAnalysis", "Provides wrappers for data analysis algorithms implemented in external libraries (linear regression, linear discriminant analysis, k-means clustering, support vector classification and regression)", "3.4.3.$WCREV$")]
     28  [Plugin("HeuristicLab.Algorithms.DataAnalysis", "Provides wrappers for data analysis algorithms implemented in external libraries (linear regression, linear discriminant analysis, k-means clustering, support vector classification and regression)", "3.4.5.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
    3131  [PluginDependency("HeuristicLab.Algorithms.GradientDescent", "3.3")]
    3232  [PluginDependency("HeuristicLab.Analysis", "3.3")]
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisSolutionEvaluationView.Designer.cs

    r7967 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisSolutionEvaluationView.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/DoubleLimitView.Designer.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/DoubleLimitView.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r9119 r10553  
    9393  </PropertyGroup>
    9494  <ItemGroup>
    95     <Reference Include="ALGLIB-3.6.0">
    96       <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.6.0.dll</HintPath>
     95    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
     97      <Private>False</Private>
    9798    </Reference>
    9899    <Reference Include="HeuristicLab.Analysis-3.3">
     
    222223      <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon>
    223224    </Compile>
    224     <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.cs">
    225       <SubType>UserControl</SubType>
    226     </Compile>
    227     <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.Designer.cs">
    228       <DependentUpon>EnhancedStringConvertibleMatrixView.cs</DependentUpon>
    229     </Compile>
    230225    <Compile Include="FeatureCorrelation\FeatureCorrelationCalculator.cs" />
    231226    <Compile Include="FeatureCorrelation\FeatureCorrelationView.cs">
     
    235230      <DependentUpon>FeatureCorrelationView.cs</DependentUpon>
    236231    </Compile>
     232    <Compile Include="MenuItems\ShrinkDataAnalysisRunsMenuItem.cs" />
    237233    <Compile Include="Plugin.cs" />
    238234    <Compile Include="ProblemDataView.cs">
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/CreateEnsembleMenuItem.cs

    r7738 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Windows.Forms;
    26 using HeuristicLab.Core;
     25using HeuristicLab.Common;
    2726using HeuristicLab.MainForm;
     27using HeuristicLab.MainForm.WindowsForms;
    2828using HeuristicLab.Optimization;
     29using HeuristicLab.Optimization.Views;
    2930using HeuristicLab.Optimizer;
    3031
    31 namespace HeuristicLab.Problems.DataAnalysis.MenuItems {
     32namespace HeuristicLab.Problems.DataAnalysis.Views {
    3233  internal class CreateEnsembleMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
    3334    public override string Name {
     
    3536    }
    3637    public override IEnumerable<string> Structure {
    37       get { return new string[] { "&Edit" }; }
     38      get { return new string[] { "&Edit", "&Data Analysis" }; }
    3839    }
    3940    public override int Position {
    40       get { return 2500; }
     41      get { return 5100; }
    4142    }
    4243    public override string ToolTipText {
     
    4950    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    5051      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    51       if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
    52         var optimizer = activeView.Content as IOptimizer;
    53         ToolStripItem.Enabled = GetDataAnalysisResults(optimizer).Any();
    54       } else {
    55         ToolStripItem.Enabled = false;
    56       }
     52      ToolStripItem.Enabled = GetDataAnalysisResults(activeView).Any();
     53    }
     54    protected override void OnViewChanged(object sender, EventArgs e) {
     55      base.OnViewChanged(sender, e);
     56      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     57      ToolStripItem.Enabled = GetDataAnalysisResults(activeView).Any();
    5758    }
    5859
    5960    public override void Execute() {
    6061      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    61       if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
    62         var optimizer = activeView.Content as IOptimizer;
    63         var solutionGroups = from pair in GetDataAnalysisResults(optimizer)
    64                              group pair.Value by pair.Key into g
    65                              select g;
    66         foreach (var group in solutionGroups) {
    67           // check if all solutions in the group are either only regression or only classification solutions
    68           if (group.All(s => s is IRegressionSolution)) {
    69             // show all regression ensembles
    70             // clone problemdata (N.B. this assumes all solutions are based on the same problem data!)
    71             var problemData = (RegressionProblemData)group
    72               .OfType<IRegressionSolution>()
    73               .First()
    74               .ProblemData.Clone();
    75             var ensemble = new RegressionEnsembleSolution(problemData);
    76             ensemble.Name = group.Key + " ensemble";
    77             var nestedSolutions = group.OfType<RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions);
    78             var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType<IRegressionSolution>();
    79             ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions));
    80             MainFormManager.MainForm.ShowContent(ensemble);
    81           } else if (group.All(s => s is IClassificationSolution)) {
    82             // show all classification ensembles
    83             var problemData = (ClassificationProblemData)group
    84               .OfType<IClassificationSolution>()
    85               .First()
    86               .ProblemData.Clone();
    87             var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData);
    88             ensemble.Name = group.Key + " ensemble";
    89             var nestedSolutions = group.OfType<ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions);
    90             var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType<IClassificationSolution>();
    91             ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions));
    92             MainFormManager.MainForm.ShowContent(ensemble);
    93           }
     62      var solutionGroups = from pair in GetDataAnalysisResults(activeView)
     63                           group pair.Value by pair.Key into g
     64                           select g;
     65      foreach (var group in solutionGroups) {
     66        // check if all solutions in the group are either only regression or only classification solutions
     67        if (group.All(s => s is IRegressionSolution)) {
     68          // show all regression ensembles
     69          // N.B. this assumes all solutions are based on the same problem data!
     70          // the problem data is not cloned because the individual solutions were already cloned
     71          var problemData = group.OfType<IRegressionSolution>().First().ProblemData;
     72          var ensemble = new RegressionEnsembleSolution(problemData);
     73          ensemble.Name = group.Key + " ensemble";
     74          var nestedSolutions = group.OfType<RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions);
     75          var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType<IRegressionSolution>();
     76          ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions));
     77          MainFormManager.MainForm.ShowContent(ensemble);
     78        } else if (group.All(s => s is IClassificationSolution)) {
     79          // show all classification ensembles
     80          // N.B. this assumes all solutions are based on the same problem data!
     81          // the problem data is not cloned because the individual solutions were already cloned
     82          var problemData = (ClassificationProblemData)group.OfType<IClassificationSolution>().First().ProblemData;
     83          var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData);
     84          ensemble.Name = group.Key + " ensemble";
     85          var nestedSolutions = group.OfType<ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions);
     86          var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType<IClassificationSolution>();
     87          ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions));
     88          MainFormManager.MainForm.ShowContent(ensemble);
    9489        }
    9590      }
    9691    }
    9792
    98     private IEnumerable<KeyValuePair<string, IItem>> GetDataAnalysisResults(IOptimizer optimizer) {
    99       var allResults = from r in optimizer.Runs
     93    private IEnumerable<KeyValuePair<string, IDataAnalysisSolution>> GetDataAnalysisResults(IContentView view) {
     94      var empty = Enumerable.Empty<KeyValuePair<string, IDataAnalysisSolution>>();
     95      if (view == null) return empty;
     96      if (view.Content == null) return empty;
     97      if (view.Locked) return empty;
     98
     99      var optimizer = view.Content as IOptimizer;
     100      if (optimizer != null) return GetDataAnalysisResults(optimizer.Runs);
     101
     102      RunCollectionBubbleChartView bubbleChart;
     103      var viewHost = view as ViewHost;
     104      if (viewHost != null)
     105        bubbleChart = viewHost.ActiveView as RunCollectionBubbleChartView;
     106      else bubbleChart = view as RunCollectionBubbleChartView;
     107      if (bubbleChart != null && bubbleChart.SelectedRuns.Any()) return GetDataAnalysisResults(bubbleChart.SelectedRuns);
     108
     109      return empty;
     110    }
     111
     112    private IEnumerable<KeyValuePair<string, IDataAnalysisSolution>> GetDataAnalysisResults(IEnumerable<IRun> runs) {
     113      var cloner = new Cloner();
     114      var allResults = from r in runs
    100115                       select r.Results;
    101116      return from r in allResults
    102117             from result in r
    103              let s = result.Value as IDataAnalysisSolution
     118             let s = cloner.Clone(result.Value) as IDataAnalysisSolution
    104119             where s != null
    105              select result;
     120             select new KeyValuePair<string, IDataAnalysisSolution>(result.Key, s);
    106121    }
    107122  }
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/Plugin.cs.frame

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Views {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Views", "Provides views for base classes for data analysis tasks.", "3.4.3.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Views", "Provides views for base classes for data analysis tasks.", "3.4.5.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Views-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
    3131  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3232  [PluginDependency("HeuristicLab.Collections", "3.3")]
     
    4242  [PluginDependency("HeuristicLab.Optimization.Views","3.3")]
    4343  [PluginDependency("HeuristicLab.Optimizer", "3.3")]
     44  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    4445  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
    4546  [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.Designer.cs

    r8924 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs

    r8833 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    7676        var values = variableValues.ElementAt(i);
    7777        IList clonedValues = null;
    78         if (values is List<double>)
     78        if (values is IList<double>)
    7979          clonedValues = new List<double>(values.Cast<double>());
    80         else if (values is List<string>)
     80        else if (values is IList<string>)
    8181          clonedValues = new List<string>(values.Cast<string>());
    82         else if (values is List<DateTime>)
     82        else if (values is IList<DateTime>)
    8383          clonedValues = new List<DateTime>(values.Cast<DateTime>());
    8484        else {
    8585          this.variableNames = new List<string>();
    8686          this.variableValues = new Dictionary<string, IList>();
    87           throw new ArgumentException("The variable values must be of type List<double>, List<string> or List<DateTime>");
     87          throw new ArgumentException("The variable values must be of type IList<double>, IList<string> or IList<DateTime>");
    8888        }
    8989        this.variableValues.Add(this.variableNames[i], clonedValues);
     
    191191        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
    192192      List<double> values = list as List<double>;
    193       if (values == null) throw new ArgumentException("The varialbe " + variableName + " is not a double variable.");
     193      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable.");
    194194
    195195      return rows.Select(index => values[index]);
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/DoubleLimit.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r9119 r10553  
    9393  </PropertyGroup>
    9494  <ItemGroup>
    95     <Reference Include="ALGLIB-3.6.0">
    96       <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.6.0.dll</HintPath>
    97       <Private>False</Private>
    98     </Reference>
    99     <Reference Include="HeuristicLab.ALGLIB-3.6.0">
    100       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.ALGLIB-3.6.0.dll</HintPath>
     95    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    10197      <Private>False</Private>
    10298    </Reference>
     
    194190    </Compile>
    195191    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
     192    <Compile Include="Interfaces\IDataAnalysisSolutionExporter.cs" />
    196193    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    197194    <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs">
     
    214211    <Compile Include="OnlineCalculators\MatthewsCorrelationCoefficientCalculator.cs" />
    215212    <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" />
     213    <Compile Include="OnlineCalculators\OnlineCovarianceCalculator.cs" />
    216214    <Compile Include="OnlineCalculators\OnlineDirectionalSymmetryCalculator.cs" />
    217215    <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" />
     
    246244    <Compile Include="Interfaces\Regression\IRegressionProblemData.cs" />
    247245    <Compile Include="Interfaces\Regression\IRegressionSolution.cs" />
    248     <Compile Include="OnlineCalculators\OnlineCovarianceCalcualtor.cs" />
    249246    <Compile Include="OnlineCalculators\OnlineMeanAbsolutePercentageErrorCalculator.cs" />
    250247    <Compile Include="OnlineCalculators\OnlineMeanAndVarianceCalculator.cs" />
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblem.cs

    r7823 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r8139 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4343
    4444    event EventHandler Changed;
     45
     46    void AdjustProblemDataProperties(IDataAnalysisProblemData problemData);
    4547  }
    4648}
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisSolution.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs

    r8861 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs

    r8113 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/AutoCorrelationCalculator.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/NormalizedGiniCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineBoundedMeanSquaredErrorCalculator.cs

    r8664 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineLinearScalingParameterCalculator.cs

    r8113 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMaxAbsoluteErrorCalculator.cs

    r7678 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAndVarianceCalculator.cs

    r8966 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanErrorCalculator.cs

    r7272 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r7259 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs

    r8798 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r8581 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.3.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.5.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB","3.6")]
     30  [PluginDependency("HeuristicLab.ALGLIB","3.7.0")]
    3131  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.