org.apache.commons.math3.distribution.ExponentialDistribution Java Examples

The following examples show how to use org.apache.commons.math3.distribution.ExponentialDistribution. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
public DistributionFactory getFactory(List<String> params)
{
    if (params.size() != 1)
        throw new IllegalArgumentException("Invalid parameter list for gaussian distribution: " + params);
    try
    {
        String[] bounds = params.get(0).split("\\.\\.+");
        final long min = parseLong(bounds[0]);
        final long max = parseLong(bounds[1]);
        if (min == max)
            return new FixedFactory(min);
        ExponentialDistribution findBounds = new ExponentialDistribution(1d);
        // max probability should be roughly equal to accuracy of (max-min) to ensure all values are visitable,
        // over entire range, but this results in overly skewed distribution, so take sqrt
        final double mean = (max - min) / findBounds.inverseCumulativeProbability(1d - Math.sqrt(1d/(max-min)));
        return new ExpFactory(min, max, mean);
    } catch (Exception ignore)
    {
        throw new IllegalArgumentException("Invalid parameter list for uniform distribution: " + params);
    }
}
 
Example #2
Source File: FragPileupGen.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a new Distribution 
 * @param p a double specifying which distribution to use
 * @param m a double representing the mean for the desired distribution
 * @param l a double representing the standard deviation, or more generally, the lambda of the desired distribution
 * @return A new AbstractRealDistribution
 */
private AbstractRealDistribution getDist(double p,double m, double l){
	if (p == 1){
		//return new LaplaceDistribution(m,l);
		return new ExponentialDistribution(m);
	}
	if (p == 2){
		return new NormalDistribution(m,l);
	}
	if (p == 0.5 || p == 3){
		return new ExponentialDistribution(m);
	}
	if (p == 0){
		//return new ModifiedLaplaceDistribution(m,l);
		return new ExponentialDistribution(m);
	}
	else{
		return null;
	}
	
}
 
Example #3
Source File: pileup.java    From HMMRATAC with GNU General Public License v3.0 6 votes vote down vote up
private AbstractRealDistribution getDist(double p,double m, double l){
	if (p == 1){
		return new LaplaceDistribution(m,l);
		//return new ExponentialDistribution(m);
	}
	if (p == 2){
		return new NormalDistribution(m,l);
	}
	if (p == 0.5 || p == 3){
		return new ExponentialDistribution(m);
	}
	if (p == 0){
		//return new ModifiedLaplaceDistribution(m,l);
		return new ExponentialDistribution(m);
	}
	else{
		return null;
	}
	
}
 
Example #4
Source File: VMRequestRandomGenerator.java    From cloudsimsdn with GNU General Public License v2.0 6 votes vote down vote up
public void generateVMsRandom(int totalVmNum) {
	int vmCount = 0;
	double lastStartTime = 0;
	
	double startMean = 1800; // sec = 30min
	double durScale=14400; // sec = 4 hours
	double durShape=1.2;
	
	Random rVmNum = new Random(seed);
	ExponentialDistribution rStartTime = new ExponentialDistribution(new Well19937c(seed), startMean, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);	
	ParetoDistribution rDuration = new ParetoDistribution(new Well19937c(seed), durScale, durShape);
	
	int vmGroup=0;
	while(vmCount < totalVmNum) {
		int vmsInGroup = rVmNum.nextInt(4)+2;
		double duration = Math.floor(rDuration.sample());
		
		vmGenerator.generateVMGroup(vmsInGroup, lastStartTime, lastStartTime+duration, null, vmGroup, -1);
		lastStartTime += Math.floor(rStartTime.sample());
		
		vmCount += vmsInGroup;
		vmGroup++;			
	}
}
 
