Package de.jungblut.math

Examples of de.jungblut.math.DoubleVector


  /**
   * @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()));
  }
View Full Code Here


      }
      if (conf.lambda != 0d) {
        thetaGradients[i] = thetaGradients[i].add((thetas[i]
            .multiply(conf.lambda / m)));
        // subtract the regularized bias
        DoubleVector regBias = thetas[i]
            .slice(0, thetas[i].getRowCount(), 0, 1).multiply(conf.lambda / m)
            .getColumnVector(0);
        thetaGradients[i].setColumnVector(0, regBias);
      }
    }
View Full Code Here

      LimitedPriorityQueue<VectorDistanceTuple<VALUE>> queue) {
    if (current == null) {
      return;
    }
    int s = current.splitDimension;
    DoubleVector pivot = current.keyVector;
    double distancePivotToTarget = EuclidianDistance.get().measureDistance(
        pivot, target);

    HyperRectangle leftHyperRectangle = hyperRectangle;
    HyperRectangle rightHyperRectangle = new HyperRectangle(
        hyperRectangle.min.deepCopy(), hyperRectangle.max.deepCopy());
    leftHyperRectangle.max.set(s, pivot.get(s));
    rightHyperRectangle.min.set(s, pivot.get(s));
    boolean left = target.get(s) > pivot.get(s);
    KDTreeNode nearestNode;
    HyperRectangle nearestHyperRectangle;
    KDTreeNode furtherstNode;
    HyperRectangle furtherstHyperRectangle;
    if (left) {
      nearestNode = current.left;
      nearestHyperRectangle = leftHyperRectangle;
      furtherstNode = current.right;
      furtherstHyperRectangle = rightHyperRectangle;
    } else {
      nearestNode = current.right;
      nearestHyperRectangle = rightHyperRectangle;
      furtherstNode = current.left;
      furtherstHyperRectangle = leftHyperRectangle;
    }
    getNearestNeighbourInternal(nearestNode, target, nearestHyperRectangle,
        maxDistSquared, k, radius, queue);

    double distanceSquared = queue.isFull() ? queue.getMaximumPriority()
        : Double.MAX_VALUE;
    maxDistSquared = Math.min(maxDistSquared, distanceSquared);
    DoubleVector closest = furtherstHyperRectangle.closestPoint(target);
    double closestDistance = EuclidianDistance.get().measureDistance(closest,
        target);
    // check subtrees even if they aren't in your maxDist but within our radius
    if (closestDistance < maxDistSquared || closestDistance < radius) {
      if (distancePivotToTarget < distanceSquared) {
View Full Code Here

  /**
   * Merges two centers when they are within the given distance of each other.
   */
  private static void merge(List<DoubleVector> centers, double mergeWindow) {
    for (int i = 0; i < centers.size(); i++) {
      DoubleVector referenceVector = centers.get(i);
      // find centers to merge if they are within our merge window
      for (int j = i + 1; j < centers.size(); j++) {
        DoubleVector center = centers.get(j);
        double dist = EuclidianDistance.get().measureDistance(referenceVector,
            center);
        if (dist < mergeWindow) {
          centers.remove(j);
          centers.set(i, referenceVector.add(center).divide(2d));
View Full Code Here

   */
  private static int meanShift(KDTree<Integer> kdTree,
      List<DoubleVector> centers, double h) {
    int remainingConvergence = 0;
    for (int i = 0; i < centers.size(); i++) {
      DoubleVector v = centers.get(i);
      List<VectorDistanceTuple<Integer>> neighbours = kdTree
          .getNearestNeighbours(v, h);
      double weightSum = 0d;
      DoubleVector numerator = new DenseDoubleVector(v.getLength());
      for (VectorDistanceTuple<Integer> neighbour : neighbours) {
        if (neighbour.getDistance() < h) {
          double normDistance = neighbour.getDistance() / h;
          weightSum -= gaussianGradient(normDistance);
          numerator = numerator.add(neighbour.getVector().multiply(weightSum));
        }
      }
      if (weightSum > 0d) {
        DoubleVector shift = v.divide(numerator);
        DoubleVector newCenter = v.add(shift);
        if (v.subtract(newCenter).abs().sum() > 1e-5) {
          remainingConvergence++;
          // apply the shift
          centers.set(i, newCenter);
        }
View Full Code Here

    BitSet assignedIndices = new BitSet(kdTree.size());
    // we are doing one pass over the dataset to determine the first centers
    // that are within h range
    for (int i = 0; i < points.size(); i++) {
      if (!assignedIndices.get(i)) {
        DoubleVector v = points.get(i);
        List<VectorDistanceTuple<Integer>> neighbours = kdTree
            .getNearestNeighbours(v, h);
        DoubleVector center = new DenseDoubleVector(v.getLength());
        int added = 0;
        for (VectorDistanceTuple<Integer> neighbour : neighbours) {
          if (!assignedIndices.get(neighbour.getValue())
              && neighbour.getDistance() < h) {
            center = center.add(neighbour.getVector());
            assignedIndices.set(neighbour.getValue());
            added++;
          }
        }
        // so if our sum is positive, we can divide and add the center
        if (added > 1) {
          DoubleVector newCenter = center.divide(added);
          centers.add(newCenter);
          if (verbose && centers.size() % 1000 == 0) {
            LOG.info("#Centers found: " + centers.size());
          }
        }
View Full Code Here

public abstract class AbstractPredictor implements Predictor {

  @Override
  public int predictedClass(DoubleVector features, double threshold) {
    DoubleVector predict = predict(features);
    return extractPredictedClass(predict, threshold);
  }
View Full Code Here

*/
public abstract class AbstractActivationFunction implements ActivationFunction {

  @Override
  public DoubleVector apply(DoubleVector vector) {
    DoubleVector newInstance = newInstance(vector);
    if (vector.isSparse()) {
      Iterator<DoubleVectorElement> iterateNonZero = vector.iterateNonZero();
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement next = iterateNonZero.next();
        newInstance.set(next.getIndex(), apply(next.getValue()));
      }
    } else {
      for (int i = 0; i < vector.getDimension(); i++) {
        newInstance.set(i, apply(vector.get(i)));
      }
    }
    return newInstance;
  }
View Full Code Here

    return extractPredictedClass(predict, threshold);
  }

  @Override
  public int predictedClass(DoubleVector features) {
    DoubleVector predict = predict(features);
    return extractPredictedClass(predict);
  }
View Full Code Here

    return extractPredictedClass(predict);
  }

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

TOP

Related Classes of de.jungblut.math.DoubleVector

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.