Commit b4be2f95 authored by Björn Richerzhagen's avatar Björn Richerzhagen Committed by Jose Ignacio Monreal Bailey
Browse files

updating apache math to v3

parent 17687d0d
......@@ -246,10 +246,18 @@
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
<version>2.2</version>
</dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<!-- OLD Math for some outdated classes -->
<!-- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
<version>2.2</version>
</dependency>-->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
......
......@@ -24,7 +24,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math3.stat.StatUtils;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
......
......@@ -28,7 +28,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.util.db.dao.DAO;
......
......@@ -26,8 +26,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tud.kom.p2psim.api.churn.ChurnModel;
import de.tud.kom.p2psim.api.common.SimHost;
......@@ -42,11 +42,11 @@ public class ExponentialChurnModel implements ChurnModel {
TRANSIENT(MEAN_SESSION_LENGTH), NORMAL(10 * MEAN_SESSION_LENGTH), LONG_LASTING(
100 * MEAN_SESSION_LENGTH);
public final ExponentialDistributionImpl expDist;
public final ExponentialDistribution expDist;
private UserType(long length) {
double meanLength = Double.parseDouble(Long.toString(length));
expDist = new ExponentialDistributionImpl(meanLength);
expDist = new ExponentialDistribution(meanLength);
Long.toString(length);
}
......@@ -113,7 +113,7 @@ public class ExponentialChurnModel implements ChurnModel {
* .inverseCumulativeProbability(Simulator.getRandom()
* .nextDouble()); data.setOnlineTime((long) value);
*/
} catch (MathException e) {
} catch (OutOfRangeException e) {
e.printStackTrace();
}
return data.onlineTime;
......
......@@ -24,8 +24,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tud.kom.p2psim.api.churn.ChurnModel;
import de.tud.kom.p2psim.api.common.SimHost;
......@@ -39,11 +39,11 @@ public class HerreraChurnModel implements ChurnModel {
TRANSIENT(MEAN_SESSION_LENGTH), NORMAL(10 * MEAN_SESSION_LENGTH), LONG_LASTING(
100 * MEAN_SESSION_LENGTH);
public final ExponentialDistributionImpl expDist;
public final ExponentialDistribution expDist;
private UserType(long length) {
double meanLength = Double.parseDouble(Long.toString(length));
expDist = new ExponentialDistributionImpl(meanLength);
expDist = new ExponentialDistribution(meanLength);
Long.toString(length);
}
......@@ -81,7 +81,7 @@ public class HerreraChurnModel implements ChurnModel {
data.setOnlineTime(Math.round(data.type.expDist
.inverseCumulativeProbability(Randoms.getRandom(
HerreraChurnModel.class).nextDouble())));
} catch (MathException e) {
} catch (OutOfRangeException e) {
e.printStackTrace();
}
// Simulator.getMonitor().nextSessionTime(data.onlineTime);
......
......@@ -22,7 +22,7 @@ package de.tud.kom.p2psim.impl.churn;
import java.util.List;
import org.apache.commons.math.distribution.WeibullDistributionImpl;
import org.apache.commons.math3.distribution.WeibullDistribution;
import de.tud.kom.p2psim.api.churn.ChurnModel;
import de.tud.kom.p2psim.api.common.SimHost;
......@@ -53,11 +53,11 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public class KadChurnModel implements ChurnModel {
public WeibullDistributionImpl sessionTime, interSessionTime;
public WeibullDistribution sessionTime, interSessionTime;
public KadChurnModel() {
sessionTime = new WeibullDistributionImpl(0.61511, 169.5385);
interSessionTime = new WeibullDistributionImpl(0.47648, 413.6765);
sessionTime = new WeibullDistribution(0.61511, 169.5385);
interSessionTime = new WeibullDistribution(0.47648, 413.6765);
}
/**
......@@ -67,8 +67,8 @@ public class KadChurnModel implements ChurnModel {
* @param lambda
*/
public void setLambdaFactor(double lambda) {
sessionTime = new WeibullDistributionImpl(0.61511, 169.5385 * lambda);
interSessionTime = new WeibullDistributionImpl(0.47648,
sessionTime = new WeibullDistribution(0.61511, 169.5385 * lambda);
interSessionTime = new WeibullDistribution(0.47648,
413.6765 * lambda);
}
......
......@@ -27,7 +27,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math3.stat.StatUtils;
/**
* Implements the downhill simplx algorithm for positioning host in an
......
......@@ -25,8 +25,8 @@ import java.util.List;
import java.util.Random;
import java.util.Vector;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.AbstractNetLayer;
......@@ -68,7 +68,7 @@ public class NormalDistributionLatency implements LatencyStrategy {
*/
private long standardDeviation = 2 * Time.MICROSECOND; // 2ms
private NormalDistributionImpl normalDistribution = new NormalDistributionImpl(
private NormalDistribution normalDistribution = new NormalDistribution(
propagationMeanDelay, standardDeviation);
/**
......@@ -109,7 +109,7 @@ public class NormalDistributionLatency implements LatencyStrategy {
try {
delay = (long) normalDistribution
.inverseCumulativeProbability(rnd.nextDouble());
} catch (MathException e) {
} catch (OutOfRangeException e) {
throw new RuntimeException(e);
}
if (delay <= 0) {
......@@ -125,13 +125,13 @@ public class NormalDistributionLatency implements LatencyStrategy {
"Bad PropagationMeanDelay. It should be positiv!");
}
this.propagationMeanDelay = delay;
this.normalDistribution = new NormalDistributionImpl(
this.normalDistribution = new NormalDistribution(
this.propagationMeanDelay, this.standardDeviation);
}
public void setStandardDeviation(long standardDeviation) {
this.standardDeviation = standardDeviation;
this.normalDistribution = new NormalDistributionImpl(
this.normalDistribution = new NormalDistribution(
this.propagationMeanDelay, this.standardDeviation);
}
......
......@@ -34,6 +34,8 @@ import de.tud.kom.p2psim.impl.util.Summary;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SUMOController;
import org.apache.commons.math.random.JDKRandomGenerator;
import org.apache.commons.math.random.RandomGenerator;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.scenario.Configurator;
......
......@@ -27,7 +27,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.apache.commons.math.stat.Frequency;
import org.apache.commons.math3.stat.Frequency;
import org.jfree.data.xy.YIntervalSeries;
import de.tudarmstadt.maki.simonstrator.api.Time;
......
......@@ -20,8 +20,7 @@
package de.tud.kom.p2psim.impl.topology.views.wifi.phy.errormodel;
import org.apache.commons.math.MathException;
import org.apache.commons.math.special.Erf;
import org.apache.commons.math3.special.Erf;
import de.tud.kom.p2psim.api.topology.views.wifi.phy.WifiMode;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
......@@ -130,13 +129,7 @@ public class NistErrorRateModel extends AbstractErrorRateModel {
}
private double getErfc(double z) {
try {
return Erf.erfc(z);
} catch (MathException e) {
Monitor.log(NistErrorRateModel.class, Level.ERROR,
"Unable to compute the complimentary error function! Returning '0'...");
}
return 0;
return Erf.erfc(z);
}
private double getBpskBer(double snr) {
......
......@@ -22,8 +22,7 @@ package de.tud.kom.p2psim.impl.topology.views.wifi.phy.errormodel;
import java.util.HashMap;
import org.apache.commons.math.MathException;
import org.apache.commons.math.special.Erf;
import org.apache.commons.math3.special.Erf;
import de.tud.kom.p2psim.api.topology.views.wifi.phy.WifiMode;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
......@@ -200,13 +199,7 @@ public class YansErrorRateModel extends AbstractErrorRateModel {
}
private double getErfc(double z) {
try {
return Erf.erfc(z);
} catch (MathException e) {
Monitor.log(YansErrorRateModel.class, Level.ERROR,
"Unable to compute the complimentary error function! Returning '0'...");
}
return 0;
return Erf.erfc(z);
}
private double getQamBer(double snr, int m, int signalSpread, int phyRate) {
......
......@@ -38,8 +38,8 @@ import java.util.Vector;
import javax.swing.JComponent;
import org.apache.commons.math.random.JDKRandomGenerator;
import org.apache.commons.math.random.RandomGenerator;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
......
......@@ -22,7 +22,7 @@ package de.tud.kom.p2psim.impl.util.db.dao.metric;
import java.util.List;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import de.tud.kom.p2psim.impl.util.db.dao.DAO;
import de.tud.kom.p2psim.impl.util.db.metric.CustomMeasurement;
......
......@@ -30,7 +30,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
/**
*
......
......@@ -19,74 +19,71 @@
*/
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class ExponentialDistribution implements Distribution {
private ExponentialDistributionImpl distr = null;
private double mu;
@XMLConfigurableConstructor({"mu"})
public ExponentialDistribution(double mu) {
this.mu = mu;
this.distr = new ExponentialDistributionImpl(mu);
}
/**
* returns a random value that is distributed as the configured
* distribution.
*/
@Override
public double returnValue() {
if (distr == null) throw new ConfigurationException("Mu was not set for exponential distribution " + this);
public class ExponentialDistribution implements Distribution {
private org.apache.commons.math3.distribution.ExponentialDistribution distr = null;
private double mu;
@XMLConfigurableConstructor({"mu"})
public ExponentialDistribution(double mu) {
this.mu = mu;
this.distr = new org.apache.commons.math3.distribution.ExponentialDistribution(mu);
}
/**
* returns a random value that is distributed as the configured
* distribution.
*/
@Override
public double returnValue() {
if (distr == null) throw new ConfigurationException("Mu was not set for exponential distribution " + this);
double random = Randoms.getRandom(ExponentialDistribution.class)
.nextDouble();
double result;
try {
result = distr.inverseCumulativeProbability(random);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
/**
* returns a random value exponentially distributed with mu = _mu.
*
* @param _mu
* @return as double
*/
public static double returnValue(double _mu) {
try {
ExponentialDistributionImpl d = new ExponentialDistributionImpl(_mu);
.nextDouble();
double result;
try {
result = distr.inverseCumulativeProbability(random);
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
/**
* returns a random value exponentially distributed with mu = _mu.
*
* @param _mu
* @return as double
*/
public static double returnValue(double _mu) {
try {
org.apache.commons.math3.distribution.ExponentialDistribution d = new org.apache.commons.math3.distribution.ExponentialDistribution(_mu);
return d.inverseCumulativeProbability(Randoms.getRandom(
ExponentialDistribution.class)
.nextDouble());
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
@Override
public String toString() {
return "ExponentialDistribution [distr=" + distr + ", mu=" + mu + "]";
}
}
ExponentialDistribution.class)
.nextDouble());
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
@Override
public String toString() {
return "ExponentialDistribution [distr=" + distr + ", mu=" + mu + "]";
}
}
......@@ -19,311 +19,268 @@
*/
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math3.distribution.NormalDistribution;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class LimitedNormalDistribution implements Distribution {
private NormalDistributionImpl limitedNormal;
private double mu;
private double sigma;
private boolean limitedMin;
private boolean limitedMax;
private double min;
private double max;
private double pmin = 0;
private double pmax = 1;
// pfactor and pmin are used to determine the range in which the random
// values are allowed.
private double pfactor;
private int limitType;
private LimitedNormalConfigurer conf;
private final static int LIMIT_NORMAL_DIST_NONE = 0;
private final static int LIMIT_NORMAL_DIST_MIN = 1;
private final static int LIMIT_NORMAL_DIST_MAX = 2;
private final static int LIMIT_NORMAL_DIST_BOTH = 3;
@XMLConfigurableConstructor({"mu", "sigma", "min", "max", "limitedMin", "limitedMax"})
public LimitedNormalDistribution(double mu, double sigma, double min,
double max, boolean limitedMin, boolean limitedMax) {
conf = new LimitedNormalConfigurer(mu, sigma, min, max, limitedMin, limitedMax);
config(conf);
}
public void config(LimitedNormalConfigurer dc) {
mu = dc.getMu();
sigma = dc.getSigma();
limitedMin = dc.isLimitedMin();
limitedMax = dc.isLimitedMax();
limitedNormal = new NormalDistributionImpl(mu, sigma);
if (limitedMin == false) {
if (limitedMax == false) {
limitType = LIMIT_NORMAL_DIST_NONE;
} else {
// only max is limted
limitType = LIMIT_NORMAL_DIST_MAX;
max = dc.getMax();
try {
pmax = limitedNormal.cumulativeProbability(max);
} catch (MathException e) {
e.printStackTrace();
}
}
} else {
if (limitedMax == false) {
// only min is limited.
limitType = LIMIT_NORMAL_DIST_MIN;
min = dc.getMin();
try {
pmin = limitedNormal.cumulativeProbability(min);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// both sides limited.
limitType = LIMIT_NORMAL_DIST_BOTH;
// make sure min is really smaller than max.
if (max > min) {
min = dc.getMin();
max = dc.getMax();
} else {
max = dc.getMin();
min = dc.getMax();
}
// get min and max probabilites that are possible
try {
pmin = limitedNormal.cumulativeProbability(min);
pmax = limitedNormal.cumulativeProbability(max);
pfactor = pmax - pmin;
} catch (MathException e) {
e.printStackTrace();
}
}
}
pfactor = pmax - pmin;
}
public double returnValue() {
public class LimitedNormalDistribution implements Distribution {
private NormalDistribution limitedNormal;
private double mu;
private double sigma;
private boolean limitedMin;
private boolean limitedMax;
private double min;
private double max;
private double pmin = 0;
private double pmax = 1;
// pfactor and pmin are used to determine the range in which the random
// values are allowed.
private double pfactor;
private int limitType;
private LimitedNormalConfigurer conf;
private final static int LIMIT_NORMAL_DIST_NONE = 0;
private final static int LIMIT_NORMAL_DIST_MIN = 1;
private final static int LIMIT_NORMAL_DIST_MAX = 2;
private final static int LIMIT_NORMAL_DIST_BOTH = 3;
@XMLConfigurableConstructor({"mu", "sigma", "min", "max", "limitedMin", "limitedMax"})
public LimitedNormalDistribution(double mu, double sigma, double min,
double max, boolean limitedMin, boolean limitedMax) {
conf = new LimitedNormalConfigurer(mu, sigma, min, max, limitedMin, limitedMax);
config(conf);
}
public void config(LimitedNormalConfigurer dc) {
mu = dc.getMu();
sigma = dc.getSigma();
limitedMin = dc.isLimitedMin();
limitedMax = dc.isLimitedMax();
limitedNormal = new NormalDistribution(mu, sigma);
if (limitedMin == false) {
if (limitedMax == false) {
limitType = LIMIT_NORMAL_DIST_NONE;
} else {
// only max is limted
limitType = LIMIT_NORMAL_DIST_MAX;
max = dc.getMax();
pmax = limitedNormal.cumulativeProbability(max);
}
} else {
if (limitedMax == false) {
// only min is limited.
limitType = LIMIT_NORMAL_DIST_MIN;
min = dc.getMin();
pmin = limitedNormal.cumulativeProbability(min);
} else {
// both sides limited.
limitType = LIMIT_NORMAL_DIST_BOTH;
// make sure min is really smaller than max.
if (max > min) {
min = dc.getMin();
max = dc.getMax();
} else {
max = dc.getMin();
min = dc.getMax();
}
// get min and max probabilites that are possible
pmin = limitedNormal.cumulativeProbability(min);
pmax = limitedNormal.cumulativeProbability(max);
pfactor = pmax - pmin;
}
}
pfactor = pmax - pmin;
}
public double returnValue() {
double random = pmin
+ Randoms.getRandom(LimitedNormalDistribution.class)
.nextDouble() * pfactor;
double result;
try {
result = limitedNormal.inverseCumulativeProbability(random);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
/**
* @return Returns the limitType.
*/
public int getLimitType() {
return limitType;
}
/**
* Returns a random value that is distributed as a Normal Distribution with
* an upper and lower limit.
*
* @param _mu
* average
* @param _sigma
* standard deviation
* @param _min
* lower limit, set to "null", if no limit
* @param _max
* upper limit, set to "null", if no limit
* @return as double
*/
public static double returnValue(double _mu, double _sigma, Double _min,
Double _max) {
int llimitType;
double lmax;
double lmin;
double lpmax = 1;
double lpmin = 0;
double lpfactor;
NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu,
_sigma);
if (_min == null) {
if (_max == null) {
llimitType = LIMIT_NORMAL_DIST_NONE;
} else {
// only max is limted
llimitType = LIMIT_NORMAL_DIST_MAX;
lmax = _max.doubleValue();
try {
lpmax = llimitedNormal.cumulativeProbability(lmax);
} catch (MathException e) {
e.printStackTrace();
}
}
} else {
if (_max == null) {
// only min is limited.
llimitType = LIMIT_NORMAL_DIST_MIN;
lmin = _min.doubleValue();
try {
lpmin = llimitedNormal.cumulativeProbability(lmin);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// both sides limited.
llimitType = LIMIT_NORMAL_DIST_BOTH;
// make sure min is really smaller than max.
if (_max.doubleValue() > _min.doubleValue()) {
lmin = _min.doubleValue();
lmax = _max.doubleValue();
} else {
lmax = _min.doubleValue();
lmin = _max.doubleValue();
}
// get min and max probabilites that are possible
try {
lpmin = llimitedNormal.cumulativeProbability(lmin);
lpmax = llimitedNormal.cumulativeProbability(lmax);
lpfactor = lpmax - lpmin;
} catch (MathException e) {
e.printStackTrace();
}
}
}
lpfactor = lpmax - lpmin;
.nextDouble() * pfactor;
double result;
result = limitedNormal.inverseCumulativeProbability(random);
return result;
}
/**
* @return Returns the limitType.
*/
public int getLimitType() {
return limitType;
}
/**
* Returns a random value that is distributed as a Normal Distribution with
* an upper and lower limit.
*
* @param _mu
* average
* @param _sigma
* standard deviation
* @param _min
* lower limit, set to "null", if no limit
* @param _max
* upper limit, set to "null", if no limit
* @return as double
*/
public static double returnValue(double _mu, double _sigma, Double _min,
Double _max) {
int llimitType;
double lmax;
double lmin;
double lpmax = 1;
double lpmin = 0;
double lpfactor;
NormalDistribution llimitedNormal = new NormalDistribution(_mu,
_sigma);
if (_min == null) {
if (_max == null) {
llimitType = LIMIT_NORMAL_DIST_NONE;
} else {
// only max is limted
llimitType = LIMIT_NORMAL_DIST_MAX;
lmax = _max.doubleValue();
lpmax = llimitedNormal.cumulativeProbability(lmax);
}
} else {
if (_max == null) {
// only min is limited.
llimitType = LIMIT_NORMAL_DIST_MIN;
lmin = _min.doubleValue();
lpmin = llimitedNormal.cumulativeProbability(lmin);
} else {
// both sides limited.
llimitType = LIMIT_NORMAL_DIST_BOTH;
// make sure min is really smaller than max.
if (_max.doubleValue() > _min.doubleValue()) {
lmin = _min.doubleValue();
lmax = _max.doubleValue();
} else {
lmax = _min.doubleValue();
lmin = _max.doubleValue();
}
// get min and max probabilites that are possible
lpmin = llimitedNormal.cumulativeProbability(lmin);
lpmax = llimitedNormal.cumulativeProbability(lmax);
lpfactor = lpmax - lpmin;
}
}
lpfactor = lpmax - lpmin;
double lrandom = lpmin
+ Randoms.getRandom(LimitedNormalDistribution.class)
.nextDouble()
* lpfactor;
double lresult;
try {
lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
lresult = 0;
}
return lresult;
}
private class LimitedNormalConfigurer {
private double mu;
private double sigma;
private double min;
private double max;
private boolean limitedMin;
private boolean limitedMax;
public LimitedNormalConfigurer(double mu, double sigma, double min,
double max, boolean limitedMin, boolean limitedMax) {
super();
this.mu = mu;
this.sigma = sigma;
this.min = min;
this.max = max;
this.limitedMin = limitedMin;
this.limitedMax = limitedMax;
}
/**
* @return Returns the mu.
*/
public double getMu() {
return mu;
}
/**
* @return Returns the sigma.
*/
public double getSigma() {
return sigma;
}
/**
* @return Returns the max.
*/
public double getMax() {
return max;
}
/**
* @return Returns the min.
*/
public double getMin() {
return min;
}
/**
* @return Returns the limitedMax.
*/
public boolean isLimitedMax() {
return limitedMax;
}
/**
* @return Returns the limitedMin.
*/
public boolean isLimitedMin() {
return limitedMin;
}
@Override
public String toString() {
return "LimitedNormalDistribution [mu=" + mu + ", sigma=" + sigma
+ ", min=" + min + ", max=" + max + ", limitedMin="
+ limitedMin + ", limitedMax=" + limitedMax + "]";
}
}
public String toString(){
return conf.toString();
}
}
* lpfactor;
double lresult;
lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
return lresult;
}
private class LimitedNormalConfigurer {
private double mu;
private double sigma;
private double min;
private double max;
private boolean limitedMin;
private boolean limitedMax;
public LimitedNormalConfigurer(double mu, double sigma, double min,
double max, boolean limitedMin, boolean limitedMax) {
super();
this.mu = mu;
this.sigma = sigma;
this.min = min;
this.max = max;
this.limitedMin = limitedMin;
this.limitedMax = limitedMax;
}
/**
* @return Returns the mu.
*/
public double getMu() {
return mu;
}
/**
* @return Returns the sigma.
*/
public double getSigma() {
return sigma;
}
/**
* @return Returns the max.
*/
public double getMax() {
return max;
}
/**
* @return Returns the min.
*/
public double getMin() {
return min;
}
/**
* @return Returns the limitedMax.
*/
public boolean isLimitedMax() {
return limitedMax;
}
/**
* @return Returns the limitedMin.
*/
public boolean isLimitedMin() {
return limitedMin;
}
@Override
public String toString() {
return "LimitedNormalDistribution [mu=" + mu + ", sigma=" + sigma
+ ", min=" + min + ", max=" + max + ", limitedMin="
+ limitedMin + ", limitedMax=" + limitedMax + "]";
}
}
public String toString(){
return conf.toString();
}
}
/*
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.util.stat.distributions;
import java.util.Random;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class NormalDistribution implements Distribution {
private NormalDistributionImpl normal;
private Random randomGen = Randoms.getRandom(NormalDistribution.class);
private double mu;
private double sigma;
@XMLConfigurableConstructor({"mu", "sigma"})
public NormalDistribution(double mu, double sigma) {
this.mu = mu;
this.sigma = sigma;
normal = new NormalDistributionImpl(mu, sigma);
}
@Override
public double returnValue() {
double random = randomGen.nextDouble();
double result;
try {
result = normal.inverseCumulativeProbability(random);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
@Override
public String toString() {
return "NormalDistribution [mu=" + mu + ", sigma=" + sigma + "]";
}
/**
* returns a random value normally distributed with mu = _mu and sigma =
* _sigma.
*
* @param _mu
* @param _sigma
* @return as double
*/
public static double returnValue(double _mu, double _sigma) {
try {
NormalDistributionImpl d = new NormalDistributionImpl(_mu, _sigma);
return d.inverseCumulativeProbability(Randoms.getRandom(
NormalDistribution.class)
.nextDouble());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
}
/*
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.util.stat.distributions;
import java.util.Random;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class NormalDistribution implements Distribution {
private org.apache.commons.math3.distribution.NormalDistribution normal;
private Random randomGen = Randoms.getRandom(NormalDistribution.class);
private double mu;
private double sigma;
@XMLConfigurableConstructor({"mu", "sigma"})
public NormalDistribution(double mu, double sigma) {
this.mu = mu;
this.sigma = sigma;
normal = new org.apache.commons.math3.distribution.NormalDistribution(mu, sigma);
}
@Override
public double returnValue() {
double random = randomGen.nextDouble();
double result;
try {
result = normal.inverseCumulativeProbability(random);
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
@Override
public String toString() {
return "NormalDistribution [mu=" + mu + ", sigma=" + sigma + "]";
}
/**
* returns a random value normally distributed with mu = _mu and sigma =
* _sigma.
*
* @param _mu
* @param _sigma
* @return as double
*/
public static double returnValue(double _mu, double _sigma) {
try {
org.apache.commons.math3.distribution.NormalDistribution d = new org.apache.commons.math3.distribution.NormalDistribution(_mu, _sigma);
return d.inverseCumulativeProbability(Randoms.getRandom(
NormalDistribution.class)
.nextDouble());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
}
......@@ -19,64 +19,62 @@
*/
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.PoissonDistributionImpl;
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PoissonDistribution implements Distribution {
private double lambda;
private PoissonDistributionImpl poisson;
@XMLConfigurableConstructor({"lambda"})
public PoissonDistribution(double lambda){
this.lambda = lambda;
this.poisson = new PoissonDistributionImpl(lambda);
}
// returns the x-value for a random value in the cdf
public double returnValue() {
public class PoissonDistribution implements Distribution {
private double lambda;
private org.apache.commons.math3.distribution.PoissonDistribution poisson;
@XMLConfigurableConstructor({"lambda"})
public PoissonDistribution(double lambda){
this.lambda = lambda;
this.poisson = new org.apache.commons.math3.distribution.PoissonDistribution(lambda);
}
// returns the x-value for a random value in the cdf
public double returnValue() {
double random = Randoms.getRandom(PoissonDistribution.class)
.nextDouble();
int result;
try {
result = poisson.inverseCumulativeProbability(random);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
/**
* returns a random value Poisson distributed with lamda = _lamda.
* @param _lamda
* @return as double
*/
public static double returnValue(double _lamda) {
try {
PoissonDistributionImpl d = new PoissonDistributionImpl(_lamda);
.nextDouble();
int result;
try {
result = poisson.inverseCumulativeProbability(random);
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
return result;
}
/**
* returns a random value Poisson distributed with lamda = _lamda.
* @param _lamda
* @return as double
*/
public static double returnValue(double _lamda) {
try {
org.apache.commons.math3.distribution.PoissonDistribution d = new org.apache.commons.math3.distribution.PoissonDistribution(_lamda);
return d.inverseCumulativeProbability(Randoms.getRandom(
PoissonDistribution.class).nextDouble());
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
@Override
public String toString() {
return "PoissonDistribution [lambda=" + lambda + "]";
}
}
PoissonDistribution.class).nextDouble());
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
@Override
public String toString() {
return "PoissonDistribution [lambda=" + lambda + "]";
}
}
......@@ -20,9 +20,8 @@
package de.tud.kom.p2psim.impl.util.stats;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.TDistribution;
import org.apache.commons.math.distribution.TDistributionImpl;
import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.exception.OutOfRangeException;
/**
* As it is not possible to get a perfect estimate of the population mean from
......@@ -55,14 +54,14 @@ public class ConfidenceInterval {
* @return the upper/lower bound as positiv number
*/
public static double getDeltaBound(double sdev, int n, double alpha) {
TDistribution tDist = new TDistributionImpl(n - 1);
TDistribution tDist = new TDistribution(n - 1);
double errorConfCoeff = 1d - (alpha / 2);
double delta;
try {
double t = Math.abs(tDist
.inverseCumulativeProbability(errorConfCoeff));
delta = t * sdev / Math.sqrt(n);
} catch (MathException e) {
} catch (OutOfRangeException e) {
throw new IllegalStateException(e);
}
return delta;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment