Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2440


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
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r2422 r2440  
    137137        int i = 0;
    138138        foreach (HeuristicLab.Modeling.IAlgorithm a in activeAlgorithms.Values) {
    139           retVal[i++] = a.Name + " " + a.Dataset.GetVariableName(a.TargetVariable);
     139          retVal[i++] = a.Name + " " + a.TargetVariable;
    140140        }
    141141        return retVal;
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs

    r2422 r2440  
    172172    private void SetProblemParameters(HeuristicLab.Modeling.IAlgorithm algo, ProblemSpecification spec) {
    173173      algo.Dataset = spec.Dataset;
    174       algo.TargetVariable = spec.Dataset.GetVariableIndex(spec.TargetVariable);
     174      algo.TargetVariable = spec.TargetVariable;
    175175      algo.TrainingSamplesStart = spec.TrainingSamplesStart;
    176176      algo.TrainingSamplesEnd = spec.TrainingSamplesEnd;
     
    179179      algo.TestSamplesStart = spec.TestSamplesStart;
    180180      algo.TestSamplesEnd = spec.TestSamplesEnd;
    181       List<int> allowedFeatures = new List<int>();
     181      List<string> allowedFeatures = new List<string>();
    182182      foreach (string inputVariable in spec.InputVariables) {
    183183        if (inputVariable != spec.TargetVariable) {
    184           allowedFeatures.Add(spec.Dataset.GetVariableIndex(inputVariable));
     184          allowedFeatures.Add(inputVariable);
    185185        }
    186186      }
     
    192192        timeSeriesAlgo.TrainingSamplesStart = spec.TrainingSamplesStart - spec.MinTimeOffset + 1; // first possible index is 1 because of differential symbol
    193193        if (spec.AutoRegressive) {
    194           allowedFeatures.Add(spec.Dataset.GetVariableIndex(spec.TargetVariable));
     194          allowedFeatures.Add(spec.TargetVariable);
    195195        }
    196196      }
     
    240240      return problemSpecifications[targetVariable];
    241241    }
    242 
    243     //internal void EnableInputVariable(string target, string name) {
    244     //  problemSpecifications[target].AddInputVariable(name);
    245     //}
    246 
    247     //internal void DisableInputVariable(string target, string name) {
    248     //  problemSpecifications[target].RemoveInputVariable(name);
    249     //}
    250 
    251     //internal void SetLearningTask(string target, LearningTask task) {
    252     //  problemSpecifications[target].LearningTask = task;
    253     //}
    254 
    255     //internal void SetDatasetBoundaries(
    256     //  string target,
    257     //  int trainingStart, int trainingEnd,
    258     //  int validationStart, int validationEnd,
    259     //  int testStart, int testEnd) {
    260     //  problemSpecifications[target].TrainingSamplesStart = trainingStart;
    261     //  problemSpecifications[target].TrainingSamplesEnd = trainingEnd;
    262     //  problemSpecifications[target].ValidationSamplesStart = validationStart;
    263     //  problemSpecifications[target].ValidationSamplesEnd = validationEnd;
    264     //  problemSpecifications[target].TestSamplesStart = testStart;
    265     //  problemSpecifications[target].TestSamplesEnd = testEnd;
    266     //}
    267242
    268243    private ProblemSpecification CreateDefaultProblemSpecification(string targetVariable) {
  • trunk/sources/HeuristicLab.GP.Boolean/3.3/Evaluator.cs

    r2222 r2440  
    3535      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the boolean expression to evaluate", typeof(IGeneticProgrammingModel), VariableKind.In));
    3636      AddVariableInfo(new VariableInfo("Dataset", "The boolean dataset (values 0.0 = false, 1.0=true)", typeof(Dataset), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     37      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    4444      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    4545      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    46       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     46      int targetVariable = dataset.GetVariableIndex(GetVariableValue<StringData>("TargetVariable", scope, true).Data);
    4747      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
    4848      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassModeller.cs

    r2328 r2440  
    4747      : base() {
    4848      AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new dataset parts in the newly created subscopes", typeof(Dataset), VariableKind.In));
    49       AddVariableInfo(new VariableInfo(TARGETVARIABLE, "TargetVariable", typeof(IntData), VariableKind.In));
     49      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "TargetVariable", typeof(StringData), VariableKind.In));
    5050      AddVariableInfo(new VariableInfo(TARGETCLASSVALUES, "Class values of the target variable in the original dataset and in the new dataset parts", typeof(ItemList<DoubleData>), VariableKind.In | VariableKind.New));
    5151      AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the new class A", typeof(DoubleData), VariableKind.New));
     
    5959    public override IOperation Apply(IScope scope) {
    6060      Dataset origDataset = GetVariableValue<Dataset>(DATASET, scope, true);
    61       int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     61      int targetVariable = origDataset.GetVariableIndex(GetVariableValue<StringData>(TARGETVARIABLE, scope, true).Data);
    6262      ItemList<DoubleData> classValues = GetVariableValue<ItemList<DoubleData>>(TARGETCLASSVALUES, scope, true);
    6363      int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs

    r2328 r2440  
    5252      : base() {
    5353      AddVariableInfo(new VariableInfo(DATASET, "The dataset to use", typeof(Dataset), VariableKind.In));
    54       AddVariableInfo(new VariableInfo(TARGETVARIABLE, "Target variable", typeof(IntData), VariableKind.In));
     54      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "Target variable", typeof(StringData), VariableKind.In));
    5555      AddVariableInfo(new VariableInfo(TARGETCLASSVALUES, "Class values of the target variable in the original dataset", typeof(ItemList<DoubleData>), VariableKind.In));
    5656      AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the class A in the subscope", typeof(DoubleData), VariableKind.In));
     
    6767    public override IOperation Apply(IScope scope) {
    6868      Dataset dataset = GetVariableValue<Dataset>(DATASET, scope, true);
    69       int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     69      string targetVariable = GetVariableValue<StringData>(TARGETVARIABLE, scope, true).Data;
     70      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    7071      int trainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
    7172      int trainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data;
     
    9596      int correctlyClassified = 0;
    9697      for(int i = 0; i < (samplesEnd - samplesStart); i++) {
    97         double originalClassValue = dataset.GetValue(i + samplesStart, targetVariable);
     98        double originalClassValue = dataset.GetValue(i + samplesStart, targetVariableIndex);
    9899        double estimatedClassValue = classValues[0].Data;
    99100        int maxVotes = votes[i, 0];
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs

    r2341 r2440  
    3232      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IGeneticProgrammingModel), VariableKind.In));
    3333      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    34       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     34      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    3535      AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));
    3636      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    4141    public override IOperation Apply(IScope scope) {
    4242      // get all variable values
    43       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    4443      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
     44      int targetVariable = dataset.GetVariableIndex(GetVariableValue<StringData>("TargetVariable", scope, true).Data);
    4545      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true);
    4646      double totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL2TreeEvaluatorInjector.cs

    r2327 r2440  
    3737      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In));
    39       AddVariableInfo(new VariableInfo("TargetVariable", "Index of 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("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("TreeEvaluator", "The tree evaluator to evaluate models", typeof(ITreeEvaluator), VariableKind.New));
     
    5151      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    5252      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    53       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     53      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
    5454      double mean = dataset.GetMean(targetVariable, start, end);
    5555      double range = dataset.GetRange(targetVariable, start, end);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL3TreeEvaluatorInjector.cs

    r2327 r2440  
    3737      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In));
    39       AddVariableInfo(new VariableInfo("TargetVariable", "Index of 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("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("TreeEvaluator", "The tree evaluator to evaluate models", typeof(ITreeEvaluator), VariableKind.New));
     
    5151      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    5252      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    53       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     53      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
    5454      double mean = dataset.GetMean(targetVariable, start, end);
    5555      double range = dataset.GetRange(targetVariable, start, end);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffspringSelectionGPRegression.cs

    r2419 r2440  
    3939    public override string Name { get { return "OffspringSelectionGP - StructureIdentification"; } }
    4040
    41     public virtual int TargetVariable {
    42       get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
    43       set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
     41    public virtual string TargetVariable {
     42      get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; }
     43      set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; }
    4444    }
    4545
     
    5757      }
    5858    }
    59     public IEnumerable<int> AllowedVariables {
     59    public IEnumerable<string> AllowedVariables {
    6060      get {
    61         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
     61        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
    6262        return allowedVariables.Select(x => x.Data);
    6363      }
    6464      set {
    65         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
    66         foreach (int x in value) allowedVariables.Add(new IntData(x));
     65        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
     66        foreach (string x in value) allowedVariables.Add(new StringData(x));
    6767      }
    6868    }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/PredictorBuilder.cs

    r2332 r2440  
    4040      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In));
    42       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the target variable", typeof(IntData), VariableKind.In));
     42      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    4343      AddVariableInfo(new VariableInfo("Predictor", "The predictor combines the function tree and the evaluator and can be used to generate estimated values", typeof(IPredictor), VariableKind.New));
    4444    }
     
    5555      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    5656      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    57       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     57      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
    5858      IPredictor predictor = CreatePredictor(model, evaluator, punishmentFactor, dataset, targetVariable, start, end);
    5959      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGPRegression.cs

    r2419 r2440  
    3939    public override string Name { get { return "StandardGP - StructureIdentification"; } }
    4040
    41     public virtual int TargetVariable {
    42       get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
    43       set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
     41    public virtual string TargetVariable {
     42      get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; }
     43      set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; }
    4444    }
    4545
     
    5858    }
    5959
    60     public IEnumerable<int> AllowedVariables {
     60    public IEnumerable<string> AllowedVariables {
    6161      get {
    62         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
     62        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
    6363        return allowedVariables.Select(x => x.Data);
    6464      }
    6565      set {
    66         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
    67         foreach (int x in value) allowedVariables.Add(new IntData(x));
     66        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
     67        foreach (string x in value) allowedVariables.Add(new StringData(x));
    6868      }
    6969    }
  • 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);
  • 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;
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorBuilder.cs

    r2421 r2440  
    5252      Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true);
    5353      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    54       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     54      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
    5555      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    5656      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
     
    6161      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    6262
    63       string targetVariableName = ds.GetVariableName(targetVariable);
     63     
    6464      ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true);
    6565      var inputVariableNames = from x in inputVariables
     
    6969      double range = ds.GetRange(targetVariable, start, end);
    7070
    71       Predictor predictor = new Predictor(model, targetVariableName, inputVariableNames, minTimeOffset, maxTimeOffset);
     71      Predictor predictor = new Predictor(model, targetVariable, inputVariableNames, minTimeOffset, maxTimeOffset);
    7272      predictor.LowerPredictionLimit = mean - punishmentFactor * range;
    7373      predictor.UpperPredictionLimit = mean + punishmentFactor * range;
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs

    r2421 r2440  
    4040      //Dataset infos
    4141      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    42       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     42      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    4343      AddVariableInfo(new VariableInfo("InputVariables", "List of allowed input variable names", typeof(ItemList), VariableKind.In));
    4444      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    7070      abortRequested = false;
    7171      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    72       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    73       ItemList inputVaribales = GetVariableValue<ItemList>("InputVariables", scope, true);
    74       var inputVariableNames = from x in inputVaribales
     72      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
     73      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
     74      ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true);
     75      var inputVariableNames = from x in inputVariables
    7576                               select ((StringData)x).Data;
    7677      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
     
    9394      parameter.Probability = false;
    9495
    95       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, inputVariableNames, start, end, minTimeOffset, maxTimeOffset);
     96      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariableIndex, inputVariableNames, start, end, minTimeOffset, maxTimeOffset);
    9697      SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem);
    9798      SVM.Problem scaledProblem = rangeTransform.Scale(problem);
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs

    r2421 r2440  
    3636      //Dataset infos
    3737      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    38       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
     38      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("InputVariables", "List of allowed input variable names", typeof(ItemList), VariableKind.In));
    4040      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    5252      var inputVariableNames = from x in inputVariables
    5353                               select ((StringData)x).Data;
    54       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     54      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
     55      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    5556      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
    5657      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
     
    6162      SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true);
    6263
    63       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, inputVariableNames, start, end, minTimeOffset, maxTimeOffset);
     64      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariableIndex, inputVariableNames, start, end, minTimeOffset, maxTimeOffset);
    6465      SVM.Problem scaledProblem = modelData.RangeTransform.Scale(problem);
    6566
    6667      double[,] values = new double[scaledProblem.Count, 2];
    6768      for (int i = 0; i < scaledProblem.Count; i++) {
    68         values[i, 0] = dataset.GetValue(start + i, targetVariable);
     69        values[i, 0] = dataset.GetValue(start + i, targetVariableIndex);
    6970        values[i, 1] = SVM.Prediction.Predict(modelData.Model, scaledProblem.X[i]);
    7071      }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r2419 r2440  
    5252    }
    5353
    54     public int TargetVariable {
    55       get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
    56       set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
     54    public string TargetVariable {
     55      get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; }
     56      set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; }
    5757    }
    5858
     
    7878      }
    7979    }
    80     public IEnumerable<int> AllowedVariables {
     80    public IEnumerable<string> AllowedVariables {
    8181      get {
    82         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
     82        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
    8383        return allowedVariables.Select(x => x.Data);
    8484      }
    8585      set {
    86         ItemList<IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);
    87         foreach (int x in value) allowedVariables.Add(new IntData(x));
     86        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
     87        foreach (string x in value) allowedVariables.Add(new StringData(x));
    8888      }
    8989    }
Note: See TracChangeset for help on using the changeset viewer.