diff --git a/src/main/java/net/berack/upo/valpre/sim/Net.java b/src/main/java/net/berack/upo/valpre/sim/Net.java index 95770ae..40255f0 100644 --- a/src/main/java/net/berack/upo/valpre/sim/Net.java +++ b/src/main/java/net/berack/upo/valpre/sim/Net.java @@ -127,7 +127,8 @@ public final class Net implements Iterable { * @return the node */ public ServerNode getNode(String name) { - return this.servers.get(this.getNodeIndex(name)); + var index = this.getNodeIndex(name); + return index < 0 ? null : this.servers.get(index); } /** diff --git a/src/main/java/net/berack/upo/valpre/sim/SimulationMultiple.java b/src/main/java/net/berack/upo/valpre/sim/SimulationMultiple.java index 2a1367a..9448834 100644 --- a/src/main/java/net/berack/upo/valpre/sim/SimulationMultiple.java +++ b/src/main/java/net/berack/upo/valpre/sim/SimulationMultiple.java @@ -18,7 +18,7 @@ public class SimulationMultiple { /** * Create a new object that can simulate the net in input multiple times * - * @param net the net that sould be simulated + * @param net the net that should be simulated */ public SimulationMultiple(Net net) { this.net = net; @@ -85,5 +85,4 @@ public class SimulationMultiple { return new ResultSummary(results); } } - } diff --git a/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java b/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java index c41e9da..854a199 100644 --- a/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java +++ b/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java @@ -45,21 +45,6 @@ public class StatisticsSummary { this.distr = new TDistribution(null, values.length - 1); } - /** - * Calculates the error at the selected alpha level. - * This method computes the error for the average and standard deviation values, - * considering the sample size and the confidence level (alpha). - * The result is adjusted using a t-distribution to account for the variability - * in smaller sample sizes. - * - * @param alpha the alpha value - * @return the error of the values - */ - public double calcError(double alpha) { - var percentile = this.distr.inverseCumulativeProbability(alpha); - return percentile * (this.stdDev / Math.sqrt(this.values.length)); - } - /** * Get the frequency of the values in the array. * @@ -90,6 +75,38 @@ public class StatisticsSummary { return this.values[index]; } + /** + * Calculates the error at the selected alpha level. + * This method computes the error for the average and standard deviation values, + * considering the sample size and the confidence level (alpha). + * The result is adjusted using a t-distribution to account for the variability + * in smaller sample sizes. + * + * @param alpha the alpha value + * @return the error of the values + */ + public double calcError(double alpha) { + return StatisticsSummary.calcError(this.distr, this.stdDev, alpha); + } + + /** + * Calculates the error at the selected alpha level. + * This method computes the error for the average and standard deviation values, + * considering the sample size and the confidence level (alpha). + * The result is adjusted using a t-distribution to account for the variability + * in smaller sample sizes. + * + * @param distribution the t-distribution to use + * @param stdDev the standard deviation of the values + * @param alpha the alpha value + * @return the error of the values + */ + public static double calcError(TDistribution distribution, double stdDev, double alpha) { + var percentile = distribution.inverseCumulativeProbability(alpha); + var n = distribution.getDegreesOfFreedom() + 1; + return percentile * (stdDev / Math.sqrt(n)); + } + /** * Get a summary of the statistics. *