Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/13/15 20:51:23 (8 years ago)
Author:
gkronber
Message:

#2497: merged r13118:13119 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r13145 r13147  
    124124      this.meanFunction = cloner.Clone(original.meanFunction);
    125125      this.covarianceFunction = cloner.Clone(original.covarianceFunction);
    126       this.inputScaling = cloner.Clone(original.inputScaling);
     126      if (original.inputScaling != null)
     127        this.inputScaling = cloner.Clone(original.inputScaling);
    127128      this.trainingDataset = cloner.Clone(original.trainingDataset);
    128129      this.negativeLogLikelihood = original.negativeLogLikelihood;
     
    144145    }
    145146    public GaussianProcessModel(IDataset ds, string targetVariable, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows,
    146       IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction)
     147      IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction,
     148      bool scaleInputs = true)
    147149      : base() {
    148150      this.name = ItemName;
     
    163165                                             .ToArray();
    164166      sqrSigmaNoise = Math.Exp(2.0 * hyp.Last());
    165       CalculateModel(ds, rows);
    166     }
    167 
    168     private void CalculateModel(IDataset ds, IEnumerable<int> rows) {
     167      CalculateModel(ds, rows, scaleInputs);
     168    }
     169
     170    private void CalculateModel(IDataset ds, IEnumerable<int> rows, bool scaleInputs = true) {
    169171      this.trainingDataset = (IDataset)ds.Clone();
    170172      this.trainingRows = rows.ToArray();
    171       this.inputScaling = new Scaling(trainingDataset, allowedInputVariables, rows);
    172       this.x = CalculateX(trainingDataset, allowedInputVariables, rows, inputScaling);
    173       var y = ds.GetDoubleValues(targetVariable, rows);
     173      this.inputScaling = scaleInputs ? new Scaling(ds, allowedInputVariables, rows) : null;
     174
     175      x = GetData(ds, this.allowedInputVariables, this.trainingRows, this.inputScaling);
     176
     177      IEnumerable<double> y;
     178      y = ds.GetDoubleValues(targetVariable, rows);
    174179
    175180      int n = x.GetLength(0);
     
    184189        .Select(r => mean.Mean(x, r))
    185190        .ToArray();
    186 
    187 
    188191
    189192      // calculate sum of diagonal elements for likelihood
     
    249252    }
    250253
    251     private static double[,] CalculateX(IDataset ds, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows, Scaling inputScaling) {
    252       return AlglibUtil.PrepareAndScaleInputMatrix(ds, allowedInputVariables, rows, inputScaling);
     254    private static double[,] GetData(IDataset ds, IEnumerable<string> allowedInputs, IEnumerable<int> rows, Scaling scaling) {
     255      if (scaling != null) {
     256        return AlglibUtil.PrepareAndScaleInputMatrix(ds, allowedInputs, rows, scaling);
     257      } else {
     258        return AlglibUtil.PrepareInputMatrix(ds, allowedInputs, rows);
     259      }
    253260    }
    254261
     
    300307    private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) {
    301308      if (x == null) {
    302         this.x = CalculateX(trainingDataset, allowedInputVariables, trainingRows, inputScaling);
     309        x = GetData(trainingDataset, allowedInputVariables, trainingRows, inputScaling);
    303310      }
    304311      int n = x.GetLength(0);
    305312
    306       var newX = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, inputScaling);
     313      double[,] newX = GetData(dataset, allowedInputVariables, rows, inputScaling);
    307314      int newN = newX.GetLength(0);
    308315
     
    325332    public IEnumerable<double> GetEstimatedVariance(IDataset dataset, IEnumerable<int> rows) {
    326333      if (x == null) {
    327         this.x = CalculateX(trainingDataset, allowedInputVariables, trainingRows, inputScaling);
     334        x = GetData(trainingDataset, allowedInputVariables, trainingRows, inputScaling);
    328335      }
    329336      int n = x.GetLength(0);
    330337
    331       var newX = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, inputScaling);
     338      var newX = GetData(dataset, allowedInputVariables, rows, inputScaling);
    332339      int newN = newX.GetLength(0);
    333340
Note: See TracChangeset for help on using the changeset viewer.