Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.67 KB | None | 0 0
  1. val SIGMA_FACTOR = 1.5
  2.  
  3. def calcAdjMatrix(users: Users, numeration: Seq[String]): DoubleMatrix = {
  4.   val n = users.keys.size
  5.   val distances = new DoubleMatrix(n, n)
  6.   for (i <- (0 until n).par; j <- (i + 1 until n).par) {
  7.     val a = users(numeration(i))
  8.     val b = users(numeration(j))
  9.     val diff = a.zip(b).map { case (x, y) => x - y }
  10.     val dist = Measures.euclidNorm(diff)
  11.     distances.put(i, j, dist)
  12.     distances.put(j, i, dist)
  13.   }
  14.   val sigma = SIGMA_FACTOR * distances.data.sorted.apply(n * n / 2)
  15.   val adj = distances.map { dist =>
  16.     math.exp(-math.pow(dist, 2) / 2 / math.pow(sigma, 2))
  17.   }
  18.   0 until n foreach (i => adj.put(i, i, 0))
  19.   adj
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement