Package edu.cmu.sphinx.decoder.search

Examples of edu.cmu.sphinx.decoder.search.Token


     * Returns the maximum relative beam for a the chain of tokens reachable from the given token
     *
     * @param result the result of interest
     */
    private void collectRelativeBeamStatistics(Result result) {
        Token token = result.getBestToken();
        int count = 0;
        double sumBeam = 0.0;

        maxRelativeBeam = -Float.MAX_VALUE;

        while (token != null) {
            if (token.isEmitting()) {
                TokenRank rank = (TokenRank) token.getTokenProps().get(TOKEN_RANK);
                if (rank != null) {
                    if (rank.getRelativeRank() > maxRelativeBeam) {
                        maxRelativeBeam = rank.getRelativeRank();
                    }
                    sumBeam += rank.getRelativeRank();
                    count++;
                } else {
                    if (token.getFrameNumber() > 0) {
                        System.out.println("Null rank! for " + token);
                    }
                }
            }
            token = token.getPredecessor();
        }

        if (count > 0) {
            avgRelativeBeam = (float) (sumBeam / count);
            if (maxRelativeBeam > totMaxRelativeBeam) {
View Full Code Here


      int tokenListSize, boolean tokenListLarger) {

    Random random = new Random(System.currentTimeMillis());
    Partitioner partitioner = new Partitioner();

    Token parent = new Token(null, 0);
    Token[] tokens = new Token[tokenListSize];

    for (int i = 0; i < tokens.length; i++) {
      float logTotalScore = random.nextFloat();
      tokens[i] = new Token(parent, null, logTotalScore, 0.0f, 0.0f, i);
    }

    final int r = partitioner.partition(tokens, tokens.length,
        absoluteBeamWidth);

    if (tokenListLarger) {
      Assert.assertEquals(r, absoluteBeamWidth - 1);
    } else {
      Assert.assertEquals (r, tokenListSize - 1);
    }

    List<Token> firstList = new LinkedList<Token>();
    if (r >= 0) {
      float lowestScore = tokens[r].getScore();

      for (int i = 0; i <= r; i++) {
        Assert.assertTrue(tokens[i].getScore() >= lowestScore);
        firstList.add(tokens[i]);
      }
      for (int i = r + 1; i < tokens.length; i++) {
        Assert.assertTrue(lowestScore > tokens[i].getScore());
      }

      Collections.sort(firstList, Scoreable.COMPARATOR);

      List<Token> secondList = Arrays.asList(tokens);
      Collections.sort(secondList, Scoreable.COMPARATOR);

      for (Iterator<Token> i1 = firstList.iterator(), i2 = secondList
          .iterator(); i1.hasNext() && i2.hasNext();) {
        Token t1 = i1.next();
        Token t2 = i2.next();
        Assert.assertEquals(t1, t2);
      }
    }
  }
View Full Code Here

    int p;
    Token[] tokens = new Token[100000];
    Partitioner partitioner = new Partitioner();

    for (int i = 0; i < 100000; i++)
      tokens[i] = new Token(null, null, 1 - i, 0, 0, 0);
    p = partitioner.partition(tokens, 100000, 3000);
    Assert.assertEquals(p, 2999);
    testSorted(tokens, p);

    for (int i = 0; i < 100000; i++)
      tokens[i] = new Token(null, null, i, 0, 0, 0);
    p = partitioner.partition(tokens, 100000, 3000);
    Assert.assertEquals(p, 2999);
    testSorted(tokens, p);

    for (int i = 0; i < 100000; i++)
      tokens[i] = new Token(null, null, 0, 0, 0, 0);
    p = partitioner.partition(tokens, 100000, 3000);
    Assert.assertEquals(p, 2999);
    testSorted(tokens, p);

    for (int i = 0; i < 100000; i++)
      tokens[i] = new Token(null, null, (float) Math.random(), 0, 0, 0);
    p = partitioner.partition(tokens, 100000, 3000);
    Assert.assertEquals(p, 2999);
    testSorted(tokens, p);
  }
View Full Code Here

TOP

Related Classes of edu.cmu.sphinx.decoder.search.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.