Changeset 13118 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 11/05/15 07:46:38 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs
r12797 r13118 51 51 protected const string HyperparameterGradientsParameterName = "HyperparameterGradients"; 52 52 protected const string SolutionCreatorParameterName = "GaussianProcessSolutionCreator"; 53 protected const string ScaleInputValuesParameterName = "ScaleInputValues"; 53 54 54 55 public new IDataAnalysisProblem Problem { … … 72 73 public IValueParameter<BoolValue> SetSeedRandomlyParameter { 73 74 get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; } 75 } 76 public IFixedValueParameter<BoolValue> ScaleInputValuesParameter { 77 get { return (IFixedValueParameter<BoolValue>)Parameters[ScaleInputValuesParameterName]; } 74 78 } 75 79 #endregion … … 89 93 public int Seed { get { return SeedParameter.Value.Value; } set { SeedParameter.Value.Value = value; } } 90 94 public bool SetSeedRandomly { get { return SetSeedRandomlyParameter.Value.Value; } set { SetSeedRandomlyParameter.Value.Value = value; } } 95 96 public bool ScaleInputValues { 97 get { return ScaleInputValuesParameter.Value.Value; } 98 set { ScaleInputValuesParameter.Value.Value = value; } 99 } 91 100 #endregion 92 101 … … 107 116 Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false))); 108 117 Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed 118 119 Parameters.Add(new FixedValueParameter<BoolValue>(ScaleInputValuesParameterName, 120 "Determines if the input variable values are scaled to the range [0..1] for training.", new BoolValue(true))); 121 Parameters[ScaleInputValuesParameterName].Hidden = true; 109 122 110 123 // necessary for BFGS … … 191 204 Parameters["Maximization"].Hidden = true; 192 205 } 206 207 if (!Parameters.ContainsKey(ScaleInputValuesParameterName)) { 208 Parameters.Add(new FixedValueParameter<BoolValue>(ScaleInputValuesParameterName, 209 "Determines if the input variable values are scaled to the range [0..1] for training.", new BoolValue(true))); 210 Parameters[ScaleInputValuesParameterName].Hidden = true; 211 } 193 212 #endregion 194 213 } -
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 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs
r12012 r13118 38 38 private const string NegativeLogLikelihoodParameterName = "NegativeLogLikelihood"; 39 39 private const string HyperparameterGradientsParameterName = "HyperparameterGradients"; 40 protected const string ScaleInputValuesParameterName = "ScaleInputValues"; 40 41 41 42 #region Parameter Properties … … 60 61 get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogLikelihoodParameterName]; } 61 62 } 62 63 public ILookupParameter<BoolValue> ScaleInputValuesParameter { 64 get { return (ILookupParameter<BoolValue>)Parameters[ScaleInputValuesParameterName]; } 65 } 63 66 #endregion 64 67 … … 67 70 protected IMeanFunction MeanFunction { get { return MeanFunctionParameter.ActualValue; } } 68 71 protected ICovarianceFunction CovarianceFunction { get { return CovarianceFunctionParameter.ActualValue; } } 72 public bool ScaleInputValues { get { return ScaleInputValuesParameter.ActualValue.Value; } } 69 73 #endregion 70 74 … … 82 86 Parameters.Add(new LookupParameter<RealVector>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)")); 83 87 Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogLikelihoodParameterName, "The negative log-likelihood of the produced Gaussian process model given the data.")); 88 89 90 Parameters.Add(new LookupParameter<BoolValue>(ScaleInputValuesParameterName, 91 "Determines if the input variable values are scaled to the range [0..1] for training.")); 92 Parameters[ScaleInputValuesParameterName].Hidden = true; 93 } 94 95 [StorableHook(HookType.AfterDeserialization)] 96 private void AfterDeserialization() { 97 if (!Parameters.ContainsKey(ScaleInputValuesParameterName)) { 98 Parameters.Add(new LookupParameter<BoolValue>(ScaleInputValuesParameterName, 99 "Determines if the input variable values are scaled to the range [0..1] for training.")); 100 Parameters[ScaleInputValuesParameterName].Hidden = true; 101 } 84 102 } 85 103 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs
r12012 r13118 62 62 public override IOperation Apply() { 63 63 try { 64 var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction );64 var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction, ScaleInputValues); 65 65 ModelParameter.ActualValue = model; 66 66 NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood); … … 75 75 } 76 76 77 public static IGaussianProcessModel Create(IRegressionProblemData problemData, double[] hyperparameter, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction ) {78 return new GaussianProcessModel(problemData.Dataset, problemData.TargetVariable, problemData.AllowedInputVariables, problemData.TrainingIndices, hyperparameter, meanFunction, covarianceFunction );77 public static IGaussianProcessModel Create(IRegressionProblemData problemData, double[] hyperparameter, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction, bool scaleInputs = true) { 78 return new GaussianProcessModel(problemData.Dataset, problemData.TargetVariable, problemData.AllowedInputVariables, problemData.TrainingIndices, hyperparameter, meanFunction, covarianceFunction, scaleInputs); 79 79 } 80 80 }
Note: See TracChangeset
for help on using the changeset viewer.