Examples of SparseVector


Examples of cc.mallet.types.SparseVector

      cachedValueStale = cachedGradientStale = true;

      int idx = 0;
      for (int tidx = 0; tidx < templates.length; tidx++) {
        ACRF.Template tmpl = templates [tidx];
        SparseVector defaults = tmpl.getDefaultWeights();
        double[] values = defaults.getValues ();
        System.arraycopy (params, idx, values, 0, values.length);
        idx += values.length;
      }

      for (int tidx = 0; tidx < templates.length; tidx++) {
View Full Code Here

Examples of cc.mallet.types.SparseVector

      /* Index into current element of cachedGradient[] array. */
      int gidx = 0;

      // First do gradient wrt defaultWeights
      for (int tidx = 0; tidx < templates.length; tidx++) {
        SparseVector theseWeights = templates[tidx].getDefaultWeights ();
        SparseVector theseConstraints = defaultConstraints [tidx];
        SparseVector theseExpectations = defaultExpectations [tidx];
        for (int j = 0; j < theseWeights.numLocations(); j++) {
          double weight = theseWeights.valueAtLocation (j);
          double constraint = theseConstraints.valueAtLocation (j);
          double expectation = theseExpectations.valueAtLocation (j);
          if (printGradient) {
            System.out.println(" gradient ["+gidx+"] = "+constraint+" (ctr) - "+expectation+" (exp) - "+
                             (weight / gaussianPriorVariance)+" (reg)  [feature=DEFAULT]");
          }
          grad [gidx++] = constraint - expectation - priorScale * (weight / gaussianPriorVariance);
        }
      }

      // Now do other weights
      for (int tidx = 0; tidx < templates.length; tidx++) {
        ACRF.Template tmpl = templates [tidx];
        SparseVector[] weights = tmpl.getWeights ();
        for (int i = 0; i < weights.length; i++) {
          SparseVector thisWeightVec = weights [i];
          SparseVector thisConstraintVec = constraints [tidx][i];
          SparseVector thisExpectationVec = expectations [tidx][i];

          for (int j = 0; j < thisWeightVec.numLocations(); j++) {
            double w = thisWeightVec.valueAtLocation (j);
            double gradient;  // Computed below

            double constraint = thisConstraintVec.valueAtLocation(j);
            double expectation = thisExpectationVec.valueAtLocation(j);

            /* A parameter may be set to -infinity by an external user.
             * We set gradient to 0 because the parameter's value can
             * never change anyway and it will mess up future calculations
             * on the matrix. */
 
View Full Code Here

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

Examples of cc.mallet.types.SparseVector

    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

Examples of cc.mallet.types.SparseVector

    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

Examples of cc.mallet.types.SparseVector

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

Examples of cc.mallet.types.SparseVector

    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

Examples of cc.mallet.types.SparseVector

  }
 
  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

Examples of cc.mallet.types.SparseVector

      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

Examples of ch.akuhn.hapax.linalg.SparseVector

 
  double BIG_DELTA = 0.0000001;

    @Test
    public SparseVector empty() {
        SparseVector v = new SparseVector(10, 3);
        assertEquals(10, v.size());
        assertEquals(0, v.used());
        assertEquals(0, v.get(0), Double.MIN_VALUE);
        assertEquals(0, v.get(1), Double.MIN_VALUE);
        assertEquals(0, v.get(2), Double.MIN_VALUE);
        assertEquals(0, v.get(3), Double.MIN_VALUE);
        assertEquals(0, v.get(4), Double.MIN_VALUE);
        assertEquals(0, v.get(5), Double.MIN_VALUE);
        assertEquals(0, v.get(6), Double.MIN_VALUE);
        assertEquals(0, v.get(7), Double.MIN_VALUE);
        assertEquals(0, v.get(8), Double.MIN_VALUE);
        assertEquals(0, v.get(9), Double.MIN_VALUE);
        return v;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.