Package cc.mallet.types

Examples of cc.mallet.types.SparseVector


    return new TestSuite (TestAugmentableFeatureVector.class);
  }

  public void testDotProductBinaryToSV ()
  {
    SparseVector v = makeSparseVectorToN (5);
    AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, true);
    double dp = afv.dotProduct (v);
    assertEquals (4.0, dp, 1e-5);
    new AugmentableFeatureVector (new Alphabet(), true);
  }
View Full Code Here


    logger.info ("CRF using dense weights, num input features = "+max);
    for (int i = 0; i < parameters.weights.length; i++) {
      int nfeatures;
      if (featureSelections[i] == null) {
        nfeatures = max;
        newWeights [i] = new SparseVector (null, new double [max],
            max, max, false, false, false);
      } else {
        // Respect the featureSelection
        FeatureSelection fs = featureSelections[i];
        nfeatures = fs.getBitSet ().cardinality ();
View Full Code Here

    new AugmentableFeatureVector (new Alphabet(), true);
  }

  public void testDotProductSparseASVToSV ()
  {
    SparseVector v = makeSparseVectorToN (7);
    AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, false);
    double dp = afv.dotProduct (v);
    assertEquals (4.0, dp, 1e-5);

    afv = makeAfv (new int[] { 2, 5 }, false);
View Full Code Here

  {
    double[] vals = new double [N];
    for (int i = 0; i < N; i++) {
      vals [i] = i;
    }
    return new SparseVector (vals);
  }
View Full Code Here

    else {   
      out.println ("\n\n*** CRF WEIGHTS ***");
      for (int widx = 0; widx < parameters.weights.length; widx++) {
        out.println ("WEIGHTS NAME = " + parameters.weightAlphabet.lookupObject (widx));
        out.print (": <DEFAULT_FEATURE> = "); out.print (parameters.defaultWeights[widx]); out.print ('\n');
        SparseVector transitionWeights = parameters.weights[widx];
        if (transitionWeights.numLocations () == 0)
          continue;
        RankedFeatureVector rfv = new RankedFeatureVector (inputAlphabet, transitionWeights);
        for (int m = 0; m < rfv.numLocations (); m++) {
          double v = rfv.getValueAtRank (m);
          //int index = rfv.indexAtLocation (rfv.getIndexAtRank (m));  // This doesn't make any sense.  How did this ever work?  -akm 12/2007
View Full Code Here

  }
 
  public void testTimesEquals ()
  {
    double[] d1 = new double[] {1, 2, 3, 4, 5};
    SparseVector m1 = new SparseVector (d1);
    SparseVector m2 = new SparseVector (d1);
    m2.timesEqualsSparse(m1);
    m2.print();
  }
View Full Code Here

      try {
        int[] theseWeights = source.weightsIndices[index];
        for (int i = 0; i < theseWeights.length; i++) {
          int wi = theseWeights[i];
          SparseVector w = crf.parameters.weights[wi];

          buf.append ("WEIGHTS <br />\n" + crf.parameters.weightAlphabet.lookupObject (wi) + "<br />\n");
          buf.append ("  d.p. = "+f.format (w.dotProduct (input))+"<br />\n");

          double[] vals = new double[input.numLocations ()];
          double[] absVals = new double[input.numLocations ()];
          for (int k = 0; k < vals.length; k++) {
            int index = input.indexAtLocation (k);
            vals[k] = w.value (index) * input.value (index);
            absVals[k] = Math.abs (vals[k]);
          }

          buf.append ("DEFAULT " + f.format (crf.parameters.defaultWeights[wi]) + "<br />\n");
          RankedFeatureVector rfv = new RankedFeatureVector (crf.inputAlphabet, input.getIndices (), absVals);
View Full Code Here

    logger.info ("CRF using dense weights, num input features = "+max);
    for (int i = 0; i < parameters.weights.length; i++) {
      int nfeatures;
      if (featureSelections[i] == null) {
        nfeatures = max;
        newWeights [i] = new SparseVector (null, new double [max],
            max, max, false, false, false);
      } else {
        // Respect the featureSelection
        FeatureSelection fs = featureSelections[i];
        nfeatures = fs.getBitSet ().cardinality ();
        int[] idxs = new int [nfeatures];
        int j = 0, thisIdx = -1;
        while ((thisIdx = fs.nextSelectedIndex (thisIdx + 1)) >= 0) {
          idxs[j++] = thisIdx;
        }
        newWeights[i] = new SparseVector (idxs, new double [nfeatures], nfeatures, nfeatures, false, false, false);
      }
      newWeights [i].plusEqualsSparse (parameters.weights [i]);
      numWeights += (nfeatures + 1);
    }
    logger.info("Number of weights = "+numWeights);
View Full Code Here

    else {   
      out.println ("\n\n*** CRF WEIGHTS ***");
      for (int widx = 0; widx < parameters.weights.length; widx++) {
        out.println ("WEIGHTS NAME = " + parameters.weightAlphabet.lookupObject (widx));
        out.print (": <DEFAULT_FEATURE> = "); out.print (parameters.defaultWeights[widx]); out.print ('\n');
        SparseVector transitionWeights = parameters.weights[widx];
        if (transitionWeights.numLocations () == 0)
          continue;
        RankedFeatureVector rfv = new RankedFeatureVector (inputAlphabet, transitionWeights);
        for (int m = 0; m < rfv.numLocations (); m++) {
          double v = rfv.getValueAtRank (m);
          //int index = rfv.indexAtLocation (rfv.getIndexAtRank (m));  // This doesn't make any sense.  How did this ever work?  -akm 12/2007
View Full Code Here

      try {
        int[] theseWeights = source.weightsIndices[index];
        for (int i = 0; i < theseWeights.length; i++) {
          int wi = theseWeights[i];
          SparseVector w = crf.parameters.weights[wi];

          buf.append ("WEIGHTS <br />\n" + crf.parameters.weightAlphabet.lookupObject (wi) + "<br />\n");
          buf.append ("  d.p. = "+f.format (w.dotProduct (input))+"<br />\n");

          double[] vals = new double[input.numLocations ()];
          double[] absVals = new double[input.numLocations ()];
          for (int k = 0; k < vals.length; k++) {
            int index = input.indexAtLocation (k);
            vals[k] = w.value (index) * input.value (index);
            absVals[k] = Math.abs (vals[k]);
          }

          buf.append ("DEFAULT " + f.format (crf.parameters.defaultWeights[wi]) + "<br />\n");
          RankedFeatureVector rfv = new RankedFeatureVector (crf.inputAlphabet, input.getIndices (), absVals);
View Full Code Here

TOP

Related Classes of cc.mallet.types.SparseVector

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.