- Timestamp:
- 06/01/10 17:58:03 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/BestSupportVectorRegressionSolutionAnalyzer.cs
r3877 r3884 169 169 return base.Apply(); 170 170 } 171 172 private IEnumerable<string> GetInputVariables(SymbolicExpressionTree tree) {173 return (from varNode in tree.IterateNodesPrefix().OfType<VariableTreeNode>()174 select varNode.VariableName).Distinct();175 }176 171 } 177 172 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/SupportVectorRegressionSolution.cs
r3858 r3884 39 39 [StorableClass] 40 40 public sealed class SupportVectorRegressionSolution : DataAnalysisSolution { 41 public SupportVectorRegressionSolution() : base() { } 42 public SupportVectorRegressionSolution(DataAnalysisProblemData problemData, SupportVectorMachineModel model, IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit) 43 : base(problemData, lowerEstimationLimit, upperEstimationLimit) { 44 this.Model = model; 45 } 46 41 47 public override Image ItemImage { 42 48 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; } 43 49 } 44 50 45 [Storable] 46 private SupportVectorMachineModel model; 47 public SupportVectorMachineModel Model { 48 get { return model; } 51 public new SupportVectorMachineModel Model { 52 get { return (SupportVectorMachineModel)base.Model; } 53 set { base.Model = value; } 49 54 } 50 55 … … 53 58 } 54 59 55 public SupportVectorRegressionSolution() : base() { } 56 public SupportVectorRegressionSolution(DataAnalysisProblemData problemData, SupportVectorMachineModel model, IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit) 57 : base(problemData, lowerEstimationLimit, upperEstimationLimit) { 58 this.model = model; 59 } 60 61 protected override void OnProblemDataChanged(EventArgs e) { 62 RecalculateEstimatedValues(); 63 model.Model.SupportVectorIndizes = new int[0]; 60 protected override void OnProblemDataChanged() { 61 Model.Model.SupportVectorIndizes = new int[0]; 62 base.OnProblemDataChanged(); 64 63 } 65 64 66 65 private Dataset CalculateSupportVectors() { 67 if ( model.Model.SupportVectorIndizes.Length == 0)66 if (Model.Model.SupportVectorIndizes.Length == 0) 68 67 return new Dataset(); 69 68 70 Dataset dataset = new Dataset(ProblemData.Dataset.VariableNames, new double[ model.Model.SupportVectorCount, ProblemData.Dataset.Columns]);71 for (int i = 0; i < model.Model.SupportVectorIndizes.Length; i++) {69 Dataset dataset = new Dataset(ProblemData.Dataset.VariableNames, new double[Model.Model.SupportVectorCount, ProblemData.Dataset.Columns]); 70 for (int i = 0; i < Model.Model.SupportVectorIndizes.Length; i++) { 72 71 for (int column = 0; column < ProblemData.Dataset.Columns; column++) 73 dataset[i, column] = ProblemData.Dataset[ model.Model.SupportVectorIndizes[i], column];72 dataset[i, column] = ProblemData.Dataset[Model.Model.SupportVectorIndizes[i], column]; 74 73 } 75 74 return dataset; 76 75 } 77 76 78 pr ivate void RecalculateEstimatedValues() {77 protected override void RecalculateEstimatedValues() { 79 78 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(ProblemData, 0, ProblemData.Dataset.Rows); 80 SVM.Problem scaledProblem = Scaling.Scale( model.RangeTransform, problem);79 SVM.Problem scaledProblem = Scaling.Scale(Model.RangeTransform, problem); 81 80 82 81 estimatedValues = (from row in Enumerable.Range(0, scaledProblem.Count) 83 let prediction = SVM.Prediction.Predict( model.Model, scaledProblem.X[row])82 let prediction = SVM.Prediction.Predict(Model.Model, scaledProblem.X[row]) 84 83 let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, prediction)) 85 84 select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList(); 86 OnEstimatedValuesChanged( EventArgs.Empty);85 OnEstimatedValuesChanged(); 87 86 } 88 87 … … 112 111 } 113 112 } 114 115 public override IDeepCloneable Clone(Cloner cloner) {116 SupportVectorRegressionSolution clone = (SupportVectorRegressionSolution)base.Clone(cloner);117 clone.model = (SupportVectorMachineModel)cloner.Clone(model);118 return clone;119 }120 113 } 121 114 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r3541 r3884 39 39 [StorableClass] 40 40 [Item("SymbolicRegressionModel", "A symbolic regression model represents an entity that provides estimated values based on input values.")] 41 public class SymbolicRegressionModel : Item { 41 public class SymbolicRegressionModel : NamedItem, IDataAnalysisModel { 42 private SymbolicRegressionModel() : base() { } // for cloning 43 [StorableConstructor] 44 protected SymbolicRegressionModel(bool deserializing) 45 : base(deserializing) { 46 } 47 public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree, IEnumerable<string> inputVariables) 48 : base() { 49 this.tree = tree; 50 this.interpreter = interpreter; 51 this.inputVariables = inputVariables.ToList(); 52 } 53 42 54 [Storable] 43 55 private SymbolicExpressionTree tree; … … 50 62 get { return interpreter; } 51 63 } 64 [Storable] 52 65 private List<string> inputVariables; 53 [Storable]54 66 public IEnumerable<string> InputVariables { 55 67 get { return inputVariables.AsEnumerable(); } … … 59 71 } 60 72 } 61 public SymbolicRegressionModel() : base() { } // for cloning62 73 63 public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree, IEnumerable<string> inputVariables) 64 : base() { 65 this.tree = tree; 66 this.interpreter = interpreter; 67 this.inputVariables = inputVariables.ToList(); 68 } 69 70 public IEnumerable<double> GetEstimatedValues(Dataset dataset, int start, int end) { 71 return interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Enumerable.Range(start, end - start)); 74 public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) { 75 return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, Enumerable.Range(start, end - start)); 72 76 } 73 77 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r3710 r3884 37 37 [StorableClass] 38 38 public sealed class SymbolicRegressionSolution : DataAnalysisSolution { 39 public SymbolicRegressionSolution() : base() { } 40 public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit) 41 : base(problemData, lowerEstimationLimit, upperEstimationLimit) { 42 this.Model = model; 43 } 44 39 45 public override Image ItemImage { 40 46 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; } 41 47 } 42 [Storable] 43 private SymbolicRegressionModel model; 44 public SymbolicRegressionModel Model { 45 get { return model; } 46 set { 47 if (model != value) { 48 if (value == null) throw new ArgumentNullException(); 49 model = value; 50 OnModelChanged(EventArgs.Empty); 51 } 52 } 48 49 public new SymbolicRegressionModel Model { 50 get { return (SymbolicRegressionModel)base.Model; } 51 set { base.Model = value; } 53 52 } 54 53 55 public SymbolicRegressionSolution() : base() { } 56 public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit) 57 : base(problemData, lowerEstimationLimit, upperEstimationLimit) { 58 this.model = model; 59 } 60 61 public event EventHandler ModelChanged; 62 private void OnModelChanged(EventArgs e) { 63 RecalculateEstimatedValues(); 64 var listeners = ModelChanged; 65 if (listeners != null) 66 listeners(this, e); 67 } 68 69 protected override void OnProblemDataChanged(EventArgs e) { 70 RecalculateEstimatedValues(); 71 } 72 73 private void RecalculateEstimatedValues() { 74 estimatedValues = (from x in model.GetEstimatedValues(ProblemData.Dataset, 0, ProblemData.Dataset.Rows) 54 protected override void RecalculateEstimatedValues() { 55 estimatedValues = (from x in Model.GetEstimatedValues(ProblemData, 0, ProblemData.Dataset.Rows) 75 56 let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x)) 76 57 select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList(); 77 OnEstimatedValuesChanged( EventArgs.Empty);58 OnEstimatedValuesChanged(); 78 59 } 79 60 … … 103 84 } 104 85 } 105 106 public override IDeepCloneable Clone(Cloner cloner) {107 SymbolicRegressionSolution clone = (SymbolicRegressionSolution)base.Clone(cloner);108 clone.model = (SymbolicRegressionModel)cloner.Clone(model);109 return clone;110 }111 86 } 112 87 }
Note: See TracChangeset
for help on using the changeset viewer.