• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Functions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.mahout.math.function.Functions的典型用法代码示例。如果您正苦于以下问题:Java Functions类的具体用法?Java Functions怎么用?Java Functions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Functions类属于org.apache.mahout.math.function包,在下文中一共展示了Functions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: reduce

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
public void reduce(CompositeWritable compositeId,
    Iterable<VectorWritable> vectors, Context context) throws IOException,
    InterruptedException {
  Iterator<VectorWritable> it = vectors.iterator();
  if (!it.hasNext()) {
    return;
  }
  //All XtX rows are mapped to the same key
  if (compositeId.isXtX()) {
    writeXtXToFile(vectors, xtxOutputPath);
    return;
  }
  //Reduce YtX
  Vector accumulator = it.next().get();
  while (it.hasNext()) {
    Vector row = it.next().get();
    accumulator.assign(row, Functions.PLUS);
  }
  iw.set(compositeId.rowId);
  vw.set(accumulator);
  context.write(iw, vw);
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:24,代码来源:CompositeJob.java


示例2: observe

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
public void observe(Vector x, double weight) {
  s0 += weight;
  Vector weightedX = x.times(weight);
  if (s1 == null) {
    s1 = weightedX;
  } else {
    s1.assign(weightedX, Functions.PLUS);
  }
  Vector x2 = x.times(x).times(weight);
  if (s2 == null) {
    s2 = x2;
  } else {
    s2.assign(x2, Functions.PLUS);
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:17,代码来源:RunningSumsGaussianAccumulator.java


示例3: observe

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
public void observe(Vector x, double weight) {
  if (weight == 1.0) {
    observe(x);
  } else {
    setS0(getS0() + weight);
    Vector weightedX = x.times(weight);
    if (getS1() == null) {
      setS1(weightedX);
    } else {
      getS1().assign(weightedX, Functions.PLUS);
    }
    Vector x2 = x.times(x).times(weight);
    if (getS2() == null) {
      setS2(x2);
    } else {
      getS2().assign(x2, Functions.PLUS);
    }
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:20,代码来源:AbstractCluster.java


示例4: performSensitivityCalculation

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
/**
 * Helper method, performs the actual calculation. Looks something like this:
 *
 * (log(2) / lambda_k * log(lambda_k) * log(lambda_k^beta0 / 2)) * [
 * - (((u_i / sqrt(d_i)) - (u_j / sqrt(d_j)))^2 + (1 - lambda) * 
 *   ((u_i^2 / d_i) + (u_j^2 / d_j))) ]
 */
private double performSensitivityCalculation(double eigenvalue,
                                             double evi,
                                             double evj,
                                             double diagi,
                                             double diagj) {
  
  double firsthalf = Functions.LOGARITHM.apply(2)
      / (eigenvalue * Functions.LOGARITHM.apply(eigenvalue)
         * Functions.LOGARITHM.apply(Functions.POW.apply(eigenvalue, beta0) / 2));
  
  double secondhalf =
      -Functions.POW.apply(evi / Functions.SQRT.apply(diagi) - evj / Functions.SQRT.apply(diagj), 2)
      + (1.0 - eigenvalue) * (Functions.POW.apply(evi, 2) / diagi + Functions.POW.apply(evj, 2) / diagj);
  
  return firsthalf * secondhalf;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:24,代码来源:EigencutsSensitivityMapper.java


示例5: TopicModel

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
public TopicModel(Matrix topicTermCounts, Vector topicSums, double eta, double alpha,
  String[] dictionary, int numThreads, double modelWeight) {
  this.dictionary = dictionary;
  this.topicTermCounts = topicTermCounts;
  this.topicSums = topicSums;
  this.numTopics = topicSums.size();
  this.numTerms = topicTermCounts.numCols();
  this.eta = eta;
  this.alpha = alpha;
  this.sampler = new Sampler(RandomUtils.getRandom());
  this.numThreads = numThreads;
  if (modelWeight != 1) {
    topicSums.assign(Functions.mult(modelWeight));
    for (int x = 0; x < numTopics; x++) {
      topicTermCounts.viewRow(x).assign(Functions.mult(modelWeight));
    }
  }
  initializeThreadPool();
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:20,代码来源:TopicModel.java


示例6: trainDocTopicModel

import org.apache.mahout.math.function.Functions; //导入依赖的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


示例7: reduce

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context) throws IOException,
        InterruptedException {

  Vector vector = null;
  for (VectorWritable value : values) {
    if (vector == null) {
      vector = value.get().clone();
      continue;
    }
    //value.get().addTo(vector);
    vector.assign(value.get(), Functions.PLUS);
  }

  if (normPower != PartialVectorMerger.NO_NORMALIZING) {
    if (logNormalize) {
      vector = vector.logNormalize(normPower);
    } else {
      vector = vector.normalize(normPower);
    }
  }

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


示例8: map

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
/**
 * The mapper computes a running sum of the vectors the task has seen.
 * Element 0 of the running sum vector contains a count of the number of
 * vectors that have been seen. The remaining elements contain the
 * column-wise running sum. Nothing is written at this stage
 */
@Override
public void map(Writable r, VectorWritable v, Context context)
		throws IOException {
	if (runningSum == null) {
		/*
		 * If this is the first vector the mapper has seen, instantiate
		 * a new vector using the parameter VECTOR_CLASS
		 */
		runningSum = ClassUtils.instantiateAs(vectorClass,
				Vector.class, new Class<?>[] { int.class },
				new Object[] { v.get().size() + 1 });
		runningSum.set(0, 1);
		runningSum.viewPart(1, v.get().size()).assign(v.get());
	} else {
		runningSum.set(0, runningSum.get(0) + 1);
		runningSum.viewPart(1, v.get().size()).assign(v.get(),
				Functions.PLUS);
	}
}
 
开发者ID:cdgore,项目名称:Ankus,代码行数:26,代码来源:MahoutColumnMeans.java


示例9: reduce

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
public void reduce(IntWritable rowNum, Iterator<VectorWritable> it,
    OutputCollector<IntWritable, VectorWritable> out, Reporter reporter)
    throws IOException {

  if (!it.hasNext()) {
    return;
  }

  Vector accumulator = new RandomAccessSparseVector(it.next().get());
  while (it.hasNext()) {
    Vector row = it.next().get();
    accumulator.assign(row, Functions.PLUS);
  }

  out.collect(rowNum, new VectorWritable(new SequentialAccessSparseVector(
      accumulator)));
}
 
开发者ID:millecker,项目名称:applications,代码行数:19,代码来源:MatrixMultiplicationCpu.java


示例10: map

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
protected void map(IntWritable row, VectorWritable vector, Context context) 
  throws IOException, InterruptedException {
  
  // set up the return value and perform the computations
  double norm = vectorNorm(vector.get());
  Vector w = vector.get().assign(Functions.div(norm));
  RandomAccessSparseVector out = new RandomAccessSparseVector(w);
  
  // finally write the output
  context.write(row, new VectorWritable(out));
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:13,代码来源:UnitVectorizerJob.java


示例11: vectorNorm

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
/**
 * Sums the squares of all elements together, then takes the square root
 * of that sum.
 * @param u
 * @return
 */
private static double vectorNorm(Iterable<Vector.Element> u) {
  double retval = 0.0;
  for (Vector.Element e : u) {
    retval += Functions.POW.apply(e.get(), 2);
  }
  return Functions.SQRT.apply(retval);
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:14,代码来源:UnitVectorizerJob.java


示例12: map

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
protected void map(IntWritable key, VectorWritable row, Context ctx) 
  throws IOException, InterruptedException {
  
  for (Vector.Element e : row.get()) {
    double dii = Functions.SQRT.apply(diagonal.get(key.get()));
    double djj = Functions.SQRT.apply(diagonal.get(e.index()));
    double mij = e.get();
    e.set(dii * mij * djj);
  }
  ctx.write(key, row);
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:13,代码来源:VectorMatrixMultiplicationJob.java


示例13: update

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
public void update(int termId, Vector topicCounts) {
  for (int x = 0; x < numTopics; x++) {
    Vector v = topicTermCounts.viewRow(x);
    v.set(termId, v.get(termId) + topicCounts.get(x));
  }
  topicSums.assign(topicCounts, Functions.PLUS);
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:8,代码来源:TopicModel.java


示例14: reduce

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context ctx)
  throws IOException, InterruptedException {
  Vector vector = null;
  for (VectorWritable v : values) {
    if (vector == null) {
      vector = v.get();
    } else {
      vector.assign(v.get(), Functions.PLUS);
    }
  }
  ctx.write(key, new VectorWritable(vector));
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:14,代码来源:VectorSumReducer.java


示例15: reduce

import org.apache.mahout.math.function.Functions; //导入依赖的package包/类
@Override
public void reduce(NullWritable n, Iterable<VectorWritable> vectors,
		Context context) throws IOException, InterruptedException {

	/**
	 * Add together partial column-wise sums from mappers
	 */
	for (VectorWritable v : vectors) {
		if (outputVector == null) {
			outputVector = v.get();
		} else {
			outputVector.assign(v.get(), Functions.PLUS);
		}
	}

	/**
	 * Divide total column-wise sum by count of vectors, which
	 * corresponds to the number of rows in the DistributedRowMatrix
	 */
	if (outputVector != null) {
		outputVectorWritable.set(outputVector.viewPart(1,
				outputVector.size() - 1).divide(outputVector.get(0)));
		context.write(ONE, outputVectorWritable);
	} else {
		Vector emptyVector = ClassUtils.instantiateAs(vectorClass,
				Vector.class, new Class<?>[] { int.class },
				new Object[] { 0 });
		context.write(ONE, new VectorWritable(emptyVector));
	}
}
 
开发者ID:cdgore,项目名称:Ankus,代码行数:31,代码来源:MahoutColumnMeans.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SiddhiParserException类代码示例发布时间:2022-05-22
下一篇:
Java UDPNetSyslogServerConfig类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap