Package org.apache.mahout.math

Examples of org.apache.mahout.math.RandomAccessSparseVector


   * @param canopyId
   *          an int identifying the canopy local to this process only
   */
  public Canopy(Vector point, int canopyId) {
    this.setId(canopyId);
    this.setCenter(new RandomAccessSparseVector(point.clone()));
    this.setPointTotal(getCenter().clone());
    this.setNumPoints(1);
  }
View Full Code Here


  @Override
  public void readFields(DataInput in) throws IOException {
    super.readFields(in);
    VectorWritable temp = new VectorWritable();
    temp.readFields(in);
    this.setCenter(new RandomAccessSparseVector(temp.get()));
    this.setPointTotal(getCenter().clone());
    this.setNumPoints(1);
  }
View Full Code Here

    if ((usersToRecommendFor != null) && !usersToRecommendFor.contains(userID.get())) {
      return;
    }
    Vector userVector = vectorWritable.get();
    Iterator<Vector.Element> userVectorIterator = userVector.iterateNonZero();
    Vector recommendationVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 1000);
    while (userVectorIterator.hasNext()) {
      Vector.Element element = userVectorIterator.next();
      int index = element.index();
      double value = element.get();
      Vector columnVector;
      try {
        columnVector = cooccurrenceColumnCache.get(new IntWritable(index));
      } catch (TasteException te) {
        if (te.getCause() instanceof IOException) {
          throw (IOException) te.getCause();
        } else {
          throw new IOException(te.getCause());
        }
      }
      columnVector.times(value).addTo(recommendationVector);
    }
   
    Queue<RecommendedItem> topItems = new PriorityQueue<RecommendedItem>(recommendationsPerUser + 1,
        Collections.reverseOrder());
   
    Iterator<Vector.Element> recommendationVectorIterator = recommendationVector.iterateNonZero();
    LongWritable itemID = new LongWritable();
    while (recommendationVectorIterator.hasNext()) {
      Vector.Element element = recommendationVectorIterator.next();
      int index = element.index();
      if (userVector.get(index) == 0.0) {
View Full Code Here

    private VectorWritable columnVector;
   
    private CooccurrenceCache(MapFilesMap<IntWritable,VectorWritable> map) {
      this.map = map;
      columnVector = new VectorWritable();
      columnVector.set(new RandomAccessSparseVector(Integer.MAX_VALUE, 1000));
    }
View Full Code Here

      }
      if (value == null) {
        return null;
      }
      columnVector = new VectorWritable();
      columnVector.set(new RandomAccessSparseVector(Integer.MAX_VALUE, 1000));
      return value;
    }
View Full Code Here

   
    stats = new TimingStatistics();
    for (int l = 0; l < loop; l++) {
      for (int i = 0; i < numVectors; i++) {
        TimingStatistics.Call call = stats.newCall();
        vectors[1][i] = new RandomAccessSparseVector(randomVectors.get(i));
        call.end();
      }
    }
    printStats(stats, "Create (copy)", "RandSparseVector");
   
View Full Code Here

    printStats(stats, "Create (incrementally)", "DenseVector");

    stats = new TimingStatistics();
    for (int l = 0; l < loop; l++) {
      for (int i = 0; i < numVectors; i++) {
        vectors[1][i] = new RandomAccessSparseVector(cardinality);
        buildVectorIncrementally(stats, i, vectors[1][i], false);
      }
    }
    printStats(stats, "Create (incrementally)", "RandSparseVector");
View Full Code Here

  public void reduce(LongWritable userID,
                     Iterator<ItemPrefWritable> itemPrefs,
                     OutputCollector<LongWritable,VectorWritable> output,
                     Reporter reporter) throws IOException {
    if (itemPrefs.hasNext()) {
      RandomAccessSparseVector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
      while (itemPrefs.hasNext()) {
        ItemPrefWritable itemPref = itemPrefs.next();
        int index = ItemIDIndexMapper.idToIndex(itemPref.getItemID());
        userVector.set(index, itemPref.getPrefValue());
      }
     
      if (userVector.getNumNondefaultElements() > MAX_PREFS_CONSIDERED) {
        double cutoff = findTopNPrefsCutoff(MAX_PREFS_CONSIDERED,
          userVector);
        RandomAccessSparseVector filteredVector = new RandomAccessSparseVector(Integer.MAX_VALUE,
            MAX_PREFS_CONSIDERED);
        Iterator<Vector.Element> it = userVector.iterateNonZero();
        while (it.hasNext()) {
          Vector.Element element = it.next();
          if (element.get() >= cutoff) {
            filteredVector.set(element.index(), element.get());
          }
        }
        userVector = filteredVector;
      }
     
View Full Code Here

  public void reduce(IntWritable index1,
                     Iterator<IntWritable> index2s,
                     OutputCollector<IntWritable,VectorWritable> output,
                     Reporter reporter) throws IOException {
    if (index2s.hasNext()) {
      RandomAccessSparseVector cooccurrenceRow = new RandomAccessSparseVector(Integer.MAX_VALUE, 1000);
      while (index2s.hasNext()) {
        int index2 = index2s.next().get();
        cooccurrenceRow.set(index2, cooccurrenceRow.get(index2) + 1.0);
      }
      Iterator<Vector.Element> cooccurrences = cooccurrenceRow.iterateNonZero();
      while (cooccurrences.hasNext()) {
        Vector.Element element = cooccurrences.next();
        if (element.get() <= 1.0) { // purge small values
          element.set(0.0);
        }
View Full Code Here

      }
      Vector result;
      if (line.startsWith(ARFFModel.ARFF_SPARSE)) {
        line = line.substring(1, line.length() - 1);
        String[] splits = ARFFVectorIterable.COMMA_PATTERN.split(line);
        result = new RandomAccessSparseVector(model.getLabelSize());
        for (String split : splits) {
          String[] data = ARFFVectorIterable.SPACE_PATTERN.split(split); // first is index, second is
          int idx = Integer.parseInt(data[0]);
          result.setQuick(idx, model.getValue(data[1], idx));
        }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.RandomAccessSparseVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.