Package net.myrrix.online

Examples of net.myrrix.online.ServerRecommender


      out.write("Machine");
      out.write("</h2>");

pageContext.setAttribute("jvmEnv", new JVMEnvironment());

ServerRecommender rec = (ServerRecommender) application.getAttribute(AbstractMyrrixServlet.RECOMMENDER_KEY);
pageContext.setAttribute("rec", rec);

boolean readOnly = (Boolean) application.getAttribute(AbstractMyrrixServlet.READ_ONLY_KEY);

String localInputDir = String.valueOf(application.getAttribute(AbstractMyrrixServlet.LOCAL_INPUT_DIR_KEY));
pageContext.setAttribute("localInputDir", localInputDir);

String localInputDirDisplay;
if (localInputDir.length() > 32) {
  localInputDirDisplay = localInputDir.substring(0, 32) + "...";
} else {
  localInputDirDisplay = localInputDir;
}
pageContext.setAttribute("localInputDirDisplay", localInputDirDisplay);

pageContext.setAttribute("partition", application.getAttribute(AbstractMyrrixServlet.PARTITION_KEY));
@SuppressWarnings("unchecked")
ReloadingReference<List<?>> partitionRef =
    (ReloadingReference<List<?>>) application.getAttribute(AbstractMyrrixServlet.ALL_PARTITIONS_REF_KEY);
int numPartitions = partitionRef == null ? 0 : partitionRef.get(1, TimeUnit.SECONDS).size();
pageContext.setAttribute("numPartitions", numPartitions);

      out.write("<table>");
      out.write("<tr>");
      out.write("<td>");
      out.write("Host");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write("<code>");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${jvmEnv.hostName}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("</code>");
      out.write("</td>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("<td>");
      out.write("Cores");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${jvmEnv.numProcessors}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("</td>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("<td>");
      out.write("Heap Used");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${jvmEnv.usedMemoryMB}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("MB (");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${jvmEnv.percentUsedMemory}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write('%');
      out.write(')');
      out.write("</td>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("<td>");
      out.write("Logs");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write("<a target=\"_blank\" href=\"log.txt\">");
      out.write("View");
      out.write("</a>");
      out.write("</td>");
      out.write("</tr>");

  if (numPartitions > 1) {

      out.write("<tr>");
      out.write("<td>");
      out.write("Partition");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write('#');
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${partition}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write(' ');
      out.write('(');
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${numPartitions}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write(" total)");
      out.write("</td>");
      out.write("</tr>");

  }

      out.write("</table>");
      out.write("</td>");
      out.write("<td style=\"text-align:left\">");
      out.write("<h2>");
      out.write("Recommender");
      out.write("</h2>");
      out.write("<table>");

  if (rec.getBucket() != null || rec.getInstanceID() != null) {

      out.write("<tr>");
      out.write("<td>");
      out.write("Bucket");
      out.write("</td>");
View Full Code Here


      out.write("<body>");

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);
View Full Code Here

    Preconditions.checkArgument(originalDataDir.exists() && originalDataDir.isDirectory(),
                                "%s is not a directory", originalDataDir);
    File tempDir = Files.createTempDir();

    ServerRecommender recommender = null;
    try {

      Multimap<Long,RecommendedItem> data;
      try {
        data = readAndCopyDataFiles(originalDataDir, tempDir);
      } catch (IOException ioe) {
        throw new TasteException(ioe);
      }

      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();
        long itemID = entry.getValue().getItemID();
        // Each of which was a "1" in the factor P matrix
        double value = SimpleVectorMath.dot(X.get(userID), Y.get(itemID));
        // So store abs(1-value), except, don't penalize for reconstructing > 1. Error is 0 in this case.
        averageError.increment(FastMath.max(0.0, 1.0 - value));
      }

      return new EvaluationResultImpl(averageError.getResult());
    } finally {
      recommender.close();
      IOUtils.deleteRecursively(tempDir);
    }
  }
View Full Code Here

    File trainingModelFile = new File(originalDataDir, "model.bin.gz");
    if (trainingModelFile.exists() && trainingModelFile.isFile()) {
      Files.copy(trainingModelFile, new File(trainingDataDir, trainingModelFile.getName()));
    }

    ServerRecommender recommender = null;
    try {
      Multimap<Long,RecommendedItem> testData =
          split(originalDataDir, trainingFile, trainingPercentage, evaluationPercentage, provider);

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

      return evaluate(recommender, testData);
    } finally {
      if (recommender != null) {
        recommender.close();
      }
      IOUtils.deleteRecursively(trainingDataDir);
    }
  }
View Full Code Here

  }

  @Override
  public Object call() throws IOException, InterruptedException, NotReadyException, ExecutionException {

    final ServerRecommender recommender = new ServerRecommender(config.getLocalInputDir());
    recommender.await();

    final RescorerProvider rescorerProvider = config.getRescorerProvider();
    final int howMany = config.getHowMany();
   
    File outFile = config.getOutFile();
    outFile.delete();
    final Writer out = new OutputStreamWriter(new FileOutputStream(outFile), Charsets.UTF_8);
   
    Processor<Long> processor = new Processor<Long>() {
      @Override
      public void process(Long userID, long count) throws ExecutionException {
        IDRescorer rescorer =
            rescorerProvider == null ? null : rescorerProvider.getRecommendRescorer(new long[]{userID}, recommender);
        Iterable<RecommendedItem> recs;
        try {
          recs = recommender.recommend(userID, howMany, rescorer);
        } catch (TasteException te) {
          throw new ExecutionException(te);
        }
        String outLine = AllItemSimilarities.formatOutLine(userID, recs);
        synchronized (out) {
          try {
            out.write(outLine);
          } catch (IOException e) {
            throw new ExecutionException(e);
          }
        }
      }
    };

    Paralleler<Long> paralleler =
        new Paralleler<Long>(recommender.getAllUserIDs().iterator(), processor, "AllRecommendations");
    if (config.isParallel()) {
      paralleler.runInParallel();
    } else {
      paralleler.runInSerial();
    }
View Full Code Here

  }

  @Override
  public Object call() throws IOException, InterruptedException, NotReadyException, ExecutionException {

    final ServerRecommender recommender = new ServerRecommender(config.getLocalInputDir());
    recommender.await();

    final RescorerProvider rescorerProvider = config.getRescorerProvider();
    final int howMany = config.getHowMany();

    File outFile = config.getOutFile();
    outFile.delete();
    final Writer out = new OutputStreamWriter(new FileOutputStream(outFile), Charsets.UTF_8);
   
    Processor<Long> processor = new Processor<Long>() {
      @Override
      public void process(Long itemID, long count) throws ExecutionException {
        Rescorer<LongPair> rescorer =
            rescorerProvider == null ? null : rescorerProvider.getMostSimilarItemsRescorer(recommender);
        Iterable<RecommendedItem> similar;
        try {
          similar = recommender.mostSimilarItems(new long[]{itemID}, howMany, rescorer);
        } catch (TasteException te) {
          throw new ExecutionException(te);
        }
        String outLine = formatOutLine(itemID, similar);
        synchronized (out) {
          try {
            out.write(outLine);
          } catch (IOException e) {
            throw new ExecutionException(e);
          }
        }
      }
    };

    Paralleler<Long> paralleler =
        new Paralleler<Long>(recommender.getAllItemIDs().iterator(), processor, "AllItemSimilarities");
    if (config.isParallel()) {
      paralleler.runInParallel();
    } else {
      paralleler.runInSerial();
    }
View Full Code Here

   
    ReloadingReference<List<List<HostAndPort>>> allPartitionsReference =
        configureAllPartitionsReference(context, bucket, instanceID);
   
    MyrrixRecommender recommender =
        new ServerRecommender(bucket, instanceID, localInputDir, partition, allPartitionsReference);
    context.setAttribute(AbstractMyrrixServlet.RECOMMENDER_KEY, recommender);
   
    configureClientThread(context, bucket, instanceID, recommender);

    log.info("Myrrix is initialized");
View Full Code Here

TOP

Related Classes of net.myrrix.online.ServerRecommender

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.