Package de.jungblut.math.dense

Examples of de.jungblut.math.dense.DenseDoubleVector


    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);
View Full Code Here


    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 static DoubleVector readImageAsGreyScale(BufferedImage img) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    DoubleVector vector = new DenseDoubleVector(h * w);
    int[] rgb = img.getRGB(0, 0, w, h, null, 0, w);
    for (int i = 0; i < rgb.length; i++) {
      int red = (rgb[i] >> 16) & 0xFF;
      int green = (rgb[i] >> 8) & 0xFF;
      int blue = (rgb[i] >> 0) & 0xFF;
      vector.set(i, (red + green + blue) / 3d);
    }
    return vector;
  }
View Full Code Here

      double[] rgbValue = new double[3];
      // get the RGB values
      rgbValue[0] = (rgb[i] >> 16) & 0xFF; // RED
      rgbValue[1] = (rgb[i] >> 8) & 0xFF; // GREEN
      rgbValue[2] = (rgb[i] >> 0) & 0xFF; // BLUE
      vectors[currentIndex++] = new DenseDoubleVector(rgbValue);
    }

    return vectors;
  }
View Full Code Here

      float[] luv = space.fromRGB(rgbValue);
      double[] arr = new double[luv.length];
      for (int x = 0; x < luv.length; x++) {
        arr[x] = luv[x];
      }
      vectors[currentIndex++] = new DenseDoubleVector(arr);
    }

    return vectors;
  }
View Full Code Here

  protected DoubleVector newInstance(DoubleVector v) {
    if (v.isSparse()) {
      return new SparseDoubleVector(v.getDimension());
    } else {
      return new DenseDoubleVector(v.getDimension());
    }
  }
View Full Code Here

          numLine++;
          continue;
        }

        String[] split = line.split(",");
        DenseDoubleVector featureVector = new DenseDoubleVector(
            split.length - 1);
        for (int i = 1; i < split.length; i++) {
          featureVector.set(i - 1, Integer.parseInt(split[i]));
        }

        DenseDoubleVector predVector = new DenseDoubleVector(10);
        predVector.set(Integer.parseInt(split[0]), 1.0d);

        features.add(featureVector);
        prediction.add(predVector);
        numLine++;
      }
View Full Code Here

  @Override
  public DoubleVector predict(DoubleVector features) {
    List<VectorDistanceTuple<DoubleVector>> nearestNeighbours = getNearestNeighbours(
        features, k);

    DenseDoubleVector outcomeHistogram = new DenseDoubleVector(numOutcomes);
    for (VectorDistanceTuple<DoubleVector> tuple : nearestNeighbours) {
      int classIndex = 0;
      if (numOutcomes == 2) {
        classIndex = (int) tuple.getValue().get(0);
      } else {
        classIndex = tuple.getValue().maxIndex();
      }

      outcomeHistogram.set(classIndex, outcomeHistogram.get(classIndex) + 1);
    }
    if (numOutcomes == 2) {
      return new SingleEntryDoubleVector(outcomeHistogram.maxIndex());
    } else {
      return outcomeHistogram;
    }
  }
View Full Code Here

    return activations;
  }

  // could be simplified now due to a "copy" constructor
  private static DoubleVector addBias(DoubleVector activations) {
    return new DenseDoubleVector(1d, activations.toArray());
  }
View Full Code Here

  /*
   * Some oldschool compatibility convenience constructors
   */

  public VectorWritable(double x) {
    this.vector = new DenseDoubleVector(new double[] { x });
  }
View Full Code Here

TOP

Related Classes of de.jungblut.math.dense.DenseDoubleVector

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.