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

Java Element类代码示例

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

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



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

示例1: vectorAssign

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


示例2: printSequenceFile

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private static void printSequenceFile(String inputStr, int printRow) throws IOException {
  Configuration conf = new Configuration();
  Path finalNumberFile = new Path(inputStr);
  SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(conf),
      finalNumberFile, conf);
  IntWritable key = new IntWritable();
  VectorWritable value = new VectorWritable();
  Vector printVector = null;
  while (reader.next(key, value)) {
    if (key.get() == printRow)
      printVector = value.get();
    int cnt = 0;
    Iterator<Element> iter = value.get().nonZeroes().iterator();
    for (; iter.hasNext(); iter.next())
      cnt++;
    System.out.println("# "+ key + " " + cnt + " " + value.get().zSum());
  }
  reader.close();
  if (printVector != null)
    System.out.println("##### "+ printRow + " " + printVector);
  else
    System.out.println("##### "+ key + " " + value.get());
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:24,代码来源:TestSequenceFile.java


示例3: nextVector

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
@Override
public MySparseVector nextVector() throws IOException {
   
    if(!vecIterator.hasNext()) return null;
    
    Pair<Text, VectorWritable> entry = vecIterator.next();
    
    String name = entry.getFirst().toString();
    VectorWritable mahoutVector = entry.getSecond();
    
    ArrayList<Integer> indices = new ArrayList();
    ArrayList<Double> values = new ArrayList();
    
    for(Element e: mahoutVector.get().all()){
        double value =e.get();
        if (value==0) continue;
        values.add(value);
        int index= e.index();
        indices.add(index);            
    }
    
    return new MySparseVector(indices, values);
    
}
 
开发者ID:project-asap,项目名称:IReS-Platform,代码行数:25,代码来源:MahoutInput.java


