Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/05/15 07:46:38 (8 years ago)
Author:
gkronber
Message:

#2497: added hidden parameter to turn on/off scaling of input variables in Gaussian process models

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  
    5151    protected const string HyperparameterGradientsParameterName = "HyperparameterGradients";
    5252    protected const string SolutionCreatorParameterName = "GaussianProcessSolutionCreator";
     53    protected const string ScaleInputValuesParameterName = "ScaleInputValues";
    5354
    5455    public new IDataAnalysisProblem Problem {
     
    7273    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
    7374      get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
     75    }
     76    public IFixedValueParameter<BoolValue> ScaleInputValuesParameter {
     77      get { return (IFixedValueParameter<BoolValue>)Parameters[ScaleInputValuesParameterName]; }
    7478    }
    7579    #endregion
     
    8993    public int Seed { get { return SeedParameter.Value.Value; } set { SeedParameter.Value.Value = value; } }
    9094    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    }
    91100    #endregion
    92101
     
    107116      Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false)));
    108117      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;
    109122
    110123      // necessary for BFGS
     
    191204        Parameters["Maximization"].Hidden = true;
    192205      }
     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      }
    193212      #endregion
    194213    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r12819 r13118  
    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
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs

    r12012 r13118  
    3838    private const string NegativeLogLikelihoodParameterName = "NegativeLogLikelihood";
    3939    private const string HyperparameterGradientsParameterName = "HyperparameterGradients";
     40    protected const string ScaleInputValuesParameterName = "ScaleInputValues";
    4041
    4142    #region Parameter Properties
     
    6061      get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogLikelihoodParameterName]; }
    6162    }
    62 
     63    public ILookupParameter<BoolValue> ScaleInputValuesParameter {
     64      get { return (ILookupParameter<BoolValue>)Parameters[ScaleInputValuesParameterName]; }
     65    }
    6366    #endregion
    6467
     
    6770    protected IMeanFunction MeanFunction { get { return MeanFunctionParameter.ActualValue; } }
    6871    protected ICovarianceFunction CovarianceFunction { get { return CovarianceFunctionParameter.ActualValue; } }
     72    public bool ScaleInputValues { get { return ScaleInputValuesParameter.ActualValue.Value; } }
    6973    #endregion
    7074
     
    8286      Parameters.Add(new LookupParameter<RealVector>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)"));
    8387      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      }
    84102    }
    85103  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs

    r12012 r13118  
    6262    public override IOperation Apply() {
    6363      try {
    64         var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction);
     64        var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction, ScaleInputValues);
    6565        ModelParameter.ActualValue = model;
    6666        NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood);
     
    7575    }
    7676
    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);
    7979    }
    8080  }
Note: See TracChangeset for help on using the changeset viewer.