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


Java Element类代码示例

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


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


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