Examples of DoubleVectorElement


Examples of de.jungblut.math.DoubleVector.DoubleVectorElement

    double[] scores = new double[classes];

    Iterator<DoubleVectorElement> iterateNonZero = features.iterateNonZero();
    while (iterateNonZero.hasNext()) {
      DoubleVectorElement next = iterateNonZero.next();
      for (int i = 0; i < scores.length; i++) {
        scores[i] += weights.get(i, next.getIndex());
      }
    }

    return scores;
  }
View Full Code Here

Examples of de.jungblut.math.DoubleVector.DoubleVectorElement

      out.writeInt(row);
      DoubleVector rowVector = mat.getRowVector(row);
      out.writeInt(rowVector.getLength());
      Iterator<DoubleVectorElement> iterateNonZero = rowVector.iterateNonZero();
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement next = iterateNonZero.next();
        out.writeInt(next.getIndex());
        out.writeDouble(next.getValue());
      }
    }
  }
View Full Code Here

Examples of de.jungblut.math.DoubleVector.DoubleVectorElement

  @Override
  public void funnel(DoubleVector from, PrimitiveSink into) {
    if (from.isSparse()) {
      Iterator<DoubleVectorElement> iterator = from.iterateNonZero();
      while (iterator.hasNext()) {
        DoubleVectorElement next = iterator.next();
        into.putInt(next.getIndex());
        into.putDouble(next.getValue());
      }
    } else {
      final int dimension = from.getDimension();
      // traverse backwards, because sparse vectors are iterated descending, so
      // we get the same funneling for same vectors of different types.
View Full Code Here

Examples of de.jungblut.math.DoubleVector.DoubleVectorElement

      out.writeByte(SPARSE);
      out.writeInt(vector.getLength());
      out.writeInt(vector.getDimension());
      Iterator<DoubleVectorElement> iterateNonZero = vector.iterateNonZero();
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement next = iterateNonZero.next();
        out.writeInt(next.getIndex());
        out.writeDouble(next.getValue());
      }
    } else if (vector.isSingle()) {
      // single vectors are also dense, thus we will put it before the dense
      // condition in order to save 4 bytes for the length encoding
      out.writeByte(SINGLE);
View Full Code Here

Examples of de.jungblut.math.DoubleVector.DoubleVectorElement

      DoubleVector rowVector = features.getRowVector(row);
      double[] logProbabilities = new double[classes];
      // sum the probabilities for each class over all features
      Iterator<DoubleVectorElement> iterateNonZero = rowVector.iterateNonZero();
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement next = iterateNonZero.next();
        for (int i = 0; i < classes; i++) {
          logProbabilities[i] += theta.get(i, next.getIndex());
        }
      }
      double z = logSum(logProbabilities);
      for (int i = 0; i < classes; i++) {
        double prob = Math.exp(logProbabilities[i] - z);
        iterateNonZero = rowVector.iterateNonZero();
        while (iterateNonZero.hasNext()) {
          DoubleVectorElement next = iterateNonZero.next();
          gradient.set(i, next.getIndex(), gradient.get(i, next.getIndex())
              + prob);
          if (correctPrediction(i, outcome.getRowVector(row))) {
            gradient.set(i, next.getIndex(),
                gradient.get(i, next.getIndex()) - 1d);
          }
        }
        if (correctPrediction(i, outcome.getRowVector(row))) {
          cost -= Math.log(prob);
        }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleVector.DoubleVectorElement

    DoubleVector vec = new DenseDoubleVector(expectedRes);
    Iterator<DoubleVectorElement> itr = vec.iterate();
   
    int curIdx = 0;
    while (itr.hasNext()) {
      DoubleVectorElement elem = itr.next();
      assertEquals(curIdx, elem.getIndex());
      assertEquals(expectedRes[curIdx++], elem.getValue(), 0.000001);
    }
   
    Iterator<DoubleVectorElement> itrNonZero = vec.iterateNonDefault();
   
    curIdx = 0;
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleVector.DoubleVectorElement

  public void testIterators() {
    DoubleVector v1 = new SparseDoubleVector(10, 5.5);
    Iterator<DoubleVectorElement> itr1 = v1.iterate();
    int idx1 = 0;
    while (itr1.hasNext()) {
      DoubleVectorElement elem = itr1.next();
      assertEquals(idx1++, elem.getIndex());
      assertEquals(5.5, elem.getValue(), 0.000001);
    }

    v1.set(2, 20);
    v1.set(6, 30);

    Iterator<DoubleVectorElement> itr2 = v1.iterateNonDefault();
    DoubleVectorElement elem = itr2.next();
    assertEquals(2, elem.getIndex());
    assertEquals(20, elem.getValue(), 0.000001);
    elem = itr2.next();
    assertEquals(6, elem.getIndex());
    assertEquals(30, elem.getValue(), 0.000001);

    assertFalse(itr2.hasNext());
  }
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.