Added variance for convenience.
@@ -429,14 +429,25 @@ public interface RandomVariable extends Serializable {
RandomVariable average();
/**
- * Returns the conditional expectation using a given conditional expectation estimator.
+ * Returns a random variable which is deterministic and corresponds
+ * the expectation of this random variable.
*
- * @param conditionalExpectationOperator A given conditional expectation estimator.
- * @return The conditional expectation of this random variable (as a random variable)
+ * @return New random variable being the expectation of this random variable.
*/
- default RandomVariable getConditionalExpectation(final ConditionalExpectationEstimator conditionalExpectationOperator)
+ default RandomVariable expectation() {
+ return average();
+ };
+
+ /**
+ * Returns a random variable which is deterministic and corresponds
+ * the variance of this random variable.
+ *
+ * @return New random variable being the variance of this random variable and the argument.
+ */
+ default RandomVariable variance()
{
- return conditionalExpectationOperator.getConditionalExpectation(this);
+ RandomVariable meanDeviation = this.sub(average());
+ return meanDeviation.squared().average();
}
/**
@@ -451,6 +462,17 @@ public interface RandomVariable extends Serializable {
return this.sub(average()).mult(value.sub(value.average())).average();
}
+ /**
+ * Returns the conditional expectation using a given conditional expectation estimator.
+ *
+ * @param conditionalExpectationOperator A given conditional expectation estimator.
+ * @return The conditional expectation of this random variable (as a random variable)
+ */
+ default RandomVariable getConditionalExpectation(final ConditionalExpectationEstimator conditionalExpectationOperator)
+ {
+ return conditionalExpectationOperator.getConditionalExpectation(this);
+ }
+
/**
* Applies x &rarr; x * x to this random variable.
* @return New random variable with the result of the function.
