当前位置: 首页>>代码示例>>Java>>正文


Java FastMath.useLogAddTable方法代码示例

本文整理汇总了Java中edu.jhu.prim.util.math.FastMath.useLogAddTable方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.useLogAddTable方法的具体用法?Java FastMath.useLogAddTable怎么用?Java FastMath.useLogAddTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.jhu.prim.util.math.FastMath的用法示例。


在下文中一共展示了FastMath.useLogAddTable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsideOutsideSpeed

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
/**
 * Output:
 * SEED=123456789101112
 * 100 trials: Tokens per second: 2700.2700270027003
 * 1000 trials: Tokens per second: 5395.6834532374105
 * 
 * After switching to setTailNodes() with Hypernode[] storage.
 * 100 trials: Tokens per second: 2929.6875
 * 1000 trials: Tokens per second: 6651.884700665189
 * 1000 trials (with LogPosNegSemiring): Tokens per second: 4687.5
 */
@Test
public void testInsideOutsideSpeed() {
    FastMath.useLogAddTable = true;

    int trials = 1000;
    int n = 30;

    // Just create one tree.
    double[] root = Multinomials.randomMultinomial(n);
    double[][] child = new double[n][];
    for (int i=0; i<n; i++) {
        child[i] =  Multinomials.randomMultinomial(n);
    }
    
    Timer timer = new Timer();
    timer.start();
    for (int t=0; t<trials; t++) {
        HyperDepParser.insideOutsideSingleRoot(root, child);
    }
    timer.stop();
    System.out.println("Total time: " + timer.totMs());
    int numSents = trials;
    int numTokens = n * numSents;
    System.out.println("Sentences per second: " + numSents / timer.totSec());
    System.out.println("Tokens per second: " + numTokens / timer.totSec());
    FastMath.useLogAddTable = false;
}
 
开发者ID:mgormley,项目名称:pacaya-nlp,代码行数:39,代码来源:HyperDepParserSpeedTest.java

示例2: testInsideLogViterbiSpeed

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
/**
 * Output:
 * SEED=123456789101112
 * 1000 trials: Tokens per second: 12494.793835901708
 */
@Test
public void testInsideLogViterbiSpeed() {
    FastMath.useLogAddTable = true;

    int trials = 1000;
    int n = 30;

    // Just create one tree.
    double[] root = Multinomials.randomMultinomial(n);
    double[][] child = new double[n][];
    for (int i=0; i<n; i++) {
        child[i] =  Multinomials.randomMultinomial(n);
    }

    for (int round=0; round<2; round++) {
        Semiring s = LogViterbiSemiring.getInstance();
        Timer timer = new Timer();
        timer.start();
        for (int t=0; t<trials; t++) {
            O1DpHypergraph graph = new O1DpHypergraph(root, child, s, true);
            Scores scores = new Scores();
            Hyperalgo.insideAlgorithm(graph, graph.getPotentials(), s, scores);
        }
        timer.stop();
        System.out.println("Total time: " + timer.totMs());
        int numSents = trials;
        int numTokens = n * numSents;
        System.out.println("Sentences per second: " + numSents / timer.totSec());
        System.out.println("Tokens per second: " + numTokens / timer.totSec());
    }
    FastMath.useLogAddTable = false;
}
 
开发者ID:mgormley,项目名称:pacaya-nlp,代码行数:38,代码来源:HyperDepParserSpeedTest.java

示例3: testLogSum

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
@Test
public void testLogSum() {
    assertEquals(Double.POSITIVE_INFINITY, DoubleArrays.logSum(new double[]{ Double.POSITIVE_INFINITY, 0.1}), 1e-13);
    boolean old = FastMath.useLogAddTable;
    FastMath.useLogAddTable = false;
    assertEquals(Double.POSITIVE_INFINITY, DoubleArrays.logSum(new double[]{ Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}), 1e-13);
    FastMath.useLogAddTable = true;
    assertEquals(Double.POSITIVE_INFINITY, DoubleArrays.logSum(new double[]{ Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}), 1e-13);
    FastMath.useLogAddTable = old;
}
 
开发者ID:mgormley,项目名称:prim,代码行数:11,代码来源:DoubleArraysTest.java

示例4: testParseSpeed2

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
/**
 * Output: (round 2)
 * sum: 2001819.430589211
 * Total time: 1623.0
 * Sentences per second: 6161.429451632779
 * Tokens per second: 184842.88354898337  <<<< 
 */
