Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/src/main/python/als.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def rmse(R, ms, us):
return np.sqrt(np.sum(np.power(diff, 2)) / (M * U))


def update(i, vec, mat, ratings):
def update(i, mat, ratings):
uu = mat.shape[0]
ff = mat.shape[1]

Expand Down Expand Up @@ -88,15 +88,15 @@ def update(i, vec, mat, ratings):

for i in range(ITERATIONS):
ms = sc.parallelize(range(M), partitions) \
.map(lambda x: update(x, msb.value[x, :], usb.value, Rb.value)) \
.map(lambda x: update(x, usb.value, Rb.value)) \
.collect()
# collect() returns a list, so array ends up being
# a 3-d array, we take the first 2 dims for the matrix
ms = matrix(np.array(ms)[:, :, 0])
msb = sc.broadcast(ms)

us = sc.parallelize(range(U), partitions) \
.map(lambda x: update(x, usb.value[x, :], msb.value, Rb.value.T)) \
.map(lambda x: update(x, msb.value, Rb.value.T)) \
.collect()
us = matrix(np.array(us)[:, :, 0])
usb = sc.broadcast(us)
Expand Down