[13865] | 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;
|
---|
[14310] | 13 | using Microsoft.Win32.SafeHandles;
|
---|
[13865] | 14 |
|
---|
| 15 | namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
|
---|
| 16 | [StorableClass]
|
---|
| 17 | [Item("Model", "")]
|
---|
| 18 | public sealed class Model : NamedItem, IRegressionModel {
|
---|
[14310] | 19 | [Storable]
|
---|
[13865] | 20 | private readonly ISymbolicExpressionTree tree;
|
---|
[14310] | 21 | [Storable]
|
---|
| 22 | private string targetVariable;
|
---|
| 23 | [Storable]
|
---|
| 24 | private string[] variablesUsedForPrediction;
|
---|
[13865] | 25 |
|
---|
[14311] | 26 | [StorableConstructor]
|
---|
| 27 | private Model(bool deserializing) : base(deserializing) {
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[13865] | 30 | private Model(Model original, Cloner cloner) {
|
---|
| 31 | this.tree = cloner.Clone(original.tree);
|
---|
[14310] | 32 | this.variablesUsedForPrediction = original.variablesUsedForPrediction;
|
---|
| 33 | this.targetVariable = original.targetVariable;
|
---|
[13865] | 34 | }
|
---|
| 35 |
|
---|
[14311] | 36 | public Model(ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) {
|
---|
[13865] | 37 | this.tree = tree;
|
---|
[14310] | 38 | this.variablesUsedForPrediction = variablesUsedForPrediction;
|
---|
| 39 | this.targetVariable = targetVariable;
|
---|
[13865] | 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) {
|
---|
[14311] | 47 | return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows);
|
---|
[13865] | 48 | }
|
---|
| 49 |
|
---|
| 50 | public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
|
---|
| 51 | return new Solution(this, problemData);
|
---|
| 52 | }
|
---|
[14310] | 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 | }
|
---|
[13865] | 70 | }
|
---|
| 71 | }
|
---|