Package de.jungblut.math

Examples of de.jungblut.math.DoubleVector.sum()


    }

    final int[] rowEntries = transitionProbabilities.rowIndices();
    for (int rowIndex : rowEntries) {
      DoubleVector rowVector = transitionProbabilities.getRowVector(rowIndex);
      double sum = rowVector.sum();
      Iterator<DoubleVectorElement> iterateNonZero = rowVector.iterateNonZero();
      // loop over all counts and take the log of the probability
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement columnElement = iterateNonZero.next();
        int columnIndex = columnElement.getIndex();
View Full Code Here


  /**
   * @return the average transition probability of the given sequence.
   */
  public double averageTransitionProbability(int[] sequence) {
    DoubleVector distribution = getTransitionProbabilities(sequence);
    return FastMath.exp(distribution.sum()
        / Math.max(1d, distribution.getLength()));
  }

  /**
   * @return the transition probabilities for the states.
View Full Code Here

  }

  @Override
  public DoubleVector predictProbability(DoubleVector features) {
    DoubleVector predict = predict(features);
    return predict.divide(predict.sum());
  }

  @Override
  public int extractPredictedClass(DoubleVector predict) {
    if (predict.getLength() == 1) {
View Full Code Here

    for (int row = 0; row < transitionProbabilityMatrix.getRowCount(); row++) {
      // note that we are using row vectors here, because dense matrices give us
      // the underlying array wrapped by the vector object so we can directly
      // mutate the values beneath
      DoubleVector rowVector = transitionProbabilityMatrix.getRowVector(row);
      rowVector = rowVector.divide(rowVector.sum());
      if (log) {
        rowVector = rowVector.log();
      }
      transitionProbabilityMatrix.setRowVector(row, rowVector);
      rowVector = emissionProbabilitiyMatrix.getRowVector(row);
View Full Code Here

      if (log) {
        rowVector = rowVector.log();
      }
      transitionProbabilityMatrix.setRowVector(row, rowVector);
      rowVector = emissionProbabilitiyMatrix.getRowVector(row);
      rowVector = rowVector.divide(rowVector.sum());
      if (log) {
        rowVector = rowVector.log();
      }
      emissionProbabilitiyMatrix.setRowVector(row, rowVector);
    }
View Full Code Here

  @Override
  public DoubleVector predictProbability(DoubleVector features) {
    DoubleVector prediction = predict(features);
    if (numOutcomes != 2) {
      prediction = prediction.divide(prediction.sum());
    }
    return prediction;
  }

  /**
 
View Full Code Here

    } else {
      for (int i = 0; i < subtract.getLength(); i++) {
        subtract.set(i, Math.exp(subtract.get(i)));
      }
    }
    return subtract.divide(subtract.sum());
  }

  @Override
  public DoubleMatrix apply(DoubleMatrix matrix) {
    DoubleMatrix dm = newInstance(matrix);
View Full Code Here

    for (int state = 0; state < probabilities.getDimension(); state++) {
      probabilities.set(state, FastMath.exp(probabilities.get(state) - max)
          * hiddenPriorProbability.get(state));
    }
    // normalize again
    return probabilities.divide(probabilities.sum());
  }

  public DoubleVector predict(DoubleVector features,
      DoubleVector previousOutcome) {
    // clamp the features to the visible units, calculate the joint
View Full Code Here

    for (int state = 0; state < probabilities.getDimension(); state++) {
      probabilities.set(state, FastMath.exp(probabilities.get(state) - max)
          * hiddenPriorProbability.get(state));
    }
    // normalize again
    return probabilities.divide(probabilities.sum());
  }

  public int getNumHiddenStates() {
    return this.numHiddenStates;
  }
View Full Code Here

    return compareVector(a.getVector(), o.getVector());
  }

  public static int compareVector(DoubleVector a, DoubleVector o) {
    DoubleVector subtract = a.subtract(o);
    return (int) subtract.sum();
  }

  public static VectorWritable wrap(DenseDoubleVector a) {
    return new VectorWritable(a);
  }
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.