Examples of SparseVector


Examples of ariba.util.core.SparseVector

        {
            if (!_hasUnnavigableErrors) {
                return _orderedUndisplayedErrors;
            }

            SparseVector /*AWErrorBucket*/ sortedErrors =
                new SparseVector(_orderedUndisplayedErrors.size(), false);
            allocEmptySlots(sortedErrors, _orderedUndisplayedErrors.size());
            int bottomCounter = _orderedUndisplayedErrors.size() - 1;
            Map<Integer, AWErrorBucket> unnavigableErrors = MapUtil.map();
            int highestUnnavNumber = 0;
            for (int i = _orderedUndisplayedErrors.size() - 1; i >= 0; i--) {
                AWErrorBucket bucket = _orderedUndisplayedErrors.get(i);
                if (bucket.getUnnavigableDisplayOrder() != AWErrorInfo.NotDisplayed) {
                    // pick out the unnavigable errors
                    Integer key = Constants.getInteger(bucket.getUnnavigableDisplayOrder());
                    unnavigableErrors.put(key, bucket);
                    highestUnnavNumber = Math.max(bucket.getUnnavigableDisplayOrder(), highestUnnavNumber);
                }
                else {
                    sortedErrors.add(bottomCounter, bucket);
                    bottomCounter--;
                }
            }

            int topCounter = 0;
            int start = (positioningError.getUnnavigableDisplayOrder() != AWErrorInfo.NotDisplayed)
                ? positioningError.getUnnavigableDisplayOrder() + 1
                : 0;
            for (int i = start; i <= highestUnnavNumber; i++) {
                Integer key = Constants.getInteger(i);
                AWErrorBucket bucket = unnavigableErrors.get(key);
                if (bucket != null) {
                    sortedErrors.add(topCounter, bucket);
                    topCounter++;
                }
            }
            for (int i = 0; i < start; i++) {
                Integer key = Constants.getInteger(i);
                AWErrorBucket bucket = unnavigableErrors.get(key);
                if (bucket != null) {
                    sortedErrors.add(topCounter, bucket);
                    topCounter++;
                }
            }

            return sortedErrors;
View Full Code Here

Examples of ca.uwo.csd.ai.nlp.common.SparseVector

    @Override
    public double evaluate(svm_node x, svm_node y) {                       
        if (!(x.data instanceof SparseVector) || !(y.data instanceof SparseVector)) {
            throw new RuntimeException("Could not find sparse vectors in svm_nodes");
        }       
        SparseVector v1 = (SparseVector) x.data;
        SparseVector v2 = (SparseVector) y.data;
                       
        return v1.dot(v2);
    }   
View Full Code Here

Examples of cc.mallet.types.SparseVector

    {
      // Do the defaults first
      defaultConstraints = new SparseVector [templates.length];
      defaultExpectations = new SparseVector [templates.length];
      for (int tidx = 0; tidx < templates.length; tidx++) {
        SparseVector defaults = templates[tidx].getDefaultWeights();
        defaultConstraints[tidx] = (SparseVector) defaults.cloneMatrixZeroed ();
        defaultExpectations[tidx] = (SparseVector) defaults.cloneMatrixZeroed ();
      }

      // And now the others
      constraints = new SparseVector [templates.length][];
      expectations = new SparseVector [templates.length][];
View Full Code Here

Examples of cc.mallet.types.SparseVector

        throw new IllegalArgumentException("Argument is not of the " +
                                           " correct dimensions");
      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 (values, 0, buf, idx, values.length);
        idx += values.length;
      }

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

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 - (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

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

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

    SparseVector s3p = new SparseVector
                       (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

    SparseVector s4 = new SparseVector
                      (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 })

    SparseVector s5 = new SparseVector (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);
    }

    SparseVector s6 = new SparseVector (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

Examples of cc.mallet.types.SparseVector

    // Now add -infinite weight onto a transition, and make sure that it's
    // honored.
    CRF.State state = crf.getState("notstart");
    int widx = crf.getWeightsIndex("BadBad");
    int numFeatures = crf.getInputAlphabet().size();
    SparseVector w = new SparseVector(new double[numFeatures]);
    w.setAll(Double.NEGATIVE_INFINITY);
    crf.setWeights(widx, w);

    state.addWeight(0, "BadBad");
    state.addWeight(1, "BadBad");
View Full Code Here

Examples of cc.mallet.types.SparseVector

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

  public void testDotProduct () {
    SparseVector t1 = new SparseVector (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);

    assertEquals (11.9, s1.dotProduct (d1), 0.00001);
    assertEquals (10.1, s2.dotProduct (d1), 0.00001);

    // test dotproduct when vector with more locations has a lower
    //   max-index than short vector
    SparseVector t2 = new SparseVector (new int[] { 3, 30 }, new double[] { 0.2, 3.5 });
    SparseVector t3 = new SparseVector (null, new double[] { 1, 1, 1, 1, });
    assertEquals (0.2, t3.dotProduct (t2), 0.00001);
  }
View Full Code Here

Examples of cc.mallet.types.SparseVector

    assertEquals (0.2, t3.dotProduct (t2), 0.00001);
  }

  public void testIncrementValue ()
  {
    SparseVector s = (SparseVector) 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
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.