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.Modeling/3.2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/DefaultModelAnalyzerOperators.cs

    r2388 r2440  
    5858      Dataset ds = modelScope.GetVariableValue<Dataset>("Dataset", true);
    5959      model.Dataset = ds;
    60       model.TargetVariable = ds.GetVariableName(modelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
     60      model.TargetVariable = modelScope.GetVariableValue<StringData>("TargetVariable", true).Data;
    6161      model.Type = ModelType.Regression;
    6262      model.TrainingSamplesStart = modelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
  • trunk/sources/HeuristicLab.Modeling/3.2/IAlgorithm.cs

    r2377 r2440  
    3232
    3333    Dataset Dataset { get; set; }
    34     IEnumerable<int> AllowedVariables { get; set; }
     34    IEnumerable<string> AllowedVariables { get; set; }
    3535    int TrainingSamplesStart { get; set; }
    3636    int TrainingSamplesEnd { get; set; }
     
    3939    int TestSamplesStart { get; set; }
    4040    int TestSamplesEnd { get; set; }
    41     int TargetVariable { get; set; }
     41    string TargetVariable { get; set; }
    4242    IEngine Engine { get; }
    4343    IAnalyzerModel Model { get; }
  • trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs

    r2174 r2440  
    4141      AddVariable(new Variable("Dataset", new Dataset()));
    4242
    43       AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.New));
     43      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(StringData), VariableKind.New));
    4444      GetVariableInfo("TargetVariable").Local = true;
    45       AddVariable(new Variable("TargetVariable", new IntData()));
     45      AddVariable(new Variable("TargetVariable", new StringData()));
    4646
    47       AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<IntData>), VariableKind.New));
     47      AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<StringData>), VariableKind.In));
    4848      GetVariableInfo("AllowedFeatures").Local = true;
    49       AddVariable(new Variable("AllowedFeatures", new ItemList<IntData>()));
     49      AddVariable(new Variable("AllowedFeatures", new ItemList<StringData>()));
    5050
    5151      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.New));
     
    9494
    9595      Dataset operatorDataset = (Dataset)GetVariable("Dataset").Value;
    96       int targetVariable = ((IntData)GetVariable("TargetVariable").Value).Data;
    97       ItemList<IntData> operatorAllowedFeatures = (ItemList<IntData>)GetVariable("AllowedFeatures").Value;
     96      string targetVariable = ((StringData)GetVariable("TargetVariable").Value).Data;
     97      ItemList<StringData> operatorAllowedFeatures = (ItemList<StringData>)GetVariable("AllowedFeatures").Value;
    9898
    9999      Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures);
     
    104104
    105105      scope.AddVariable(new Variable(scope.TranslateName("Dataset"), scopeDataset));
    106       scope.AddVariable(new Variable(scope.TranslateName("TargetVariable"), new IntData(0)));
     106      scope.AddVariable(new Variable(scope.TranslateName("TargetVariable"), new StringData(targetVariable)));
    107107      scope.AddVariable(new Variable(scope.TranslateName("NumberOfInputVariables"), new IntData(scopeDataset.Columns - 1)));
    108108      scope.AddVariable(new Variable(scope.TranslateName("InputVariables"), inputVariables));
     
    127127    }
    128128
    129     private Dataset CreateNewDataset(Dataset operatorDataset, int targetVariable, ItemList<IntData> operatorAllowedFeatures) {
    130       int columns = (operatorAllowedFeatures.Count() + 1);
    131       double[] values = new double[operatorDataset.Rows * columns];
    132 
    133       for (int i = 0; i < values.Length; i++) {
    134         int row = i / columns;
    135         int column = i % columns;
    136         if (column == 0) {
    137           values[i] = operatorDataset.GetValue(row, targetVariable);
    138         } else {
    139           values[i] = operatorDataset.GetValue(row, operatorAllowedFeatures[column-1].Data);
     129    private Dataset CreateNewDataset(Dataset operatorDataset, string targetVariable, ItemList<StringData> operatorAllowedVariables) {
     130      int columns = (operatorAllowedVariables.Count() + 1);
     131      int rows = operatorDataset.Rows;
     132      double[] values = new double[rows * columns];
     133      int targetVariableIndex = operatorDataset.GetVariableIndex(targetVariable);
     134      for (int row = 0; row < rows; row++) {
     135        int column = 0;
     136        values[row*columns + column] = operatorDataset.GetValue(row, targetVariableIndex); // set target variable value to column index 0
     137        column++; // start input variables at column index 1
     138        foreach (var inputVariable in operatorAllowedVariables) {
     139          int variableColumnIndex = operatorDataset.GetVariableIndex(inputVariable.Data);
     140          values[row * columns + column] = operatorDataset.GetValue(row, variableColumnIndex);
     141          column++;
    140142        }
    141143      }
     
    148150      double[] scalingFactor = new double[columns];
    149151      double[] scalingOffset = new double[columns];
    150       ds.SetVariableName(0, operatorDataset.GetVariableName(targetVariable));
    151       scalingFactor[0] = operatorDataset.ScalingFactor[targetVariable];
    152       scalingOffset[0] = operatorDataset.ScalingOffset[targetVariable];
     152      ds.SetVariableName(0, targetVariable);
     153      scalingFactor[0] = operatorDataset.ScalingFactor[targetVariableIndex];
     154      scalingOffset[0] = operatorDataset.ScalingOffset[targetVariableIndex];
    153155      for (int column = 1; column < columns; column++) {
    154         ds.SetVariableName(column, operatorDataset.GetVariableName(operatorAllowedFeatures[column - 1].Data));
    155         scalingFactor[column] = operatorDataset.ScalingFactor[operatorAllowedFeatures[column - 1].Data];
    156         scalingOffset[column] = operatorDataset.ScalingOffset[operatorAllowedFeatures[column - 1].Data];
     156        int variableColumnIndex = operatorDataset.GetVariableIndex(operatorAllowedVariables[column - 1].Data);
     157        ds.SetVariableName(column, operatorAllowedVariables[column - 1].Data);
     158        scalingFactor[column] = operatorDataset.ScalingFactor[variableColumnIndex];
     159        scalingOffset[column] = operatorDataset.ScalingOffset[variableColumnIndex];
    157160      }
    158161      ds.ScalingOffset = scalingOffset;
  • trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjectorView.cs

    r2285 r2440  
    106106          TrySetVariable("TestSamplesStart", parser.TestSamplesStart);
    107107          TrySetVariable("TestSamplesEnd", parser.TestSamplesEnd);
    108           TrySetVariable("TargetVariable", parser.TargetVariable);
    109 
     108         
    110109          for (int i = 0; i < parser.VariableNames.Length; i++) {
    111110            dataset.SetVariableName(i, parser.VariableNames[i]);
    112111          }
    113112
     113          ((StringData)(ProblemInjector.GetVariable("TargetVariable").Value)).Data =
     114            dataset.GetVariableName(parser.TargetVariable);
     115
    114116          IVariable var = ProblemInjector.GetVariable("AllowedFeatures");
    115117          if (var != null) {
    116             ItemList<IntData> allowedFeatures = (ItemList<IntData>)var.Value;
     118            ItemList<StringData> allowedFeatures = (ItemList<StringData>)var.Value;
    117119            allowedFeatures.Clear();
    118120            List<int> nonInputVariables = parser.NonInputVariables;
    119121            for (int i = 0; i < dataset.Columns; i++) {
    120               if (!nonInputVariables.Contains(i)) allowedFeatures.Add(new IntData(i));
     122              if (!nonInputVariables.Contains(i)) allowedFeatures.Add(new StringData(dataset.GetVariableName(i)));
    121123            }
    122124          }
  • trunk/sources/HeuristicLab.Modeling/3.2/TargetClassesCalculator.cs

    r2351 r2440  
    3232      : base() {
    3333      AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In));
    34       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the target variable", typeof(IntData), VariableKind.In));
     34      AddVariableInfo(new VariableInfo("TargetVariable", "Name the target variable", typeof(StringData), VariableKind.In));
    3535      AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList<DoubleData>), VariableKind.New));
    3636    }
     
    3838    public override IOperation Apply(IScope scope) {
    3939      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    40       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     40      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
    4141
    4242      ItemList<DoubleData> classes = new ItemList<DoubleData>();
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs

    r2379 r2440  
    3737      AddVariableInfo(new VariableInfo("Predictor", "The predictor used to evaluate the model", typeof(IPredictor), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In));
    39       AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.In));
     39      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(StringData), VariableKind.In));
    4040      AddVariableInfo(new VariableInfo("InputVariableNames", "Names of used variables in the model (optional)", typeof(ItemList<StringData>), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("SamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In));
     
    5151      IPredictor predictor = GetVariableValue<IPredictor>("Predictor", scope, true);
    5252      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    53       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    54       string targetVariableName = dataset.GetVariableName(targetVariable);
     53      string targetVariableName = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
     54      int targetVariable = dataset.GetVariableIndex(targetVariableName);
    5555      ItemList<StringData> inputVariableNames = GetVariableValue<ItemList<StringData>>("InputVariableNames", scope, true, false);
    5656      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs

    r2379 r2440  
    3636      AddVariableInfo(new VariableInfo("Predictor", "The predictor used to evaluate the model", typeof(IPredictor), VariableKind.In));
    3737      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In));
    38       AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.In));
     38      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(StringData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("InputVariableNames", "Names of used variables in the model (optional)", typeof(ItemList<StringData>), VariableKind.In));
    4040      AddVariableInfo(new VariableInfo("SamplesStart", "SamplesStart", typeof(IntData), VariableKind.In));
     
    5050      IPredictor predictor = GetVariableValue<IPredictor>("Predictor", scope, true);
    5151      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    52       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    53       string targetVariableName = dataset.GetVariableName(targetVariable);
     52      string targetVariableName = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
     53      int targetVariable = dataset.GetVariableIndex(targetVariableName);
    5454      ItemList<StringData> inputVariableNames = GetVariableValue<ItemList<StringData>>("InputVariableNames", scope, true, false);
    5555      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
Note: See TracChangeset for help on using the changeset viewer.