Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val SIGMA_FACTOR = 1.5
- def calcAdjMatrix(users: Users, numeration: Seq[String]): DoubleMatrix = {
- val n = users.keys.size
- val distances = new DoubleMatrix(n, n)
- for (i <- (0 until n).par; j <- (i + 1 until n).par) {
- val a = users(numeration(i))
- val b = users(numeration(j))
- val diff = a.zip(b).map { case (x, y) => x - y }
- val dist = Measures.euclidNorm(diff)
- distances.put(i, j, dist)
- distances.put(j, i, dist)
- }
- val sigma = SIGMA_FACTOR * distances.data.sorted.apply(n * n / 2)
- val adj = distances.map { dist =>
- math.exp(-math.pow(dist, 2) / 2 / math.pow(sigma, 2))
- }
- 0 until n foreach (i => adj.put(i, i, 0))
- adj
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement