Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
215c13dd
Commit
215c13dd
authored
11 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Fix code style and a nondeterministic RDD issue in ALS
parent
46ea0c1b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mllib/src/main/scala/spark/mllib/recommendation/ALS.scala
+20
-11
20 additions, 11 deletions
mllib/src/main/scala/spark/mllib/recommendation/ALS.scala
with
20 additions
and
11 deletions
mllib/src/main/scala/spark/mllib/recommendation/ALS.scala
+
20
−
11
View file @
215c13dd
...
...
@@ -123,18 +123,27 @@ class ALS private (var numBlocks: Int, var rank: Int, var iterations: Int, var l
val
(
userInLinks
,
userOutLinks
)
=
makeLinkRDDs
(
numBlocks
,
ratingsByUserBlock
)
val
(
productInLinks
,
productOutLinks
)
=
makeLinkRDDs
(
numBlocks
,
ratingsByProductBlock
)
// Initialize user and product factors randomly
var
users
=
userOutLinks
.
mapPartitions
{
itr
=>
val
rand
=
new
Random
()
itr
.
map
({
case
(
x
,
y
)
=>
(
x
,
y
.
elementIds
.
map
(
u
=>
randomFactor
(
rank
,
rand
)))
})
// Initialize user and product factors randomly, but use a deterministic seed for each partition
// so that fault recovery works
val
seedGen
=
new
Random
()
val
seed1
=
seedGen
.
nextInt
()
val
seed2
=
seedGen
.
nextInt
()
// Hash an integer to propagate random bits at all positions, similar to java.util.HashTable
def
hash
(
x
:
Int
)
:
Int
=
{
val
r
=
x
^
(
x
>>>
20
)
^
(
x
>>>
12
)
r
^
(
r
>>>
7
)
^
(
r
>>>
4
)
}
var
products
=
productOutLinks
.
mapPartitions
{
itr
=>
val
rand
=
new
Random
()
itr
.
map
({
case
(
x
,
y
)
=>
(
x
,
y
.
elementIds
.
map
(
u
=>
randomFactor
(
rank
,
rand
)))
})
var
users
=
userOutLinks
.
mapPartitionsWithIndex
{
(
index
,
itr
)
=>
val
rand
=
new
Random
(
hash
(
seed1
^
index
))
itr
.
map
{
case
(
x
,
y
)
=>
(
x
,
y
.
elementIds
.
map
(
_
=>
randomFactor
(
rank
,
rand
)))
}
}
var
products
=
productOutLinks
.
mapPartitionsWithIndex
{
(
index
,
itr
)
=>
val
rand
=
new
Random
(
hash
(
seed2
^
index
))
itr
.
map
{
case
(
x
,
y
)
=>
(
x
,
y
.
elementIds
.
map
(
_
=>
randomFactor
(
rank
,
rand
)))
}
}
for
(
iter
<-
0
until
iterations
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment