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