示例4: train

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
public Vector train(Vector datapoint) {
	this.initializeAtoms(datapoint);		
	Vector projection = this.transformer.transform(datapoint, this.dictionaryMatrix);

	for (int i=0; i < this.numberOfAtoms; i++) {
		Vector atom = this.dictionaryMatrix.viewColumn(i);
		double projectionWeight = projection.get(i);
		Vector difference = atom.minus(datapoint);
		for (Element elem : difference.nonZeroes()) {
			atom.incrementQuick(elem.index(), - this.learningRate * projectionWeight * elem.get());
		}
	}
	this.regularize();
	this.transformer.clearCaches();		
	
	return projection;
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:18,代码来源:DictionaryLearner.java


示例5: regularize

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private void regularize() {
	for (int i=0; i < this.numberOfAtoms; i++) {
		Vector atom = this.dictionaryMatrix.viewColumn(i);
		List<Integer> indicesToRemove = new ArrayList<Integer>();
		for (Element elem : atom.nonZeroes()) {
			double regularizedValue = elem.get() - (this.learningRate 
					* (elem.get() 
							* this.l2Penalty
							+ this.l1Penalty * Math.signum(elem.get())));
			if (regularizedValue == 0.0 || Math.abs(regularizedValue) < this.l1Penalty) {
				indicesToRemove.add(elem.index());
			} else {
				atom.setQuick(elem.index(), regularizedValue);
			}
		}
		for (int indexToRemove : indicesToRemove) {
			atom.setQuick(indexToRemove, 0.0);
		}
	}
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:21,代码来源:DictionaryLearner.java


示例6: printDistributedRowMatrix

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
public int printDistributedRowMatrix() {
  System.out.println("RowPath: " + this.rowPath);
  Iterator<MatrixSlice> iterator = this.iterateAll();
  int count = 0;
  while (iterator.hasNext()) {
    MatrixSlice slice = iterator.next();
    Vector v = slice.vector();
    int size = v.size();
    for (int i = 0; i < size; i++) {
      Element e = v.getElement(i);
      count++;
      System.out.print(e.get() + " ");
    }
    System.out.println();
  }
  return count;
}
 
开发者ID:millecker,项目名称:applications,代码行数:18,代码来源:DistributedRowMatrix.java


示例7: computePrincipalComponents

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
/**
 * Compute principal component analysis where the input is a path for a hadoop sequence File <IntWritable key, VectorWritable value>
 * @param sc 
 * 	 		Spark context that contains the configuration parameters and represents connection to the cluster 
 * 			(used to create RDDs, accumulators and broadcast variables on that cluster)
 * @param inputPath
 * 			Path to the sequence file that represents the input matrix
 * @param nRows
 * 			Number of rows in input Matrix
 * @param nCols
 * 			Number of columns in input Matrix
 * @param nPCs
 * 			Number of desired principal components
 * @param errRate
 * 			The sampling rate that is used for computing the reconstruction error
 * @param maxIterations 
 * 			Maximum number of iterations before terminating
 * @return Matrix of size nCols X nPCs having the desired principal components
 */
public static org.apache.spark.mllib.linalg.Matrix computePrincipalComponents(JavaSparkContext sc, String inputPath, String outputPath, final int nRows, final int nCols, final int nPCs, final double errRate, final int maxIterations, final int computeProjectedMatrix) {
  

//Read from sequence file
JavaPairRDD<IntWritable,VectorWritable> seqVectors = sc.sequenceFile(inputPath, IntWritable.class, VectorWritable.class);
	   
	   
//Convert sequence file to RDD<org.apache.spark.mllib.linalg.Vector> of Vectors
JavaRDD<org.apache.spark.mllib.linalg.Vector> vectors=seqVectors.map(new Function<Tuple2<IntWritable,VectorWritable>, org.apache.spark.mllib.linalg.Vector>() {

              public org.apache.spark.mllib.linalg.Vector call(Tuple2<IntWritable, VectorWritable> arg0)
                              throws Exception {

                org.apache.mahout.math.Vector mahoutVector = arg0._2.get();
                Iterator<Element> elements =  mahoutVector.nonZeroes().iterator();
                ArrayList<Tuple2<Integer, Double>> tupleList = new  ArrayList<Tuple2<Integer, Double>>();
                while(elements.hasNext())
                {
                         Element e = elements.next();
                         if(e.index() >= nCols || e.get() == 0 )
                            continue;
                         Tuple2<Integer,Double> tuple = new Tuple2<Integer,Double>(e.index(), e.get());
                         tupleList.add(tuple);
                }
                org.apache.spark.mllib.linalg.Vector sparkVector = Vectors.sparse(nCols,tupleList);
                return sparkVector;
          }
}).persist(StorageLevel.MEMORY_ONLY_SER());

return computePrincipalComponents(sc, vectors, outputPath, nRows, nCols, nPCs, errRate, maxIterations, computeProjectedMatrix);
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:51,代码来源:SparkPCA.java


示例8: computeProd2piR

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
/**
 * Compute the product(r[i]*SQRT2PI) over all i. Note that the cluster Radius
 * corresponds to the Stdev of a Gaussian and the Center to its Mean.
 */
private void computeProd2piR() {
  zProd2piR = 1.0;
  for (Iterator<Element> it = getRadius().iterateNonZero(); it.hasNext();) {
    Element radius = it.next();
    zProd2piR *= radius.get() * UncommonDistributions.SQRT2PI;
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:12,代码来源:GaussianCluster.java


示例9: sumXminusCdivRsquared

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
/**
 * @param x
 *          a Vector
 * @return the zSum(((x[i]-c[i])/r[i])^2) over all i
 */
private double sumXminusCdivRsquared(Vector x) {
  double result = 0;
  for (Iterator<Element> it = getRadius().iterateNonZero(); it.hasNext();) {
    Element radiusElem = it.next();
    int index = radiusElem.index();
    double quotient = (x.get(index) - getCenter().get(index))
        / radiusElem.get();
    result += quotient * quotient;
  }
  return result;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:17,代码来源:GaussianCluster.java


示例10: writeAllAboveThreshold

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private static void writeAllAboveThreshold(List<Cluster> clusterModels, Double clusterClassificationThreshold,
    SequenceFile.Writer writer, VectorWritable vw, Vector pdfPerCluster) throws IOException {
  Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
  while (iterateNonZero.hasNext()) {
    Element pdf = iterateNonZero.next();
    if (pdf.get() >= clusterClassificationThreshold) {
      WeightedVectorWritable wvw = new WeightedVectorWritable(pdf.get(), vw.get());
      int clusterIndex = pdf.index();
      write(clusterModels, writer, wvw, clusterIndex);
    }
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:13,代码来源:ClusterClassificationDriver.java


示例11: writeAllAboveThreshold

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private void writeAllAboveThreshold(VectorWritable vw, Context context,
    Vector pdfPerCluster) throws IOException, InterruptedException {
  Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
  while (iterateNonZero.hasNext()) {
    Element pdf = iterateNonZero.next();
    if (pdf.get() >= threshold) {
      int clusterIndex = pdf.index();
      write(vw, context, clusterIndex, pdf.get());
    }
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:12,代码来源:ClusterClassificationMapper.java


示例12: map

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
@Override
protected void map(WritableComparable<?> key, VectorWritable value, Context context) throws IOException,
    InterruptedException {
  Vector probabilities = classifier.classify(value.get());
  Vector selections = policy.select(probabilities);
  for (Iterator<Element> it = selections.iterateNonZero(); it.hasNext();) {
    Element el = it.next();
    classifier.train(el.index(), value.get(), el.get());
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:11,代码来源:CIMapper.java


示例13: distance

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
/**
 *  Math.pow is clever about integer-valued doubles
 */
@Override
public double distance(Vector v1, Vector v2) {
  Vector distVector = v1.minus(v2);
  double sum = 0.0;
  Iterator<Element> it = distVector.iterateNonZero();
  while (it.hasNext()) {
    Element e = it.next();
    sum += Math.pow(Math.abs(e.get()), exponent);
  }
  return Math.pow(sum, 1.0 / exponent);
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:15,代码来源:MinkowskiDistanceMeasure.java


示例14: computeAverageNonzeroElementRank

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
public static double computeAverageNonzeroElementRank(Vector inputVector, Vector ranking) {
    RankMap rankMap = getRankMap(ranking);
    double averageRank = 0.0;
    for (Element elem : inputVector.nonZeroes()) {
        averageRank += rankMap.get(elem.index());
    }
    averageRank = averageRank / inputVector.getNumNonZeroElements();
    return averageRank;
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:10,代码来源:EvaluationUtils.java


示例15: transposedDictionaryTimesDatapoint

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
public static Vector transposedDictionaryTimesDatapoint(SparseColumnMatrix dictionary, Vector datapoint) {
	Vector output = new DenseVector(dictionary.numCols());
	for (int i=0; i < dictionary.numCols(); i++) {
		Vector row = dictionary.viewColumn(i);
		double value = 0.0;
		for (Element elem : row.nonZeroes()) {
			value = value + elem.get() * datapoint.get(elem.index());
		}
		output.setQuick(i, value);
	}
	return output;
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:13,代码来源:MathUtils.java


示例16: inverseTransform

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
public static Vector inverseTransform(SparseColumnMatrix dictionary, Vector projection) {
	Vector output = new RandomAccessSparseVector(dictionary.numRows());
	for (int i=0; i < dictionary.numCols(); i++) {
		Vector atom = dictionary.viewColumn(i);
		double projectionWeight = projection.get(i);
		for (Element elem : atom.nonZeroes()) {
			output.incrementQuick(elem.index(), elem.get() * projectionWeight);
		}
	}
	return output;
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:12,代码来源:MathUtils.java


示例17: sparsifyData

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private static Matrix sparsifyData(Matrix denseData, int cardinality) {
	ArrayList<Vector> vectors = new ArrayList<Vector>();
	for (Vector denseVector : denseData) {
		Vector sparsefiedVector = new RandomAccessSparseVector(cardinality);
		for (Element elem : denseVector.nonZeroes()) {
			sparsefiedVector.set(elem.index(), elem.get());
		}
		vectors.add(sparsefiedVector);
	}
	return new SparseRowMatrix(vectors.size(), cardinality, vectors.toArray(new Vector[3]));
}
 
开发者ID:maciejkula,项目名称:dictionarylearning,代码行数:12,代码来源:DictionaryLearningTestCase.java


示例18: writeAllAboveThreshold

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private void writeAllAboveThreshold(WritableComparable<?> key, Context context,
    Vector pdfPerCluster) throws IOException, InterruptedException {
  for (Element pdf : pdfPerCluster.nonZeroes()) {
    if (pdf.get() >= threshold) {
      int clusterIndex = pdf.index();
      write(key, context, clusterIndex, pdf.get());
    }
  }
}
 
开发者ID:pgorecki,项目名称:visearch,代码行数:10,代码来源:ImageToTextMapper.java


示例19: writeAllAboveThreshold

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
private static void writeAllAboveThreshold(List<Cluster> clusterModels,
		Double clusterClassificationThreshold, SequenceFile.Writer writer,
		Text key, Vector pdfPerCluster) throws IOException {
	for (Element pdf : pdfPerCluster.nonZeroes()) {
		if (pdf.get() >= clusterClassificationThreshold) {
			int clusterIndex = pdf.index();
			write(clusterModels, writer, key, clusterIndex);
			// nie ma sensu zapisywac wiecej niz 1, bo i tak nie zapisujemy
			// wagi
			break;
		}
	}
}
 
开发者ID:pgorecki,项目名称:visearch,代码行数:14,代码来源:ImageToTextDriver.java


示例20: map

import org.apache.mahout.math.Vector.Element; //导入依赖的package包/类
@Override
public void map(IntWritable key, VectorWritable value, Context context) throws IOException, InterruptedException
{

	Vector similarityMatrixRow = value.get();

	// Remove self similarity
	similarityMatrixRow.set(key.get(), Double.NEGATIVE_INFINITY); // from the equation

	// determine max non-zero element: (==item index)
	List<RecommendationElement> recommendations = new ArrayList<RecommendationElement>();

	// collect non-zero items:
	Iterator<Element> it = similarityMatrixRow.iterateNonZero();
	while (it.hasNext())
	{
		Element e = it.next();
		recommendations.add(new RecommendationElement(e.index(), e.get()));
		// LOG.info("created new recommendation for " + e.index());
	}

	// sorted list of recommendations: now we have an item id, and similarity value:
	Collections.sort(recommendations, new SimilarityComparator());
	LOG.info("sorted: " + recommendations.size());

	int rank = 1;
	Put put = new Put(RowKeys.getRecommendationKey(collection, recommender, key.get()));
	for (RecommendationElement el : recommendations)
	{
		// if (el.getSimilarityValue() > 0)
		// {
		byte[] data = Recommend.getRecommendation(el.getItemIndex(), rank, el.getSimilarityValue());
		put.add(RECOMMENDATION_COLUMN, Bytes.toBytes(rank), data);
		rank++;
		// }
	}
	context.write(new LongWritable(key.get()), put);

}
 
开发者ID:beeldengeluid,项目名称:zieook,代码行数:40,代码来源:RecommendationsImportMap.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java GradientFill类代码示例发布时间:2022-05-22
下一篇:
Java LoopItem类代码示例发布时间: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