Changeset 5649 for branches/DataAnalysis Refactoring
- Timestamp:
- 03/10/11 10:00:09 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring
- Files:
-
- 20 added
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
r5617 r5649 76 76 base.Start(); 77 77 OnStarted(); 78 Run(); 79 OnStopped(); 78 try { 79 Run(); 80 } 81 catch (Exception e) { 82 OnExceptionOccurred(e); 83 } 84 finally { 85 OnStopped(); 86 } 80 87 } 81 88 -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r5624 r5649 42 42 [StorableClass] 43 43 public sealed class LinearRegression : FixedDataAnalysisAlgorithm<IRegressionProblem> { 44 private const string LinearRegressionModelResultName = "Linear RegressionModel";44 private const string LinearRegressionModelResultName = "Linear regression solution"; 45 45 46 46 [StorableConstructor] … … 51 51 public LinearRegression() 52 52 : base() { 53 Problem = new RegressionProblem(); 53 54 } 54 55 [StorableHook(HookType.AfterDeserialization)] … … 63 64 double rmsError, cvRmsError; 64 65 var solution = CreateLinearRegressionSolution(Problem.ProblemData, out rmsError, out cvRmsError); 65 Results.Add(new Result(LinearRegressionModelResultName, "The linear regression model.", solution));66 Results.Add(new Result("Root mean square error", "The root of the mean of squared errors of the linear regression modelon the training set.", new DoubleValue(rmsError)));67 Results.Add(new Result("Estimated root mean square error (cross-validation)", "The estimated root of the mean of squared errors of the linear regression modelvia cross validation.", new DoubleValue(cvRmsError)));66 Results.Add(new Result(LinearRegressionModelResultName, "The linear regression solution.", solution)); 67 Results.Add(new Result("Root mean square error", "The root of the mean of squared errors of the linear regression solution on the training set.", new DoubleValue(rmsError))); 68 Results.Add(new Result("Estimated root mean square error (cross-validation)", "The estimated root of the mean of squared errors of the linear regression solution via cross validation.", new DoubleValue(cvRmsError))); 68 69 } 69 70 … … 71 72 Dataset dataset = problemData.Dataset; 72 73 string targetVariable = problemData.TargetVariable; 73 IEnumerable<string> allowedInputVariables = problemData. InputVariables.CheckedItems.Select(x => x.Value);74 IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables; 74 75 int samplesStart = problemData.TrainingPartitionStart.Value; 75 76 int samplesEnd = problemData.TrainingPartitionEnd.Value; 76 77 IEnumerable<string> selectedInputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value);78 77 79 78 double[,] inputMatrix = LinearRegressionUtil.PrepareInputMatrix(dataset, targetVariable, allowedInputVariables, samplesStart, samplesEnd); … … 87 86 int retVal = 1; 88 87 alglib.lrbuild(inputMatrix, nRows, nFeatures, out retVal, out lm, out ar); 89 if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression model");88 if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution"); 90 89 rmsError = ar.rmserror; 91 90 cvRmsError = ar.cvrmserror; -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs
r5626 r5649 88 88 public SupportVectorClassification() 89 89 : base() { 90 Problem = new ClassificationProblem(); 91 90 92 List<StringValue> svrTypes = (from type in new List<string> { "NU_SVC", "EPSILON_SVC" } 91 93 select new StringValue(type).AsReadOnly()) … … 95 97 select new StringValue(type).AsReadOnly()) 96 98 .ToList(); 97 ItemSet<StringValue> kernelTypeSet = new ItemSet<StringValue>( svrTypes);99 ItemSet<StringValue> kernelTypeSet = new ItemSet<StringValue>(kernelTypes); 98 100 Parameters.Add(new ConstrainedValueParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", svrTypeSet, svrTypes[0])); 99 101 Parameters.Add(new ConstrainedValueParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", kernelTypeSet, kernelTypes[3])); … … 112 114 protected override void Run() { 113 115 IClassificationProblemData problemData = Problem.ProblemData; 114 IEnumerable<string> selectedInputVariables = problemData. InputVariables.CheckedItems.Select(x => x.Value);116 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; 115 117 var solution = CreateSupportVectorClassificationSolution(problemData, selectedInputVariables, SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value); 116 118 … … 140 142 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 141 143 SVM.Problem scaledProblem = SVM.Scaling.Scale(rangeTransform, problem); 142 var model = new SupportVectorMachineModel(); 143 model.Model = SVM.Training.Train(scaledProblem, parameter); 144 model.RangeTransform = rangeTransform; 144 var model = new SupportVectorMachineModel(SVM.Training.Train(scaledProblem, parameter), rangeTransform, targetVariable, allowedInputVariables); 145 145 146 return new SupportVectorClassificationSolution(model, problemData , allowedInputVariables, double.NegativeInfinity, double.PositiveInfinity);146 return new SupportVectorClassificationSolution(model, problemData); 147 147 } 148 148 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassificationSolution.cs
r5626 r5649 41 41 } 42 42 43 [Storable]44 private double lowerEstimationLimit;45 public double LowerEstimationLimit {46 get { return lowerEstimationLimit; }47 }48 49 [Storable]50 private double upperEstimationLimit;51 public double UpperEstimationLimit {52 get { return upperEstimationLimit; }53 }54 55 private List<string> inputVariables;56 [Storable]57 private IEnumerable<string> InputVariablesStorable {58 get { return inputVariables; }59 set { inputVariables = new List<string>(value); }60 }61 62 43 public Dataset SupportVectors { 63 44 get { return CalculateSupportVectors(); } … … 68 49 private SupportVectorClassificationSolution(SupportVectorClassificationSolution original, Cloner cloner) 69 50 : base(original, cloner) { 70 inputVariables = new List<string>(original.inputVariables);71 lowerEstimationLimit = original.lowerEstimationLimit;72 upperEstimationLimit = original.upperEstimationLimit;73 51 } 74 public SupportVectorClassificationSolution(SupportVectorMachineModel model, IClassificationProblemData problemData , IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit)52 public SupportVectorClassificationSolution(SupportVectorMachineModel model, IClassificationProblemData problemData) 75 53 : base(model, problemData) { 76 this.inputVariables = new List<string>(inputVariables);77 this.lowerEstimationLimit = lowerEstimationLimit;78 this.upperEstimationLimit = upperEstimationLimit;79 54 } 80 55 … … 87 62 base.OnProblemDataChanged(e); 88 63 } 89 64 90 65 private Dataset CalculateSupportVectors() { 91 66 if (Model.Model.SupportVectorIndizes.Length == 0) -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r5626 r5649 30 30 using SVM; 31 31 using HeuristicLab.Problems.DataAnalysis; 32 using System.Drawing; 32 33 33 34 namespace HeuristicLab.Algorithms.DataAnalysis { … … 38 39 [Item("SupportVectorMachineModel", "Represents a support vector machine model.")] 39 40 public sealed class SupportVectorMachineModel : NamedItem, IRegressionModel, IClassificationModel { 40 [StorableConstructor]41 private SupportVectorMachineModel(bool deserializing) : base(deserializing) { }42 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner)43 : base(original, cloner) {44 // only using a shallow copy here! (gkronber)45 this.model = original.model;46 this.rangeTransform = original.rangeTransform;47 }48 public SupportVectorMachineModel() : base() { }49 41 50 42 private SVM.Model model; … … 77 69 } 78 70 } 71 72 [Storable] 73 private string targetVariable; 74 [Storable] 75 private string[] allowedInputVariables; 76 77 [StorableConstructor] 78 private SupportVectorMachineModel(bool deserializing) : base(deserializing) { } 79 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner) 80 : base(original, cloner) { 81 // only using a shallow copy here! (gkronber) 82 this.model = original.model; 83 this.rangeTransform = original.rangeTransform; 84 85 } 86 public SupportVectorMachineModel(SVM.Model model, SVM.RangeTransform rangeTransform, string targetVariable, IEnumerable<string> allowedInputVariables) 87 : base() { 88 this.name = ItemName; 89 this.description = ItemDescription; 90 this.model = model; 91 this.rangeTransform = rangeTransform; 92 this.targetVariable = targetVariable; 93 this.allowedInputVariables = allowedInputVariables.ToArray(); 94 } 95 96 public override IDeepCloneable Clone(Cloner cloner) { 97 return new SupportVectorMachineModel(this, cloner); 98 } 99 100 79 101 #region IRegressionModel Members 80 public IEnumerable<double> GetEstimatedValues( IRegressionProblemData problemData, IEnumerable<int> rows) {81 return GetEstimatedValues (problemData, problemData.TargetVariable, rows);102 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 103 return GetEstimatedValuesHelper(dataset, rows); 82 104 } 83 105 #endregion 84 106 #region IClassificationModel Members 85 public IEnumerable<double> GetEstimatedValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 86 return GetEstimatedValues(problemData, problemData.TargetVariable, rows); 87 } 88 89 public IEnumerable<double> GetEstimatedClassValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 90 return GetEstimatedValues(problemData, problemData.TargetVariable, rows); 107 public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 108 return GetEstimatedValuesHelper(dataset, rows); 91 109 } 92 110 #endregion 93 private IEnumerable<double> GetEstimatedValues(IDataAnalysisProblemData problemData, string targetVariable, IEnumerable<int> rows) { 94 var allowedInputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value); 95 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData.Dataset, targetVariable, allowedInputVariables, rows); 111 private IEnumerable<double> GetEstimatedValuesHelper(Dataset dataset, IEnumerable<int> rows) { 112 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows); 96 113 SVM.Problem scaledProblem = Scaling.Scale(RangeTransform, problem); 97 114 … … 149 166 } 150 167 #endregion 151 152 public override IDeepCloneable Clone(Cloner cloner) {153 return new SupportVectorMachineModel(this, cloner);154 }155 156 /// <summary>157 /// Exports the <paramref name="model"/> in string representation to stream <paramref name="s"/>158 /// </summary>159 /// <param name="model">The support vector machine model to export</param>160 /// <param name="s">The stream to export the model to</param>161 public static void Export(SupportVectorMachineModel model, Stream s) {162 StreamWriter writer = new StreamWriter(s);163 writer.WriteLine("RangeTransform:");164 writer.Flush();165 using (MemoryStream memStream = new MemoryStream()) {166 SVM.RangeTransform.Write(memStream, model.RangeTransform);167 memStream.Seek(0, SeekOrigin.Begin);168 memStream.WriteTo(s);169 }170 writer.WriteLine("Model:");171 writer.Flush();172 using (MemoryStream memStream = new MemoryStream()) {173 SVM.Model.Write(memStream, model.Model);174 memStream.Seek(0, SeekOrigin.Begin);175 memStream.WriteTo(s);176 }177 s.Flush();178 }179 180 /// <summary>181 /// Imports a support vector machine model given as string representation.182 /// </summary>183 /// <param name="reader">The reader to retrieve the string representation from</param>184 /// <returns>The imported support vector machine model.</returns>185 public static SupportVectorMachineModel Import(TextReader reader) {186 SupportVectorMachineModel model = new SupportVectorMachineModel();187 while (reader.ReadLine().Trim() != "RangeTransform:") ; // read until line "RangeTransform";188 model.RangeTransform = SVM.RangeTransform.Read(reader);189 // read until "Model:"190 while (reader.ReadLine().Trim() != "Model:") ;191 model.Model = SVM.Model.Read(reader);192 return model;193 }194 168 } 195 169 } -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r5626 r5649 95 95 public SupportVectorRegression() 96 96 : base() { 97 Problem = new RegressionProblem(); 98 97 99 List<StringValue> svrTypes = (from type in new List<string> { "NU_SVR", "EPSILON_SVR" } 98 100 select new StringValue(type).AsReadOnly()) … … 102 104 select new StringValue(type).AsReadOnly()) 103 105 .ToList(); 104 ItemSet<StringValue> kernelTypeSet = new ItemSet<StringValue>( svrTypes);106 ItemSet<StringValue> kernelTypeSet = new ItemSet<StringValue>(kernelTypes); 105 107 Parameters.Add(new ConstrainedValueParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", svrTypeSet, svrTypes[0])); 106 108 Parameters.Add(new ConstrainedValueParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", kernelTypeSet, kernelTypes[3])); … … 120 122 protected override void Run() { 121 123 IRegressionProblemData problemData = Problem.ProblemData; 122 IEnumerable<string> selectedInputVariables = problemData. InputVariables.CheckedItems.Select(x => x.Value);124 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; 123 125 var solution = CreateSupportVectorRegressionSolution(problemData, selectedInputVariables, SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value); 124 126 … … 149 151 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 150 152 SVM.Problem scaledProblem = SVM.Scaling.Scale(rangeTransform, problem); 151 var model = new SupportVectorMachineModel(); 152 model.Model = SVM.Training.Train(scaledProblem, parameter); 153 model.RangeTransform = rangeTransform; 154 155 return new SupportVectorRegressionSolution(model, problemData, allowedInputVariables, double.NegativeInfinity, double.PositiveInfinity); 153 var model = new SupportVectorMachineModel(SVM.Training.Train(scaledProblem, parameter), rangeTransform, targetVariable, allowedInputVariables); 154 return new SupportVectorRegressionSolution(model, problemData); 156 155 } 157 156 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegressionSolution.cs
r5626 r5649 41 41 } 42 42 43 [Storable]44 private double lowerEstimationLimit;45 public double LowerEstimationLimit {46 get { return lowerEstimationLimit; }47 }48 49 [Storable]50 private double upperEstimationLimit;51 public double UpperEstimationLimit {52 get { return upperEstimationLimit; }53 }54 55 private List<string> inputVariables;56 [Storable]57 private IEnumerable<string> InputVariablesStorable {58 get { return inputVariables; }59 set { inputVariables = new List<string>(value); }60 }61 62 43 public Dataset SupportVectors { 63 44 get { return CalculateSupportVectors(); } … … 68 49 private SupportVectorRegressionSolution(SupportVectorRegressionSolution original, Cloner cloner) 69 50 : base(original, cloner) { 70 inputVariables = new List<string>(original.inputVariables);71 lowerEstimationLimit = original.lowerEstimationLimit;72 upperEstimationLimit = original.upperEstimationLimit;73 51 } 74 public SupportVectorRegressionSolution(SupportVectorMachineModel model, IRegressionProblemData problemData , IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit)52 public SupportVectorRegressionSolution(SupportVectorMachineModel model, IRegressionProblemData problemData) 75 53 : base(model, problemData) { 76 this.inputVariables = new List<string>(inputVariables);77 this.lowerEstimationLimit = lowerEstimationLimit;78 this.upperEstimationLimit = upperEstimationLimit;79 54 } 80 55 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r5630 r5649 108 108 </ItemGroup> 109 109 <ItemGroup> 110 <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModel.cs" /> 111 <Compile Include="SymbolicDiscriminantFunctionClassificationModel.cs" /> 112 <Compile Include="SymbolicDiscriminantFunctionClassificationSolution.cs" /> 110 113 <Compile Include="Interfaces\ISymbolicClassificationModel.cs" /> 111 114 <Compile Include="Interfaces\ISymbolicClassificationSolution.cs" /> … … 121 124 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveProblem.cs" /> 122 125 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs" /> 123 <Compile Include="SymbolicClassificationModel.cs" /> 126 <Compile Include="SymbolicClassificationModel.cs"> 127 <SubType>Code</SubType> 128 </Compile> 124 129 <Compile Include="SymbolicClassificationSolution.cs" /> 125 130 <None Include="HeuristicLab.snk" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicClassificationSolution.cs
r5624 r5649 22 22 23 23 using HeuristicLab.Problems.DataAnalysis.Symbolic; 24 using System.Collections.Generic; 25 using System; 24 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 25 27 public interface ISymbolicClassificationSolution : IClassificationSolution, ISymbolicDataAnalysisSolution { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r5557 r5649 37 37 [Item("SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic classification solution for multi objective symbolic classification problems.")] 38 38 [StorableClass] 39 public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution> { 39 public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 40 ISymbolicDataAnalysisInterpreterOperator { 41 private const string ProblemDataParameterName = "ProblemData"; 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 43 #region parameter properties 44 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { 45 get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } 46 } 47 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 48 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 49 } 50 #endregion 51 #region properties 52 public IClassificationProblemData ProblemData { 53 get { return ProblemDataParameter.ActualValue; } 54 } 55 public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicDataAnalysisTreeInterpreter { 56 get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; } 57 } 58 #endregion 40 59 [StorableConstructor] 41 60 private SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 43 62 public SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer() 44 63 : base() { 64 Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution.")); 45 65 } 46 66 public override IDeepCloneable Clone(Cloner cloner) { … … 50 70 51 71 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 52 throw new System.NotImplementedException(); 72 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreter, ProblemData.ClassValues); 73 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemData); 53 74 } 54 75 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r5557 r5649 37 37 [Item("SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic classification solution for single objective symbolic classification problems.")] 38 38 [StorableClass] 39 public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution> { 40 39 public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 40 ISymbolicDataAnalysisInterpreterOperator { 41 private const string ProblemDataParameterName = "ProblemData"; 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 43 #region parameter properties 44 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { 45 get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } 46 } 47 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 48 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 49 } 50 #endregion 51 #region properties 52 public IClassificationProblemData ProblemData { 53 get { return ProblemDataParameter.ActualValue; } 54 } 55 public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicDataAnalysisTreeInterpreter { 56 get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; } 57 } 58 #endregion 41 59 [StorableConstructor] 42 60 private SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 50 68 51 69 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 52 throw new System.NotImplementedException(); 70 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreter, ProblemData.ClassValues); 71 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemData); 53 72 } 54 73 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs
r5624 r5649 55 55 #region IClassificationModel Members 56 56 57 public IEnumerable<double> GetEstimatedValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 58 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, problemData.Dataset, rows); 59 } 60 61 public IEnumerable<double> GetEstimatedClassValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 62 throw new NotImplementedException(); 57 public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 58 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows); 63 59 } 64 60 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r5624 r5649 53 53 } 54 54 55 public IEnumerable<double> GetEstimatedValues( IRegressionProblemData problemData, IEnumerable<int> rows) {56 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, problemData.Dataset, rows);55 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 56 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows); 57 57 } 58 58 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs
r5624 r5649 55 55 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 56 56 } 57 public I ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {58 get { return (I ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }57 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 58 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 59 59 } 60 60 public IValueLookupParameter<T> ProblemDataParameter { … … 119 119 : base() { 120 120 Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use.")); 121 Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));121 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree.")); 122 122 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree.")); 123 123 Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisInterpreterOperator.cs
r5624 r5649 24 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 25 25 public interface ISymbolicDataAnalysisInterpreterOperator : IOperator { 26 I ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { get; }26 ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { get; } 27 27 } 28 28 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r5624 r5649 31 31 using HeuristicLab.Optimization; 32 32 using System; 33 using System.Drawing; 33 34 34 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 38 39 [StorableClass] 39 40 public abstract class SymbolicDataAnalysisModel : NamedItem, ISymbolicDataAnalysisModel { 41 public override Image ItemImage { 42 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 43 } 44 40 45 #region properties 41 46 … … 63 68 public SymbolicDataAnalysisModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter) 64 69 : base() { 70 this.name = ItemName; 71 this.description = ItemDescription; 65 72 this.symbolicExpressionTree = tree; 66 73 this.interpreter = interpreter; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationProblem.cs
r5625 r5649 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 27 [StorableClass] 28 [Item("ClassificationProblem", " ")]28 [Item("ClassificationProblem", "A general classification problem.")] 29 29 [Creatable("Problems")] 30 30 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationProblemData.cs
r5601 r5649 194 194 #endregion 195 195 196 #region prope ties196 #region properties 197 197 public string TargetVariable { 198 198 get { return TargetVariableParameter.Value.Value; } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/ClassificationSolution.cs
r5624 r5649 37 37 [StorableClass] 38 38 public abstract class ClassificationSolution : DataAnalysisSolution, IClassificationSolution { 39 private const string ThresholdsResultsName = "Thresholds"; 39 private const string TrainingAccuracyResultName = "Accuracy (training)"; 40 private const string TestAccuracyResultName = "Accuracy (test)"; 40 41 [StorableConstructor] 41 42 protected ClassificationSolution(bool deserializing) : base(deserializing) { } … … 45 46 public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData) 46 47 : base(model, problemData) { 47 DoubleArray thresholds = new DoubleArray(); 48 Add(new Result(ThresholdsResultsName, "The threshold values for class boundaries.", thresholds)); 49 thresholds.Reset += new EventHandler(thresholds_Reset); 50 thresholds.ItemChanged += new EventHandler<EventArgs<int>>(thresholds_ItemChanged); 48 double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values 49 IEnumerable<double> originalTrainingClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes); 50 double[] estimatedTestClassValues = EstimatedTestClassValues.ToArray(); // cache values 51 IEnumerable<double> originalTestClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 52 53 double trainingAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues); 54 double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues); 55 56 Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue(trainingAccuracy))); 57 Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue(testAccuracy))); 51 58 } 52 59 … … 61 68 } 62 69 63 public virtual IEnumerable<double> EstimatedValues { 64 get { 65 return GetEstimatedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); 66 } 67 } 68 69 public virtual IEnumerable<double> EstimatedTrainingValues { 70 get { 71 return GetEstimatedValues(ProblemData.TrainingIndizes); 72 } 73 } 74 75 public virtual IEnumerable<double> EstimatedTestValues { 76 get { 77 return GetEstimatedValues(ProblemData.TestIndizes); 78 } 79 } 80 81 public virtual IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 82 return Model.GetEstimatedValues(ProblemData, rows); 83 } 84 85 public IEnumerable<double> Thresholds { 86 get { 87 return (DoubleArray)this[ThresholdsResultsName].Value; 88 } 89 } 90 91 public IEnumerable<double> EstimatedClassValues { 70 public virtual IEnumerable<double> EstimatedClassValues { 92 71 get { 93 72 return GetEstimatedClassValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); … … 95 74 } 96 75 97 public IEnumerable<double> EstimatedTrainingClassValues {76 public virtual IEnumerable<double> EstimatedTrainingClassValues { 98 77 get { 99 78 return GetEstimatedClassValues(ProblemData.TrainingIndizes); … … 101 80 } 102 81 103 public IEnumerable<double> EstimatedTestClassValues {82 public virtual IEnumerable<double> EstimatedTestClassValues { 104 83 get { 105 84 return GetEstimatedClassValues(ProblemData.TestIndizes); … … 107 86 } 108 87 109 public IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) { 110 return Model.GetEstimatedClassValues(ProblemData, rows); 111 } 112 113 #endregion 114 #region events 115 private void thresholds_ItemChanged(object sender, EventArgs<int> e) { 116 OnThresholdsChanged(EventArgs.Empty); 117 } 118 119 private void thresholds_Reset(object sender, EventArgs e) { 120 OnThresholdsChanged(EventArgs.Empty); 121 } 122 123 public event EventHandler ThresholdsChanged; 124 private void OnThresholdsChanged(EventArgs e) { 125 var listeners = ThresholdsChanged; 126 if (listeners != null) listeners(this, e); 88 public virtual IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) { 89 return Model.GetEstimatedClassValues(ProblemData.Dataset, rows); 127 90 } 128 91 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisProblemData.cs
r5601 r5649 44 44 get { return (IFixedValueParameter<Dataset>)Parameters[DatasetParameterName]; } 45 45 } 46 public IFixedValueParameter<ICheckedItem Collection<StringValue>> InputVariablesParameter {47 get { return (IFixedValueParameter<ICheckedItem Collection<StringValue>>)Parameters[InputVariablesParameterName]; }46 public IFixedValueParameter<ICheckedItemList<StringValue>> InputVariablesParameter { 47 get { return (IFixedValueParameter<ICheckedItemList<StringValue>>)Parameters[InputVariablesParameterName]; } 48 48 } 49 49 public IFixedValueParameter<IntValue> TrainingPartitionStartParameter { … … 65 65 get { return DatasetParameter.Value; } 66 66 } 67 public ICheckedItem Collection<StringValue> InputVariables {67 public ICheckedItemList<StringValue> InputVariables { 68 68 get { return InputVariablesParameter.Value; } 69 69 } 70 70 public IEnumerable<string> AllowedInputVariables { 71 get { return InputVariables.CheckedItems.Select(x => x.Value ); }71 get { return InputVariables.CheckedItems.Select(x => x.Value.Value); } 72 72 } 73 73 … … 110 110 throw new ArgumentException("All allowed input variables must be present in the dataset."); 111 111 112 var inputVariables = new CheckedItem Collection<StringValue>(dataset.VariableNames.Select(x => new StringValue(x)));112 var inputVariables = new CheckedItemList<StringValue>(dataset.VariableNames.Select(x => new StringValue(x))); 113 113 foreach (StringValue x in inputVariables) 114 114 inputVariables.SetItemCheckedState(x, allowedInputVariables.Contains(x.Value)); … … 120 120 121 121 Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", dataset)); 122 Parameters.Add(new FixedValueParameter<ICheckedItem Collection<StringValue>>(InputVariablesParameterName, "", inputVariables.AsReadOnly()));122 Parameters.Add(new FixedValueParameter<ICheckedItemList<StringValue>>(InputVariablesParameterName, "", inputVariables.AsReadOnly())); 123 123 Parameters.Add(new FixedValueParameter<IntValue>(TrainingPartitionStartParameterName, "", new IntValue(trainingPartitionStart))); 124 124 Parameters.Add(new FixedValueParameter<IntValue>(TrainingPartitionEndParameterName, "", new IntValue(trainingPartitionEnd))); … … 132 132 private void RegisterEventHandlers() { 133 133 DatasetParameter.ValueChanged += new EventHandler(Parameter_ValueChanged); 134 InputVariables.CheckedItemsChanged += new CollectionItemsChangedEventHandler< StringValue>(InputVariables_CheckedItemsChanged);134 InputVariables.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<StringValue>>(InputVariables_CheckedItemsChanged); 135 135 TrainingPartitionStart.ValueChanged += new EventHandler(Parameter_ValueChanged); 136 136 TrainingPartitionEnd.ValueChanged += new EventHandler(Parameter_ValueChanged); … … 139 139 } 140 140 141 private void InputVariables_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs< StringValue> e) {141 private void InputVariables_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> e) { 142 142 OnChanged(); 143 143 } 144 144 145 private void Parameter_ValueChanged(object sender, EventArgs e) { 145 146 OnChanged(); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisSolution.cs
r5624 r5649 82 82 public DataAnalysisSolution(IDataAnalysisModel model, IDataAnalysisProblemData problemData) 83 83 : base() { 84 name = string.Empty;85 description = string.Empty;84 name = ItemName; 85 description = ItemDescription; 86 86 Add(new Result(ModelResultName, "The symbolic data analysis model.", model)); 87 87 Add(new Result(ProblemDataResultName, "The symbolic data analysis problem data.", problemData)); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r5620 r5649 111 111 <Compile Include="ClassificationProblem.cs" /> 112 112 <Compile Include="ClassificationSolution.cs" /> 113 <Compile Include="ClusteringProblem.cs" /> 114 <Compile Include="ClusteringProblemData.cs" /> 115 <Compile Include="ClusteringSolution.cs" /> 116 <Compile Include="DiscriminantFunctionClassificationModel.cs" /> 117 <Compile Include="DiscriminantFunctionClassificationSolution.cs" /> 113 118 <Compile Include="DataAnalysisSolution.cs" /> 119 <Compile Include="Interfaces\Classification\IDiscriminantFunctionClassificationModel.cs" /> 120 <Compile Include="Interfaces\Classification\IDiscriminantFunctionClassificationSolution.cs" /> 121 <Compile Include="Interfaces\Clustering\IClusteringModel.cs" /> 122 <Compile Include="Interfaces\Clustering\IClusteringProblem.cs" /> 123 <Compile Include="Interfaces\Clustering\IClusteringProblemData.cs" /> 124 <Compile Include="Interfaces\Clustering\IClusteringSolution.cs" /> 125 <Compile Include="OnlineEvaluators\OnlineAccuracyEvaluator.cs" /> 114 126 <Compile Include="RegressionProblemData.cs" /> 115 127 <Compile Include="DataAnalysisProblemData.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs
r5620 r5649 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface IClassificationModel : IDataAnalysisModel { 25 IEnumerable<double> GetEstimatedValues(IClassificationProblemData problemData, IEnumerable<int> rows); 26 IEnumerable<double> GetEstimatedClassValues(IClassificationProblemData problemData, IEnumerable<int> rows); 25 IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows); 27 26 } 28 27 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationSolution.cs
r5509 r5649 27 27 new IClassificationProblemData ProblemData { get; } 28 28 29 IEnumerable<double> EstimatedValues { get; }30 IEnumerable<double> EstimatedTrainingValues { get; }31 IEnumerable<double> EstimatedTestValues { get; }32 IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);33 34 IEnumerable<double> Thresholds { get; }35 29 IEnumerable<double> EstimatedClassValues { get; } 36 30 IEnumerable<double> EstimatedTrainingClassValues { get; } 37 31 IEnumerable<double> EstimatedTestClassValues { get; } 38 32 IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows); 39 40 event EventHandler ThresholdsChanged;41 33 } 42 34 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r5601 r5649 28 28 public interface IDataAnalysisProblemData : IParameterizedNamedItem { 29 29 Dataset Dataset { get; } 30 ICheckedItem Collection<StringValue> InputVariables { get; }30 ICheckedItemList<StringValue> InputVariables { get; } 31 31 IEnumerable<string> AllowedInputVariables { get; } 32 32 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs
r5496 r5649 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface IRegressionModel : IDataAnalysisModel { 25 IEnumerable<double> GetEstimatedValues( IRegressionProblemData problemData, IEnumerable<int> rows);25 IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows); 26 26 } 27 27 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/RegressionProblem.cs
r5625 r5649 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 27 [StorableClass] 28 [Item("RegressionProblem", " ")]28 [Item("RegressionProblem", "A general regression problem")] 29 29 [Creatable("Problems")] 30 30 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/RegressionSolution.cs
r5624 r5649 37 37 [StorableClass] 38 38 public abstract class RegressionSolution : DataAnalysisSolution, IRegressionSolution { 39 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 40 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; 41 private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)"; 42 private const string TestSquaredCorrelationResultName = "Pearson's R² (test)"; 43 private const string TrainingRelativeErrorResultName = "Average relative error (training)"; 44 private const string TestRelativeErrorResultName = "Average relative error (test)"; 45 39 46 [StorableConstructor] 40 47 protected RegressionSolution(bool deserializing) : base(deserializing) { } … … 44 51 public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData) 45 52 : base(model, problemData) { 53 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values 54 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes); 55 double[] estimatedTestValues = EstimatedTestValues.ToArray(); // cache values 56 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 57 58 double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 59 double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 60 double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 61 double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues); 62 double trainingRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 63 double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 64 65 Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue(trainingMSE))); 66 Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue(testMSE))); 67 Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue(trainingR2))); 68 Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue(testR2))); 69 Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue(trainingRelError))); 70 Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue(testRelError))); 46 71 } 47 72 73 protected override void OnProblemDataChanged(EventArgs e) { 74 base.OnProblemDataChanged(e); 75 throw new NotImplementedException(); // need to recalculate results 76 } 77 protected override void OnModelChanged(EventArgs e) { 78 base.OnModelChanged(e); 79 throw new NotImplementedException(); // need to recalculate results 80 } 48 81 #region IRegressionSolution Members 49 82 … … 75 108 76 109 public virtual IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 77 return Model.GetEstimatedValues(ProblemData , rows);110 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 78 111 } 79 80 112 #endregion 81 113 }
Note: See TracChangeset
for help on using the changeset viewer.