def test_estimate_for_monte_carlo(num_models, num_samples, mc_sample_allocation): mc_outputs = [np.empty(0) for _ in range(num_models)] mc_outputs[0] = np.random.random(num_samples) covariance = np.eye(num_models) est = Estimator(mc_sample_allocation, covariance) expected_estimate = np.mean(mc_outputs[0]) assert est.get_estimate(mc_outputs) == pytest.approx(expected_estimate)
def test_two_model_estimate(): compressed_allocation = np.array([[1, 1, 1, 1], [5, 1, 1, 0], [10, 0, 0, 1]]) allocation = MLMCSampleAllocation(compressed_allocation) model_outputs = [np.arange(1, 7), np.arange(1, 17)] covariance = np.array([[1, 0.5], [0.5, 1]]) est = Estimator(allocation, covariance) expected_estimate = 10.545454545454547 assert est.get_estimate(model_outputs) == pytest.approx(expected_estimate)