p3j.misc.math
Class RandomNumberChecks

java.lang.Object
  extended by p3j.misc.math.RandomNumberChecks

public final class RandomNumberChecks
extends Object

Class to hold static functions for checking random numbers regarding their mathematical validity, and some non-static functions for selecting an object randomly. Singleton pattern. Created on January 21, 2007

Author:
Christina Bohk, Roland Ewald

Method Summary
<V extends IStochasticOccurrence>
void
checkProbabilitySetting(String name, Collection<V> objects, List<GeneratorError> errors)
          Tries to repeat values before throwing an exceptions.
<V extends IStochasticOccurrence>
V
chooseNormalizedRandomObject(Collection<V> objects, james.core.math.random.generators.IRandom rand)
          Choose random object if the sum of all probabilities is 100.
<V extends IStochasticOccurrence>
V
chooseRandomObject(Collection<V> objects, james.core.math.random.generators.IRandom rand)
          Choose random object if the sum of all probabilities is 100.
protected
<V extends IStochasticOccurrence>
V
chooseRandomObject(Collection<V> objects, james.core.math.random.generators.IRandom rand, double overallProbSum)
          Choose random entity based on a certain probability sum.
static RandomNumberChecks getInstance()
          Gets the single instance of RandomNumberChecks.
 double getProbSum(Collection<? extends IStochasticOccurrence> objects)
          Get the probability sum from a list of of IStochasticOccurrence instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static RandomNumberChecks getInstance()
Gets the single instance of RandomNumberChecks.

Returns:
single instance of RandomNumberChecks

checkProbabilitySetting

public <V extends IStochasticOccurrence> void checkProbabilitySetting(String name,
                                                                      Collection<V> objects,
                                                                      List<GeneratorError> errors)
Tries to repeat values before throwing an exceptions. All values get normalised (also all 0's: this will be changed to a uniform distribution).

Type Parameters:
V - type of entity that shall be chosen by chance
Parameters:
name - name of the objects to be checked (for generation of a suitable error messages)
objects - the collection of objects to be checked
errors - list of error messages (to be filled if something goes wrong)

chooseNormalizedRandomObject

public <V extends IStochasticOccurrence> V chooseNormalizedRandomObject(Collection<V> objects,
                                                                        james.core.math.random.generators.IRandom rand)
Choose random object if the sum of all probabilities is 100.

Type Parameters:
V - type of randomly chosen entity
Parameters:
objects - collection of objects from which to choose
rand - randomiser to be used
Returns:
randomly chosen object

chooseRandomObject

public <V extends IStochasticOccurrence> V chooseRandomObject(Collection<V> objects,
                                                              james.core.math.random.generators.IRandom rand)
Choose random object if the sum of all probabilities is 100.

Type Parameters:
V - type of randomly chosen entity
Parameters:
objects - collection of objects from which to choose
rand - the randomiser to be used
Returns:
randomly chosen object

chooseRandomObject

protected <V extends IStochasticOccurrence> V chooseRandomObject(Collection<V> objects,
                                                                 james.core.math.random.generators.IRandom rand,
                                                                 double overallProbSum)
Choose random entity based on a certain probability sum.

Type Parameters:
V - type of randomly chosen entity
Parameters:
objects - collection of objects from which to choose
rand - the randomiser to be used
overallProbSum - overall probability sum
Returns:
randomly chosen object

getProbSum

public double getProbSum(Collection<? extends IStochasticOccurrence> objects)
Get the probability sum from a list of of IStochasticOccurrence instances.

Parameters:
objects - collection of objects from which to choose
Returns:
sum of the occurrence probabilities of all objects in the list


Copyright © 2012. All Rights Reserved.