Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Model.cs @ 14310

Last change on this file since 14310 was 14310, checked in by gkronber, 8 years ago

changed interpreter and grammar to smooth ch and ins uptake using a compartement model

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
11using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12using HeuristicLab.Problems.DataAnalysis;
13using Microsoft.Win32.SafeHandles;
14
15namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
16  [StorableClass]
17  [Item("Model", "")]
18  public sealed class Model : NamedItem, IRegressionModel {
19    [Storable]
20    private readonly IRegressionProblemData problemData;
21    [Storable]
22    private readonly ISymbolicExpressionTree tree;
23    [Storable]
24    private string targetVariable;
25    [Storable]
26    private string[] variablesUsedForPrediction;
27
28    private Model(Model original, Cloner cloner) {
29      this.problemData = cloner.Clone(original.problemData);
30      this.tree = cloner.Clone(original.tree);
31      this.variablesUsedForPrediction = original.variablesUsedForPrediction;
32      this.targetVariable = original.targetVariable;
33    }
34
35    public Model(IRegressionProblemData problemData, ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) {
36      this.problemData = problemData;
37      this.tree = tree;
38      this.variablesUsedForPrediction = variablesUsedForPrediction;
39      this.targetVariable = targetVariable;
40    }
41
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new Model(this, cloner);
44    }
45
46    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
47      return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), problemData.Dataset, rows);
48    }
49
50    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
51      return new Solution(this, problemData);
52    }
53
54
55    public string TargetVariable {
56      get {
57        return targetVariable;
58      }
59      set {
60        throw new NotSupportedException();
61      }
62    }
63
64    public event EventHandler TargetVariableChanged;
65
66
67    public IEnumerable<string> VariablesUsedForPrediction {
68      get { return variablesUsedForPrediction; }
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.