本文整理匯總了Java中org.apache.commons.math3.random.RandomDataGenerator.nextPermutation方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomDataGenerator.nextPermutation方法的具體用法?Java RandomDataGenerator.nextPermutation怎麽用?Java RandomDataGenerator.nextPermutation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.random.RandomDataGenerator
的用法示例。
在下文中一共展示了RandomDataGenerator.nextPermutation方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RandomizedNeighborhoodScoringMethod
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public RandomizedNeighborhoodScoringMethod(AnnotationProvider annotationProvider,
RandomGenerator generator,
int totalPermutations,
Neighborhood[] neighborhoods) {
this.annotationProvider = annotationProvider;
this.neighborhoods = neighborhoods;
RandomDataGenerator random = new RandomDataGenerator(generator);
permutations = random.nextPermutation(neighborhoods.length, totalPermutations);
}
示例2: RandomizedMemberScoringMethod
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public RandomizedMemberScoringMethod(AnnotationProvider annotationProvider,
RandomGenerator generator,
int totalPermutations,
int totalNodes) {
this.annotationProvider = annotationProvider;
RandomDataGenerator random = new RandomDataGenerator(generator);
permutations = new int[totalPermutations][];
for (int i = 0; i < totalPermutations; i++) {
permutations[i] = random.nextPermutation(totalNodes, totalNodes);
}
}
示例3: generateRandomStructure
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public void generateRandomStructure() {
RandomDataGenerator rdg = new RandomDataGenerator();
bn = new BayesNet();
nodes = new BayesNode[nVariables];
for (int i = 0; i < nVariables; i++) {
nodes[i] = bn.createNode("n"+(i+1));
int nValues = r.nextInt(2, maxNValuesPerNode);
for (int j = 0; j < nValues; j++) {
nodes[i].addOutcome("s"+j);
}
}
eo = rdg.nextPermutation(nVariables, nVariables);
for (int i = 1; i < eo.length; i++) {
BayesNode child = nodes[eo[i]];
// looking for the parents of node eo[i]
int nParents = r.nextInt(0, FastMath.min(i, maxNParents));
if(nParents>0){
int[] parentsIDsInEO = r.nextPermutation(i, nParents);
ArrayList<BayesNode>parents = new ArrayList<>();
for(int eoID:parentsIDsInEO){
BayesNode parent = nodes[eo[eoID]];
parents.add(parent);
}
child.setParents(parents);
}
}
System.out.println("Generated BN structure as follows:");
System.out.println(toString());
}
示例4: testPermutedArrayHash
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
/**
* Make sure that permuted arrays do not hash to the same value.
*/
@Test
public void testPermutedArrayHash() {
double[] original = new double[10];
double[] permuted = new double[10];
RandomDataGenerator random = new RandomDataGenerator();
// Generate 10 distinct random values
for (int i = 0; i < 10; i++) {
final RealDistribution u = new UniformRealDistribution(i + 0.5, i + 0.75);
original[i] = u.sample();
}
// Generate a random permutation, making sure it is not the identity
boolean isIdentity = true;
do {
int[] permutation = random.nextPermutation(10, 10);
for (int i = 0; i < 10; i++) {
if (i != permutation[i]) {
isIdentity = false;
}
permuted[i] = original[permutation[i]];
}
} while (isIdentity);
// Verify that permuted array has different hash
Assert.assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted));
}
示例5: getSortedUniformSample
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
/**
* Returns a sorted array of n integers, drawn uniformly from the range [0,range).
*
* @param range the range
* @param smplSize sample size
* @return sorted array of integers
*/
private static int[] getSortedUniformSample(int range, int smplSize) {
if (smplSize == 0)
return new int[] {};
RandomDataGenerator rng = new RandomDataGenerator();
int[] sample = rng.nextPermutation(range, smplSize);
Arrays.sort(sample);
return sample;
}
示例6: generateNetwork
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
@Override
public void generateNetwork() {
int numNodes = config.getInt(NUM_NODES_PARAM);
int k = config.getInt(K_PARAM);
Node[] nodes = new Node[numNodes];
// add nodes to the network
for (int i = 0; i < numNodes; i++) {
Node newNode = network.createNode();
network.addNode(newNode);
nodes[i] = newNode;
}
// use the existing random number generator to shuffle our nodeArray
RandomDataGenerator randomPerm = new RandomDataGenerator(random);
int[] perm = randomPerm.nextPermutation(numNodes, numNodes);
// create the regular network
for (int i = 0; i < numNodes; i++) {
int j = 1;
// add links to the next k neighbours without duplicated links
while (j <= k) {
Node n1 = nodes[perm[i]];
Node n2 = nodes[perm[(i + j) % numNodes]];
if (!network.containsLinks(n1, n2)) {
network.addLink(n1, n2);
}
j++;
}
}
}
示例7: chooseHyperParameterCombos
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
/**
* @param ranges ranges of hyperparameters to try, one per hyperparameters
* @param howMany how many combinations of hyperparameters to return
* @return combinations of concrete hyperparameter values. For example, for 5 parameters each
* with 3 values to try, the total number of combinations returned could be up to pow(3,5)
* or 243. The number could be less if the ranges do not actually have that many distinct
* values. If {@code howMany} is smaller than the total number of combinations, a random
* subset of all combinations are returned. The order is shuffled randomly. If no parameters
* are specified or {@code perParam} is 0, a single empty combination is returned.
*/
static List<List<?>> chooseHyperParameterCombos(List<HyperParamValues<?>> ranges, int howMany) {
// Put some reasonable upper limit on the number of combos
Preconditions.checkArgument(howMany > 0 && howMany <= MAX_COMBOS);
int numParams = ranges.size();
int perParam = chooseValuesPerHyperParam(ranges, howMany);
if (numParams == 0 || perParam == 0) {
return Collections.singletonList(Collections.emptyList());
}
int howManyCombos = 1;
List<List<?>> paramRanges = new ArrayList<>(numParams);
for (HyperParamValues<?> range : ranges) {
List<?> values = range.getTrialValues(perParam);
paramRanges.add(values);
howManyCombos *= values.size();
}
List<List<?>> allCombinations = new ArrayList<>(howManyCombos);
for (int combo = 0; combo < howManyCombos; combo++) {
List<Object> combination = new ArrayList<>(numParams);
for (int param = 0; param < numParams; param++) {
int whichValueToTry = combo;
for (int i = 0; i < param; i++) {
whichValueToTry /= paramRanges.get(i).size();
}
whichValueToTry %= paramRanges.get(param).size();
combination.add(paramRanges.get(param).get(whichValueToTry));
}
allCombinations.add(combination);
}
if (howMany >= howManyCombos) {
Collections.shuffle(allCombinations);
return allCombinations;
}
RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
int[] indices = rdg.nextPermutation(howManyCombos, howMany);
List<List<?>> result = new ArrayList<>(indices.length);
for (int i = 0; i < indices.length; i++) {
result.add(allCombinations.get(i));
}
Collections.shuffle(result);
return result;
}
示例8: generateNetwork
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
@Override
public void generateNetwork() {
resetModel();
// get configuration values
int n = config.getInt(PARAM_NUM_NODES);
// pool representing the links
int[] linkPool = new int[2 * (n - 1)];
// seed network with 1 connection
linkPool[0] = 0;
linkPool[1] = 1;
int numLinks = 1;
// create the other edges
for (int v = 2; v < n; v++) {
int index = 2 * numLinks;
linkPool[index] = v;
int r = random.nextInt(index);
linkPool[index + 1] = linkPool[r];
numLinks++;
}
Node[] nodes = new Node[n];
// add nodes to the network
for (int i = 0; i < n; i++) {
Node newNode = network.createNode();
network.addNode(newNode);
nodes[i] = newNode;
}
// use the existing random number generator to shuffle our nodes
RandomDataGenerator randomPerm = new RandomDataGenerator(random);
int[] perm = randomPerm.nextPermutation(n, n);
// add links to the Network
for (int i = 0; i < linkPool.length; i += 2) {
Node node1 = nodes[perm[linkPool[i]]];
Node node2 = nodes[perm[linkPool[i + 1]]];
network.addLink(node1, node2);
}
}