本文整理汇总了Java中edu.jhu.prim.util.math.FastMath.logAdd方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.logAdd方法的具体用法?Java FastMath.logAdd怎么用?Java FastMath.logAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.jhu.prim.util.math.FastMath
的用法示例。
在下文中一共展示了FastMath.logAdd方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCell
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
public void updateCell(int nt, double score, int mid, Rule r) {
assert(!isClosed);
if (bps[nt] == null) {
// If the non-terminal hasn't been added yet, include it in the set of non terminals.
nts.add(nt);
}
if (computeInside) {
// Compute the inside score.
scores[nt] = FastMath.logAdd(scores[nt], score);
// Add a dummy backpointer, so that the above non-null check still works.
bps[nt] = BackPointer.NON_NULL_BACKPOINTER;
} else {
// Compute the viterbi score.
if (score > scores[nt]) {
scores[nt] = score;
bps[nt] = new BackPointer(r, mid);
}
}
}
示例2: updateCell
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
public final void updateCell(int s, int t, int d, int ic, double score, int r) {
int idx = getIndex(s, t, d, ic);
if (this.type == DepParseType.VITERBI) {
if (score > scores[idx]) {
scores[idx] = score;
bps[idx] = r;
}
} else {
scores[idx] = FastMath.logAdd(scores[idx], score);
// Don't update the backpointer.
// Commented out for speed.
// log.debug(String.format("Cell: s=%d (r=%d) t=%d d=%s ic=%s score=%10.2f exp(score)=%.2f",
// s, r, t,
// d == ProjectiveDependencyParser.RIGHT ? "R" : "L",
// ic == ProjectiveDependencyParser.COMPLETE ? "C" : "I",
// scores[s][t][d][ic],
// FastMath.exp(scores[s][t][d][ic])));
}
}
示例3: logSum
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
public static double logSum(double[] logProps) {
double logPropSum = Double.NEGATIVE_INFINITY;
for (int d = 0; d < logProps.length; d++) {
logPropSum = FastMath.logAdd(logPropSum, logProps[d]);
}
return logPropSum;
}
示例4: logSum
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
public static float logSum(float[] logProps) {
float logPropSum = Float.NEGATIVE_INFINITY;
for (int d = 0; d < logProps.length; d++) {
logPropSum = FastMath.logAdd(logPropSum, logProps[d]);
}
return logPropSum;
}
示例5: call
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
public double call(double v1, double v2) {
return FastMath.logAdd(v1, v2);
}
示例6: plus
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
@Override
public double plus(double x, double y) {
return FastMath.logAdd(x, y);
}
示例7: testSimpleSentence1Helper
import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
private void testSimpleSentence1Helper(LoopOrder loopOrder) throws IOException {
// time flies like an arrow.
CnfGrammarReader builder = new CnfGrammarReader();
builder.loadFromResource(CnfGrammarReaderTest.timeFliesGrammarResource);
CnfGrammar grammar = builder.getGrammar(loopOrder);
Sentence sent = getSentenceFromString("time flies like an arrow", grammar.getLexAlphabet());
PcfgIoChart chart = parseSentence(sent , grammar, loopOrder);
// There are three valid trees with weights -11, -12, -15.
double sum = FastMath.logAdd(-11, -12);
sum = FastMath.logAdd(sum, -15);
assertEquals(-10.673, sum, 1e-3);
assertEquals(-10.660, chart.getLogInsideScore(grammar.getRootSymbol(), 0, sent.size()), 1e-3);
assertEquals(0, chart.getLogOutsideScore(grammar.getRootSymbol(), 0, sent.size()), 1e-3);
// Each of the three trees uses this NP from 3 to 5. So the outside
// score should be the sums of those trees minus 3 from each of their
// weights, since 3 is the weight of this NP.
sum = FastMath.logAdd(-8, -9);
sum = FastMath.logAdd(sum, -12);
assertEquals(sum, chart.getLogOutsideScore(grammar.getNtAlphabet().lookupIndex("NP"), 3, 5), 1e-6);
System.out.println("");
int numNonInfs = 0;
for (int width = 1; width <= sent.size(); width++) {
for (int start = 0; start <= sent.size() - width; start++) {
int end = start + width;
for (int nt = 0; nt < grammar.getNumNonTerminals(); nt++) {
String msg = String.format("start=%d end=%d nt=%s", start, end, grammar.getNtAlphabet().lookupObject(nt));
msg += " is: " + chart.getLogInsideScore(nt, start, end) + " os: " + chart.getLogOutsideScore(nt, start, end);
double product = chart.getLogInsideScore(nt, start, end) + chart.getLogOutsideScore(nt, start, end);
if (product != Double.NEGATIVE_INFINITY) {
System.out.println(msg);
numNonInfs++;
}
}
}
}
assertEquals(18, numNonInfs);
}