Changeset 2440 for trunk/sources/HeuristicLab.Modeling
- Timestamp:
- 10/20/09 11:20:13 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Modeling/3.2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.