1 /*
2 * Copyright 2014 University of Glasgow.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package broadwick.montecarlo;
17
18 import broadwick.statistics.Samples;
19
20 /**
21 * A default implementation for the MonteCarloResults interface.
22 */
23 public class MonteCarloDefaultResults implements MonteCarloResults {
24
25 /**
26 * Create a default implementation of the MonteCarloResults class. This class stores a single result from a Monte
27 * Carlo simulation and returns the mean of this value over all simulations as the expected value.
28 */
29 MonteCarloDefaultResults() {
30 this.samples = new Samples();
31 }
32
33 @Override
34 public final double getExpectedValue() {
35 return samples.getMean();
36 }
37
38 @Override
39 public final Samples getSamples() {
40 return samples;
41 }
42
43 @Override
44 public final String toCsv() {
45 return String.format("%f (%f)", samples.getMean(), samples.getStdDev());
46 }
47
48 @Override
49 public final MonteCarloResults join(final MonteCarloResults results) {
50 samples.add(results.getSamples());
51 return this;
52 }
53
54 @Override
55 public final void reset() {
56 this.samples = new Samples();
57 }
58
59 private Samples samples;
60
61 }