Changeset 2440
- Timestamp:
- 10/20/09 11:20:13 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2422 r2440 137 137 int i = 0; 138 138 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; 140 140 } 141 141 return retVal; -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs
r2422 r2440 172 172 private void SetProblemParameters(HeuristicLab.Modeling.IAlgorithm algo, ProblemSpecification spec) { 173 173 algo.Dataset = spec.Dataset; 174 algo.TargetVariable = spec. Dataset.GetVariableIndex(spec.TargetVariable);174 algo.TargetVariable = spec.TargetVariable; 175 175 algo.TrainingSamplesStart = spec.TrainingSamplesStart; 176 176 algo.TrainingSamplesEnd = spec.TrainingSamplesEnd; … … 179 179 algo.TestSamplesStart = spec.TestSamplesStart; 180 180 algo.TestSamplesEnd = spec.TestSamplesEnd; 181 List< int> allowedFeatures = new List<int>();181 List<string> allowedFeatures = new List<string>(); 182 182 foreach (string inputVariable in spec.InputVariables) { 183 183 if (inputVariable != spec.TargetVariable) { 184 allowedFeatures.Add( spec.Dataset.GetVariableIndex(inputVariable));184 allowedFeatures.Add(inputVariable); 185 185 } 186 186 } … … 192 192 timeSeriesAlgo.TrainingSamplesStart = spec.TrainingSamplesStart - spec.MinTimeOffset + 1; // first possible index is 1 because of differential symbol 193 193 if (spec.AutoRegressive) { 194 allowedFeatures.Add(spec. Dataset.GetVariableIndex(spec.TargetVariable));194 allowedFeatures.Add(spec.TargetVariable); 195 195 } 196 196 } … … 240 240 return problemSpecifications[targetVariable]; 241 241 } 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 //}267 242 268 243 private ProblemSpecification CreateDefaultProblemSpecification(string targetVariable) { -
trunk/sources/HeuristicLab.GP.Boolean/3.3/Evaluator.cs
r2222 r2440 35 35 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the boolean expression to evaluate", typeof(IGeneticProgrammingModel), VariableKind.In)); 36 36 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)); 38 38 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); 39 39 AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 44 44 IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true); 45 45 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); 47 47 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; 48 48 int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data; -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassModeller.cs
r2328 r2440 47 47 : base() { 48 48 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)); 50 50 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)); 51 51 AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the new class A", typeof(DoubleData), VariableKind.New)); … … 59 59 public override IOperation Apply(IScope scope) { 60 60 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); 62 62 ItemList<DoubleData> classValues = GetVariableValue<ItemList<DoubleData>>(TARGETCLASSVALUES, scope, true); 63 63 int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data; -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs
r2328 r2440 52 52 : base() { 53 53 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)); 55 55 AddVariableInfo(new VariableInfo(TARGETCLASSVALUES, "Class values of the target variable in the original dataset", typeof(ItemList<DoubleData>), VariableKind.In)); 56 56 AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the class A in the subscope", typeof(DoubleData), VariableKind.In)); … … 67 67 public override IOperation Apply(IScope scope) { 68 68 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); 70 71 int trainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data; 71 72 int trainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data; … … 95 96 int correctlyClassified = 0; 96 97 for(int i = 0; i < (samplesEnd - samplesStart); i++) { 97 double originalClassValue = dataset.GetValue(i + samplesStart, targetVariable );98 double originalClassValue = dataset.GetValue(i + samplesStart, targetVariableIndex); 98 99 double estimatedClassValue = classValues[0].Data; 99 100 int maxVotes = votes[i, 0]; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs
r2341 r2440 32 32 AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IGeneticProgrammingModel), VariableKind.In)); 33 33 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)); 35 35 AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out)); 36 36 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 41 41 public override IOperation Apply(IScope scope) { 42 42 // get all variable values 43 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;44 43 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 44 int targetVariable = dataset.GetVariableIndex(GetVariableValue<StringData>("TargetVariable", scope, true).Data); 45 45 IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, true); 46 46 double totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL2TreeEvaluatorInjector.cs
r2327 r2440 37 37 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In)); 38 38 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)); 40 40 AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In)); 41 41 AddVariableInfo(new VariableInfo("TreeEvaluator", "The tree evaluator to evaluate models", typeof(ITreeEvaluator), VariableKind.New)); … … 51 51 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 52 52 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; 54 54 double mean = dataset.GetMean(targetVariable, start, end); 55 55 double range = dataset.GetRange(targetVariable, start, end); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL3TreeEvaluatorInjector.cs
r2327 r2440 37 37 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In)); 38 38 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)); 40 40 AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In)); 41 41 AddVariableInfo(new VariableInfo("TreeEvaluator", "The tree evaluator to evaluate models", typeof(ITreeEvaluator), VariableKind.New)); … … 51 51 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 52 52 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; 54 54 double mean = dataset.GetMean(targetVariable, start, end); 55 55 double range = dataset.GetRange(targetVariable, start, end); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/OffspringSelectionGPRegression.cs
r2419 r2440 39 39 public override string Name { get { return "OffspringSelectionGP - StructureIdentification"; } } 40 40 41 public virtual intTargetVariable {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; } 44 44 } 45 45 … … 57 57 } 58 58 } 59 public IEnumerable< int> AllowedVariables {59 public IEnumerable<string> AllowedVariables { 60 60 get { 61 ItemList< IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);61 ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false); 62 62 return allowedVariables.Select(x => x.Data); 63 63 } 64 64 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)); 67 67 } 68 68 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/PredictorBuilder.cs
r2332 r2440 40 40 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In)); 41 41 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)); 43 43 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)); 44 44 } … … 55 55 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 56 56 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; 58 58 IPredictor predictor = CreatePredictor(model, evaluator, punishmentFactor, dataset, targetVariable, start, end); 59 59 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor)); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGPRegression.cs
r2419 r2440 39 39 public override string Name { get { return "StandardGP - StructureIdentification"; } } 40 40 41 public virtual intTargetVariable {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; } 44 44 } 45 45 … … 58 58 } 59 59 60 public IEnumerable< int> AllowedVariables {60 public IEnumerable<string> AllowedVariables { 61 61 get { 62 ItemList< IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);62 ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false); 63 63 return allowedVariables.Select(x => x.Data); 64 64 } 65 65 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)); 68 68 } 69 69 } -
trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegression.cs
r2419 r2440 52 52 } 53 53 54 public virtual intTargetVariable {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; } 57 57 } 58 58 … … 70 70 } 71 71 } 72 public IEnumerable< int> AllowedVariables {72 public IEnumerable<string> AllowedVariables { 73 73 get { 74 ItemList< IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);74 ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false); 75 75 return allowedVariables.Select(x => x.Data); 76 76 } 77 77 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)); 80 80 } 81 81 } -
trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs
r2430 r2440 37 37 38 38 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)); 40 40 AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In)); 41 41 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 47 47 48 48 public override IOperation Apply(IScope scope) { 49 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;50 49 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 50 string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data; 51 int targetVariableIndex = dataset.GetVariableIndex(targetVariable); 51 52 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; 52 53 int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data; … … 56 57 int minTimeOffset = minTimeOffsetData == null ? 0 : minTimeOffsetData.Data; 57 58 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); 60 61 61 62 double[,] inputMatrix = PrepareInputMatrix(dataset, allowedColumns, allowedRows, minTimeOffset, maxTimeOffset); 62 double[] targetVector = PrepareTargetVector(dataset, targetVariable , allowedRows);63 double[] targetVector = PrepareTargetVector(dataset, targetVariableIndex, allowedRows); 63 64 double[] coefficients = CalculateCoefficients(inputMatrix, targetVector); 64 65 IFunctionTree tree = CreateModel(coefficients, allowedColumns.Select(i => dataset.GetVariableName(i)).ToList(), minTimeOffset, maxTimeOffset); -
trunk/sources/HeuristicLab.Modeling/3.2/DefaultModelAnalyzerOperators.cs
r2388 r2440 58 58 Dataset ds = modelScope.GetVariableValue<Dataset>("Dataset", true); 59 59 model.Dataset = ds; 60 model.TargetVariable = ds.GetVariableName(modelScope.GetVariableValue<IntData>("TargetVariable", true).Data);60 model.TargetVariable = modelScope.GetVariableValue<StringData>("TargetVariable", true).Data; 61 61 model.Type = ModelType.Regression; 62 62 model.TrainingSamplesStart = modelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data; -
trunk/sources/HeuristicLab.Modeling/3.2/IAlgorithm.cs
r2377 r2440 32 32 33 33 Dataset Dataset { get; set; } 34 IEnumerable< int> AllowedVariables { get; set; }34 IEnumerable<string> AllowedVariables { get; set; } 35 35 int TrainingSamplesStart { get; set; } 36 36 int TrainingSamplesEnd { get; set; } … … 39 39 int TestSamplesStart { get; set; } 40 40 int TestSamplesEnd { get; set; } 41 intTargetVariable { get; set; }41 string TargetVariable { get; set; } 42 42 IEngine Engine { get; } 43 43 IAnalyzerModel Model { get; } -
trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs
r2174 r2440 41 41 AddVariable(new Variable("Dataset", new Dataset())); 42 42 43 AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof( IntData), VariableKind.New));43 AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(StringData), VariableKind.New)); 44 44 GetVariableInfo("TargetVariable").Local = true; 45 AddVariable(new Variable("TargetVariable", new IntData()));45 AddVariable(new Variable("TargetVariable", new StringData())); 46 46 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)); 48 48 GetVariableInfo("AllowedFeatures").Local = true; 49 AddVariable(new Variable("AllowedFeatures", new ItemList< IntData>()));49 AddVariable(new Variable("AllowedFeatures", new ItemList<StringData>())); 50 50 51 51 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.New)); … … 94 94 95 95 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; 98 98 99 99 Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures); … … 104 104 105 105 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))); 107 107 scope.AddVariable(new Variable(scope.TranslateName("NumberOfInputVariables"), new IntData(scopeDataset.Columns - 1))); 108 108 scope.AddVariable(new Variable(scope.TranslateName("InputVariables"), inputVariables)); … … 127 127 } 128 128 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++; 140 142 } 141 143 } … … 148 150 double[] scalingFactor = new double[columns]; 149 151 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]; 153 155 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]; 157 160 } 158 161 ds.ScalingOffset = scalingOffset; -
trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjectorView.cs
r2285 r2440 106 106 TrySetVariable("TestSamplesStart", parser.TestSamplesStart); 107 107 TrySetVariable("TestSamplesEnd", parser.TestSamplesEnd); 108 TrySetVariable("TargetVariable", parser.TargetVariable); 109 108 110 109 for (int i = 0; i < parser.VariableNames.Length; i++) { 111 110 dataset.SetVariableName(i, parser.VariableNames[i]); 112 111 } 113 112 113 ((StringData)(ProblemInjector.GetVariable("TargetVariable").Value)).Data = 114 dataset.GetVariableName(parser.TargetVariable); 115 114 116 IVariable var = ProblemInjector.GetVariable("AllowedFeatures"); 115 117 if (var != null) { 116 ItemList< IntData> allowedFeatures = (ItemList<IntData>)var.Value;118 ItemList<StringData> allowedFeatures = (ItemList<StringData>)var.Value; 117 119 allowedFeatures.Clear(); 118 120 List<int> nonInputVariables = parser.NonInputVariables; 119 121 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))); 121 123 } 122 124 } -
trunk/sources/HeuristicLab.Modeling/3.2/TargetClassesCalculator.cs
r2351 r2440 32 32 : base() { 33 33 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)); 35 35 AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList<DoubleData>), VariableKind.New)); 36 36 } … … 38 38 public override IOperation Apply(IScope scope) { 39 39 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; 41 41 42 42 ItemList<DoubleData> classes = new ItemList<DoubleData>(); -
trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs
r2379 r2440 37 37 AddVariableInfo(new VariableInfo("Predictor", "The predictor used to evaluate the model", typeof(IPredictor), VariableKind.In)); 38 38 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)); 40 40 AddVariableInfo(new VariableInfo("InputVariableNames", "Names of used variables in the model (optional)", typeof(ItemList<StringData>), VariableKind.In)); 41 41 AddVariableInfo(new VariableInfo("SamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In)); … … 51 51 IPredictor predictor = GetVariableValue<IPredictor>("Predictor", scope, true); 52 52 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); 55 55 ItemList<StringData> inputVariableNames = GetVariableValue<ItemList<StringData>>("InputVariableNames", scope, true, false); 56 56 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; -
trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs
r2379 r2440 36 36 AddVariableInfo(new VariableInfo("Predictor", "The predictor used to evaluate the model", typeof(IPredictor), VariableKind.In)); 37 37 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)); 39 39 AddVariableInfo(new VariableInfo("InputVariableNames", "Names of used variables in the model (optional)", typeof(ItemList<StringData>), VariableKind.In)); 40 40 AddVariableInfo(new VariableInfo("SamplesStart", "SamplesStart", typeof(IntData), VariableKind.In)); … … 50 50 IPredictor predictor = GetVariableValue<IPredictor>("Predictor", scope, true); 51 51 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); 54 54 ItemList<StringData> inputVariableNames = GetVariableValue<ItemList<StringData>>("InputVariableNames", scope, true, false); 55 55 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorBuilder.cs
r2421 r2440 52 52 Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true); 53 53 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; 55 55 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 56 56 int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; … … 61 61 double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data; 62 62 63 string targetVariableName = ds.GetVariableName(targetVariable);63 64 64 ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true); 65 65 var inputVariableNames = from x in inputVariables … … 69 69 double range = ds.GetRange(targetVariable, start, end); 70 70 71 Predictor predictor = new Predictor(model, targetVariable Name, inputVariableNames, minTimeOffset, maxTimeOffset);71 Predictor predictor = new Predictor(model, targetVariable, inputVariableNames, minTimeOffset, maxTimeOffset); 72 72 predictor.LowerPredictionLimit = mean - punishmentFactor * range; 73 73 predictor.UpperPredictionLimit = mean + punishmentFactor * range; -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs
r2421 r2440 40 40 //Dataset infos 41 41 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)); 43 43 AddVariableInfo(new VariableInfo("InputVariables", "List of allowed input variable names", typeof(ItemList), VariableKind.In)); 44 44 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 70 70 abortRequested = false; 71 71 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 75 76 select ((StringData)x).Data; 76 77 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; … … 93 94 parameter.Probability = false; 94 95 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); 96 97 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 97 98 SVM.Problem scaledProblem = rangeTransform.Scale(problem); -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs
r2421 r2440 36 36 //Dataset infos 37 37 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)); 39 39 AddVariableInfo(new VariableInfo("InputVariables", "List of allowed input variable names", typeof(ItemList), VariableKind.In)); 40 40 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 52 52 var inputVariableNames = from x in inputVariables 53 53 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); 55 56 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; 56 57 int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data; … … 61 62 SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true); 62 63 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); 64 65 SVM.Problem scaledProblem = modelData.RangeTransform.Scale(problem); 65 66 66 67 double[,] values = new double[scaledProblem.Count, 2]; 67 68 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); 69 70 values[i, 1] = SVM.Prediction.Predict(modelData.Model, scaledProblem.X[i]); 70 71 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs
r2419 r2440 52 52 } 53 53 54 public intTargetVariable {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; } 57 57 } 58 58 … … 78 78 } 79 79 } 80 public IEnumerable< int> AllowedVariables {80 public IEnumerable<string> AllowedVariables { 81 81 get { 82 ItemList< IntData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<IntData>>("AllowedFeatures", null, false);82 ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false); 83 83 return allowedVariables.Select(x => x.Data); 84 84 } 85 85 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)); 88 88 } 89 89 }
Note: See TracChangeset
for help on using the changeset viewer.