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


Java Vector.assign方法代码示例

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


在下文中一共展示了Vector.assign方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: produceSamples

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

}
 
开发者ID:thrill,项目名称:fst-bench,代码行数:27,代码来源:GenKMeansDataset.java

示例2: reduce

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

示例3: TopicModel

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

示例4: trainDocTopicModel

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

示例5: reduce

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

示例6: getPoints

import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
 
开发者ID:thrill,项目名称:fst-bench,代码行数:11,代码来源:GenKMeansDataset.java

示例7: map

import org.apache.mahout.math.Vector; //导入方法依赖的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();
    }
}
 
开发者ID:thrill,项目名称:fst-bench,代码行数:37,代码来源:GenKMeansDataset.java

示例8: produceInitialCentroids

import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
 
开发者ID:thrill,项目名称:fst-bench,代码行数:15,代码来源:GenKMeansDataset.java

示例9: testMAHOUT_1221

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Test
public void testMAHOUT_1221() {
  // create a matrix with an unassigned row 0
  Matrix matrix = new SparseMatrix(1, 1);
  Vector view = matrix.viewRow(0);
  final double value = 1.23;
  view.assign(value);
  // test whether the update in the view is reflected in the matrix
  assertEquals("Matrix valye", view.getQuick(0), matrix.getQuick(0, 0),
      EPSILON);
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:12,代码来源:MahoutCompatibilityTest.java

示例10: classify

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public Vector classify(Vector data, ClusterClassifier prior) {
  List<Cluster> models = prior.getModels();
  int i = 0;
  Vector pdfs = new DenseVector(models.size());
  for (Cluster model : models) {
    pdfs.set(i++, model.pdf(new VectorWritable(data)));
  }
  return pdfs.assign(new TimesFunction(), 1.0 / pdfs.zSum());
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:11,代码来源:AbstractClusteringPolicy.java

示例11: reduce

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

示例12: main

import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
public static void main(String args[]) throws FileNotFoundException, IOException {

        String input = args[0];
        String output = args[1];
        Configuration conf;
        conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        InputStream is = null;
        
        if (args.length>2 && args[2].equals("localInput")){
            System.out.println("Using local file "+input);
            is=(new FileInputStream( new File(input)));
        }            
        else{
            System.out.println("Using HDFS file "+input);
            is=fs.open(new Path(input));
        }

        try (
                BufferedReader reader =  new BufferedReader(new InputStreamReader(is));
                SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, new Path(output), IntWritable.class, VectorWritable.class)) {
            String line;
            int counter = 0;
            while ((line = reader.readLine()) != null) {
                String[] c = line.split(",");
                if (c.length > 1) {
                    double[] d = new double[c.length];
                    for (int i = 0; i < c.length; i++) {
                        d[i] = Double.parseDouble(c[i]);
                    }
                    Vector vec = new RandomAccessSparseVector(c.length);
                    vec.assign(d);

                    VectorWritable writable = new VectorWritable();
                    writable.set(vec);
                    writer.append(new IntWritable(counter++), writable);
                }
            }
            writer.close();
        }
    }
 
开发者ID:project-asap,项目名称:IReS-Platform,代码行数:42,代码来源:CSVLoader.java


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