Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs449 Template M2 2022
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
Hugo Manuel Serge Lanfranchi
Cs449 Template M2 2022
Commits
8f051ddb
Commit
8f051ddb
authored
2 years ago
by
Parshikov Tikhon
Browse files
Options
Downloads
Patches
Plain Diff
First fixes approximate
parent
f10298c3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/shared/predictions.scala
+13
-10
13 additions, 10 deletions
src/main/scala/shared/predictions.scala
with
13 additions
and
10 deletions
src/main/scala/shared/predictions.scala
+
13
−
10
View file @
8f051ddb
...
@@ -249,22 +249,25 @@ package object predictions
...
@@ -249,22 +249,25 @@ package object predictions
}
}
//5
//5
def
distributed_knn_approximate
(
preprocessed_ratings
:
CSC
Matrix
[
Double
],
k
:
Int
,
spark_context
:
SparkContext
,
nbPartitions
:
Int
,
replication
:
Int
)
:
Array
[
Int
]
=
{
def
distributed_knn_approximate
(
preprocessed_ratings
:
Dense
Matrix
[
Double
],
k
:
Int
,
spark_context
:
SparkContext
,
nbPartitions
:
Int
,
replication
:
Int
)
:
DenseMatrix
[
Double
]
=
{
val
new_ratings
=
new
CSCMatrix
[
Double
](
ratings
.
rows
,
ratings
.
cols
)
val
new_ratings
=
new
CSCMatrix
[
Double
](
preprocessed_
ratings
.
rows
,
preprocessed_
ratings
.
cols
)
//Seq[Set[Int]
users_partition
=
partitionUsers
(
preprocessed_ratings
.
rows
,
nbPartitions
,
replication
)
val
users_partition
=
partitionUsers
(
preprocessed_ratings
.
rows
,
nbPartitions
,
replication
)
val
broadcast
=
sc
.
broadcast
(
preprocessed_ratings
.
toDense
)
val
broadcast
=
sc
.
broadcast
(
preprocessed_ratings
)
val
approximate_topk
=
sc
.
parallelize
(
users_partition
).
map
(
partition_iterator
=>
{
val
approximate_topk
=
sc
.
parallelize
(
users_partition
).
map
(
partition_iterator
=>
{
val
ratings
=
broadcast
.
value
val
ratings
=
broadcast
.
value
val
partition
=
ratings
(
partition_iterator
,::)
val
all_users
=
(
0
until
ratings
.
rows
).
toSeq
val
exclude_users
=
all_users
.
diff
(
partition_iterator
.
toSeq
)
val
partition
=
ratings
.
delete
(
exclude_users
,
Axis
.
_0
)
val
similarities
=
partition
*
partition
.
t
val
similarities
=
partition
*
partition
.
t
val
partition_index
=
partition
.
zipWith
(
Array
[
Int
](
partition
.
rows
))
//
val partition_index = partition.zipWith(Array[Int](partition.rows))
//TODO how to integrate indexes in knn
//TODO how to integrate indexes in knn
val
topk
=
partition_index
.
map
(
x
=>
knn
(
x
,
k
,
similarities
))
val
sorted_users
=
partition_iterator
.
toArray
.
sorted
val
topk
=
partition_iterator
.
map
(
x
=>
(
x
,
knn
(
sorted_users
.
indexOf
(
x
),
k
,
similarities
)))
topk
}).
collect
()
}).
collect
()
//redo knn
//redo knn
...
...
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