Package cc.mallet.types

Examples of cc.mallet.types.IndexedSparseVector


      int[] indices = new int[numLocations];
      for (int j = 0; j < numLocations; j++) {
        indices[j] = weightsPresent[i].nextSetBit (j == 0 ? 0 : indices[j-1]+1);
        //System.out.println ("CRF4 has index "+indices[j]);
      }
      newWeights[i] = new IndexedSparseVector (indices, new double[numLocations],
          numLocations, numLocations, false, false, false);
      newWeights[i].plusEqualsSparse (parameters.weights[i])// Put in the previous weights
      numWeights += (numLocations + 1);
    }
    logger.info("Number of weights = "+numWeights);
View Full Code Here


        int[] idxs = new int [nfeatures];
        int j = 0, thisIdx = -1;
        while ((thisIdx = fs.nextSelectedIndex (thisIdx + 1)) >= 0) {
          idxs[j++] = thisIdx;
        }
        newWeights[i] = new IndexedSparseVector (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

      parameters.weights = new SparseVector[1];
      parameters.defaultWeights = new double[1];
      featureSelections = new FeatureSelection[1];
      parameters.weightsFrozen = new boolean [1];
      // Use initial capacity of 8
      parameters.weights[0] = new IndexedSparseVector ();
      parameters.defaultWeights[0] = 0;
      featureSelections[0] = null;
      weightsStructureChanged();
    } else if (wi == parameters.weights.length) {
      SparseVector[] newWeights = new SparseVector[parameters.weights.length+1];
      double[] newDefaultWeights = new double[parameters.weights.length+1];
      FeatureSelection[] newFeatureSelections = new FeatureSelection[parameters.weights.length+1];
      for (int i = 0; i < parameters.weights.length; i++) {
        newWeights[i] = parameters.weights[i];
        newDefaultWeights[i] = parameters.defaultWeights[i];
        newFeatureSelections[i] = featureSelections[i];
      }
      newWeights[wi] = new IndexedSparseVector ();
      newDefaultWeights[wi] = 0;
      newFeatureSelections[wi] = null;
      parameters.weights = newWeights;
      parameters.defaultWeights = newDefaultWeights;
      featureSelections = newFeatureSelections;
View Full Code Here

    }
  }

  public void testPlusEquals ()
  {
    IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
    s.plusEqualsSparse (s2, 2.0);
    checkAnswer (s, new double[] { 3, 5, 7, 6, 7 });

    IndexedSparseVector s2p = new IndexedSparseVector
                       (new int[] { 13 },
                        new double[] { 0.8 });
    s.plusEqualsSparse (s2p, 1.0);
    checkAnswer (s, new double[] { 3, 5, 7, 6.8, 7 });

    IndexedSparseVector s3p = new IndexedSparseVector
                       (new int[] { 14 },
                        new double[] { 0.8 });
    s.plusEqualsSparse (s3p, 1.0);
    checkAnswer (s, new double[] { 3, 5, 7, 6.8, 7 });     // verify s unchanged

    IndexedSparseVector s4 = new IndexedSparseVector
                      (new int[] { 7, 14, 15 },
                       new double[] { 0.2, 0.8, 1.2 });
    s.plusEqualsSparse (s4, 1.0);
    checkAnswer (s, new double[] { 3, 5, 7.2, 6.8, 8.2 });

    IndexedSparseVector s5 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
    s5.plusEqualsSparse (s1);
    for (int i = 0; i < s5.numLocations(); i++) {
      assertEquals (7, s5.indexAtLocation (i));
      assertEquals (3.2, s5.valueAtLocation (i), 0.0);
    }

    IndexedSparseVector s6 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
    s6.plusEqualsSparse (s1, 3.5);
    for (int i = 0; i < s6.numLocations(); i++) {
      assertEquals (7, s6.indexAtLocation (i));
      assertEquals (10.7, s6.valueAtLocation (i), 0.0);
    }
  }
View Full Code Here

      assertEquals (10.7, s6.valueAtLocation (i), 0.0);
    }
  }

  public void testDotProduct () {
    IndexedSparseVector t1 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
    assertEquals (0.6, t1.dotProduct (s1), 0.00001);
    assertEquals (0.6, s1.dotProduct (t1), 0.00001);

    assertEquals (19.0, s1.dotProduct (s2), 0.00001);
    assertEquals (19.0, s2.dotProduct (s1), 0.00001);
View Full Code Here

    assertEquals (10.1, s2.dotProduct (d1), 0.00001);
  }

  public void testIncrementValue ()
  {
    IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
    s.incrementValue (5, 0.75);

    double[] ans = new double[] {1, 2.75, 3, 4, 5};
    for (int i = 0; i < s.numLocations(); i++) {
      assertTrue (s.valueAtLocation (i) == ans[i]);
    }
  }
View Full Code Here

  }


  public void testSetValue ()
  {
    IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
    s.setValue (5, 0.3);

    double[] ans = new double[] {1, 0.3, 3, 4, 5};
    for (int i = 0; i < s.numLocations(); i++) {
      assertTrue (s.valueAtLocation (i) == ans[i]);
    }
  }
View Full Code Here

  private static int[] idx2 = { 3, 7, 12, 15, 18 };

  public void testBinaryVector ()
  {
    IndexedSparseVector binary1 = new IndexedSparseVector (idxs, null, idxs.length, idxs.length,
                                             false, false, false);
    IndexedSparseVector binary2 = new IndexedSparseVector (idx2, null, idx2.length, idx2.length,
                                            false, false, false);

    assertEquals (3, binary1.dotProduct (binary2), 0.0001);
    assertEquals (3, binary2.dotProduct (binary1), 0.0001);

    assertEquals (15.0, binary1.dotProduct (s1), 0.0001);
    assertEquals (15.0, s1.dotProduct (binary1), 0.0001);

    assertEquals (9.0, binary2.dotProduct (s1), 0.0001);
    assertEquals (9.0, s1.dotProduct (binary2), 0.0001);

    IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix ();
    dblVec.plusEqualsSparse (binary1);
    checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 });

    IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix ();
    dblVec2.plusEqualsSparse (binary2);
    checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 });
  }
View Full Code Here

    checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 });
  }

  public void testCloneMatrixZeroed ()
  {
    IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrixZeroed ();
    for (int i = 0; i < s.numLocations(); i++) {
      assertTrue (s.valueAtLocation (i) == 0.0);
      assertTrue (s.indexAtLocation (i) == idxs [i]);
    }
  }
View Full Code Here

    }
  }

  public void testEmptyLocations ()
  {
    IndexedSparseVector s = new IndexedSparseVector (new int[0], new double [0]);
    assertEquals (0.0, s.value (38), 1e-10);
    assertEquals (0.0, s.dotProduct (s1), 1e-10);
  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.IndexedSparseVector

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.