当前位置: 首页>>代码示例>>Java>>正文


Java NumberVector.toArray方法代码示例

本文整理汇总了Java中de.lmu.ifi.dbs.elki.data.NumberVector.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java NumberVector.toArray方法的具体用法?Java NumberVector.toArray怎么用?Java NumberVector.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de.lmu.ifi.dbs.elki.data.NumberVector的用法示例。


在下文中一共展示了NumberVector.toArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: meansWithTreshhold

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Returns the mean vectors of the given clusters in the given database.
 *
 * @param clusters the clusters to compute the means
 * @param means the recent means
 * @param database the database containing the vectors
 * @return the mean vectors of the given clusters in the given database
 */
protected double[][] meansWithTreshhold(List<? extends ModifiableDoubleDBIDList> clusters, double[][] means, Relation<V> database, Double tresh) {
  // TODO: use Kahan summation for better numerical precision?
  double[][] newMeans = new double[k][];
  for(int i = 0; i < k; i++) {
    DoubleDBIDList list = clusters.get(i);
    double[] raw = null;
    int count = 0;
    // Update with remaining instances
    for(DoubleDBIDListIter iter = list.iter(); iter.valid(); iter.advance()) {
      if(iter.doubleValue() >= tresh) {
        continue;
      }
      NumberVector vec = database.get(iter);
      if(raw == null) { // Initialize:
        raw = vec.toArray();
      }
      for(int j = 0; j < raw.length; j++) {
        raw[j] += vec.doubleValue(j);
      }
      count++;
    }
    newMeans[i] = (raw != null) ? VMath.timesEquals(raw, 1.0 / count) : means[i];
  }
  return newMeans;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:34,代码来源:KMeansMinusMinus.java

示例2: drawCross

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Wireframe "cross" hypersphere
 *
 * @param svgp SVG Plot
 * @param proj Visualization projection
 * @param mid mean vector
 * @param radius radius
 * @return path element
 */
public static Element drawCross(SVGPlot svgp, Projection2D proj, NumberVector mid, double radius) {
  final double[] v_mid = mid.toArray();
  final long[] dims = proj.getVisibleDimensions2D();

  SVGPath path = new SVGPath();
  for(int dim = BitsUtil.nextSetBit(dims, 0); dim >= 0; dim = BitsUtil.nextSetBit(dims, dim + 1)) {
    v_mid[dim] += radius;
    double[] p1 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] -= radius;
    path.moveTo(p1[0], p1[1]);
    v_mid[dim] -= radius;
    double[] p2 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] += radius;
    path.drawTo(p2[0], p2[1]);
    path.close();
  }
  return path.makeElement(svgp);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:SVGHyperSphere.java

示例3: applyPrescaling

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Prescale each vector (except when in {@code skip}) with the given scaling
 * function.
 *
 * @param scaling Scaling function
 * @param relation Relation to read
 * @param skip DBIDs to pass unmodified
 * @return New relation
 */
public static Relation<NumberVector> applyPrescaling(ScalingFunction scaling, Relation<NumberVector> relation, DBIDs skip) {
  if(scaling == null) {
    return relation;
  }
  NumberVector.Factory<NumberVector> factory = RelationUtil.getNumberVectorFactory(relation);
  DBIDs ids = relation.getDBIDs();
  WritableDataStore<NumberVector> contents = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, NumberVector.class);
  for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
    NumberVector v = relation.get(iter);
    double[] raw = v.toArray();
    if(!skip.contains(iter)) {
      applyScaling(raw, scaling);
    }
    contents.put(iter, factory.newNumberVector(raw, ArrayLikeUtil.DOUBLEARRAYADAPTER));
  }
  return new MaterializedRelation<>(relation.getDataTypeInformation(), ids, "rescaled", contents);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:27,代码来源:GreedyEnsembleExperiment.java

