Package cc.mallet.types

Examples of cc.mallet.types.FeatureVector


      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++) {
          fi = fv.indexAtLocation(loc);
          // binary constraint features
          if (constraints.containsKey(fi)) {
            cache.add(fi);
          }
        }
        if (constraints.containsKey(fv.getAlphabet().size())) {
          cache.add(fv.getAlphabet().size());
        }
        for (int s = 0; s < map.getNumStates(); ++s) {
          int li = map.getLabelIndex(s);
          if (li != StateLabelMap.START_LABEL) {
            double gammaProb = Math.exp(gammas[ip+1][s]);
View Full Code Here


  // find examples that contain constrained input features
  public BitSet preProcess(InstanceList data) {
    // count
    int ii = 0;
    int fi;
    FeatureVector fv;
    BitSet bitSet = new BitSet(data.size());
    for (Instance instance : data) {
      FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
      for (int ip = 0; ip < fvs.size(); ip++) {
        fv = fvs.get(ip);
        for (int loc = 0; loc < fv.numLocations(); loc++) {
          fi = fv.indexAtLocation(loc);
          if (constraints.containsKey(fi)) {
            constraints.get(fi).count += 1;
            bitSet.set(ii);
          }
        }
View Full Code Here

    // Initialize the constraints

    logger.fine("Number of instances in training list = " + trainingList.size());

    for (Instance instance : trainingList) {
      FeatureVector multinomialValues = (FeatureVector) instance.getTarget();

      if (multinomialValues == null)
        continue;

      FeatureVector features = (FeatureVector) instance.getData();
      assert (features.getAlphabet() == alphabet);

      boolean hasNaN = false;

      for (int i = 0; i < features.numLocations(); i++) {
        if (Double.isNaN(features.valueAtLocation(i))) {
          logger.info("NaN for feature " + alphabet.lookupObject(features.indexAtLocation(i)).toString());
          hasNaN = true;
        }
      }

      if (hasNaN) {
View Full Code Here

    int instanceIndex = 0;
   
    for (Instance instance: trainingList) {

      FeatureVector multinomialValues = (FeatureVector) instance.getTarget();
      if (multinomialValues == null) { continue; }

      //System.out.println("L Now "+inputAlphabet.size()+" regular features.");
               
      // Get the predicted probability of each class
      //   under the current model parameters
      this.classifier.getUnnormalizedClassificationScores(instance, scores);

      double sumScores = 0.0;

      // Exponentiate the scores
      for (int i=0; i<scores.length; i++) {
        // Due to underflow, it's very likely that some of these scores will be 0.0.
        scores[i] = Math.exp(scores[i]);
        sumScores += scores[i];
      }

      FeatureVector features = (FeatureVector) instance.getData();

      // This is really an int, but since FeatureVectors are defined as doubles,
      //  avoid casting.
      double totalLength = 0;
View Full Code Here

    int instanceIndex = 0;

    for (Instance instance: trainingList) {

      FeatureVector multinomialValues = (FeatureVector) instance.getTarget();
      if (multinomialValues == null) { continue; }

      // Get the predicted probability of each class
      //   under the current model parameters
      this.classifier.getUnnormalizedClassificationScores(instance, scores);

      double sumScores = 0.0;

      // Exponentiate the scores
      for (int i=0; i<scores.length; i++) {
        // Due to underflow, it's very likely that some of these scores will be 0.0.
        scores[i] = Math.exp(scores[i]);
        sumScores += scores[i];
      }

      FeatureVector features = (FeatureVector) instance.getData();

      double totalLength = 0;

      for (double count : multinomialValues.getValues()) {
        totalLength += count;
      }
     
      double digammaDifferenceForSums =
        Dirichlet.digamma(sumScores + totalLength) -
        Dirichlet.digamma(sumScores);
     
      for (int loc = 0; loc < features.numLocations(); loc++) {
        int index = features.indexAtLocation(loc);
        double value = features.valueAtLocation(loc);
                   
        if (value == 0.0) { continue; }

        // In a FeatureVector, there's no easy way to say "do you know
        //   about this id?" so I've broken this into two for loops,
View Full Code Here

  }

  // "size" is the number of 1.0-weight features in the feature vector
  public FeatureVector randomFeatureVector (Randoms r, int size)
  {
    return new FeatureVector (randomFeatureSequence (r, size));
  }
View Full Code Here

  // find examples that contain constrained input features
  public BitSet preProcess(InstanceList data) {
    // count
    int ii = 0;
    int fi;
    FeatureVector fv;
    BitSet bitSet = new BitSet(data.size());
    for (Instance instance : data) {
      FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
      for (int ip = 0; ip < fvs.size(); ip++) {
        fv = fvs.get(ip);
        for (int loc = 0; loc < fv.numLocations(); loc++) {
          fi = fv.indexAtLocation(loc);
          if (constraints.containsKey(fi)) {
            constraints.get(fi).count += 1;
            bitSet.set(ii);
          }
        }
        if (constraints.containsKey(fv.getAlphabet().size())) {
          bitSet.set(ii);
          constraints.get(fv.getAlphabet().size()).count += 1;
        }
      }

      ii++;
    }
View Full Code Here

      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++) {
          fi = fv.indexAtLocation(loc);
          // binary constraint features
          if (constraints.containsKey(fi)) {
            cache.add(fi);
          }
        }
        if (constraints.containsKey(fv.getAlphabet().size())) {
          cache.add(fv.getAlphabet().size());
        }
        for (int s = 0; s < map.getNumStates(); ++s) {
          int li = map.getLabelIndex(s);
          if (li != StateLabelMap.START_LABEL) {
            double gammaProb = Math.exp(gammas[ip+1][s]);
View Full Code Here

 
 
  public Instance pipe (Instance carrier)
  {
    FeatureSequence fs = (FeatureSequence) carrier.getData();
    carrier.setData(new FeatureVector (fs, binary));
    return carrier;
  }
View Full Code Here

      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++) {
          fi = fv.indexAtLocation(loc);
          // binary constraint features
          if (constraintsMap.containsKey(fi)) {
            cache.add(constraintsMap.get(fi));
          }
        }
View Full Code Here

TOP

Related Classes of cc.mallet.types.FeatureVector

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.