Commit 0ce6cda0 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

updating apache math to v3

parent 826d3956
......@@ -235,10 +235,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);
}
......
......@@ -30,8 +30,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Random;
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;
/**
*
......
......@@ -22,8 +22,7 @@
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
......@@ -32,13 +31,13 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class ExponentialDistribution implements Distribution {
private ExponentialDistributionImpl distr = null;
private org.apache.commons.math3.distribution.ExponentialDistribution distr = null;
private double mu;
@XMLConfigurableConstructor({"mu"})
public ExponentialDistribution(double mu) {
this.mu = mu;
this.distr = new ExponentialDistributionImpl(mu);
this.distr = new org.apache.commons.math3.distribution.ExponentialDistribution(mu);
}
/**
......@@ -56,7 +55,7 @@ public class ExponentialDistribution implements Distribution {
try {
result = distr.inverseCumulativeProbability(random);
} catch (MathException e) {
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
......@@ -73,11 +72,11 @@ public class ExponentialDistribution implements Distribution {
*/
public static double returnValue(double _mu) {
try {
ExponentialDistributionImpl d = new ExponentialDistributionImpl(_mu);
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) {
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
......
......@@ -22,15 +22,14 @@
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
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 NormalDistribution limitedNormal;
private double mu;
......@@ -77,7 +76,7 @@ public class LimitedNormalDistribution implements Distribution {
limitedMin = dc.isLimitedMin();
limitedMax = dc.isLimitedMax();
limitedNormal = new NormalDistributionImpl(mu, sigma);
limitedNormal = new NormalDistribution(mu, sigma);
if (limitedMin == false) {
if (limitedMax == false) {
......@@ -86,23 +85,14 @@ public class LimitedNormalDistribution implements Distribution {
// only max is limted
limitType = LIMIT_NORMAL_DIST_MAX;
max = dc.getMax();
try {
pmax = limitedNormal.cumulativeProbability(max);
} catch (MathException e) {
e.printStackTrace();
}
pmax = limitedNormal.cumulativeProbability(max);
}
} 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();
}
pmin = limitedNormal.cumulativeProbability(min);
} else {
// both sides limited.
limitType = LIMIT_NORMAL_DIST_BOTH;
......@@ -117,15 +107,9 @@ public class LimitedNormalDistribution implements Distribution {
}
// 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();
}
pmin = limitedNormal.cumulativeProbability(min);
pmax = limitedNormal.cumulativeProbability(max);
pfactor = pmax - pmin;
}
}
pfactor = pmax - pmin;
......@@ -137,14 +121,8 @@ public class LimitedNormalDistribution implements Distribution {
.nextDouble() * pfactor;
double result;
try {
result = limitedNormal.inverseCumulativeProbability(random);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
}
result = limitedNormal.inverseCumulativeProbability(random);
return result;
}
......@@ -178,7 +156,7 @@ public class LimitedNormalDistribution implements Distribution {
double lpmin = 0;
double lpfactor;
NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu,
NormalDistribution llimitedNormal = new NormalDistribution(_mu,
_sigma);
if (_min == null) {
if (_max == null) {
......@@ -187,23 +165,14 @@ public class LimitedNormalDistribution implements Distribution {
// only max is limted
llimitType = LIMIT_NORMAL_DIST_MAX;
lmax = _max.doubleValue();
try {
lpmax = llimitedNormal.cumulativeProbability(lmax);
} catch (MathException e) {
e.printStackTrace();
}
lpmax = llimitedNormal.cumulativeProbability(lmax);
}
} 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();
}
lpmin = llimitedNormal.cumulativeProbability(lmin);
} else {
// both sides limited.
llimitType = LIMIT_NORMAL_DIST_BOTH;
......@@ -218,15 +187,10 @@ public class LimitedNormalDistribution implements Distribution {
}
// get min and max probabilites that are possible
try {
lpmin = llimitedNormal.cumulativeProbability(lmin);
lpmax = llimitedNormal.cumulativeProbability(lmax);
lpfactor = lpmax - lpmin;
lpmin = llimitedNormal.cumulativeProbability(lmin);
lpmax = llimitedNormal.cumulativeProbability(lmax);
} catch (MathException e) {
e.printStackTrace();
}
lpfactor = lpmax - lpmin;
}
}
lpfactor = lpmax - lpmin;
......@@ -237,13 +201,8 @@ public class LimitedNormalDistribution implements Distribution {
* lpfactor;
double lresult;
try {
lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
} catch (MathException e) {
// TODO Auto-generated catch block
e.printStackTrace();
lresult = 0;
}
lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
return lresult;
......
......@@ -24,8 +24,7 @@ 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 org.apache.commons.math3.exception.OutOfRangeException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
......@@ -33,7 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class NormalDistribution implements Distribution {
private NormalDistributionImpl normal;
private org.apache.commons.math3.distribution.NormalDistribution normal;
private Random randomGen = Randoms.getRandom(NormalDistribution.class);
......@@ -45,7 +44,7 @@ public class NormalDistribution implements Distribution {
public NormalDistribution(double mu, double sigma) {
this.mu = mu;
this.sigma = sigma;
normal = new NormalDistributionImpl(mu, sigma);
normal = new org.apache.commons.math3.distribution.NormalDistribution(mu, sigma);
}
@Override
......@@ -56,7 +55,7 @@ public class NormalDistribution implements Distribution {
try {
result = normal.inverseCumulativeProbability(random);
} catch (MathException e) {
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
......@@ -80,7 +79,7 @@ public class NormalDistribution implements Distribution {
*/
public static double returnValue(double _mu, double _sigma) {
try {
NormalDistributionImpl d = new NormalDistributionImpl(_mu, _sigma);
org.apache.commons.math3.distribution.NormalDistribution d = new org.apache.commons.math3.distribution.NormalDistribution(_mu, _sigma);
return d.inverseCumulativeProbability(Randoms.getRandom(
NormalDistribution.class)
.nextDouble());
......
......@@ -22,8 +22,7 @@
package de.tud.kom.p2psim.impl.util.stat.distributions;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.PoissonDistributionImpl;
import org.apache.commons.math3.exception.OutOfRangeException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
......@@ -32,12 +31,12 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PoissonDistribution implements Distribution {
private double lambda;
private PoissonDistributionImpl poisson;
private org.apache.commons.math3.distribution.PoissonDistribution poisson;
@XMLConfigurableConstructor({"lambda"})
public PoissonDistribution(double lambda){
this.lambda = lambda;
this.poisson = new PoissonDistributionImpl(lambda);
this.poisson = new org.apache.commons.math3.distribution.PoissonDistribution(lambda);
}
// returns the x-value for a random value in the cdf
......@@ -48,7 +47,7 @@ public class PoissonDistribution implements Distribution {
try {
result = poisson.inverseCumulativeProbability(random);
} catch (MathException e) {
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = 0;
......@@ -64,10 +63,10 @@ public class PoissonDistribution implements Distribution {
*/
public static double returnValue(double _lamda) {
try {
PoissonDistributionImpl d = new PoissonDistributionImpl(_lamda);
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) {
} catch (OutOfRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
......
......@@ -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