- Timestamp:
- 07/15/09 17:33:39 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/3.2/Dataset.cs
r2144 r2162 69 69 public double[] ScalingFactor { 70 70 get { return scalingFactor; } 71 set { 72 if (value.Length != scalingFactor.Length) 73 throw new ArgumentException("Length of scaling factor array doesn't match number of variables"); 74 scalingFactor = value; 75 } 71 76 } 72 77 public double[] ScalingOffset { 73 78 get { return scalingOffset; } 79 set { 80 if (value.Length != scalingOffset.Length) 81 throw new ArgumentException("Length of scaling offset array doesn't match number of variables"); 82 scalingOffset = value; } 74 83 } 75 84 -
trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs
r2161 r2162 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.DataAnalysis; 29 using System.Linq; 29 30 30 31 namespace HeuristicLab.Modeling { … … 83 84 84 85 public override IOperation Apply(IScope scope) { 85 AddVariableToScope("Dataset", scope);86 AddVariableToScope("TargetVariable", scope);87 AddVariableToScope("AllowedFeatures", scope);88 86 AddVariableToScope("TrainingSamplesStart", scope); 89 87 AddVariableToScope("TrainingSamplesEnd", scope); … … 92 90 AddVariableToScope("TestSamplesStart", scope); 93 91 AddVariableToScope("TestSamplesEnd", scope); 92 93 Dataset operatorDataset = (Dataset)GetVariable("Dataset").Value; 94 int targetVariable = ((IntData)GetVariable("TargetVariable").Value).Data; 95 ItemList<IntData> operatorAllowedFeatures = (ItemList<IntData>)GetVariable("AllowedFeatures").Value; 96 97 Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures); 98 99 ItemList<IntData> allowedFeatures = new ItemList<IntData>(); 100 allowedFeatures.AddRange(Enumerable.Range(1, scopeDataset.Columns -1 ).Select(x=>new IntData(x))); 101 102 scope.AddVariable(new Variable("Dataset", scopeDataset)); 103 scope.AddVariable(new Variable("AllowedFeatures", allowedFeatures)); 104 scope.AddVariable(new Variable("TargetVariable", new IntData(0))); 94 105 95 106 int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; … … 110 121 } 111 122 123 private Dataset CreateNewDataset(Dataset operatorDataset, int targetVariable, ItemList<IntData> operatorAllowedFeatures) { 124 int columns = (operatorAllowedFeatures.Count() + 1); 125 double[] values = new double[operatorDataset.Rows * columns]; 126 127 for (int i = 0; i < values.Length; i++) { 128 int row = i / columns; 129 int column = i % columns; 130 if (column == 0) { 131 values[i] = operatorDataset.GetValue(row, targetVariable); 132 } else { 133 values[i] = operatorDataset.GetValue(row, operatorAllowedFeatures[column-1].Data); 134 } 135 } 136 137 Dataset ds = new Dataset(); 138 ds.Columns = columns; 139 ds.Rows = operatorDataset.Rows; 140 ds.Name = operatorDataset.Name; 141 ds.Samples = values; 142 double[] scalingFactor = new double[columns]; 143 double[] scalingOffset = new double[columns]; 144 ds.SetVariableName(0, operatorDataset.GetVariableName(targetVariable)); 145 scalingFactor[0] = operatorDataset.ScalingFactor[targetVariable]; 146 scalingOffset[0] = operatorDataset.ScalingOffset[targetVariable]; 147 for (int column = 1; column < columns; column++) { 148 ds.SetVariableName(column, operatorDataset.GetVariableName(operatorAllowedFeatures[column - 1].Data)); 149 scalingFactor[column] = operatorDataset.ScalingFactor[operatorAllowedFeatures[column - 1].Data]; 150 scalingOffset[column] = operatorDataset.ScalingOffset[operatorAllowedFeatures[column - 1].Data]; 151 } 152 ds.ScalingOffset = scalingOffset; 153 ds.ScalingFactor = scalingFactor; 154 return ds; 155 } 156 112 157 private void AddVariableToScope(string variableName, IScope scope) { 113 158 scope.AddVariable(new Variable(variableName, (IItem)GetVariable(variableName).Value.Clone()));
Note: See TracChangeset
for help on using the changeset viewer.