示例4: nextEvent

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
@Override
public Event nextEvent() {
  while(true) {
    Event ev = source.nextEvent();
    switch(ev){
    case END_OF_STREAM:
      return ev;
    case META_CHANGED:
      updateMeta(source.getMeta());
      return ev;
    case NEXT_OBJECT:
      if(densecols == null) {
        updateMeta(source.getMeta());
      }
      rows.clear();
      for(int j = 0; j < densecols.length; j++) {
        Object o = source.data(j);
        if(densecols[j] != null) {
          NumberVector v = (NumberVector) o;
          if(v == null) {
            continue;
          }
          double[] ro = null; // replacement
          for(int i = 0; i < v.getDimensionality(); i++) {
            if(Double.isNaN(v.doubleValue(i))) {
              ro = ro != null ? ro : v.toArray();
              ro[i] = dist.nextRandom();
            }
          }
          // If there was no NaN, ro will still be null.
          if(ro != null) {
            o = densecols[j].newNumberVector(ro);
          }
        }
        rows.add(o);
      }
      return ev;
    }
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:41,代码来源:ReplaceNaNWithRandomFilter.java

示例5: filter

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
@Override
public MultipleObjectsBundle filter(final MultipleObjectsBundle objects) {
  if(LOG.isDebuggingFinest()) {
    LOG.debugFinest("Removing records with NaN values.");
  }

  updateMeta(objects.meta());
  MultipleObjectsBundle bundle = new MultipleObjectsBundle();
  for(int j = 0; j < objects.metaLength(); j++) {
    bundle.appendColumn(objects.meta(j), new ArrayList<>());
  }
  for(int i = 0; i < objects.dataLength(); i++) {
    final Object[] row = objects.getRow(i);
    for(int j = 0; j < densecols.length; j++) {
      if(densecols[j] != null) {
        NumberVector v = (NumberVector) row[j];
        double[] ro = null; // replacement
        if(v != null) {
          for(int d = 0; d < v.getDimensionality(); d++) {
            if(Double.isNaN(v.doubleValue(d))) {
              if(ro != null) {
                ro = v.toArray();
              }
              ro[d] = dist.nextRandom();
            }
          }
        }
        row[j] = densecols[j].newNumberVector(ro);
      }
    }
    bundle.appendSimple(row);
  }
  return bundle;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:35,代码来源:ReplaceNaNWithRandomFilter.java

示例6: drawManhattan

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Wireframe "manhattan" hypersphere
 *
 * @param svgp SVG Plot
 * @param proj Visualization projection
 * @param mid mean vector
 * @param radius radius
 * @return path element
 */
public static Element drawManhattan(SVGPlot svgp, Projection2D proj, NumberVector mid, double radius) {
  final double[] v_mid = mid.toArray(); // a copy
  final long[] dims = proj.getVisibleDimensions2D();

  SVGPath path = new SVGPath();
  for(int dim = BitsUtil.nextSetBit(dims, 0); dim >= 0; dim = BitsUtil.nextSetBit(dims, dim + 1)) {
    v_mid[dim] += radius;
    double[] p1 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] -= radius;
    v_mid[dim] -= radius;
    double[] p2 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] += radius;
    for(int dim2 = BitsUtil.nextSetBit(dims, 0); dim2 >= 0; dim2 = BitsUtil.nextSetBit(dims, dim2 + 1)) {
      if(dim < dim2) {
        v_mid[dim2] += radius;
        double[] p3 = proj.fastProjectDataToRenderSpace(v_mid);
        v_mid[dim2] -= radius;
        v_mid[dim2] -= radius;
        double[] p4 = proj.fastProjectDataToRenderSpace(v_mid);
        v_mid[dim2] += radius;

        path.moveTo(p1[0], p1[1]);
        path.drawTo(p3[0], p3[1]);
        path.moveTo(p1[0], p1[1]);
        path.drawTo(p4[0], p4[1]);
        path.moveTo(p2[0], p2[1]);
        path.drawTo(p3[0], p3[1]);
        path.moveTo(p2[0], p2[1]);
        path.drawTo(p4[0], p4[1]);
        path.close();
      }
    }
  }
  return path.makeElement(svgp);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:45,代码来源:SVGHyperSphere.java

示例7: drawEuclidean

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Wireframe "euclidean" hypersphere
 *
 * @param svgp SVG Plot
 * @param proj Visualization projection
 * @param mid mean vector
 * @param radius radius
 * @return path element
 */
public static Element drawEuclidean(SVGPlot svgp, Projection2D proj, NumberVector mid, double radius) {
  double[] v_mid = mid.toArray(); // a copy
  long[] dims = proj.getVisibleDimensions2D();

  SVGPath path = new SVGPath();
  for(int dim = BitsUtil.nextSetBit(dims, 0); dim >= 0; dim = BitsUtil.nextSetBit(dims, dim + 1)) {
    v_mid[dim] += radius;
    double[] p1 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] -= radius;
    v_mid[dim] -= radius;
    double[] p2 = proj.fastProjectDataToRenderSpace(v_mid);
    v_mid[dim] += radius;
    // delta vector
    double[] dt1 = new double[v_mid.length];
    dt1[dim] = radius;
    double[] d1 = proj.fastProjectRelativeDataToRenderSpace(dt1);
    for(int dim2 = BitsUtil.nextSetBit(dims, 0); dim2 >= 0; dim2 = BitsUtil.nextSetBit(dims, dim2 + 1)) {
      if(dim < dim2) {
        v_mid[dim2] += radius;
        double[] p3 = proj.fastProjectDataToRenderSpace(v_mid);
        v_mid[dim2] -= radius;
        v_mid[dim2] -= radius;
        double[] p4 = proj.fastProjectDataToRenderSpace(v_mid);
        v_mid[dim2] += radius;
        // delta vector
        double[] dt2 = new double[v_mid.length];
        dt2[dim2] = radius;
        double[] d2 = proj.fastProjectRelativeDataToRenderSpace(dt2);

        path.moveTo(p1[0], p1[1]);
        path.cubicTo(p1[0] + d2[0] * EUCLIDEAN_KAPPA, p1[1] + d2[1] * EUCLIDEAN_KAPPA, p3[0] + d1[0] * EUCLIDEAN_KAPPA, p3[1] + d1[1] * EUCLIDEAN_KAPPA, p3[0], p3[1]);
        path.cubicTo(p3[0] - d1[0] * EUCLIDEAN_KAPPA, p3[1] - d1[1] * EUCLIDEAN_KAPPA, p2[0] + d2[0] * EUCLIDEAN_KAPPA, p2[1] + d2[1] * EUCLIDEAN_KAPPA, p2[0], p2[1]);
        path.cubicTo(p2[0] - d2[0] * EUCLIDEAN_KAPPA, p2[1] - d2[1] * EUCLIDEAN_KAPPA, p4[0] - d1[0] * EUCLIDEAN_KAPPA, p4[1] - d1[1] * EUCLIDEAN_KAPPA, p4[0], p4[1]);
        path.cubicTo(p4[0] + d1[0] * EUCLIDEAN_KAPPA, p4[1] + d1[1] * EUCLIDEAN_KAPPA, p1[0] - d2[0] * EUCLIDEAN_KAPPA, p1[1] - d2[1] * EUCLIDEAN_KAPPA, p1[0], p1[1]);
        path.close();
      }
    }
  }
  return path.makeElement(svgp);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:50,代码来源:SVGHyperSphere.java

示例8: drawCosine

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
/**
 * Visualizes Cosine and ArcCosine distance functions
 *
 * @param svgp SVG Plot
 * @param proj Visualization projection
 * @param mid mean vector
 * @param angle Opening angle in radians
 * @return path element
 */
public static Element drawCosine(SVGPlot svgp, Projection2D proj, NumberVector mid, double angle) {
  // Project origin
  double[] pointOfOrigin = proj.fastProjectDataToRenderSpace(new double[proj.getInputDimensionality()]);

  // direction of the selected Point
  double[] selPoint = proj.fastProjectDataToRenderSpace(mid);

  double[] range1, range2;
  {
    // Rotation plane:
    double[] p1 = proj.fastProjectRenderToDataSpace(selPoint[0] + 10, selPoint[1]);
    double[] p2 = proj.fastProjectRenderToDataSpace(selPoint[0], selPoint[1] + 10);
    double[] pm = mid.toArray();
    // Compute relative vectors
    minusEquals(p1, pm);
    minusEquals(p2, pm);
    // Scale p1 and p2 to unit length:
    timesEquals(p1, 1. / euclideanLength(p1));
    timesEquals(p2, 1. / euclideanLength(p2));
    {
      double test = scalarProduct(p1, p2);
      if(Math.abs(test) > 1E-10) {
        LoggingUtil.warning("Projection does not seem to be orthogonal?");
      }
    }
    // Project onto p1, p2:
    double l1 = scalarProduct(pm, p1), l2 = scalarProduct(pm, p2);
    // Rotate projection by + and - angle
    // Using sin(-x) = -sin(x) and cos(-x)=cos(x)
    final DoubleWrapper tmp = new DoubleWrapper(); // To return cosine
    final double sangle = FastMath.sinAndCos(angle, tmp), cangle = tmp.value;
    double r11 = +cangle * l1 - sangle * l2, r12 = +sangle * l1 + cangle * l2;
    double r21 = +cangle * l1 + sangle * l2, r22 = -sangle * l1 + cangle * l2;
    // Build rotated vectors - remove projected component, add rotated
    // component:
    double[] r1 = copy(pm), r2 = copy(pm);
    plusTimesEquals(r1, p1, -l1 + r11);
    plusTimesEquals(r1, p2, -l2 + r12);
    plusTimesEquals(r2, p1, -l1 + r21);
    plusTimesEquals(r2, p2, -l2 + r22);
    // Project to render space:
    range1 = proj.fastProjectDataToRenderSpace(r1);
    range2 = proj.fastProjectDataToRenderSpace(r2);
  }

  // Continue lines to viewport.
  {
    CanvasSize viewport = proj.estimateViewport();
    minusEquals(range1, pointOfOrigin);
    minusEquals(range2, pointOfOrigin);
    timesEquals(range1, viewport.continueToMargin(pointOfOrigin, range1));
    timesEquals(range2, viewport.continueToMargin(pointOfOrigin, range2));
    plusEquals(range1, pointOfOrigin);
    plusEquals(range2, pointOfOrigin);
    // Go backwards into the other direction - the origin might not be in the
    // viewport!
    double[] start1 = minus(pointOfOrigin, range1);
    double[] start2 = minus(pointOfOrigin, range2);
    timesEquals(start1, viewport.continueToMargin(range1, start1));
    timesEquals(start2, viewport.continueToMargin(range2, start2));
    plusEquals(start1, range1);
    plusEquals(start2, range2);

    // TODO: add filled variant?
    SVGPath path = new SVGPath();
    path.moveTo(start1);
    path.lineTo(range1);
    path.moveTo(start2);
    path.lineTo(range2);
    return path.makeElement(svgp);
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:82,代码来源:DistanceFunctionVisualization.java

示例9: norm

import de.lmu.ifi.dbs.elki.data.NumberVector; //导入方法依赖的package包/类
@Override
public double norm(NumberVector obj) {
  double[] v = obj.toArray();
  return transposeTimesTimes(v, weightMatrix, v);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:6,代码来源:MatrixWeightedQuadraticDistanceFunction.java


注:本文中的de.lmu.ifi.dbs.elki.data.NumberVector.toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。