@@ -36,7 +36,10 @@ public class RandomVariableLazyEvaluation implements RandomVariable {
36
36
/**
37
37
*
38
38
*/
39
+
40
+
39
41
private static final long serialVersionUID = 8413020544732461630L ;
42
+ private transient RandomVariable [][] gammaIncrements ;
40
43
41
44
private final double time ; // Time (filtration)
42
45
@@ -59,6 +62,7 @@ public RandomVariableLazyEvaluation(final RandomVariable value) {
59
62
realizations = value .isDeterministic () ? null : value ::get ;
60
63
size = value .size ();
61
64
valueIfNonStochastic = value .isDeterministic () ? value .get (0 ) : Double .NaN ;
65
+ gammaIncrements = null ; // Lazy initialization
62
66
}
63
67
64
68
/**
@@ -68,8 +72,9 @@ public RandomVariableLazyEvaluation(final RandomVariable value) {
68
72
*/
69
73
public RandomVariableLazyEvaluation (final double value ) {
70
74
this (0.0 , value );
71
- }
75
+ gammaIncrements = null ; // Lazy initialization
72
76
77
+ }
73
78
/**
74
79
* Create a random variable by applying a function to a given other implementation of <code>RandomVariable</code>.
75
80
*
@@ -87,6 +92,8 @@ public double applyAsDouble(final int i) {
87
92
};
88
93
size = value .size ();
89
94
valueIfNonStochastic = value .isDeterministic () ? function .applyAsDouble (value .get (0 )) : Double .NaN ;
95
+ gammaIncrements = null ; // Lazy initialization
96
+
90
97
}
91
98
92
99
/**
@@ -101,6 +108,17 @@ public RandomVariableLazyEvaluation(final double time, final double value) {
101
108
realizations = null ;
102
109
size = 1 ;
103
110
valueIfNonStochastic = value ;
111
+ gammaIncrements = null ; // Lazy initialization
112
+
113
+ }
114
+
115
+ public RandomVariable getIncrement (final int timeIndex , final int factor ) {
116
+ // Thread safe lazy initialization
117
+ /*
118
+ * For performance reasons we return directly the stored data (no defensive copy).
119
+ * We return an immutable object to ensure that the receiver does not alter the data.
120
+ */
121
+ return gammaIncrements [timeIndex ][factor ];
104
122
}
105
123
106
124
/**
0 commit comments