Package net.myrrix.online.generation

Examples of net.myrrix.online.generation.Generation


      generationManager.remove(userID, itemID, bulk);
    } catch (IOException ioe) {
      log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
      generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
      // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
      return;
    }

    ReadWriteLock knownItemLock = generation.getKnownItemLock();

    boolean removeUser = false;
    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {

      Lock knownItemReadLock = knownItemLock.readLock();
      FastIDSet userKnownItemIDs;
      knownItemReadLock.lock();
      try {
        userKnownItemIDs = knownItemIDs.get(userID);
      } finally {
        knownItemReadLock.unlock();
      }

      if (userKnownItemIDs == null) {
        // Doesn't exist? So ignore this request
        return;
      }

      synchronized (userKnownItemIDs) {
        if (!userKnownItemIDs.remove(itemID)) {
          // Item unknown, so ignore this request
          return;
        }
        removeUser = userKnownItemIDs.isEmpty();
      }
    }

    // We can proceed with the request

    FastByIDMap<float[]> X = generation.getX();

    ReadWriteLock xLock = generation.getXLock();

    if (removeUser) {

      Lock knownItemWriteLock = knownItemLock.writeLock();
      knownItemWriteLock.lock();
View Full Code Here


      generationManager.appendUserTag(userID, tag, value, bulk);
    } catch (IOException ioe) {
      log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
      generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
      // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
      return;
    }
   
    long tagID = tagHasher.toLongID(tag);   
   
    FastIDSet userTagIDs = generation.getUserTagIDs();
    Lock userTagWriteLock = generation.getYLock().writeLock();
    userTagWriteLock.lock();
    try {
      userTagIDs.add(tagID);
    } finally {
      userTagWriteLock.unlock();
    }

    float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock());
    float[] tagFeatures = getFeatures(tagID, generation.getY(), generation.getYLock());
    updateFeatures(userFeatures, tagFeatures, value, generation);

    updateClusters(userID, userFeatures, generation.getUserClusters(), generation.getUserClustersLock().readLock());
  }
View Full Code Here

      generationManager.appendItemTag(tag, itemID, value, bulk);
    } catch (IOException ioe) {
      log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
      generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
      // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
      return;
    }

    long tagID = tagHasher.toLongID(tag);
   
    FastIDSet itemTagIDs = generation.getItemTagIDs();
    Lock itemTagWriteLock = generation.getXLock().writeLock();
    itemTagWriteLock.lock();
    try {
      itemTagIDs.add(tagID);
    } finally {
      itemTagWriteLock.unlock();
    }
   
    float[] tagFeatures = getFeatures(tagID, generation.getX(), generation.getXLock());
    float[] itemFeatures = getFeatures(itemID, generation.getY(), generation.getYLock());
    updateFeatures(tagFeatures, itemFeatures, value, generation);

    updateClusters(itemID, itemFeatures, generation.getItemClusters(), generation.getItemClustersLock().readLock())
  }
