本文整理汇总了Java中org.apache.mahout.math.RandomAccessSparseVector类的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessSparseVector类的具体用法?Java RandomAccessSparseVector怎么用?Java RandomAccessSparseVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RandomAccessSparseVector类属于org.apache.mahout.math包,在下文中一共展示了RandomAccessSparseVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: produceSamples
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public long produceSamples(List<Vector> target) throws Exception {
long numTotal = this.numSamples;
int centriodNum = genParams.length;
int numPerCluster = (int) Math.ceil((double) numTotal / (double) centriodNum);
LOG.info("Cluster number=" + centriodNum + " numbers per cluster=" + numPerCluster);
GaussianGenerator[] gg = new GaussianGenerator[dimension];
for (int k = 0; k < genParams.length; k++) {
if (genParams[k].length != dimension)
throw new Exception("The dimension of mean vector or std vector does not match desired dimension!");
for (int d = 0; d < dimension; d++) {
if (genParams[k][d].length != 2)
throw new Exception("The dimension of mean vector or std vector does not match desired dimension");
gg[d] = new GaussianGenerator(genParams[k][d][0], genParams[k][d][1], rng);
}
double[] vec = new double[dimension];
for (int i = 0; i < numPerCluster; i++) {
for (int d = 0; d < dimension; d++)
vec[d] = gg[d].nextValue();
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
target.add(p);
}
}
return numPerCluster * centriodNum;
}
示例2: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Override
protected void reduce(Text row, Iterable<VertexWritable> entries,
Context context) throws IOException, InterruptedException {
// now to assemble the vectors
RandomAccessSparseVector output = new RandomAccessSparseVector(
context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE), 100);
int rownum = Integer.parseInt(row.toString());
for (VertexWritable e : entries) {
// first, are we setting a diagonal?
if (e.getCol() == rownum) {
// add to what's already present
output.setQuick(e.getCol(), output.getQuick(e.getCol()) + e.getValue());
} else {
// simply set the value
output.setQuick(e.getCol(), e.getValue());
}
}
context.write(new IntWritable(rownum), new VectorWritable(output));
}
示例3: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Override
protected void reduce(IntWritable row, Iterable<DistributedRowMatrix.MatrixEntryWritable> values, Context context)
throws IOException, InterruptedException {
int size = context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE);
RandomAccessSparseVector out = new RandomAccessSparseVector(size, 100);
for (DistributedRowMatrix.MatrixEntryWritable element : values) {
out.setQuick(element.getCol(), element.getVal());
if (log.isDebugEnabled()) {
log.debug("(DEBUG - REDUCE) Row[{}], Column[{}], Value[{}]",
new Object[] {row.get(), element.getCol(), element.getVal()});
}
}
SequentialAccessSparseVector output = new SequentialAccessSparseVector(out);
context.write(row, new VectorWritable(output));
}
示例4: testMapper
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Test
public void testMapper() throws IOException{
Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE);
vector.set(6006, 1.0);vector.set(5987, 1.0);vector.set(4581,1.0);
mapDriver.withInput(new VarLongWritable(16),new VectorWritable(vector))
.withOutput(new IntWritable(6006), new IntWritable(6006))
.withOutput(new IntWritable(6006), new IntWritable(5987))
.withOutput(new IntWritable(6006), new IntWritable(4581))
.withOutput(new IntWritable(5987), new IntWritable(6006))
.withOutput(new IntWritable(5987), new IntWritable(5987))
.withOutput(new IntWritable(5987), new IntWritable(4581))
.withOutput(new IntWritable(4581), new IntWritable(6006))
.withOutput(new IntWritable(4581), new IntWritable(5987))
.withOutput(new IntWritable(4581), new IntWritable(4581))
.runTest();
}
开发者ID:faustineinsun,项目名称:MahoutHadoopUseCase,代码行数:17,代码来源:UserVectorToCooccurrenceMapReduceTest.java
示例5: testMapReduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Test
public void testMapReduce() throws RuntimeException, IOException{
Vector vectorInput = new RandomAccessSparseVector(Integer.MAX_VALUE);
vectorInput.set(6006, 1.0);vectorInput.set(5987, 1.0);vectorInput.set(4581,1.0);
Vector vectorOuput = new RandomAccessSparseVector(Integer.MAX_VALUE);
vectorOuput.set(5987, 1.0);vectorOuput.set(4581, 1.0);vectorOuput.set(6006,1.0);
mapReduceDriver.withInput(new VarLongWritable(16),new VectorWritable(vectorInput))
.withOutput(new IntWritable(4581), new VectorWritable(vectorOuput))
.withOutput(new IntWritable(5987), new VectorWritable(vectorOuput))
.withOutput(new IntWritable(6006), new VectorWritable(vectorOuput))
.runTest();
// Input : 16 {6006:1.0,5987:1.0,4581:1.0}
// Output : 4581, {6006:1.0,5987:1.0,4581:1.0}
// 5987, {6006:1.0,5987:1.0,4581:1.0}
// 6006, {6006:1.0,5987:1.0,4581:1.0}
}
开发者ID:faustineinsun,项目名称:MahoutHadoopUseCase,代码行数:19,代码来源:UserVectorToCooccurrenceMapReduceTest.java
示例6: buildVector
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public Vector buildVector(String s, Integer numFeature) {
s = s.toLowerCase();
Map<String, Integer> dict = new FeatureDictBuilder().readDictWithMI(numFeature);
Stemmer stemmer = new Stemmer();
ArrayList<String> stemResult = stemmer.stemInput(s);
Vector result = new RandomAccessSparseVector(dict.size());
for(int i = 0; i < dict.size(); i++) {
result.set(i, 0);
}
for(String word: stemResult) {
if (dict.containsKey(word)) {
result.set(dict.get(word), 1);
}
}
return result;
}
示例7: toString
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public String toString() {
Vector vector = new RandomAccessSparseVector(numFeatures);
double[] mixtureCoefficients = multiClassClassifier.predictClassProbs(vector);
final StringBuilder sb = new StringBuilder("CBM{\n");
sb.append("numLabels=").append(numLabels).append("\n");
sb.append("numComponents=").append(numComponents).append("\n");
for (int k = 0; k< numComponents; k++){
sb.append("cluster ").append(k).append(":\n");
sb.append("proportion = ").append(mixtureCoefficients[k]).append("\n");
}
sb.append("multi-class component = \n");
sb.append(multiClassClassifier);
sb.append("binary components = \n");
for (int k = 0; k< numComponents; k++){
for (int l=0;l<numLabels;l++){
sb.append("component ").append(k).append(" class ").append(l).append("\n");
sb.append(binaryClassifiers[k][l]).append("\n");
}
}
sb.append('}');
return sb.toString();
}
示例8: produceSamples
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public long produceSamples(List<Vector> target) throws Exception {
long numTotal = this.numSamples;
int centriodNum = genParams.length;
int numPerCluster = (int)Math.ceil((double)numTotal/(double)centriodNum);
LOG.info("Cluster number="+centriodNum+" numbers per cluster="+numPerCluster);
GaussianGenerator [] gg = new GaussianGenerator [dimension];
for (int k= 0; k<genParams.length; k++){
if(genParams[k].length != dimension)
throw new Exception("The dimension of mean vector or std vector does not match desired dimension!");
for (int d = 0; d<dimension; d++) {
if(genParams[k][d].length != 2) throw new Exception("The dimension of mean vector or std vector does not match desired dimension");
gg[d] = new GaussianGenerator(genParams[k][d][0],genParams[k][d][1],rng);
}
double [] vec = new double[dimension];
for(int i = 0; i<numPerCluster; i++){
for(int d = 0; d<dimension ; d++)
vec[d] = gg[d].nextValue();
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
target.add(p);
}
}
return numPerCluster*centriodNum;
}
示例9: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Override
public void reduce(VarLongWritable userID, Iterable<LongWritable> items,
Context context) throws IOException, InterruptedException {
Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 10);
int itemNum = 0;
for (LongWritable item : items) {
itemNum +=1;
userVector.set(Integer.parseInt(item.toString()), 1.0);
if (itemNum > 100) {
break;
}
}
if (itemNum < 101) {
context.write(userID, new VectorWritable(userVector));
}
/*
* Set<String> itemNum = new HashSet<String>(); for(LongWritable
* item:items){ itemNum.add(item.toString()); }
*
* context.write(userID, new Text(itemNum.toString()));
*/
}
示例10: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
@Override
protected void reduce(SimilarityMatrixEntryKey key, Iterable<DistributedRowMatrix.MatrixEntryWritable> entries,
Context ctx) throws IOException, InterruptedException
{
RandomAccessSparseVector temporaryVector = new RandomAccessSparseVector(Integer.MAX_VALUE,
maxSimilaritiesPerRow);
int similaritiesSet = 0;
for (DistributedRowMatrix.MatrixEntryWritable entry : entries)
{
temporaryVector.setQuick(entry.getCol(), entry.getVal());
if (++similaritiesSet == maxSimilaritiesPerRow)
{
break;
}
}
SequentialAccessSparseVector vector = new SequentialAccessSparseVector(temporaryVector);
ctx.write(new IntWritable(key.getRow()), new VectorWritable(vector));
}
示例11: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的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)));
}
示例12: getPoints
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public static List<Vector> getPoints(double[][] raw) {
List<Vector> points = new ArrayList<Vector>();
for (int i = 0; i < raw.length; i++) {
double[] fr = raw[i];
Vector vec = new RandomAccessSparseVector(fr.length);
vec.assign(fr);
points.add(vec);
}
return points;
}
示例13: map
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public void map(IntWritable key,
Text value,
OutputCollector<LongWritable, VectorWritable> output,
Reporter reporter) throws IOException {
try {
MersenneTwisterRNG rng = new MersenneTwisterRNG();
//create gussian generators based on seeds
GaussianGenerator[] gg = new GaussianGenerator[dimension];
String[] numbers = value.toString().split("\t");
int i = 0;
long numSamples = Long.parseLong(numbers[i++]);
for (int d = 0; d < dimension; d++) {
double mean = Double.parseDouble(numbers[i++]);
double std = Double.parseDouble(numbers[i++]);
LOG.info("dimension=" + d + ": mean=" + mean + ", std=" + std);
gg[d] = new GaussianGenerator(mean, std, rng);
}
//generate samples
double[] vec = new double[dimension];
for (long count = 0; count < numSamples; count++) {
for (int d = 0; d < dimension; d++)
vec[d] = gg[d].nextValue();
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
output.collect(new LongWritable(count), new VectorWritable(p));
reporter.setStatus(Long.toString(count + 1) + " samples generated");
reporter.incrCounter(HiBench.Counters.BYTES_DATA_GENERATED,
8 + p.getNumNondefaultElements() * 8);
}
} catch (Exception e) {
LOG.warn("Exception in GussianSampleGenerator.MapClass");
e.printStackTrace();
}
}
示例14: produceInitialCentroids
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
public int produceInitialCentroids(int numClusters, List<Vector> iCentroids) throws Exception {
//create iniital centroids
ContinuousUniformGenerator ug = new ContinuousUniformGenerator(this.cMin, this.cMax, rng);
double[] vec = new double[dimension];
for (int k = 0; k < numClusters; k++) {
for (int d = 0; d < dimension; d++) {
vec[d] = ug.nextValue();
}
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
iCentroids.add(p);
}
return numClusters;
}
示例15: AbstractCluster
import org.apache.mahout.math.RandomAccessSparseVector; //导入依赖的package包/类
protected AbstractCluster(Vector point, int id2) {
setNumObservations(0);
setTotalObservations(0);
setCenter(new RandomAccessSparseVector(point));
setRadius(center.like());
setS0(0);
setS1(center.like());
setS2(center.like());
this.id = id2;
}