Package cc.mallet.fst

Examples of cc.mallet.fst.SumLattice


  public void computeExpectations(ArrayList<SumLattice> lattices) {
    double[][] gammas;   
    TIntArrayList cache = new TIntArrayList();
    for (int i = 0; i < lattices.size(); i++) {
      if (lattices.get(i) == null) { continue; }
      SumLattice lattice = lattices.get(i);
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
      gammas = lattice.getGammas();
      for (int ip = 0; ip < fvs.size(); ++ip) {
        cache.resetQuick();
        FeatureVector fv = fvs.getFeatureVector(ip);
        int fi;
        for (int loc = 0; loc < fv.numLocations(); loc++) {
View Full Code Here


  }
 
  public void computeExpectations(ArrayList<SumLattice> lattices) {
    double[][][] xis;
    for (int i = 0; i < lattices.size(); i++) {
      SumLattice lattice = lattices.get(i);
      xis = lattice.getXis();
      int numStates = xis[0].length;
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
      for (int ip = 0; ip < fvs.size(); ++ip) {
        for (int si = 0; si < numStates; si++) {
          this.expectation += Math.exp(xis[ip][si][si]);
        }
      }
View Full Code Here

  public void computeExpectations(ArrayList<SumLattice> lattices) {
    double[][] gammas;   
    TIntArrayList cache = new TIntArrayList();
    for (int i = 0; i < lattices.size(); i++) {
      if (lattices.get(i) == null) { continue; }
      SumLattice lattice = lattices.get(i);
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
      gammas = lattice.getGammas();
      for (int ip = 0; ip < fvs.size(); ++ip) {
        cache.resetQuick();
        FeatureVector fv = fvs.getFeatureVector(ip);
        int fi;
        for (int loc = 0; loc < fv.numLocations(); loc++) {
View Full Code Here

    double[][][] xis;
    TIntArrayList cache = new TIntArrayList();
    for (int i = 0; i < lattices.size(); i++) {
      if (lattices.get(i) == null) { continue; }
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattices.get(i).getInput();
      SumLattice lattice = lattices.get(i);
      xis = lattice.getXis();
      for (int ip = 1; ip < fvs.size(); ++ip) {
        cache.resetQuick();
        FeatureVector fv = fvs.getFeatureVector(ip);
        int fi;
        for (int loc = 0; loc < fv.numLocations(); loc++) {
View Full Code Here

   
    // compute GE gradient
    if (numThreads == 1) {
      for (int ii = 0; ii < data.size(); ii++) {
        if (instancesWithConstraints.get(ii)) {
          SumLattice lattice = lattices.get(ii);
          FeatureVectorSequence fvs = (FeatureVectorSequence)data.get(ii).getData();
          new GELattice(fvs, lattice.getGammas(), lattice.getXis(), crf, reverseTrans, reverseTransIndices, cachedGradient,this.constraints, false);
        }
      }
    }
    else {
      // multi-threaded version
View Full Code Here

  }

  public Void call() throws Exception {
    for (int ii = start; ii < end; ii++) {
      if (instancesWithConstraints.get(ii)) {
        SumLattice lattice = lattices.get(ii);
        FeatureVectorSequence fvs = (FeatureVectorSequence)data.get(ii).getData();
        new GELattice(fvs, lattice.getGammas(), lattice.getXis(),
          crf, reverseTrans, reverseTransIndices, gradient,this.constraints, false);
      }
    }
    return null;
  }
View Full Code Here

    expectations.zero();

    // now, update the expectations due to each instance for entropy reg.
    for (int ii = 0; ii < data.size(); ii++) {
      FeatureVectorSequence input = (FeatureVectorSequence) data.get(ii).getData();
      SumLattice lattice = new SumLatticeDefault(crf,input, true);

      // udpate the expectations
      EntropyLattice entropyLattice = new EntropyLattice(
          input, lattice.getGammas(), lattice.getXis(), crf,
          incrementor, scalingFactor);
      cachedValue += entropyLattice.getEntropy();
    }
  }
View Full Code Here

            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }),
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }), });

    SumLattice lattice = new SumLatticeDefault(crf, fvs, true);
    // We start in state0
    assertTrue(lattice.getGammaProbability(0, crf.getState(0)) == 1.0);
    assertTrue(lattice.getGammaProbability(0, crf.getState(1)) == 0.0);
    // We go to state1
    assertTrue(lattice.getGammaProbability(1, crf.getState(0)) == 0.0);
    assertTrue(lattice.getGammaProbability(1, crf.getState(1)) == 1.0);
    // And on through a self-transition
    assertTrue(lattice
        .getXiProbability(1, crf.getState(1), crf.getState(1)) == 1.0);
    assertTrue(lattice
        .getXiProbability(1, crf.getState(1), crf.getState(0)) == 0.0);
    assertTrue("Lattice weight = " + lattice.getTotalWeight(), lattice
        .getTotalWeight() == 4.0);
    // Gammas at all times sum to 1.0
    for (int time = 0; time < lattice.length() - 1; time++) {
      double gammasum = lattice
          .getGammaProbability(time, crf.getState(0))
          + lattice.getGammaProbability(time, crf.getState(1));
      assertEquals("Gammas at time step " + time + " sum to " + gammasum,
          1.0, gammasum, 0.0001);
    }
    // Xis at all times sum to 1.0
    for (int time = 0; time < lattice.length() - 1; time++) {
      double xissum = lattice.getXiProbability(time, crf.getState(0), crf
          .getState(0))
          + lattice.getXiProbability(time, crf.getState(0), crf
              .getState(1))
          + lattice.getXiProbability(time, crf.getState(1), crf
              .getState(0))
          + lattice.getXiProbability(time, crf.getState(1), crf
              .getState(1));
      assertEquals("Xis at time step " + time + " sum to " + xissum, 1.0,
          xissum, 0.0001);
    }
  }
View Full Code Here

    for (int iter = 0; iter < 10000; iter++) {
      for (int ii = 0; ii < lists[1].size(); ii++) {
        FeatureVectorSequence input = (FeatureVectorSequence) lists[1]
            .get(ii).getData();
        totalTimeDefault -= System.currentTimeMillis();
        SumLattice defaultLattice = new SumLatticeDefault(crf, input,
            true);
        totalTimeDefault += System.currentTimeMillis();
        totalTimeScaling -= System.currentTimeMillis();
        SumLattice scalingLattice = new SumLatticeScaling(crf, input,
            true);
        totalTimeScaling += System.currentTimeMillis();
        if (iter == 0) {
          // check that total weight is same
          assertEquals(defaultLattice.getTotalWeight(),
              scalingLattice.getTotalWeight(), 0.0001);
          // check that gammas
          double[][] g1 = defaultLattice.getGammas(), g2 = scalingLattice
              .getGammas();
          for (int i = 0; i < g1.length; i++) {
            for (int j = 0; j < g1[i].length; j++) {
              assertEquals(g1[i][j], g2[i][j], 0.0001);
            }
          }
          // check that xis match
          double[][][] x1 = defaultLattice.getXis(), x2 = scalingLattice
              .getXis();
          for (int i = 0; i < x1.length; i++) {
            for (int j = 0; j < x1[i].length; j++) {
              for (int k = 0; k < x1[i][j].length; k++) {
                assertEquals(x1[i][j][k], x2[i][j][k], 0.0001);
View Full Code Here

          if (!constraintBits.get(i)) {
            continue;
          }
          FeatureVectorSequence fvs =
              (FeatureVectorSequence) data.get(i).getData();
          SumLattice lattice = lattices.get(i);
          assert(lattice != null)
              : "Lattice is null:: " + i + ", size: " + lattices.size();
          new GELattice(
              fvs, lattice.getGammas(), lattice.getXis(), crf, incrementor,
              geCriteria, false);
        }
        synchronized(LatticeCreationExecutor.this) {
          threadIds.set(index);
        }
View Full Code Here

TOP

Related Classes of cc.mallet.fst.SumLattice

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.