@Test
public void testParseSpeed2() {
    FastMath.useLogAddTable = true;

    int rounds = 2;
    int trials = 10000;
    int n = 30;
    
    double[] root = new double[n];
    double[][] child = new double[n][n];
    for (int i=0; i<n; i++) {
        root[i] = Math.log(i+1);
        for (int j=0; j<n; j++) {
            child[i][j] = Math.log(i*n + j+1);
        }
    }
    
    for (int round=0; round<rounds; round++) {
        Timer timer = new Timer();
        timer.start();
        double sum = 0.0;
        for (int t=0; t<trials; t++) {
            int[] parents = new int[n];
            sum += ProjectiveDependencyParser.parseSingleRoot(root, child, parents);
        }
        System.out.println("sum: " + sum);
        timer.stop();
        System.out.println("Total time: " + timer.totMs());
        int numSents = trials;
        int numTokens = n * numSents;
        System.out.println("Sentences per second: " + numSents / timer.totSec());
        System.out.println("Tokens per second: " + numTokens / timer.totSec());
    }
    FastMath.useLogAddTable = false;
}
 
开发者ID:mgormley,项目名称:pacaya,代码行数:43,代码来源:ProjectiveDependencyParserSpeedTest.java

示例5: testInsideOutsideSpeed

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
/**
 * Output:
 * SEED=123456789101112
 * 100 trials: Tokens per second: 5338.078291814946
 * 1000 trials: Tokens per second: 11406.84410646388
 * 
 * Case 1: useLogAddTable=false
 * sum: 229809.96390368755
 * Total time: 9836.0
 * Sentences per second: 101.667344448963
 * Tokens per second: 3050.0203334688895
 *
 * Case 2: useLogAddTable=true
 * sum: 229809.96390396365
 * Total time: 8432.0
 * Sentences per second: 118.59582542694497
 * Tokens per second: 3557.874762808349
 * 
 * Case 3: useLogAddTable=true, w/ LogAddTable in place of SmoothedLogAddTable.
 * sum: 229794.61076560934
 * Total time: 2317.0
 * Sentences per second: 431.5925766076823
 * Tokens per second: 12947.777298230469
 */
@Test
public void testInsideOutsideSpeed() {
    FastMath.useLogAddTable = true;

    int rounds = 2;
    int trials = 1000;
    int n = 30;
    
    double[] root = new double[n];
    double[][] child = new double[n][n];
    for (int i=0; i<n; i++) {
        root[i] = Math.log(i+1);
        for (int j=0; j<n; j++) {
            child[i][j] = Math.log(i*n + j+1);
        }
    }
    
    for (int round=0; round<rounds; round++) {
        Timer timer = new Timer();
        timer.start();
        double sum = 0.0;
        for (int t=0; t<trials; t++) {
            DepIoChart chart = ProjectiveDependencyParser.insideOutsideSingleRoot(root, child);
            sum += chart.getLogPartitionFunction();
        }
        System.out.println("sum: " + sum);
        timer.stop();
        System.out.println("Total time: " + timer.totMs());
        int numSents = trials;
        int numTokens = n * numSents;
        System.out.println("Sentences per second: " + numSents / timer.totSec());
        System.out.println("Tokens per second: " + numTokens / timer.totSec());
    }
    FastMath.useLogAddTable = false;
}
 
开发者ID:mgormley,项目名称:pacaya,代码行数:60,代码来源:ProjectiveDependencyParserSpeedTest.java

示例6: annotate

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
@Override
public void annotate(AnnoSentenceCollection sents) {
    log.info("Ensuring that static options (singleRoot and useLogAddTable) are set to their train-time values.");
    InsideOutsideDepParse.singleRoot = singleRoot;
    FastMath.useLogAddTable = useLogAddTable;
}
 
开发者ID:mgormley,项目名称:pacaya-nlp,代码行数:7,代码来源:JointNlpRunner.java

示例7: setUp

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
@Before
public void setUp() {
    previous = FastMath.useLogAddTable;
    FastMath.useLogAddTable = true;
}
 
开发者ID:mgormley,项目名称:pacaya,代码行数:6,代码来源:LogSemiringWithTableTest.java

示例8: tearDown

import edu.jhu.prim.util.math.FastMath; //导入方法依赖的package包/类
@After
public void tearDown() {
    FastMath.useLogAddTable = previous;
}
 
开发者ID:mgormley,项目名称:pacaya,代码行数:5,代码来源:LogSemiringWithTableTest.java


注:本文中的edu.jhu.prim.util.math.FastMath.useLogAddTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。