本文整理汇总了Java中org.apache.mahout.math.Vector.Element.get方法的典型用法代码示例。如果您正苦于以下问题:Java Element.get方法的具体用法?Java Element.get怎么用?Java Element.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector.Element
的用法示例。
在下文中一共展示了Element.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
}
示例3: 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;
}
}
示例4: 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;
}
示例5: 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);
}
}
}
示例6: 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());
}
}
}
示例7: 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;
}
示例8: 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());
}
}
}
示例9: 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;
}
}
}
示例10: compare
import org.apache.mahout.math.Vector.Element; //导入方法依赖的package包/类
@Override
public int compare(Element a, Element b) {
return a.get() < b.get() ? 1 : a.get() == b.get() ? 0 : -1;
}
示例11: map
import org.apache.mahout.math.Vector.Element; //导入方法依赖的package包/类
@Override
protected void map(IntWritable key, VectorWritable value, Context context) throws IOException, InterruptedException
{
int maxIndex = -1;
Vector similarityMatrixRow = value.get();
/* remove self similarity */
similarityMatrixRow.set(key.get(), Double.NEGATIVE_INFINITY);
//
// determine maximum index
//
Iterator<Element> it = similarityMatrixRow.iterateNonZero();
while (it.hasNext())
{
Element e = it.next();
// e.index() // == item id
if (e.index() > maxIndex)
{
maxIndex = e.index();
}
}
// System.out.println(String.format("key: %d maxIndex: %d", key.get(), maxIndex));
if (maxIndex > 0)
{
RecommendationElement[] itemBasedRecommendations = new RecommendationElement[maxIndex];
for (int i = 0; i < maxIndex; i++)
{
Element element = similarityMatrixRow.getElement(i);
double similarityValue = Double.NEGATIVE_INFINITY;
if (element != null)
{
similarityValue = element.get();
}
itemBasedRecommendations[i] = new RecommendationElement(i, similarityValue);
}
Arrays.sort(itemBasedRecommendations, new SimilarityComparator());
RecommendationElementArray array = new RecommendationElementArray(itemBasedRecommendations);
context.write(new VarIntWritable(key.get()), array);
}
}