use of edu.cmu.tetrad.util.RandomUtil in project tetrad by cmu-phil.
the class MlBayesIm method simulateData.
/**
* Simulates a sample with the given sample size.
*
* @param sampleSize the sample size.
* @param seed the random number generator seed allows you
* recreate the simulated data by passing in the same
* seed (so you don't have to store the sample data
* @return the simulated sample as a DataSet.
*/
public DataSet simulateData(int sampleSize, long seed, boolean latentDataSaved) {
RandomUtil random = RandomUtil.getInstance();
long _seed = random.getSeed();
random.setSeed(seed);
DataSet dataSet = simulateData(sampleSize, latentDataSaved);
random.revertSeed(_seed);
return dataSet;
}
use of edu.cmu.tetrad.util.RandomUtil in project tetrad by cmu-phil.
the class DirichletBayesIm method getRandomWeights.
/**
* This method chooses random probabilities for a row which add up to 1.0.
* Random doubles are drawn from a random distribution, and the final row is
* then normalized.
*
* @param size the length of the row.
* @return an array with randomly distributed probabilities of this length.
* @see #randomizeRow
*/
private static double[] getRandomWeights(int size) {
assert size >= 0;
double[] weights = new double[size];
double sum = 0.0;
for (int i = 0; i < size; i++) {
RandomUtil randomUtil = RandomUtil.getInstance();
weights[i] = randomUtil.nextDouble();
sum += weights[i];
}
for (int i = 0; i < size; i++) {
weights[i] /= sum;
}
return weights;
}
use of edu.cmu.tetrad.util.RandomUtil in project tetrad by cmu-phil.
the class MlBayesImObs method simulateData.
public DataSet simulateData(DataSet dataSet, long seed, boolean latentDataSaved) {
RandomUtil random = RandomUtil.getInstance();
random.setSeed(seed);
return simulateDataHelper(dataSet, latentDataSaved);
}
use of edu.cmu.tetrad.util.RandomUtil in project tetrad by cmu-phil.
the class ApproximateUpdater method getSinglePoint.
private static int[] getSinglePoint(BayesIm bayesIm, int[] tiers) {
int[] point = new int[bayesIm.getNumNodes()];
int[] combination = new int[bayesIm.getNumNodes()];
RandomUtil randomUtil = RandomUtil.getInstance();
for (int nodeIndex : tiers) {
double cutoff = randomUtil.nextDouble();
for (int k = 0; k < bayesIm.getNumParents(nodeIndex); k++) {
combination[k] = point[bayesIm.getParent(nodeIndex, k)];
}
int rowIndex = bayesIm.getRowIndex(nodeIndex, combination);
double sum = 0.0;
for (int k = 0; k < bayesIm.getNumColumns(nodeIndex); k++) {
double probability = bayesIm.getProbability(nodeIndex, rowIndex, k);
if (Double.isNaN(probability)) {
throw new IllegalStateException("Some probability " + "values in the BayesIm are not filled in; " + "cannot simulate data to do approximate updating.");
}
sum += probability;
if (sum >= cutoff) {
point[nodeIndex] = k;
break;
}
}
}
return point;
}
use of edu.cmu.tetrad.util.RandomUtil in project tetrad by cmu-phil.
the class TestColtDataSet method testRemoveColumn.
@Test
public void testRemoveColumn() {
int rows = 10;
int cols = 5;
List<Node> variables = new LinkedList<>();
for (int i = 0; i < cols; i++) {
variables.add(new ContinuousVariable("X" + i));
}
DataSet dataSet = new ColtDataSet(rows, variables);
RandomUtil randomUtil = RandomUtil.getInstance();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
dataSet.setDouble(i, j, randomUtil.nextDouble());
}
}
int[] _cols = new int[2];
_cols[0] = 1;
_cols[1] = 2;
dataSet.removeCols(_cols);
List<Node> _variables = new LinkedList<>(variables);
_variables.remove(2);
_variables.remove(1);
assertEquals(dataSet.getVariables(), _variables);
}
Aggregations