Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.mahout.math.als;
 
see Collaborative Filtering for Implicit Feedback Datasets
 
 
   private final int numFeatures;
   private final double alpha;
   private final double lambda;
 
   private final OpenIntObjectHashMap<VectorY;
   private final Matrix YtransposeY;
 
   public ImplicitFeedbackAlternatingLeastSquaresSolver(int numFeaturesdouble lambdadouble alpha,
       OpenIntObjectHashMap<VectorY) {
     this. = numFeatures;
     this. = lambda;
     this. = alpha;
     this. = Y;
      = getYtransposeY(Y);
   }
 
   public Vector solve(Vector ratings) {
   }
 
   private static Vector solve(Matrix AMatrix y) {
     return new QRDecomposition(A).solve(y).viewColumn(0);
   }
 
   double confidence(double rating) {
     return 1 +  * rating;
   }
 
   /* Y' Y */
 
     IntArrayList indexes = Y.keys();
     indexes.quickSort();
     int numIndexes = indexes.size();
 
     double[][] YtY = new double[][];
 
     // Compute Y'Y by dot products between the 'columns' of Y
     for (int i = 0; i < i++) {
       for (int j = ij < j++) {
         double dot = 0;
         for (int k = 0; k < numIndexesk++) {
           Vector row = Y.get(indexes.getQuick(k));
           dot += row.getQuick(i) * row.getQuick(j);
         }
         YtY[i][j] = dot;
         if (i != j) {
           YtY[j][i] = dot;
         }
       }
     }
     return new DenseMatrix(YtYtrue);
   }

  
Y' (Cu - I) Y + λ I
 
   private Matrix getYtransponseCuMinusIYPlusLambdaI(Vector userRatings) {
     Preconditions.checkArgument(userRatings.isSequentialAccess(), "need sequential access to ratings!");
 
     /* (Cu -I) Y */
     OpenIntObjectHashMap<VectorCuMinusIY = new OpenIntObjectHashMap<Vector>(userRatings.getNumNondefaultElements());
     for (Element e : userRatings.nonZeroes()) {
       CuMinusIY.put(e.index(), .get(e.index()).times(confidence(e.get()) - 1));
     }
 
     Matrix YtransponseCuMinusIY = new DenseMatrix();
 
    /* Y' (Cu -I) Y by outer products */
    for (Element e : userRatings.nonZeroes()) {
      for (Vector.Element feature : .get(e.index()).all()) {
        Vector partial = CuMinusIY.get(e.index()).times(feature.get());
        YtransponseCuMinusIY.viewRow(feature.index()).assign(partial.);
      }
    }
    /* Y' (Cu - I) Y + λ I  add lambda on the diagonal */
    for (int feature = 0; feature < feature++) {
      YtransponseCuMinusIY.setQuick(featurefeatureYtransponseCuMinusIY.getQuick(featurefeature) + );
    }
    return YtransponseCuMinusIY;
  }

  
Y' Cu p(u)
  private Matrix getYtransponseCuPu(Vector userRatings) {
    Preconditions.checkArgument(userRatings.isSequentialAccess(), "need sequential access to ratings!");
    Vector YtransponseCuPu = new DenseVector();
    for (Element e : userRatings.nonZeroes()) {
      YtransponseCuPu.assign(.get(e.index()).times(confidence(e.get())), .);
    }
    return columnVectorAsMatrix(YtransponseCuPu);
  }
    double[][] matrix =  new double[][1];
    for (Vector.Element e : v.all()) {
      matrix[e.index()][0] =  e.get();
    }
    return new DenseMatrix(matrixtrue);
  }
New to GrepCode? Check out our FAQ X