Changeset 3462 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
- Timestamp:
- 04/21/10 15:21:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r3442 r3462 38 38 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 39 39 [StorableClass] 40 public class SymbolicRegressionModel : DeepCloneable, IModel { 40 [Item("SymbolicRegressionModel", "A symbolic regression model represents an entity that provides estimated values based on input values.")] 41 public class SymbolicRegressionModel : Item { 41 42 [Storable] 42 43 private SymbolicExpressionTree tree; … … 45 46 } 46 47 [Storable] 47 private SimpleArithmeticExpressionEvaluator evaluator;48 public SimpleArithmeticExpressionEvaluator Evaluator {49 get { return evaluator; }48 private ISymbolicExpressionTreeInterpreter interpreter; 49 public ISymbolicExpressionTreeInterpreter Interpreter { 50 get { return interpreter; } 50 51 } 51 private Dataset emptyDataset; 52 private IEnumerable<int> firstRow = new int[] { 0 }; 52 [Storable] 53 private List<string> inputVariables; 54 public IEnumerable<string> InputVariables { 55 get { return inputVariables.AsEnumerable(); } 56 } 53 57 54 58 public SymbolicRegressionModel() : base() { } // for cloning 55 59 56 public SymbolicRegressionModel( SymbolicExpressionTree tree, IEnumerable<string> inputVariables)60 public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree, IEnumerable<string> inputVariables) 57 61 : base() { 58 62 this.tree = tree; 59 this. evaluator = new SimpleArithmeticExpressionEvaluator();60 emptyDataset = new Dataset(inputVariables, new double[1, inputVariables.Count()]);63 this.interpreter = interpreter; 64 this.inputVariables = inputVariables.ToList(); 61 65 } 62 66 63 #region IModel Members 64 65 public double GetValue(double[] xs) { 66 if (xs.Length != emptyDataset.Columns) throw new ArgumentException("Length of input vector doesn't match model"); 67 for (int i = 0; i < xs.Length; i++) { 68 emptyDataset[0, i] = xs[i]; 69 } 70 return evaluator.EstimatedValues(tree, emptyDataset, firstRow).First(); 67 public IEnumerable<double> GetEstimatedValues(Dataset dataset, int start, int end) { 68 return interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Enumerable.Range(start, end - start)); 71 69 } 72 70 73 #endregion 71 public override IDeepCloneable Clone(Cloner cloner) { 72 var clone = (SymbolicRegressionModel)base.Clone(cloner); 73 clone.tree = (SymbolicExpressionTree)tree.Clone(cloner); 74 clone.interpreter = (ISymbolicExpressionTreeInterpreter)interpreter.Clone(cloner); 75 clone.inputVariables = new List<string>(inputVariables); 76 return clone; 77 } 74 78 } 75 79 }
Note: See TracChangeset
for help on using the changeset viewer.