Example #5
Source File: EstimatorLayeredGraph.java    From systemds with Apache License 2.0 5 votes vote down vote up
public long estimateNnz() {
	//step 1: assign random vectors ~exp(lambda=1) to all leaf nodes
	//(lambda is not the mean, if lambda is 2 mean is 1/2)
	ExponentialDistribution random = new ExponentialDistribution(new Well1024a(), 1);
	for( Node n : _nodes.get(0) ) {
		double[] rvect = new double[_rounds];
		for (int g = 0; g < _rounds; g++)
			rvect[g] = random.sample();
		n.setVector(rvect);
	}
	
	//step 2: propagate vectors bottom-up and aggregate nnz
	return Math.round(Arrays.stream(_nodes.get(_nodes.size()-1))
		.mapToDouble(n -> calcNNZ(n.computeVector(_rounds), _rounds)).sum());
}
 
Example #6
Source File: PatternSpikeGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private static AbstractRealDistribution makeDist(DistributionType type, double mean, double sigma, int seed) {
    switch (type) {
        case LOGNORMAL:
            return new LogNormalDistribution(new Well19937c(seed), mean, sigma, 1.0E-9D);
        case EXPONENTIAL:
            return new ExponentialDistribution(new Well19937c(seed), mean, 1.0E-9D);
        case UNIFORM:
            return new UniformRealDistribution(new Well19937c(seed), mean - sigma, mean + sigma);
        case FIXED:
            return new UniformRealDistribution(new Well19937c(seed), mean, mean + 1.0E-9D);
        default:
            throw new IllegalArgumentException(String.format("Unsupported distribution type '%s", type));
    }
}
 
Example #7
Source File: AbstractSliceSampler.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new sampler for a bounded univariate random variable, given a random number generator, hard limits
 * on the random variable, and a step width.
 * @param rng      random number generator, never {@code null}
 * @param xMin     minimum allowed value of the random variable
 * @param xMax     maximum allowed value of the random variable
 * @param width    step width for slice expansion
 */
AbstractSliceSampler(final RandomGenerator rng,
                     final double xMin,
                     final double xMax,
                     final double width) {
    Utils.nonNull(rng);
    Utils.validateArg(xMin < xMax, "Maximum bound must be greater than minimum bound.");
    ParamUtils.isPositive(width, "Slice-sampling width must be positive.");
    this.rng = rng;
    this.xMin = xMin;
    this.xMax = xMax;
    this.width = width;
    exponentialDistribution = new ExponentialDistribution(rng, 1.);
}
 
Example #8
Source File: EstimatorLayeredGraph.java    From systemds with Apache License 2.0 5 votes vote down vote up
public long estimateNnz() {
	//step 1: assign random vectors ~exp(lambda=1) to all leaf nodes
	//(lambda is not the mean, if lambda is 2 mean is 1/2)
	ExponentialDistribution random = new ExponentialDistribution(new Well1024a(), 1);
	for( Node n : _nodes.get(0) ) {
		double[] rvect = new double[_rounds];
		for (int g = 0; g < _rounds; g++)
			rvect[g] = random.sample();
		n.setVector(rvect);
	}
	
	//step 2: propagate vectors bottom-up and aggregate nnz
	return Math.round(Arrays.stream(_nodes.get(_nodes.size()-1))
		.mapToDouble(n -> calcNNZ(n.computeVector(_rounds), _rounds)).sum());
}
 
Example #9
Source File: SliceSampler.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new sampler, given a random number generator, a continuous, univariate, unimodal, unnormalized
 * log probability density function, hard limits on the random variable, and a step width.
 * @param rng      random number generator
 * @param logPDF   continuous, univariate, unimodal log probability density function (up to additive constant)
 * @param xMin     minimum allowed value of the random variable
 * @param xMax     maximum allowed value of the random variable
 * @param width    step width for slice expansion
 */
public SliceSampler(final RandomGenerator rng, final Function<Double, Double> logPDF,
                    final double xMin, final double xMax, final double width) {
    Utils.nonNull(rng);
    Utils.nonNull(logPDF);
    Utils.validateArg(xMin < xMax, "Maximum bound must be greater than minimum bound.");
    ParamUtils.isPositive(width, "Slice-sampling width must be positive.");
    this.rng = rng;
    this.logPDF = logPDF;
    this.xMin = xMin;
    this.xMax = xMax;
    this.width = width;
    exponentialDistribution = new ExponentialDistribution(rng, 1.);
}
 