View Full Code Here

  public List<RecommendedItem> mostSimilarItems(long itemID, int howMany, Rescorer<LongPair> rescorer)
      throws NoSuchItemException, NotReadyException {

    Preconditions.checkArgument(howMany > 0, "howMany must be positive");

    Generation generation = getCurrentGeneration();
    FastByIDMap<float[]> Y = generation.getY();

    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {

      float[] itemFeatures = Y.get(itemID);
      if (itemFeatures == null) {
        throw new NoSuchItemException(itemID);
      }

      return TopN.selectTopN(new MostSimilarItemIterator(Y.entrySet().iterator(),
                                                         generation.getUserTagIDs(),
                                                         new long[] { itemID },
                                                         new float[][] { itemFeatures },
                                                         rescorer),
                             howMany);
    } finally {
View Full Code Here

  public List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany, Rescorer<LongPair> rescorer)
      throws NoSuchItemException, NotReadyException {

    Preconditions.checkArgument(howMany > 0, "howMany must be positive");

    Generation generation = getCurrentGeneration();
    FastByIDMap<float[]> Y = generation.getY();

    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {

      List<float[]> itemFeatures = Lists.newArrayListWithCapacity(itemIDs.length);
      for (long itemID : itemIDs) {
        float[] features = Y.get(itemID);
        if (features != null) {
          itemFeatures.add(features);
        }
      }
      if (itemFeatures.isEmpty()) {
        throw new NoSuchItemException(Arrays.toString(itemIDs));
      }
      float[][] itemFeaturesArray = itemFeatures.toArray(new float[itemFeatures.size()][]);

      return TopN.selectTopN(new MostSimilarItemIterator(Y.entrySet().iterator(),
                                                         generation.getUserTagIDs(),
                                                         itemIDs,
                                                         itemFeaturesArray,
                                                         rescorer),
                             howMany);
    } finally {
View Full Code Here

  }

  @Override
  public float[] similarityToItem(long toItemID, long... itemIDs) throws TasteException {

    Generation generation = getCurrentGeneration();
    FastByIDMap<float[]> Y = generation.getY();

    float[] similarities = new float[itemIDs.length];
    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {

      float[] toFeatures = Y.get(toItemID);
      if (toFeatures == null) {
View Full Code Here

  public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany)
      throws NoSuchUserException, NoSuchItemException, NotReadyException {

    Preconditions.checkArgument(howMany > 0, "howMany must be positive");

    Generation generation = getCurrentGeneration();
    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs == null) {
      throw new UnsupportedOperationException("No known item IDs available");
    }

    Lock knownItemLock = generation.getKnownItemLock().readLock();
    FastIDSet userKnownItemIDs;
    knownItemLock.lock();
    try {
      userKnownItemIDs = knownItemIDs.get(userID);
    } finally {
      knownItemLock.unlock();
    }
    if (userKnownItemIDs == null) {
      throw new NoSuchUserException(userID);
    }

    FastByIDMap<float[]> Y = generation.getY();

    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {

      float[] features = Y.get(itemID);
      if (features == null) {
        throw new NoSuchItemException(itemID);
      }
      FastByIDMap<float[]> toFeatures;
      synchronized (userKnownItemIDs) {
        toFeatures = new FastByIDMap<float[]>(userKnownItemIDs.size());
        LongPrimitiveIterator it = userKnownItemIDs.iterator();
        while (it.hasNext()) {
          long fromItemID = it.nextLong();
          float[] fromFeatures = Y.get(fromItemID);
          toFeatures.put(fromItemID, fromFeatures);
        }
      }

      return TopN.selectTopN(new RecommendedBecauseIterator(toFeatures.entrySet().iterator(),
                                                            generation.getUserTagIDs(),
                                                            features),
                             howMany);
    } finally {
      yLock.unlock();
    }
View Full Code Here

    return true;
  }

  @Override
  public FastIDSet getAllUserIDs() throws NotReadyException {
    Generation generation = getCurrentGeneration();
    return getIDsFromKeys(generation.getX(), generation.getXLock().readLock(), generation.getItemTagIDs());
  }
View Full Code Here

    return getIDsFromKeys(generation.getX(), generation.getXLock().readLock(), generation.getItemTagIDs());
  }

  @Override
  public FastIDSet getAllItemIDs() throws NotReadyException {
    Generation generation = getCurrentGeneration();
    return getIDsFromKeys(generation.getY(), generation.getYLock().readLock(), generation.getUserTagIDs());
  }
View Full Code Here

    }
  }

  @Override
  public int getNumUserClusters() throws NotReadyException {
    Generation generation = getCurrentGeneration();
    Collection<IDCluster> clusters = generation.getUserClusters();
    if (clusters == null || clusters.isEmpty()) {
      throw new UnsupportedOperationException();
    }
    Lock lock = generation.getUserClustersLock().readLock();
    lock.lock();
    try {
      return clusters.size();
    } finally {
      lock.unlock();
View Full Code Here

TOP

Related Classes of net.myrrix.online.generation.Generation

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.