Package de.jungblut.math.DoubleVector

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


      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

  @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

      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

      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

TOP

Related Classes of de.jungblut.math.DoubleVector.DoubleVectorElement

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.