Example #10
Source File: SyntheticOptionsTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testRealDistributionDeserializerWithExpDistribution() throws Exception {
  String syntheticOptions =
      "{\"seed\":12345," + "\"delayDistribution\":{\"type\":\"exp\",\"mean\":10}}";
  SyntheticOptions sourceOptions = optionsFromString(syntheticOptions, SyntheticOptions.class);
  assertEquals(
      10,
      (long)
          ((ExponentialDistribution) (sourceOptions.delayDistribution.getDistribution()))
              .getMean());
}
 
Example #11
Source File: TaskProperty.java    From EdgeCloudSim with GNU General Public License v3.0 5 votes vote down vote up
public TaskProperty(int _mobileDeviceId, int _taskType, double _startTime, ExponentialDistribution[][] expRngList) {
   	mobileDeviceId=_mobileDeviceId;
   	startTime=_startTime;
   	taskType=_taskType;
   	
   	inputFileSize = (long)expRngList[_taskType][0].sample();
   	outputFileSize =(long)expRngList[_taskType][1].sample();
   	length = (long)expRngList[_taskType][2].sample();
   	
   	pesNumber = (int)SimSettings.getInstance().getTaskLookUpTable()[_taskType][8];
}
 
Example #12
Source File: Model.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
public Model(OrderEntry orderEntry, Config config, long instrument) {
    super(orderEntry);

    this.config = config;

    this.enterOrder = new POE.EnterOrder();

    this.enterOrder.instrument = instrument;
    this.enterOrder.quantity   = config.sigma();

    this.cancelOrder = new POE.CancelOrder();

    this.orders = new PriorityQueue<>();

    this.sleepDistribution      = new ExponentialDistribution(config.tau());
    this.expirationDistribution = new ExponentialDistribution(1 / config.delta());

    this.uniformDistribution = new Random();
}
 
Example #13
Source File: Driver.java    From concurrency-limits with Apache License 2.0 4 votes vote down vote up
public Builder exponential(double mean, long duration, TimeUnit units) {
    final ExponentialDistribution distribution = new ExponentialDistribution(mean);
    return add("exponential(" + mean + ")", () -> (long)distribution.sample(), duration, units);
}
 
Example #14
Source File: TimestampedValueGroupGenerationServiceImpl.java    From sample-data-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<TimestampedValueGroup> generateValueGroups(MeasureGenerationRequest request) {

    ExponentialDistribution interPointDurationDistribution =
            new ExponentialDistribution(request.getMeanInterPointDuration().getSeconds());

    long totalDurationInS = Duration.between(request.getStartDateTime(), request.getEndDateTime()).getSeconds();

    OffsetDateTime effectiveDateTime = request.getStartDateTime();
    List<TimestampedValueGroup> timestampedValueGroups = new ArrayList<>();

    do {
        effectiveDateTime = effectiveDateTime.plus((long) interPointDurationDistribution.sample(), SECONDS);

        if (!effectiveDateTime.isBefore(request.getEndDateTime())) {
            break;
        }

        if (request.isSuppressNightTimeMeasures() != null && request.isSuppressNightTimeMeasures() &&
                (effectiveDateTime.getHour() >= NIGHT_TIME_START_HOUR ||
                        effectiveDateTime.getHour() < NIGHT_TIME_END_HOUR)) {
            continue;
        }

        TimestampedValueGroup valueGroup = new TimestampedValueGroup();
        valueGroup.setTimestamp(effectiveDateTime);

        double trendProgressFraction = (double)
                Duration.between(request.getStartDateTime(), effectiveDateTime).getSeconds() / totalDurationInS;

        for (Map.Entry<String, BoundedRandomVariableTrend> trendEntry : request.getTrends().entrySet()) {

            String key = trendEntry.getKey();
            BoundedRandomVariableTrend trend = trendEntry.getValue();

            double value = trend.nextValue(trendProgressFraction);
            valueGroup.setValue(key, value);
        }

        timestampedValueGroups.add(valueGroup);
    }
    while (true);

    return timestampedValueGroups;
}
 
