using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; using Microsoft.Win32.SafeHandles; namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction { [StorableClass] [Item("Model", "")] public sealed class Model : NamedItem, IRegressionModel { [Storable] private readonly ISymbolicExpressionTree tree; [Storable] private string targetVariable; [Storable] private string[] variablesUsedForPrediction; [StorableConstructor] private Model(bool deserializing) : base(deserializing) { } private Model(Model original, Cloner cloner) { this.tree = cloner.Clone(original.tree); this.variablesUsedForPrediction = original.variablesUsedForPrediction; this.targetVariable = original.targetVariable; } public Model(ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) { this.tree = tree; this.variablesUsedForPrediction = variablesUsedForPrediction; this.targetVariable = targetVariable; } public override IDeepCloneable Clone(Cloner cloner) { return new Model(this, cloner); } public IEnumerable GetEstimatedValues(IDataset dataset, IEnumerable rows) { return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows); } public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { return new Solution(this, problemData); } public string TargetVariable { get { return targetVariable; } set { throw new NotSupportedException(); } } public event EventHandler TargetVariableChanged; public IEnumerable VariablesUsedForPrediction { get { return variablesUsedForPrediction; } } } }