Package net.myrrix.online.generation

Examples of net.myrrix.online.generation.Generation


String maxMapSizeParam = request.getParameter("maxMapSize");
int maxMapSize = maxMapSizeParam == null ? 40 : Integer.parseInt(maxMapSizeParam);
boolean userMatrix = "user".equalsIgnoreCase(request.getParameter("matrix"));
ServerRecommender rec = (ServerRecommender) application.getAttribute(AbstractMyrrixServlet.RECOMMENDER_KEY);
Generation generation = rec.getGenerationManager().getCurrentGeneration();
if (generation != null) {
  FastByIDMap<float[]> matrix = userMatrix ? generation.getX() : generation.getY();
  if (matrix != null && !matrix.isEmpty()) {
    Node[][] map = new SelfOrganizingMaps().buildSelfOrganizedMap(userMatrix ? generation.getX() : generation.getY(),
                                                                  maxMapSize);

      out.write("<table class=\"htt\">");

      int nodeMaxSize = 9;
View Full Code Here


      }

      recommender = new ServerRecommender(tempDir);
      recommender.await();

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

      Mean averageError = new Mean();
      // Only compute average over existing entries...
      for (Map.Entry<Long,RecommendedItem> entry : data.entries()) {
        long userID = entry.getKey();
View Full Code Here

  /**
   * @throws NotReadyException if {@link GenerationManager#getCurrentGeneration()} returns null
   */
  private Generation getCurrentGeneration() throws NotReadyException {
    Generation generation = generationManager.getCurrentGeneration();
    if (generation == null) {
      throw new NotReadyException();
    }
    return generation;
  }
View Full Code Here

                                               boolean considerKnownItems,
                                               IDRescorer rescorer) throws NoSuchUserException, NotReadyException {

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

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

    Lock xLock = generation.getXLock().readLock();
    List<float[]> userFeatures = Lists.newArrayListWithCapacity(userIDs.length);
    xLock.lock();
    try {
      for (long userID : userIDs) {
        float[] theUserFeatures = X.get(userID);
        if (theUserFeatures != null) {
          userFeatures.add(theUserFeatures);
        }
      }
    } finally {
      xLock.unlock();
    }
    if (userFeatures.isEmpty()) {
      throw new NoSuchUserException(Arrays.toString(userIDs));
    }

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs == null && !considerKnownItems) {
      throw new UnsupportedOperationException("Can't ignore known items because no known items available");
    }
    FastIDSet usersKnownItemIDs = null;
    if (!considerKnownItems) {
      Lock knownItemLock = generation.getKnownItemLock().readLock();
      knownItemLock.lock();
      try {
        for (long userID : userIDs) {
          FastIDSet theKnownItemIDs = knownItemIDs.get(userID);
          if (theKnownItemIDs == null) {
            continue;
          }
          if (usersKnownItemIDs == null) {
            usersKnownItemIDs = theKnownItemIDs;
          } else {
            LongPrimitiveIterator it = usersKnownItemIDs.iterator();
            while (it.hasNext()) {
              if (!theKnownItemIDs.contains(it.nextLong())) {
                it.remove();
              }
            }
          }
          if (usersKnownItemIDs.isEmpty()) {
            break;
          }
        }
      } finally {
        knownItemLock.unlock();
      }
    }

    float[][] userFeaturesArray = userFeatures.toArray(new float[userFeatures.size()][]);
    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {
      return multithreadedTopN(userFeaturesArray,
                               usersKnownItemIDs,
                               generation.getUserTagIDs(),
                               rescorer,
                               howMany,
                               generation.getCandidateFilter());
    } finally {
      yLock.unlock();
    }

  }
View Full Code Here

      userKnownItemIDs.add(itemID);
    }

    float[][] anonymousFeaturesAsArray = { anonymousUserFeatures };

    Generation generation = getCurrentGeneration();   
    Lock yLock = generation.getYLock().readLock();   
    yLock.lock();
    try {
      return multithreadedTopN(anonymousFeaturesAsArray,
                               userKnownItemIDs,
                               generation.getUserTagIDs(),
                               rescorer,
                               howMany,
                               generation.getCandidateFilter());
    } finally {
      yLock.unlock();
    }
  }
