/** * Returns an object sampled from the distribution using Math.random(). * There may be a faster way to do this if you need to... * * @return a sampled object */ public E sampleFrom() { return Counters.sample(counter); } /**
/** * Returns an object sampled from the distribution using a self-provided * random number generator. * * @return a sampled object */ public E sampleFrom(Random random) { return Counters.sample(counter, random); }
/** * Does not assumes c is normalized. * * @return A sample from c */ public static <T> T sample(Counter<T> c) { return sample(c, null); }
public E drawSample(Random random) { E drawn = Counters.sample(sampled); if (drawn == null) { drawn = baseMeasure.drawSample(random); } sampled.incrementCount(drawn); return drawn; }
public Tree produceTree(String state) { Counter<String> terminal = terminals.get(state); if (terminal != null) { // found a terminal production. make a leaf with a randomly // chosen expansion and make a preterminal with that one leaf // as a child. String label = Counters.sample(terminal, random); Tree child = tf.newLeaf(label); List<Tree> children = Collections.singletonList(child); Tree root = tf.newTreeNode(state, children); return root; } Counter<List<String>> nonTerminal = nonTerminals.get(state); if (nonTerminal != null) { // found a nonterminal production. produce a list of // recursive expansions, then attach them all to a node with // the expected state List<String> labels = Counters.sample(nonTerminal, random); List<Tree> children = new ArrayList<>(); for (String childLabel : labels) { children.add(produceTree(childLabel)); } Tree root = tf.newTreeNode(state, children); return root; } throw new RuntimeException("Unknown state " + state); }
/** * Returns an object sampled from the distribution using Math.random(). * There may be a faster way to do this if you need to... * * @return a sampled object */ public E sampleFrom() { return Counters.sample(counter); } /**
/** * Returns an object sampled from the distribution using a self-provided * random number generator. * * @return a sampled object */ public E sampleFrom(Random random) { return Counters.sample(counter, random); }
/** * Does not assumes c is normalized. * * @return A sample from c */ public static <T> T sample(Counter<T> c) { return sample(c, null); }
/** * Returns an object sampled from the distribution using a self-provided * random number generator. * * @return a sampled object */ public E sampleFrom(Random random) { return Counters.sample(counter, random); }
/** * Returns an object sampled from the distribution using Math.random(). * There may be a faster way to do this if you need to... * * @return a sampled object */ public E sampleFrom() { return Counters.sample(counter); } /**
/** * Does not assumes c is normalized. * * @return A sample from c */ public static <T> T sample(Counter<T> c) { return sample(c, null); }
/** * Returns an object sampled from the distribution using a self-provided * random number generator. * * @return a sampled object */ public E sampleFrom(Random random) { return Counters.sample(counter, random); }
/** * Does not assumes c is normalized. * * @return A sample from c */ public static <T> T sample(Counter<T> c) { return sample(c, null); }
/** * Returns an object sampled from the distribution using a self-provided * random number generator. * * @return a sampled object */ public E sampleFrom(Random random) { return Counters.sample(counter, random); }
/** * Returns an object sampled from the distribution using Math.random(). * There may be a faster way to do this if you need to... * * @return a sampled object */ public E sampleFrom() { return Counters.sample(counter); } /**
/** * Does not assumes c is normalized. * @return A sample from c */ public static <T> T sample(Counter<T> c) { return sample(c, null); }
/** * Returns an object sampled from the distribution using Math.random(). * There may be a faster way to do this if you need to... * * @return a sampled object */ public E sampleFrom() { return Counters.sample(counter); } /**