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


Java Vector.setQuick方法代码示例

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


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

示例1: updateMinMax

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
 * Man and Max over sparse vector skip over zero elements. We take the zero
 * elements into account in this method.
 * 
 * @param minV
 *          the min
 * @param maxV
 *          the max
 * @param cntV
 *          the number of non-zero elements
 * @param total
 *          number of processed rows
 */
private void updateMinMax(Vector minV, Vector maxV, Vector cntV, int total) {
  for (int i = 0; i < cntV.size(); i++) {
    int cnt = (int) cntV.getQuick(i);
    if (cnt != total) {
      // this implies that there was a zero element not counted in
      // computing min and max. So, we count it in now.
      double min = minV.getQuick(i);
      double max = maxV.getQuick(i);
      min = Math.min(min, 0);
      max = Math.max(max, 0);
      minV.setQuick(i, min);
      maxV.setQuick(i, max);
    }
  }
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:29,代码来源:MeanAndSpanJob.java

示例2: vectorAssign

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
 * This method overrides the Vector.assign method to allow optimization for
 * ZeroIndifferent functions
 * 
 * @param vector
 *          the vector to be updated
 * @param other
 *          the other vector
 * @param function
 *          the function that operates on elements of the two vectors
 * @return the modified vector
 */
static public Vector vectorAssign(Vector vector, Vector other, ZeroIndifferentFunc function) {
  if (vector.size() != other.size()) {
    throw new CardinalityException(vector.size(), other.size());
  }
  // special case: iterate only over the non-zero elements of the vector to
  // add
  Iterator<Element> it = other.nonZeroes().iterator();
  Element e;
  while (it.hasNext() && (e = it.next()) != null) {
    double val = vector.getQuick(e.index());
    double newVal = function.apply(val, e.get());
    vector.setQuick(e.index(), newVal);
  }
  return vector;
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:28,代码来源:MeanAndSpanJob.java

示例3: trainDocTopicModel

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
public void trainDocTopicModel(Vector original, Vector topics, Matrix docTopicModel) {
  // first calculate p(topic|term,document) for all terms in original, and all topics,
  // using p(term|topic) and p(topic|doc)
  pTopicGivenTerm(original, topics, docTopicModel);
  normalizeByTopic(docTopicModel);
  // now multiply, term-by-term, by the document, to get the weighted distribution of
  // term-topic pairs from this document.
  Iterator<Vector.Element> it = original.iterateNonZero();
  while (it.hasNext()) {
    Vector.Element e = it.next();
    for (int x = 0; x < numTopics; x++) {
      Vector docTopicModelRow = docTopicModel.viewRow(x);
      docTopicModelRow.setQuick(e.index(), docTopicModelRow.getQuick(e.index()) * e.get());
    }
  }
  // now recalculate p(topic|doc) by summing contributions from all of pTopicGivenTerm
  topics.assign(0.0);
  for (int x = 0; x < numTopics; x++) {
    topics.set(x, docTopicModel.viewRow(x).norm(1));
  }
  // now renormalize so that sum_x(p(x|doc)) = 1
  topics.assign(Functions.mult(1/topics.norm(1)));
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:24,代码来源:TopicModel.java

示例4: reduce

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
protected void reduce(NullWritable key, Iterable<IntDoublePairWritable> values,
  Context context) throws IOException, InterruptedException {
  // create the return vector
  Vector retval = new DenseVector(context.getConfiguration().getInt(
      EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE));
  // put everything in its correct spot
  for (IntDoublePairWritable e : values) {
    retval.setQuick(e.getKey(), e.getValue());
  }
  // write it out
  context.write(key, new VectorWritable(retval));
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigData-Max,代码行数:14,代码来源:MatrixDiagonalizeJob.java

示例5: reduce

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context)
        throws IOException, InterruptedException {
  Iterator<VectorWritable> it = values.iterator();
  if (!it.hasNext()) {
    return;
  }
  Vector value = it.next().get();
  Vector vector = value.clone();
  if (maxDf > -1) {
    Iterator<Vector.Element> it1 = value.iterateNonZero();
    while (it1.hasNext()) {
      Vector.Element e = it1.next();
      if (!dictionary.containsKey(e.index())) {
        vector.setQuick(e.index(), 0.0);
        continue;
      }
      long df = dictionary.get(e.index());
      if (df > maxDf) {
        vector.setQuick(e.index(), 0.0);
      }
    }
  }

  VectorWritable vectorWritable = new VectorWritable(vector);
  context.write(key, vectorWritable);
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigData-Max,代码行数:28,代码来源:WordsPrunerReducer.java

示例6: listToVector

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
 * Iteratively loops through the list, converting it to a Vector of double
 * primitives worthy of other Mahout operations
 */
private static Vector listToVector(Collection<Double> list) {
  Vector retval = new DenseVector(list.size());
  int index = 0;
  for (Double d : list) {
    retval.setQuick(index++, d);
  }
  return retval;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:13,代码来源:EigencutsDriver.java

示例7: reduce

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
protected void reduce(IntWritable key, Iterable<EigencutsSensitivityNode> arr, Context context)
  throws IOException, InterruptedException {
  Configuration conf = context.getConfiguration();
  Vector v = new RandomAccessSparseVector(conf.getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE), 100);
  double threshold = Double.parseDouble(conf.get(EigencutsKeys.TAU))
      / Double.parseDouble(conf.get(EigencutsKeys.DELTA));
  
  for (EigencutsSensitivityNode n : arr) {
    if (n.getSensitivity() < threshold && n.getSensitivity() < v.getQuick(n.getColumn())) {
      v.setQuick(n.getColumn(), n.getSensitivity());
    }
  }
  context.write(key, new VectorWritable(v));
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:16,代码来源:EigencutsSensitivityReducer.java

示例8: sampleFromPrior

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public Model<VectorWritable>[] sampleFromPrior(int howMany) {
  Model<VectorWritable>[] result = new DistanceMeasureCluster[howMany];
  Vector prototype = getModelPrototype().get().like();
  for (int i = 0; i < prototype.size(); i++) {
    prototype.setQuick(i, UncommonDistributions.rNorm(0, 1));
  }
  for (int i = 0; i < howMany; i++) {
    result[i] = new DistanceMeasureCluster(prototype, i, measure);
  }
  return result;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigData-Ave,代码行数:13,代码来源:DistanceMeasureClusterDistribution.java

示例9: classifyFull

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
 * Returns n probabilities, one for each category into a pre-allocated vector.  One
 * vector allocation is still done in the process of multiplying by the coefficient
 * matrix, but that is hard to avoid.  The cost of such an ephemeral allocation is
 * very small in any case compared to the multiplication itself.
 *
 * @param r        Where to put the results.
 * @param instance A vector of features to be classified.
 * @return A vector of probabilities, one for each category.
 */
public Vector classifyFull(Vector r, Vector instance) {
  r.viewPart(1, numCategories() - 1).assign(classify(instance));
  r.setQuick(0, 1.0 - r.zSum());
  return r;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:16,代码来源:AbstractVectorClassifier.java


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