cern.jet.random.Uniform Java Examples

The following examples show how to use cern.jet.random.Uniform. 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: DataSet.java    From hlta with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Generate the training data of the given size. The original data becomes
 * the testing data.
 * 
 * @param nOfTraining
 * @return
 */
public DataSet splitIntoTrainingAndTesting(int nOfTraining) {
	DataSet training = new DataSet(_variables);
	for (int i = 0; i < nOfTraining; i++) {
		double total = getTotalWeight();
		double random = Uniform.staticNextDoubleFromTo(0.0, total);
		double accumulator = 0.0;
		// Find the datacase to be moved
		for (DataCase data : getData()) {
			double weight = data.getWeight();
			accumulator += weight;
			if (accumulator > random) {
				training.addDataCase(data.getStates(), 1.0);
				if (weight == 1.0) {
					getData().remove(data);
				} else {
					data.setWeight(weight - 1.0);
				}
				_totalWeight = _totalWeight - 1.0;
				break;
			}
		}
	}
	return training;
}
 
Example #2
Source File: DataSet.java    From hlta with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Generate the training data of the given size from the current data. The
 * method is sample from the current data with replacement. No side effect
 * on the input.
 * 
 * @param nOfTraining
 * @return
 */
public DataSet sampleWithReplacement(int nOfTraining) {
	DataSet training = new DataSet(_variables);
	for (int i = 0; i < nOfTraining; i++) {
		double total = getTotalWeight();
		double random = Uniform.staticNextDoubleFromTo(0.0, total);
		double accumulator = 0.0;
		// Find the datacase to be moved
		for (DataCase data : getData()) {
			double weight = data.getWeight();
			accumulator += weight;
			if (accumulator > random) {
				training.addDataCase(data.getStates(), 1.0);
				break;
			}
		}
	}
	return training;
}
 
Example #3
Source File: WeightedRandomSampler.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a deep copy of the receiver.
 */
public Object clone() {
	WeightedRandomSampler copy = (WeightedRandomSampler) super.clone();
	copy.generator = (Uniform) this.generator.clone();
	return copy;
}
 
Example #4
Source File: WeightedRandomSampler.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns a deep copy of the receiver.
 */
public Object clone() {
	WeightedRandomSampler copy = (WeightedRandomSampler) super.clone();
	copy.generator = (Uniform) this.generator.clone();
	return copy;
}
 
Example #5
Source File: WeightedRandomSampler.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Chooses exactly one random element from successive blocks of <tt>weight</tt> input elements each.
 * For example, if weight==2, and the input is 5*2=10 elements long, then chooses 5 random elements from the 10 elements such that
 * one is chosen from the first block, one from the second, ..., one from the last block.
 * weight == 1.0 --> all elements are consumed (sampled). 10.0 --> Consumes one random element from successive blocks of 10 elements each. Etc.
 * @param weight the weight.
 * @param randomGenerator a random number generator. Set this parameter to <tt>null</tt> to use the default random number generator.
 */
public WeightedRandomSampler(int weight, RandomEngine randomGenerator) {
	if (randomGenerator==null) randomGenerator = cern.jet.random.AbstractDistribution.makeDefaultGenerator();
	this.generator = new Uniform(randomGenerator);
	setWeight(weight);
}
 
Example #6
Source File: WeightedRandomSampler.java    From jAudioGIT with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Chooses exactly one random element from successive blocks of <tt>weight</tt> input elements each.
 * For example, if weight==2, and the input is 5*2=10 elements long, then chooses 5 random elements from the 10 elements such that
 * one is chosen from the first block, one from the second, ..., one from the last block.
 * weight == 1.0 --> all elements are consumed (sampled). 10.0 --> Consumes one random element from successive blocks of 10 elements each. Etc.
 * @param weight the weight.
 * @param randomGenerator a random number generator. Set this parameter to <tt>null</tt> to use the default random number generator.
 */
public WeightedRandomSampler(int weight, RandomEngine randomGenerator) {
	if (randomGenerator==null) randomGenerator = cern.jet.random.AbstractDistribution.makeDefaultGenerator();
	this.generator = new Uniform(randomGenerator);
	setWeight(weight);
}