public String dumpToString () { StringBuffer s = new StringBuffer (1024); s.append (this.toString ()); s.append ("\n"); int indices[] = new int[numVars]; for (int loc = 0; loc < probs.numLocations (); loc++) { int idx = probs.indexAtLocation (loc); probs.singleToIndices (idx, indices); for (int j = 0; j < numVars; j++) { s.append (indices[j]); s.append (" "); } double val = probs.singleValue (idx); s.append (val); s.append ("\n"); } s.append (" Sum = ").append (sum ()).append ("\n"); return s.toString (); }
public String dumpToString () { StringBuffer s = new StringBuffer (1024); s.append (this.toString ()); s.append ("\n"); int indices[] = new int[numVars]; for (int loc = 0; loc < probs.numLocations (); loc++) { int idx = probs.indexAtLocation (loc); probs.singleToIndices (idx, indices); for (int j = 0; j < numVars; j++) { s.append (indices[j]); s.append (" "); } double val = probs.singleValue (idx); s.append (val); s.append ("\n"); } s.append (" Sum = ").append (sum ()).append ("\n"); return s.toString (); }
public String dumpToString () { StringBuffer s = new StringBuffer (1024); s.append (this.toString ()); s.append ("\n"); int indices[] = new int[numVars]; for (int loc = 0; loc < probs.numLocations (); loc++) { int idx = probs.indexAtLocation (loc); probs.singleToIndices (idx, indices); for (int j = 0; j < numVars; j++) { s.append (indices[j]); s.append (" "); } double val = probs.singleValue (idx); s.append (val); s.append ("\n"); } s.append (" Sum = ").append (sum ()).append ("\n"); return s.toString (); }
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); }
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); }
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); }