1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Problems.DataAnalysis;
|
---|
10 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
11 | using HeuristicLab.Random;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Problems.DynamicalSystemsModelling {
|
---|
14 | [StorableClass]
|
---|
15 | public class Solution : Item {
|
---|
16 | [Storable]
|
---|
17 | private ISymbolicExpressionTree[] trees;
|
---|
18 | public ISymbolicExpressionTree[] Trees {
|
---|
19 | get { return trees; }
|
---|
20 | }
|
---|
21 | // [Storable]
|
---|
22 | // private double[] theta;
|
---|
23 |
|
---|
24 | [Storable]
|
---|
25 | private IRegressionProblemData problemData;
|
---|
26 | public IRegressionProblemData ProblemData {
|
---|
27 | get { return problemData; }
|
---|
28 | }
|
---|
29 | [Storable]
|
---|
30 | private string[] targetVars;
|
---|
31 | public string[] TargetVariables {
|
---|
32 | get { return targetVars; }
|
---|
33 | }
|
---|
34 | [Storable]
|
---|
35 | private string[] latentVariables;
|
---|
36 | public string[] LatentVariables {
|
---|
37 | get { return latentVariables; }
|
---|
38 | }
|
---|
39 | [Storable]
|
---|
40 | private IEnumerable<IntRange> trainingEpisodes;
|
---|
41 | public IEnumerable<IntRange> TrainingEpisodes {
|
---|
42 | get { return trainingEpisodes; }
|
---|
43 | }
|
---|
44 | [Storable]
|
---|
45 | private string odeSolver;
|
---|
46 | [Storable]
|
---|
47 | private int numericIntegrationSteps;
|
---|
48 |
|
---|
49 | [StorableConstructor]
|
---|
50 | private Solution(bool deserializing) : base(deserializing) { }
|
---|
51 | [StorableHook(HookType.AfterDeserialization)]
|
---|
52 | private void AfterDeserialization() {
|
---|
53 | }
|
---|
54 |
|
---|
55 | // cloning
|
---|
56 | private Solution(Solution original, Cloner cloner)
|
---|
57 | : base(original, cloner) {
|
---|
58 | this.trees = new ISymbolicExpressionTree[original.trees.Length];
|
---|
59 | for (int i = 0; i < trees.Length; i++) this.trees[i] = cloner.Clone(original.trees[i]);
|
---|
60 | // this.theta = new double[original.theta.Length];
|
---|
61 | // Array.Copy(original.theta, this.theta, this.theta.Length);
|
---|
62 | this.problemData = cloner.Clone(original.problemData);
|
---|
63 | this.targetVars = original.TargetVariables.ToArray();
|
---|
64 | this.latentVariables = original.LatentVariables.ToArray();
|
---|
65 | this.trainingEpisodes = original.TrainingEpisodes.Select(te => cloner.Clone(te)).ToArray();
|
---|
66 | this.odeSolver = original.odeSolver;
|
---|
67 | this.numericIntegrationSteps = original.numericIntegrationSteps;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public Solution(ISymbolicExpressionTree[] trees,
|
---|
71 | IRegressionProblemData problemData,
|
---|
72 | string[] targetVars, string[] latentVariables, IEnumerable<IntRange> trainingEpisodes,
|
---|
73 | string odeSolver, int numericIntegrationSteps) : base() {
|
---|
74 | this.trees = trees;
|
---|
75 |
|
---|
76 | this.problemData = problemData;
|
---|
77 | this.targetVars = targetVars;
|
---|
78 | this.latentVariables = latentVariables;
|
---|
79 | this.trainingEpisodes = trainingEpisodes;
|
---|
80 | this.odeSolver = odeSolver;
|
---|
81 | this.numericIntegrationSteps = numericIntegrationSteps;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
85 | return new Solution(this, cloner);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public IEnumerable<double[]> Predict(IntRange episode, int forecastHorizon, out double snmse) {
|
---|
89 | var forecastEpisode = new IntRange(episode.Start, episode.End + forecastHorizon);
|
---|
90 | //
|
---|
91 | // var random = new FastRandom(12345);
|
---|
92 | // snmse = Problem.OptimizeForEpisodes(trees, problemData, targetVars, latentVariables, random, new[] { forecastEpisode }, 100, numericIntegrationSteps, odeSolver);
|
---|
93 | var optimizationData = new Problem.OptimizationData(trees, targetVars, problemData.AllowedInputVariables.ToArray(), problemData, null, new[] { forecastEpisode }, numericIntegrationSteps, latentVariables, odeSolver);
|
---|
94 | //
|
---|
95 | //
|
---|
96 | // var theta = Problem.ExtractParametersFromTrees(trees);
|
---|
97 |
|
---|
98 | snmse = 0.0; // TODO
|
---|
99 | return Problem.Integrate(optimizationData).Select(p => p.Select(pi => pi.Item1).ToArray()).ToArray();
|
---|
100 | }
|
---|
101 | }
|
---|
102 | } |
---|