Changeset 8531
- Timestamp:
- 08/28/12 13:11:15 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r8139 r8531 111 111 IClassificationProblemData problemData, 112 112 IEnumerable<int> rows) { 113 return new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter); 113 var model = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter); 114 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, problemData); 115 return model; 114 116 } 115 117 } -
trunk/sources/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs
r7259 r8531 105 105 106 106 public static IEnumerable<double> LimitToRange(this IEnumerable<double> values, double min, double max) { 107 if (min > max) throw new ArgumentException(string.Format("Minimum {0} is larger than maximum {1}.", min, max)); 107 108 foreach (var x in values) { 108 109 if (double.IsNaN(x)) yield return (max + min) / 2.0; -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs
r7662 r8531 75 75 foreach (Type t in GetTypes(type)) { 76 76 object instance = null; 77 try { instance = Activator.CreateInstance(t); } catch { } 77 try { instance = Activator.CreateInstance(t); } 78 catch { } 78 79 if (instance != null) instances.Add(instance); 79 80 } … … 137 138 where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition 138 139 select t; 139 } catch (TypeLoadException) { 140 } 141 catch (TypeLoadException) { 140 142 return Enumerable.Empty<Type>(); 141 } catch (ReflectionTypeLoadException) { 143 } 144 catch (ReflectionTypeLoadException) { 142 145 return Enumerable.Empty<Type>(); 143 146 } … … 163 166 foreach (var genericArgument in typeGenericArguments) { 164 167 if (otherGenericArguments[i].IsGenericParameter) { 168 //check class contraint on generic type parameter 169 if (otherGenericArguments[i].GenericParameterAttributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint)) 170 if (!genericArgument.IsClass) return false; 171 172 //check default constructor constraint on generic type parameter 173 if (otherGenericArguments[i].GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint)) 174 if (!genericArgument.IsValueType && genericArgument.GetConstructor(Type.EmptyTypes) == null) return false; 175 165 176 foreach (var constraint in otherGenericArguments[i].GetGenericParameterConstraints()) 166 177 if (!constraint.IsAssignableFrom(genericArgument)) return false; … … 173 184 if (type.IsAssignableFrom(otherGenericTypeDefinition.MakeGenericType(typeGenericArguments))) 174 185 return true; 175 } catch (Exception) { } 186 } 187 catch (Exception) { } 176 188 } 177 189 return false; -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
r7586 r8531 293 293 foreach (var genericArgument in typeGenericArguments) { 294 294 if (otherGenericArguments[i].IsGenericParameter) { 295 //check class contraint on generic type parameter 296 if (otherGenericArguments[i].GenericParameterAttributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint)) 297 if (!genericArgument.IsClass) return false; 298 299 //check default constructor constraint on generic type parameter 300 if (otherGenericArguments[i].GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint)) 301 if (!genericArgument.IsValueType && genericArgument.GetConstructor(Type.EmptyTypes) == null) return false; 302 295 303 foreach (var constraint in otherGenericArguments[i].GetGenericParameterConstraints()) 296 304 if (!constraint.IsAssignableFrom(genericArgument)) return false; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs
r8139 r8531 50 50 51 51 protected override void UpdateModel(ISymbolicExpressionTree tree) { 52 Content.Model = new SymbolicDiscriminantFunctionClassificationModel(tree, Content.Model.Interpreter);52 var model = new SymbolicDiscriminantFunctionClassificationModel(tree, Content.Model.Interpreter); 53 53 // the default policy for setting thresholds in classification models is the accuarcy maximizing policy. 54 54 // This is rather slow to calculate and can lead to a very laggy UI in the interactive solution simplifier. 55 55 // However, since we automatically prune sub-trees based on the threshold reaching the maximum accuracy we must 56 56 // also use maximum accuracy threshold calculation here in order to prevent incoherent behavior of the simplifier. 57 Content.SetAccuracyMaximizingThresholds(); 57 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, Content.ProblemData); 58 Content.Model = model; 58 59 } 59 60 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r8531 77 77 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 78 78 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 79 if (ApplyLinearScaling.Value) {80 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 81 }79 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 80 81 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 82 82 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 83 83 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r7259 r8531 66 66 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) { 67 67 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 68 if (ApplyLinearScaling.Value) {69 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 70 }68 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 69 70 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 71 71 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 72 72 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r8531 75 75 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 76 76 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 77 if (ApplyLinearScaling.Value) {78 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 79 }77 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 78 79 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 80 80 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 81 81 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r8169 r8531 60 60 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 61 61 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 62 if (ApplyLinearScaling.Value) 63 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 62 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 63 64 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 64 65 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 65 66 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs
r7259 r8531 66 66 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 67 67 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 68 if (ApplyLinearScaling.Value) {69 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 70 }68 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 69 70 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 71 71 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 72 72 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r8169 r8531 60 60 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 61 61 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 62 if (ApplyLinearScaling.Value) 63 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 62 if (ApplyLinearScaling.Value) SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 63 64 SymbolicDiscriminantFunctionClassificationModel.SetAccuracyMaximizingThresholds(model, ProblemDataParameter.ActualValue); 64 65 return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 65 66 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r8528 r8531 67 67 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 68 68 : base(tree, interpreter) { 69 th resholds = new double[] { double.NegativeInfinity };70 classValues = new double[] { 0.0 };69 this.thresholds = new double[0]; 70 this.classValues = new double[0]; 71 71 this.lowerEstimationLimit = lowerEstimationLimit; 72 72 this.upperEstimationLimit = upperEstimationLimit; … … 88 88 89 89 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 90 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows) 91 .LimitToRange(lowerEstimationLimit, upperEstimationLimit); 90 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows).LimitToRange(lowerEstimationLimit, upperEstimationLimit); 92 91 } 93 92 94 93 public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 94 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current symbolic classification model."); 95 95 foreach (var x in GetEstimatedValues(dataset, rows)) { 96 96 int classIndex = 0; … … 121 121 } 122 122 #endregion 123 124 public static void SetAccuracyMaximizingThresholds(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) { 125 double[] classValues; 126 double[] thresholds; 127 var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 128 var estimatedTrainingValues = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 129 AccuracyMaximizationThresholdCalculator.CalculateThresholds(problemData, estimatedTrainingValues, targetClassValues, out classValues, out thresholds); 130 131 model.SetThresholdsAndClassValues(thresholds, classValues); 132 } 133 134 public static void SetClassDistibutionCutPointThresholds(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) { 135 double[] classValues; 136 double[] thresholds; 137 var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 138 var estimatedTrainingValues = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 139 NormalDistributionCutPointsThresholdCalculator.CalculateThresholds(problemData, estimatedTrainingValues, targetClassValues, out classValues, out thresholds); 140 141 model.SetThresholdsAndClassValues(thresholds, classValues); 142 } 123 143 124 144 public static void Scale(SymbolicDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r8139 r8531 51 51 valueEvaluationCache = new Dictionary<int, double>(); 52 52 classValueEvaluationCache = new Dictionary<int, double>(); 53 54 SetAccuracyMaximizingThresholds();55 53 } 56 54 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r8139 r8531 96 96 protected override void OnModelChanged() { 97 97 DeregisterEventHandler(); 98 SetAccuracyMaximizingThresholds();99 98 RegisterEventHandler(); 100 99 base.OnModelChanged(); … … 137 136 } 138 137 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 138 protected virtual void OnModelThresholdsChanged(EventArgs e) { 158 139 CalculateResults();
Note: See TracChangeset
for help on using the changeset viewer.