Changeset 2038
- Timestamp:
- 06/10/09 10:46:56 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/3.2/Dataset.cs
r2012 r2038 39 39 private double[] scalingFactor; 40 40 private double[] scalingOffset; 41 private bool cachedValuesInvalidated = true; 42 43 private bool fireChangeEvents = true; 44 public bool FireChangeEvents { 45 get { return fireChangeEvents; } 46 set { fireChangeEvents = value; } 47 } 41 48 42 49 public string Name { … … 74 81 if (v != samples[columns * i + j]) { 75 82 samples[columns * i + j] = v; 76 CreateDictionaries();77 FireChanged();83 cachedValuesInvalidated = true; 84 if (fireChangeEvents) FireChanged(); 78 85 } 79 86 } … … 89 96 } 90 97 samples = value; 91 CreateDictionaries();92 FireChanged();98 cachedValuesInvalidated = true; 99 if (fireChangeEvents) FireChanged(); 93 100 } 94 101 } … … 104 111 scalingOffset = new double[] { 0.0 }; 105 112 scalingFactor = new double[] { 1.0 }; 106 } 107 108 private void CreateDictionaries() { 109 // keep a means and ranges dictionary for each column (possible target variable) of the dataset. 110 cachedMeans = new Dictionary<int, Dictionary<int, double>>[columns]; 111 cachedRanges = new Dictionary<int, Dictionary<int, double>>[columns]; 112 for (int i = 0; i < columns; i++) { 113 cachedMeans[i] = new Dictionary<int, Dictionary<int, double>>(); 114 cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>(); 115 } 113 cachedValuesInvalidated = true; 114 fireChangeEvents = true; 116 115 } 117 116 … … 206 205 } 207 206 } 208 CreateDictionaries();209 207 } 210 208 … … 270 268 271 269 public double GetMean(int column, int from, int to) { 270 if (cachedValuesInvalidated) CreateDictionaries(); 272 271 if (!cachedMeans[column].ContainsKey(from) || !cachedMeans[column][from].ContainsKey(to)) { 273 272 double[] values = new double[to - from]; … … 289 288 290 289 public double GetRange(int column, int from, int to) { 290 if (cachedValuesInvalidated) CreateDictionaries(); 291 291 if (!cachedRanges[column].ContainsKey(from) || !cachedRanges[column][from].ContainsKey(to)) { 292 292 double[] values = new double[to - from]; … … 329 329 else ScaleVariable(column, 1.0 / range, -min); 330 330 } 331 CreateDictionaries();332 FireChanged();331 cachedValuesInvalidated = true; 332 if (fireChangeEvents) FireChanged(); 333 333 } 334 334 … … 340 340 samples[i * columns + column] = (origValue + offset) * factor; 341 341 } 342 CreateDictionaries();343 FireChanged();342 cachedValuesInvalidated = true; 343 if (fireChangeEvents) FireChanged(); 344 344 } 345 345 … … 353 353 scalingOffset[column] = 0.0; 354 354 } 355 cachedValuesInvalidated = true; 356 if (fireChangeEvents) FireChanged(); 357 } 358 359 private void CreateDictionaries() { 360 // keep a means and ranges dictionary for each column (possible target variable) of the dataset. 361 cachedMeans = new Dictionary<int, Dictionary<int, double>>[columns]; 362 cachedRanges = new Dictionary<int, Dictionary<int, double>>[columns]; 363 for (int i = 0; i < columns; i++) { 364 cachedMeans[i] = new Dictionary<int, Dictionary<int, double>>(); 365 cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>(); 366 } 355 367 } 356 368 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs
r2034 r2038 72 72 } 73 73 } 74 dataset.FireChangeEvents = false; 74 75 75 76 Evaluate(scope, evaluator, dataset, targetVariable, start, end, useEstimatedValues); … … 81 82 } 82 83 } 84 dataset.FireChangeEvents = true; 85 dataset.FireChanged(); 83 86 84 87 // update the value of total evaluated nodes -
trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj
r2034 r2038 83 83 <ItemGroup> 84 84 <Compile Include="ClassificationProblemInjector.cs" /> 85 <Compile Include="VariableImpactCalculator.cs" />86 85 <Compile Include="Model.cs" /> 87 86 <Compile Include="IModel.cs" /> … … 106 105 <Compile Include="TimeSeriesProblemInjector.cs" /> 107 106 <Compile Include="SimpleVarianceAccountedForEvaluator.cs" /> 107 <Compile Include="VariableQualityImpactCalculator.cs" /> 108 108 </ItemGroup> 109 109 <ItemGroup> -
trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs
r2037 r2038 30 30 31 31 namespace HeuristicLab.Modeling { 32 public class Variable ImpactCalculator : OperatorBase {32 public class VariableQualityImpactCalculator : OperatorBase { 33 33 public override string Description { 34 34 get { return @"Calculates the impact of all allowed input variables on the quality of the model using evaluator supplied as suboperator."; } 35 35 } 36 36 37 public Variable ImpactCalculator()37 public VariableQualityImpactCalculator() 38 38 : base() { 39 39 AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In)); … … 42 42 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In)); 43 43 AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.In)); 44 AddVariableInfo(new VariableInfo("Variable Impacts", "Variable impacts", typeof(ItemList), VariableKind.New));44 AddVariableInfo(new VariableInfo("VariableQualityImpacts", "Effect on quality of model (percentage of original quality) if variable is replaced by its mean.", typeof(ItemList), VariableKind.New)); 45 45 } 46 46 … … 53 53 int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 54 54 55 if (SubOperators.Count < 1) throw new InvalidOperationException("Variable ImpactCalculator needs a suboperator to evaluate the model");55 if (SubOperators.Count < 1) throw new InvalidOperationException("VariableQualityImpactCalculator needs a suboperator to evaluate the model"); 56 56 IOperator evaluationOperator = this.SubOperators[0]; 57 58 ItemList variableImpacts = new ItemList(); 57 ItemList variableQualityImpacts = new ItemList(); 59 58 60 59 // calculateReferenceQuality … … 65 64 var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable , CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end); 66 65 double newQuality = CalculateQuality(scope, dirtyDataset, evaluationOperator); 67 double ratio = referenceQuality / newQuality; 68 double impact = ratio < 1.0 ? 1.0 - ratio : 1.0 - 1.0 / ratio; 66 double ratio = newQuality / referenceQuality; 69 67 ItemList row = new ItemList(); 70 68 row.Add(new StringData(dataset.GetVariableName(currentVariable))); 71 row.Add(new DoubleData( impact));72 variable Impacts.Add(row);69 row.Add(new DoubleData(ratio)); 70 variableQualityImpacts.Add(row); 73 71 ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end); 74 72 } 75 scope.AddVariable(new Variable(scope.TranslateName("Variable Impacts"), variableImpacts));73 scope.AddVariable(new Variable(scope.TranslateName("VariableQualityImpacts"), variableQualityImpacts)); 76 74 return null; 77 75 } … … 93 91 94 92 int index = start; 93 ds.FireChangeEvents = false; 95 94 foreach(double v in newValues) { 96 95 ds.SetValue(index++, variableIndex, v); 97 96 } 97 ds.FireChangeEvents = true; 98 ds.FireChanged(); 98 99 return oldValues; 99 100 }
Note: See TracChangeset
for help on using the changeset viewer.