Changeset 13118 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
- Timestamp:
- 11/05/15 07:46:38 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
r12819 r13118 124 124 this.meanFunction = cloner.Clone(original.meanFunction); 125 125 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); 127 128 this.trainingDataset = cloner.Clone(original.trainingDataset); 128 129 this.negativeLogLikelihood = original.negativeLogLikelihood; … … 144 145 } 145 146 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) 147 149 : base() { 148 150 this.name = ItemName; … … 163 165 .ToArray(); 164 166 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) { 169 171 this.trainingDataset = (IDataset)ds.Clone(); 170 172 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); 174 179 175 180 int n = x.GetLength(0); … … 184 189 .Select(r => mean.Mean(x, r)) 185 190 .ToArray(); 186 187 188 191 189 192 // calculate sum of diagonal elements for likelihood … … 249 252 } 250 253 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 } 253 260 } 254 261 … … 300 307 private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) { 301 308 if (x == null) { 302 this.x = CalculateX(trainingDataset, allowedInputVariables, trainingRows, inputScaling);309 x = GetData(trainingDataset, allowedInputVariables, trainingRows, inputScaling); 303 310 } 304 311 int n = x.GetLength(0); 305 312 306 var newX = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, inputScaling);313 double[,] newX = GetData(dataset, allowedInputVariables, rows, inputScaling); 307 314 int newN = newX.GetLength(0); 308 315 … … 325 332 public IEnumerable<double> GetEstimatedVariance(IDataset dataset, IEnumerable<int> rows) { 326 333 if (x == null) { 327 this.x = CalculateX(trainingDataset, allowedInputVariables, trainingRows, inputScaling);334 x = GetData(trainingDataset, allowedInputVariables, trainingRows, inputScaling); 328 335 } 329 336 int n = x.GetLength(0); 330 337 331 var newX = AlglibUtil.PrepareAndScaleInputMatrix(dataset, allowedInputVariables, rows, inputScaling);338 var newX = GetData(dataset, allowedInputVariables, rows, inputScaling); 332 339 int newN = newX.GetLength(0); 333 340
Note: See TracChangeset
for help on using the changeset viewer.