Refactors
- getNode method to handle invalid node index and improve error handling - update parameter description in SimulationMultiple constructor - enhance calcError method in StatisticsSummary for better clarity and functionality.
This commit is contained in:
@@ -127,7 +127,8 @@ public final class Net implements Iterable<ServerNode> {
|
|||||||
* @return the node
|
* @return the node
|
||||||
*/
|
*/
|
||||||
public ServerNode getNode(String name) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class SimulationMultiple {
|
|||||||
/**
|
/**
|
||||||
* Create a new object that can simulate the net in input multiple times
|
* 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) {
|
public SimulationMultiple(Net net) {
|
||||||
this.net = net;
|
this.net = net;
|
||||||
@@ -85,5 +85,4 @@ public class SimulationMultiple {
|
|||||||
return new ResultSummary(results);
|
return new ResultSummary(results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,21 +45,6 @@ public class StatisticsSummary {
|
|||||||
this.distr = new TDistribution(null, values.length - 1);
|
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.
|
* Get the frequency of the values in the array.
|
||||||
*
|
*
|
||||||
@@ -90,6 +75,38 @@ public class StatisticsSummary {
|
|||||||
return this.values[index];
|
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.
|
* Get a summary of the statistics.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user