diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/predictor/LinearModel.java')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/predictor/LinearModel.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/predictor/LinearModel.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/predictor/LinearModel.java new file mode 100644 index 00000000..6a7f8497 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/predictor/LinearModel.java | |||
@@ -0,0 +1,90 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.predictor; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.StateData; | ||
4 | import com.google.common.base.Objects; | ||
5 | import java.util.ArrayList; | ||
6 | import java.util.HashMap; | ||
7 | import java.util.List; | ||
8 | import java.util.Map; | ||
9 | |||
10 | @SuppressWarnings("all") | ||
11 | public class LinearModel { | ||
12 | private double ridge; | ||
13 | |||
14 | private Map<Object, StateData> stateAndHistory; | ||
15 | |||
16 | private List<StateData> samples; | ||
17 | |||
18 | public LinearModel(final double ridge) { | ||
19 | this.ridge = ridge; | ||
20 | HashMap<Object, StateData> _hashMap = new HashMap<Object, StateData>(); | ||
21 | this.stateAndHistory = _hashMap; | ||
22 | ArrayList<StateData> _arrayList = new ArrayList<StateData>(); | ||
23 | this.samples = _arrayList; | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * reset the current train data for regression to a new trajectory | ||
28 | * @param state: the last state of the trajectory | ||
29 | */ | ||
30 | public void resetRegression(final Object state) { | ||
31 | this.samples.clear(); | ||
32 | boolean _containsKey = this.stateAndHistory.containsKey(state); | ||
33 | if (_containsKey) { | ||
34 | StateData data = this.stateAndHistory.get(state); | ||
35 | Object curState = state; | ||
36 | this.samples.add(data); | ||
37 | while ((this.stateAndHistory.containsKey(data.getLastState()) && (!Objects.equal(data.getLastState(), curState)))) { | ||
38 | { | ||
39 | curState = data.getLastState(); | ||
40 | data = this.stateAndHistory.get(data.getLastState()); | ||
41 | this.samples.add(data); | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Add a new data point to the current training set | ||
49 | * @param state: the state on which the new data point is calculated | ||
50 | * @param features: the set of feature value(x) | ||
51 | * @param value: the value of the state (y) | ||
52 | * @param lastState: the state which transformed to current state, used to record the trajectory | ||
53 | */ | ||
54 | public boolean feedData(final Object state, final double[] features, final double value, final Object lastState) { | ||
55 | boolean _xblockexpression = false; | ||
56 | { | ||
57 | StateData data = new StateData(features, value, lastState); | ||
58 | this.stateAndHistory.put(state, data); | ||
59 | _xblockexpression = this.samples.add(data); | ||
60 | } | ||
61 | return _xblockexpression; | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * get prediction for next state, without storing the data point into the training set | ||
66 | * @param features: the feature values of current state | ||
67 | * @param value: the value of the current state | ||
68 | * @param: featuresToPredict: the features of the state wanted to be predected | ||
69 | * @return the value of the state to be predicted | ||
70 | */ | ||
71 | public double getPredictionForNextDataSample(final double[] features, final double value, final double[] featuresToPredict) { | ||
72 | throw new Error("Unresolved compilation problems:" | ||
73 | + "\nMatrix cannot be resolved." | ||
74 | + "\nMatrix cannot be resolved." | ||
75 | + "\nLinearRegression cannot be resolved." | ||
76 | + "\ncoefficients cannot be resolved"); | ||
77 | } | ||
78 | |||
79 | private double predict(final double[] parameters, final double[] featuresToPredict) { | ||
80 | double result = parameters[0]; | ||
81 | for (int i = 0; (i < featuresToPredict.length); i++) { | ||
82 | double _result = result; | ||
83 | double _get = parameters[i]; | ||
84 | double _get_1 = featuresToPredict[i]; | ||
85 | double _multiply = (_get * _get_1); | ||
86 | result = (_result + _multiply); | ||
87 | } | ||
88 | return result; | ||
89 | } | ||
90 | } | ||