本文整理汇总了Java中cc.mallet.util.Randoms.nextUniform方法的典型用法代码示例。如果您正苦于以下问题:Java Randoms.nextUniform方法的具体用法?Java Randoms.nextUniform怎么用?Java Randoms.nextUniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.util.Randoms
的用法示例。
在下文中一共展示了Randoms.nextUniform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sampleLocation
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public int sampleLocation (Randoms r)
{
double sum = sum();
double sampled = r.nextUniform () * sum;
double cum = 0;
for (int idx = 0; idx < probs.numLocations (); idx++) {
double val = value (idx);
cum += val;
if (sampled <= cum + EPS) {
return idx;
}
}
throw new RuntimeException
("Internal errors: Couldn't sample from potential "+this+"\n"+dumpToString ()+"\n Using value "+sampled);
}
示例2: randomIndex
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public int randomIndex (Randoms r)
{
double f = r.nextUniform();
double sum = 0;
int i;
for (i = 0; i < values.length; i++) {
sum += values[i];
//System.out.print (" sum="+sum);
if (sum >= f)
break;
}
//if (sum < f) throw new IllegalStateException
//System.out.println ("i = "+i+", f = "+f+", sum = "+sum);
assert (sum >= f);
return i;
}
示例3: createBoltzmannChain
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
static FactorGraph createBoltzmannChain (int len)
{
Randoms r = new Randoms (3241321);
List<Variable> vars = new ArrayList<Variable> ();
for (int i = 0; i < len; i++) {
Variable x_i = new Variable (2);
x_i.setLabel ("X_"+i);
vars.add (x_i);
}
List<Factor> factors = new ArrayList<Factor> (vars.size ());
// node factors
for (int i = 0; i < len; i++) {
double u = r.nextUniform (-4.0, 4.0);
factors.add (new BoltzmannUnaryFactor (vars.get (i), u));
}
// edge factors
for (int i = 0; i < len-1; i++) {
Variable alpha = new Variable (Variable.CONTINUOUS);
alpha.setLabel ("ALPHA_"+i);
factors.add (new UniformFactor (alpha, -4.0, 4.0));
factors.add (new PottsTableFactor (vars.get (i), vars.get(i+1), alpha));
}
return new FactorGraph (factors);
}
示例4: sample
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public Assignment sample (Randoms r)
{
double val = r.nextUniform (min, max);
return new Assignment (var, val);
}