Package net.myrrix.online.factorizer

Examples of net.myrrix.online.factorizer.MatrixFactorizer


          FastIDSet userTagIDs = new FastIDSet(1000);
          InputFilesReader.readInputFiles(knownItemIDs, RbyRow, RbyColumn, itemTagIDs, userTagIDs, inputDir);
     
          if (!RbyRow.isEmpty() && !RbyColumn.isEmpty()) {
            // Compute latest generation:
            MatrixFactorizer als;
            Generation latestGeneration;
            // Repeat with fewer features if fails to build:
            while (true) {
              try {
                als = runFactorization(theCurrentGeneration, RbyRow, RbyColumn);               
                latestGeneration = new Generation(knownItemIDs, als.getX(), als.getY(), itemTagIDs, userTagIDs);
                break;
              } catch (SingularMatrixSolverException smse) {
                int currentFeatures = readNumFeatures();
                int fewerFeatures = smse.getApparentRank();
                if (fewerFeatures <= 1) {
                  throw smse;
                }
                log.warn("Could not build model with {} features; setting model.features down to {}",
                         currentFeatures, fewerFeatures);
                System.setProperty("model.features", Integer.toString(fewerFeatures));
              }
            }
            // Save it:
            saveModel(latestGeneration, modelFile);
            // Merge into potentially live current generation:
            loader.loadModel(theCurrentGeneration, als.getX(), als.getY(), knownItemIDs, itemTagIDs, userTagIDs);
          }
     
          int numItems = theCurrentGeneration.getNumItems();
          int numUsers = theCurrentGeneration.getNumUsers();
          if (numUsers == 0 || numItems == 0) {
View Full Code Here


          System.getProperty("model.als.iterations.convergenceThreshold",
                             Double.toString(AlternatingLeastSquares.DEFAULT_CONVERGENCE_THRESHOLD));
      String maxIterationsString =
          System.getProperty("model.iterations.max",
                             Integer.toString(AlternatingLeastSquares.DEFAULT_MAX_ITERATIONS));   
      MatrixFactorizer als = new AlternatingLeastSquares(rbyRow,
                                                         rbyColumn,
                                                         features,
                                                         Double.parseDouble(iterationsConvergenceString),
                                                         Integer.parseInt(maxIterationsString));
 
      if (currentGeneration != null) {
        FastByIDMap<float[]> previousY = currentGeneration.getY();
        if (previousY != null) {
          FastByIDMap<float[]> previousYClone;
          Lock yLock = currentGeneration.getYLock().readLock();
          yLock.lock();
          try {
            previousYClone = new FastByIDMap<float[]>(previousY.size());
            for (FastByIDMap.MapEntry<float[]> entry : previousY.entrySet()) {
              previousYClone.put(entry.getKey(), entry.getValue().clone());
            }
          } finally {
            yLock.unlock();
          }
          als.setPreviousY(previousYClone);
        }
      }
 
      try {
        als.call();
        log.info("Factorization complete");
      } catch (ExecutionException ee) {
        throw new IOException(ee.getCause());
      } catch (InterruptedException ignored) {
        log.warn("ALS computation was interrupted");
View Full Code Here

    previousY.put(0L, new float[] {0.1f, 0.2f});
    previousY.put(1L, new float[] {0.2f, 0.5f});
    previousY.put(2L, new float[] {0.3f, 0.1f});
    previousY.put(3L, new float[] {0.2f, 0.2f});

    MatrixFactorizer als = new AlternatingLeastSquares(byRow, byCol, 2, 0.0001, 40);
    als.setPreviousY(previousY);
    als.call();

    RealMatrix product = MatrixUtils.multiplyXYT(als.getX(), als.getY());

    StringBuilder productString = new StringBuilder(100);
    for (int row = 0; row < product.getRowDimension(); row++) {
      productString.append('\n').append(Arrays.toString(doubleToFloatArray(product.getRow(row))));
    }
View Full Code Here

    previousY.put(1L, new float[] {0.2f, 0.5f});
    previousY.put(2L, new float[] {0.3f, 0.1f});
    previousY.put(3L, new float[] {0.2f, 0.2f});
    previousY.put(4L, new float[] {0.5f, 0.4f});

    MatrixFactorizer als = new AlternatingLeastSquares(byRow, byCol, 2, 0.0001, 40);
    als.setPreviousY(previousY);
    als.call();

    RealMatrix product = MatrixUtils.multiplyXYT(als.getX(), als.getY());

    StringBuilder productString = new StringBuilder(100);
    for (int row = 0; row < product.getRowDimension(); row++) {
      productString.append('\n').append(Arrays.toString(doubleToFloatArray(product.getRow(row))));
    }
View Full Code Here

TOP

Related Classes of net.myrrix.online.factorizer.MatrixFactorizer

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.