1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Data;
|
---|
10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
11 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
12 | using HeuristicLab.Problems.DataAnalysis;
|
---|
13 | using Microsoft.Win32.SafeHandles;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
|
---|
16 | [StorableClass]
|
---|
17 | [Item("Model", "")]
|
---|
18 | public sealed class Model : NamedItem, IRegressionModel {
|
---|
19 | [Storable]
|
---|
20 | private readonly ISymbolicExpressionTree tree;
|
---|
21 | [Storable]
|
---|
22 | private string targetVariable;
|
---|
23 | [Storable]
|
---|
24 | private string[] variablesUsedForPrediction;
|
---|
25 |
|
---|
26 | [StorableConstructor]
|
---|
27 | private Model(bool deserializing) : base(deserializing) {
|
---|
28 | }
|
---|
29 |
|
---|
30 | private Model(Model original, Cloner cloner) {
|
---|
31 | this.tree = cloner.Clone(original.tree);
|
---|
32 | this.variablesUsedForPrediction = original.variablesUsedForPrediction;
|
---|
33 | this.targetVariable = original.targetVariable;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public Model(ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) {
|
---|
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), 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 | }
|
---|