Changeset 2789


Ignore:
Timestamp:
02/12/10 15:39:18 (11 years ago)
Author:
gkronber
Message:

Fixed #874 (LR doesn't work with an empty set of allowed input variables.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs

    r2542 r2789  
    3737
    3838    public LinearRegressionOperator() {
     39      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    3940      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
     41      AddVariableInfo(new VariableInfo("InputVariables", "List of allowed input variable names", typeof(ItemList), VariableKind.In));
    4142      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
    4243      AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    5657      IntData minTimeOffsetData = GetVariableValue<IntData>("MinTimeOffset", scope, true, false);
    5758      int minTimeOffset = minTimeOffsetData == null ? 0 : minTimeOffsetData.Data;
    58 
    59       IFunctionTree tree = CreateModel(dataset, targetVariable, dataset.VariableNames, start, end, minTimeOffset, maxTimeOffset);
     59      ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true, false);
     60     
     61      IFunctionTree tree;
     62      if (inputVariables != null) {
     63        tree = CreateModel(dataset, targetVariable, inputVariables.Cast<StringData>().Select(x => x.Data), start, end, minTimeOffset, maxTimeOffset);
     64      } else {
     65        tree = CreateModel(dataset, targetVariable, dataset.VariableNames, start, end, minTimeOffset, maxTimeOffset);
     66      }
    6067      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("LinearRegressionModel"), new GeneticProgrammingModel(tree)));
    6168      return null;
     
    106113      int n = targetVector.Length;
    107114      int p = inputMatrix.GetLength(1);
     115      // no features allowed -> return constant offset
     116      if (p == 0) return new double[] { Statistics.Mean(targetVector) };
    108117      double[,] dataset = new double[n, p];
    109118      for (int row = 0; row < n; row++) {
Note: See TracChangeset for help on using the changeset viewer.