View Full Code Here

      throws NotReadyException, NoSuchItemException {

    Preconditions.checkArgument(values == null || values.length == itemIDs.length,
                                "Number of values doesn't match number of items");
   
    Generation generation = getCurrentGeneration();

    FastByIDMap<float[]> Y = generation.getY();
    Solver ytySolver = generation.getYTYSolver();
    if (ytySolver == null) {
      throw new NotReadyException();
    }

    float[] anonymousUserFeatures = null;
    Lock yLock = generation.getYLock().readLock();

    boolean anyItemIDFound = false;
    for (int j = 0; j < itemIDs.length; j++) {
      long itemID = itemIDs[j];
      float[] itemFeatures;
View Full Code Here

  @Override
  public List<RecommendedItem> mostPopularItems(int howMany, IDRescorer rescorer) throws NotReadyException {

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

    Generation generation = getCurrentGeneration();
    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs == null) {
      throw new UnsupportedOperationException();
    }

    FastIDSet itemTagIDs = generation.getItemTagIDs();
    FastByIDFloatMap itemCounts = new FastByIDFloatMap();   
    Lock knownItemReadLock = generation.getKnownItemLock().readLock();
    knownItemReadLock.lock();
    try {
        // Don't count data from users that are really item tags
        Lock xReadLock = generation.getXLock().readLock();
        xReadLock.lock();
        try {
         
          for (FastByIDMap.MapEntry<FastIDSet> entry : generation.getKnownItemIDs().entrySet()) {
            long userID = entry.getKey();
            if (!itemTagIDs.contains(userID)) {
              FastIDSet itemIDs = entry.getValue();
              synchronized (itemIDs) {
                LongPrimitiveIterator it = itemIDs.iterator();
                while (it.hasNext()) {
                  long itemID = it.nextLong();
                  itemCounts.increment(itemID, 1.0f);
                }
              }
            }
          }
         
        } finally {
          xReadLock.unlock();
        }
    } finally {
      knownItemReadLock.unlock();
    }
   
    // Filter out 'items' that were really user tags
    FastIDSet userTagIDs = generation.getUserTagIDs();
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
      LongPrimitiveIterator it = itemCounts.keySetIterator();
      while (it.hasNext()) {
        if (userTagIDs.contains(it.nextLong())) {
View Full Code Here

  }

  @Override
  public float[] estimatePreferences(long userID, long... itemIDs) throws NotReadyException {
   
    Generation generation = getCurrentGeneration();
    FastByIDMap<float[]> X = generation.getX();
   
    float[] userFeatures;
    Lock xLock = generation.getXLock().readLock();
    xLock.lock();
    try {
      userFeatures = X.get(userID);
    } finally {
      xLock.unlock();
    }
    if (userFeatures == null) {
      return new float[itemIDs.length]; // All 0.0f
    }
   
    FastByIDMap<float[]> Y = generation.getY();

    Lock yLock = generation.getYLock().readLock();
    yLock.lock();
    try {
      float[] result = new float[itemIDs.length];
      for (int i = 0; i < itemIDs.length; i++) {
        long itemID = itemIDs[i];
View Full Code Here

 
  @Override
  public float estimateForAnonymous(long toItemID, long[] itemIDs, float[] values)
      throws NotReadyException, NoSuchItemException {

    Generation generation = getCurrentGeneration();   
    FastByIDMap<float[]> Y = generation.getY();
    Lock yLock = generation.getYLock().readLock();
    float[] toItemFeatures;   
    yLock.lock();
    try {
      toItemFeatures = Y.get(toItemID);
    } finally {
View Full Code Here

      generationManager.append(userID, 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;
    }

    float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock());

    boolean newItem;
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
      newItem = generation.getY().get(itemID) == null;
    } finally {
      yReadLock.unlock();
    }
    if (newItem) {
      generation.getCandidateFilter().addItem(itemID);
    }
   
    float[] itemFeatures = getFeatures(itemID, generation.getY(), generation.getYLock());

    updateFeatures(userFeatures, itemFeatures, value, generation);

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {
      FastIDSet userKnownItemIDs;
      ReadWriteLock knownItemLock = generation.getKnownItemLock();
      Lock knownItemReadLock = knownItemLock.readLock();
      knownItemReadLock.lock();
      try {
        userKnownItemIDs = knownItemIDs.get(userID);
        if (userKnownItemIDs == null) {
          userKnownItemIDs = new FastIDSet();
          Lock knownItemWriteLock = knownItemLock.writeLock();
          knownItemReadLock.unlock();
          knownItemWriteLock.lock();
          try {
            knownItemIDs.put(userID, userKnownItemIDs);
          } finally {
            knownItemReadLock.lock();
            knownItemWriteLock.unlock();
          }
        }
      } finally {
        knownItemReadLock.unlock();
      }

      synchronized (userKnownItemIDs) {
        userKnownItemIDs.add(itemID);
      }
    }
   
    updateClusters(userID, userFeatures, generation.getUserClusters(), generation.getUserClustersLock().readLock());
    updateClusters(itemID, itemFeatures, generation.getItemClusters(), generation.getItemClustersLock().readLock());
  }
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.