Advertisement
Guest User

Untitled

a guest
Nov 18th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.87 KB | None | 0 0
  1.   def mapper_predict_songs(song: Int, similar_songs: Iterable[(Int,Int,Double)]) : Iterable[(Int,Double)] = {
  2.       val result = new ListBuffer[(Int,Double)]
  3.    
  4.       val sim_songs = new scala.collection.mutable.HashMap[Int,Double]()
  5.       val playlists = new scala.collection.mutable.HashMap[Int,scala.collection.mutable.Set[Int]]
  6.      
  7.       for(tuple <- similar_songs){
  8.         val s = tuple._1
  9.         val u = tuple._2
  10.         val n = tuple._3
  11.         if(!playlists.contains(u))
  12.           playlists(u) = new scala.collection.mutable.HashSet[Int]()
  13.         playlists(u) += s
  14.        
  15.         sim_songs(s) = sim_songs.getOrElse(s, 0.0) + 1.0/n
  16.       }
  17.      
  18.       for(tuple <- sim_songs){
  19.         val s = tuple._1
  20.         val c = tuple._2
  21.         for(uAndp <- playlists){
  22.           if(!uAndp._2.contains(s)){
  23.             result += ((s,c))
  24.           }
  25.         }
  26.       }
  27.       result
  28.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement