- Timestamp:
- 09/06/12 09:52:52 (12 years ago)
- Location:
- branches/HeuristicLab.Mono
- Files:
-
- 15 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Mono
-
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r8440 r8585 93 93 </PropertyGroup> 94 94 <ItemGroup> 95 <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 96 <HintPath>..\..\bin\ALGLIB-3.6.0.dll</HintPath> 97 <Private>False</Private> 98 </Reference> 99 <Reference Include="HeuristicLab.ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 100 <HintPath>..\..\bin\HeuristicLab.ALGLIB-3.6.0.dll</HintPath> 101 <Private>False</Private> 102 </Reference> 95 103 <Reference Include="System" /> 96 104 <Reference Include="System.Core"> … … 122 130 <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" /> 123 131 <Compile Include="Implementation\Clustering\ClusteringSolution.cs" /> 132 <Compile Include="Implementation\FeatureCorrelation\FeatureCorrelationCalculator.cs" /> 133 <Compile Include="Implementation\FeatureCorrelation\FeatureCorrelationEnums.cs" /> 124 134 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 125 135 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> … … 180 190 <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" /> 181 191 <Compile Include="Implementation\Regression\RegressionSolution.cs" /> 192 <Compile Include="OnlineCalculators\SpearmansRankCorrelationCoefficientCalculator.cs" /> 182 193 <Compile Include="Plugin.cs" /> 183 194 <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" /> -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r7259 r8585 95 95 96 96 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) { 97 return new ClassificationEnsembleSolution(models, problemData);97 return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData)); 98 98 } 99 99 #endregion -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r8174 r8585 104 104 } 105 105 106 public ClassificationEnsembleSolution(IClassificationProblemData problemData) : 107 this(Enumerable.Empty<IClassificationModel>(), problemData) { } 108 106 109 public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData) 107 110 : this(models, problemData, -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r8121 r8585 223 223 } 224 224 225 private List<double> classValues ;226 p ublic List<double> ClassValues{225 private List<double> classValuesCache; 226 private List<double> ClassValuesCache { 227 227 get { 228 if (classValues == null) { 229 classValues = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().ToList(); 230 classValues.Sort(); 228 if (classValuesCache == null) { 229 classValuesCache = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().OrderBy(x => x).ToList(); 231 230 } 232 return classValues ;231 return classValuesCache; 233 232 } 234 233 } 235 IEnumerable<double> IClassificationProblemData.ClassValues { 236 get { return ClassValues; } 237 } 238 234 public IEnumerable<double> ClassValues { 235 get { return ClassValuesCache; } 236 } 239 237 public int Classes { 240 get { return ClassValues .Count; }241 } 242 243 private List<string> classNames ;244 p ublic List<string> ClassNames{238 get { return ClassValuesCache.Count; } 239 } 240 241 private List<string> classNamesCache; 242 private List<string> ClassNamesCache { 245 243 get { 246 if (classNames == null) {247 classNames = new List<string>();244 if (classNamesCache == null) { 245 classNamesCache = new List<string>(); 248 246 for (int i = 0; i < ClassNamesParameter.Value.Rows; i++) 249 classNames .Add(ClassNamesParameter.Value[i, 0]);247 classNamesCache.Add(ClassNamesParameter.Value[i, 0]); 250 248 } 251 return classNames ;249 return classNamesCache; 252 250 } 253 251 } 254 IEnumerable<string> IClassificationProblemData.ClassNames { 255 get { return ClassNames; } 256 } 257 258 private Dictionary<Tuple<double, double>, double> classificationPenaltiesCache = new Dictionary<Tuple<double, double>, double>(); 252 public IEnumerable<string> ClassNames { 253 get { return ClassNamesCache; } 254 } 259 255 #endregion 260 256 … … 277 273 278 274 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { } 275 276 public ClassificationProblemData(IClassificationProblemData classificationProblemData) 277 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { 278 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 279 TrainingPartition.End = classificationProblemData.TrainingPartition.End; 280 TestPartition.Start = classificationProblemData.TestPartition.Start; 281 TestPartition.End = classificationProblemData.TestPartition.End; 282 } 283 279 284 public ClassificationProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 280 285 : base(dataset, allowedInputVariables) { … … 310 315 DeregisterParameterEvents(); 311 316 312 classNames = null;313 317 ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1; 314 ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValues .Count;318 ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValuesCache.Count; 315 319 for (int i = 0; i < Classes; i++) 316 ClassNamesParameter.Value[i, 0] = "Class " + ClassValues [i];320 ClassNamesParameter.Value[i, 0] = "Class " + ClassValuesCache[i]; 317 321 ClassNamesParameter.Value.ColumnNames = new List<string>() { "ClassNames" }; 318 322 ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s); 319 323 320 classificationPenaltiesCache.Clear();321 ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;322 324 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes; 323 325 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes; … … 330 332 } 331 333 } 332 ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = true;333 334 RegisterParameterEvents(); 334 335 } 335 336 336 337 public string GetClassName(double classValue) { 337 if (!ClassValues .Contains(classValue)) throw new ArgumentException();338 int index = ClassValues .IndexOf(classValue);339 return ClassNames [index];338 if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException(); 339 int index = ClassValuesCache.IndexOf(classValue); 340 return ClassNamesCache[index]; 340 341 } 341 342 public double GetClassValue(string className) { 342 if (!ClassNames .Contains(className)) throw new ArgumentException();343 int index = ClassNames .IndexOf(className);344 return ClassValues [index];343 if (!ClassNamesCache.Contains(className)) throw new ArgumentException(); 344 int index = ClassNamesCache.IndexOf(className); 345 return ClassValuesCache[index]; 345 346 } 346 347 public void SetClassName(double classValue, string className) { 347 if (!classValues.Contains(classValue)) throw new ArgumentException(); 348 int index = ClassValues.IndexOf(classValue); 349 ClassNames[index] = className; 348 if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException(); 349 int index = ClassValuesCache.IndexOf(classValue); 350 350 ClassNamesParameter.Value[index, 0] = className; 351 // updating of class names cache is not necessary here as the parameter value fires a changed event which updates the cache 351 352 } 352 353 … … 355 356 } 356 357 public double GetClassificationPenalty(double correctClassValue, double estimatedClassValue) { 357 var key = Tuple.Create(correctClassValue, estimatedClassValue); 358 if (!classificationPenaltiesCache.ContainsKey(key)) { 359 int correctClassIndex = ClassValues.IndexOf(correctClassValue); 360 int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue); 361 classificationPenaltiesCache[key] = ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex]; 362 } 363 return classificationPenaltiesCache[key]; 358 int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue); 359 int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue); 360 return ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex]; 364 361 } 365 362 public void SetClassificationPenalty(string correctClassName, string estimatedClassName, double penalty) { … … 367 364 } 368 365 public void SetClassificationPenalty(double correctClassValue, double estimatedClassValue, double penalty) { 369 var key = Tuple.Create(correctClassValue, estimatedClassValue); 370 int correctClassIndex = ClassValues.IndexOf(correctClassValue); 371 int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue); 366 int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue); 367 int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue); 372 368 373 369 ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex] = penalty; … … 379 375 ClassNamesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged); 380 376 ClassNamesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged); 381 ClassificationPenaltiesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged);382 ClassificationPenaltiesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);383 377 } 384 378 private void DeregisterParameterEvents() { … … 386 380 ClassNamesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged); 387 381 ClassNamesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged); 388 ClassificationPenaltiesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged);389 ClassificationPenaltiesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);390 382 } 391 383 392 384 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 393 classValues = null; 385 classValuesCache = null; 386 classNamesCache = null; 394 387 ResetTargetVariableDependentMembers(); 395 388 OnChanged(); 396 389 } 397 390 private void Parameter_ValueChanged(object sender, EventArgs e) { 391 classNamesCache = null; 398 392 OnChanged(); 399 393 } 400 394 private void MatrixParameter_ItemChanged(object sender, EventArgs<int, int> e) { 395 classNamesCache = null; 401 396 OnChanged(); 402 397 } -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r8139 r8585 51 51 valueEvaluationCache = new Dictionary<int, double>(); 52 52 classValueEvaluationCache = new Dictionary<int, double>(); 53 54 SetAccuracyMaximizingThresholds();55 53 } 56 54 -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r8139 r8585 94 94 } 95 95 96 protected override void OnModelChanged() {97 DeregisterEventHandler();98 SetAccuracyMaximizingThresholds();99 RegisterEventHandler();100 base.OnModelChanged();101 }102 103 96 protected void CalculateRegressionResults() { 104 97 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values … … 137 130 } 138 131 139 public void SetAccuracyMaximizingThresholds() {140 double[] classValues;141 double[] thresholds;142 var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);143 AccuracyMaximizationThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);144 145 Model.SetThresholdsAndClassValues(thresholds, classValues);146 }147 148 public void SetClassDistibutionCutPointThresholds() {149 double[] classValues;150 double[] thresholds;151 var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);152 NormalDistributionCutPointsThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);153 154 Model.SetThresholdsAndClassValues(thresholds, classValues);155 }156 157 132 protected virtual void OnModelThresholdsChanged(EventArgs e) { 158 CalculateResults(); 159 CalculateRegressionResults(); 133 OnModelChanged(); 160 134 } 161 135 -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs
r8126 r8585 85 85 //all positives 86 86 if (pair.TargetClassValue.IsAlmost(classValues[i - 1])) { 87 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)87 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold) 88 88 //true positive 89 classificationScore += problemData.GetClassificationPenalty( classValues[i - 1], classValues[i - 1]);89 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue); 90 90 else 91 91 //false negative 92 classificationScore += problemData.GetClassificationPenalty( classValues[i], classValues[i - 1]);92 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]); 93 93 } 94 94 //all negatives 95 95 else { 96 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold) 97 //false positive 98 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i]); 99 else 100 //true negative, consider only upper class 101 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i]); 96 //false positive 97 if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold) 98 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 1]); 99 else if (pair.EstimatedValue <= lowerThreshold) 100 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 2]); 101 else if (pair.EstimatedValue > actualThreshold) { 102 if (pair.TargetClassValue < classValues[i - 1]) //negative in wrong class, consider upper class 103 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]); 104 else //true negative, must be optimized by the other thresholds 105 classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue); 106 } 102 107 } 103 108 } -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r8139 r8585 107 107 [StorableConstructor] 108 108 protected DataAnalysisProblemData(bool deserializing) : base(deserializing) { } 109 109 110 [StorableHook(HookType.AfterDeserialization)] 110 111 private void AfterDeserialization() { -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r7259 r8585 55 55 56 56 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 57 return new ConstantRegressionSolution(this, problemData);57 return new ConstantRegressionSolution(this, new RegressionProblemData(problemData)); 58 58 } 59 59 } -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r7259 r8585 102 102 103 103 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) { 104 return new RegressionEnsembleSolution(this.Models, problemData);104 return new RegressionEnsembleSolution(this.Models, new RegressionEnsembleProblemData(problemData)); 105 105 } 106 106 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) { -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r8121 r8585 121 121 : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { 122 122 } 123 public RegressionProblemData(IRegressionProblemData regressionProblemData) 124 : this(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) { 125 TrainingPartition.Start = regressionProblemData.TrainingPartition.Start; 126 TrainingPartition.End = regressionProblemData.TrainingPartition.End; 127 TestPartition.Start = regressionProblemData.TestPartition.Start; 128 TestPartition.End = regressionProblemData.TestPartition.End; 129 } 123 130 124 131 public RegressionProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/HoeffdingsDependenceCalculator.cs
r8355 r8585 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common;26 25 27 26 namespace HeuristicLab.Problems.DataAnalysis { -
branches/HeuristicLab.Mono/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame
r8246 r8585 28 28 [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.3.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.ALGLIB","3.6")] 30 31 [PluginDependency("HeuristicLab.Collections", "3.3")] 31 32 [PluginDependency("HeuristicLab.Common", "3.3")]
Note: See TracChangeset
for help on using the changeset viewer.