Changeset 2165 for trunk/sources/HeuristicLab.Modeling
- Timestamp:
- 07/16/09 11:34:22 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Modeling/3.2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs
r2162 r2165 77 77 78 78 AddVariableInfo(new VariableInfo("MaxNumberOfTrainingSamples", "Maximal number of training samples to use (optional)", typeof(IntData), VariableKind.In)); 79 AddVariableInfo(new VariableInfo("NumberOfInputVariables", "The number of available input variables", typeof(IntData), VariableKind.New)); 79 80 } 80 81 … … 97 98 Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures); 98 99 99 ItemList<IntData> allowedFeatures = new ItemList<IntData>();100 allowedFeatures.AddRange(Enumerable.Range(1, scopeDataset.Columns -1 ).Select(x=>new IntData(x)));101 102 100 scope.AddVariable(new Variable("Dataset", scopeDataset)); 103 scope.AddVariable(new Variable("AllowedFeatures", allowedFeatures));104 101 scope.AddVariable(new Variable("TargetVariable", new IntData(0))); 102 scope.AddVariable(new Variable("NumberOfInputVariables", new IntData(scopeDataset.Columns - 1))); 105 103 106 104 int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; -
trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs
r2136 r2165 58 58 } 59 59 60 protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end) {61 return GetOutputs(scope, dataset, targetVariable, allowedFeatures,start, end);60 protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) { 61 return GetOutputs(scope, dataset, targetVariable, start, end); 62 62 } 63 63 … … 75 75 } 76 76 77 protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end);77 protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end); 78 78 } 79 79 } -
trunk/sources/HeuristicLab.Modeling/3.2/VariableImpactCalculatorBase.cs
r2043 r2165 34 34 35 35 public override string Description { 36 get { return @"Calculates the impact of all allowedinput variables on the model."; }36 get { return @"Calculates the impact of all input variables on the model."; } 37 37 } 38 38 … … 47 47 AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In)); 48 48 AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.In)); 49 AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<IntData>), VariableKind.In));50 49 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In)); 51 50 AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.In)); … … 54 53 55 54 public override IOperation Apply(IScope scope) { 56 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);57 55 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data; 58 56 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); … … 61 59 int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 62 60 63 T referenceValue = CalculateValue(scope, dataset, targetVariable, allowedFeatures,start, end);64 double[] impacts = new double[ allowedFeatures.Count];61 T referenceValue = CalculateValue(scope, dataset, targetVariable, start, end); 62 double[] impacts = new double[dataset.Columns]; 65 63 66 for (int i = 0; i < allowedFeatures.Count && !abortRequested; i++) { 67 int currentVariable = allowedFeatures[i].Data; 68 var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end); 69 T newValue = CalculateValue(scope, dirtyDataset, targetVariable, allowedFeatures, start, end); 70 impacts[i] = CalculateImpact(referenceValue, newValue); 71 ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end); 64 for (int i = 0; i < impacts.Length && !abortRequested; i++) { 65 int currentVariable = i; 66 if (currentVariable != targetVariable) { 67 var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end); 68 T newValue = CalculateValue(scope, dirtyDataset, targetVariable, start, end); 69 impacts[i] = CalculateImpact(referenceValue, newValue); 70 ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end); 71 } 72 72 } 73 73 … … 76 76 77 77 ItemList variableImpacts = new ItemList(); 78 for (int i = 0; i < allowedFeatures.Count; i++) { 79 int currentVariable = allowedFeatures[i].Data; 80 ItemList row = new ItemList(); 81 row.Add(new StringData(dataset.GetVariableName(currentVariable))); 82 row.Add(new DoubleData(impacts[i])); 83 variableImpacts.Add(row); 78 for (int i = 0; i < impacts.Length; i++) { 79 int currentVariable = i; 80 if (currentVariable != targetVariable) { 81 ItemList row = new ItemList(); 82 row.Add(new StringData(dataset.GetVariableName(currentVariable))); 83 row.Add(new DoubleData(impacts[i])); 84 variableImpacts.Add(row); 85 } 84 86 } 85 87 … … 91 93 } 92 94 93 protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end);95 protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end); 94 96 95 97 protected abstract double CalculateImpact(T referenceValue, T newValue); -
trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs
r2043 r2165 43 43 } 44 44 45 protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end) {46 return CalculateQuality(scope, dataset, targetVariable, allowedFeatures,start, end);45 protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) { 46 return CalculateQuality(scope, dataset, targetVariable, start, end); 47 47 } 48 48 49 protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end);49 protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end); 50 50 } 51 51 }
Note: See TracChangeset
for help on using the changeset viewer.