Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/20/09 11:20:13 (15 years ago)
Author:
gkronber
Message:

Fixed #784 (ProblemInjector should be changed to read variable names instead of indexes for input and target variables)

Location:
trunk/sources/HeuristicLab.LinearRegression/3.2
Files:
2 edited

Legend:

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

    r2419 r2440  
    5252    }
    5353
    54     public virtual int TargetVariable {
    55       get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
    56       set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
     54    public virtual string TargetVariable {
     55      get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; }
     56      set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; }
    5757    }
    5858
     
    7070      }
    7171    }
    72     public IEnumerable<int> AllowedVariables {
     72    public IEnumerable<string> AllowedVariables {
    7373      get {
    74         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
     74        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
    7575        return allowedVariables.Select(x => x.Data);
    7676      }
    7777      set {
    78         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
    79         foreach (int x in value) allowedVariables.Add(new IntData(x));
     78        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
     79        foreach (string x in value) allowedVariables.Add(new StringData(x));
    8080      }
    8181    }
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs

    r2430 r2440  
    3737
    3838    public LinearRegressionOperator() {
    39       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     39      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    4040      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    4747
    4848    public override IOperation Apply(IScope scope) {
    49       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5049      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
     50      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
     51      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    5152      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
    5253      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
     
    5657      int minTimeOffset = minTimeOffsetData == null ? 0 : minTimeOffsetData.Data;
    5758
    58       List<int> allowedColumns = CalculateAllowedColumns(dataset, targetVariable, start, end);
    59       List<int> allowedRows = CalculateAllowedRows(dataset, targetVariable, allowedColumns, start, end, minTimeOffset, maxTimeOffset);
     59      List<int> allowedColumns = CalculateAllowedColumns(dataset, targetVariableIndex, start, end);
     60      List<int> allowedRows = CalculateAllowedRows(dataset, targetVariableIndex, allowedColumns, start, end, minTimeOffset, maxTimeOffset);
    6061
    6162      double[,] inputMatrix = PrepareInputMatrix(dataset, allowedColumns, allowedRows, minTimeOffset, maxTimeOffset);
    62       double[] targetVector = PrepareTargetVector(dataset, targetVariable, allowedRows);
     63      double[] targetVector = PrepareTargetVector(dataset, targetVariableIndex, allowedRows);
    6364      double[] coefficients = CalculateCoefficients(inputMatrix, targetVector);
    6465      IFunctionTree tree = CreateModel(coefficients, allowedColumns.Select(i => dataset.GetVariableName(i)).ToList(), minTimeOffset, maxTimeOffset);
Note: See TracChangeset for help on using the changeset viewer.