Example #15
Source File: TestServer.java    From concurrency-limits with Apache License 2.0 4 votes vote down vote up
public Builder exponential(double mean, long duration, TimeUnit units) {
    final ExponentialDistribution distribution = new ExponentialDistribution(mean);
    return add("exponential(" + mean + ")", () -> (long)distribution.sample(), duration, units);
}
 
Example #16
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public Distribution get()
{
    return new DistributionOffsetApache(new ExponentialDistribution(new JDKRandomGenerator(), mean, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY), min, max);
}
 
Example #17
Source File: IdleActiveLoadGenerator.java    From EdgeCloudSim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initializeModel() {
	taskList = new ArrayList<TaskProperty>();
	
	//exponential number generator for file input size, file output size and task length
	ExponentialDistribution[][] expRngList = new ExponentialDistribution[SimSettings.getInstance().getTaskLookUpTable().length][3];
	
	//create random number generator for each place
	for(int i=0; i<SimSettings.getInstance().getTaskLookUpTable().length; i++) {
		if(SimSettings.getInstance().getTaskLookUpTable()[i][0] ==0)
			continue;
		
		expRngList[i][0] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][5]);
		expRngList[i][1] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][6]);
		expRngList[i][2] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][7]);
	}
	
	//Each mobile device utilizes an app type (task type)
	taskTypeOfDevices = new int[numberOfMobileDevices];
	for(int i=0; i<numberOfMobileDevices; i++) {
		int randomTaskType = -1;
		double taskTypeSelector = SimUtils.getRandomDoubleNumber(0,100);
		double taskTypePercentage = 0;
		for (int j=0; j<SimSettings.getInstance().getTaskLookUpTable().length; j++) {
			taskTypePercentage += SimSettings.getInstance().getTaskLookUpTable()[j][0];
			if(taskTypeSelector <= taskTypePercentage){
				randomTaskType = j;
				break;
			}
		}
		if(randomTaskType == -1){
			SimLogger.printLine("Impossible is occured! no random task type!");
			continue;
		}
		
		taskTypeOfDevices[i] = randomTaskType;
		
		double poissonMean = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][2];
		double activePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][3];
		double idlePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType][4];
		double activePeriodStartTime = SimUtils.getRandomDoubleNumber(
				SimSettings.CLIENT_ACTIVITY_START_TIME, 
				SimSettings.CLIENT_ACTIVITY_START_TIME + activePeriod);  //active period starts shortly after the simulation started (e.g. 10 seconds)
		double virtualTime = activePeriodStartTime;

		ExponentialDistribution rng = new ExponentialDistribution(poissonMean);
		while(virtualTime < simulationTime) {
			double interval = rng.sample();

			if(interval <= 0){
				SimLogger.printLine("Impossible is occured! interval is " + interval + " for device " + i + " time " + virtualTime);
				continue;
			}
			//SimLogger.printLine(virtualTime + " -> " + interval + " for device " + i + " time ");
			virtualTime += interval;
			
			if(virtualTime > activePeriodStartTime + activePeriod){
				activePeriodStartTime = activePeriodStartTime + activePeriod + idlePeriod;
				virtualTime = activePeriodStartTime;
				continue;
			}
			
			taskList.add(new TaskProperty(i,randomTaskType, virtualTime, expRngList));
		}
	}
}
 
Example #18
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRandomGenerator(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #19
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRan(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #20
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRandomGenerator(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #21
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRandomGenerator(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #22
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRandomGenerator(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #23
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) throws NotStrictlyPositiveException {
    return new ExponentialDistribution(getRandomGenerator(), mean,
            ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}