@@ -111,11 +111,17 @@ class ALS private (
111
111
*/
112
112
def this () = this (- 1 , - 1 , 10 , 10 , 0.01 , false , 1.0 )
113
113
114
+ /** If true, do alternating nonnegative least squares. */
115
+ private var nonnegative = false
116
+
117
+ /** storage level for user/product in/out links */
118
+ private var intermediateDataStorageLevel : StorageLevel = StorageLevel .MEMORY_AND_DISK
119
+
114
120
/**
115
121
* Set the number of blocks for both user blocks and product blocks to parallelize the computation
116
122
* into; pass -1 for an auto-configured number of blocks. Default: -1.
117
123
*/
118
- def setBlocks (numBlocks : Int ): ALS = {
124
+ def setBlocks (numBlocks : Int ): this . type = {
119
125
this .numUserBlocks = numBlocks
120
126
this .numProductBlocks = numBlocks
121
127
this
@@ -124,39 +130,39 @@ class ALS private (
124
130
/**
125
131
* Set the number of user blocks to parallelize the computation.
126
132
*/
127
- def setUserBlocks (numUserBlocks : Int ): ALS = {
133
+ def setUserBlocks (numUserBlocks : Int ): this . type = {
128
134
this .numUserBlocks = numUserBlocks
129
135
this
130
136
}
131
137
132
138
/**
133
139
* Set the number of product blocks to parallelize the computation.
134
140
*/
135
- def setProductBlocks (numProductBlocks : Int ): ALS = {
141
+ def setProductBlocks (numProductBlocks : Int ): this . type = {
136
142
this .numProductBlocks = numProductBlocks
137
143
this
138
144
}
139
145
140
146
/** Set the rank of the feature matrices computed (number of features). Default: 10. */
141
- def setRank (rank : Int ): ALS = {
147
+ def setRank (rank : Int ): this . type = {
142
148
this .rank = rank
143
149
this
144
150
}
145
151
146
152
/** Set the number of iterations to run. Default: 10. */
147
- def setIterations (iterations : Int ): ALS = {
153
+ def setIterations (iterations : Int ): this . type = {
148
154
this .iterations = iterations
149
155
this
150
156
}
151
157
152
158
/** Set the regularization parameter, lambda. Default: 0.01. */
153
- def setLambda (lambda : Double ): ALS = {
159
+ def setLambda (lambda : Double ): this . type = {
154
160
this .lambda = lambda
155
161
this
156
162
}
157
163
158
164
/** Sets whether to use implicit preference. Default: false. */
159
- def setImplicitPrefs (implicitPrefs : Boolean ): ALS = {
165
+ def setImplicitPrefs (implicitPrefs : Boolean ): this . type = {
160
166
this .implicitPrefs = implicitPrefs
161
167
this
162
168
}
@@ -166,29 +172,38 @@ class ALS private (
166
172
* Sets the constant used in computing confidence in implicit ALS. Default: 1.0.
167
173
*/
168
174
@ Experimental
169
- def setAlpha (alpha : Double ): ALS = {
175
+ def setAlpha (alpha : Double ): this . type = {
170
176
this .alpha = alpha
171
177
this
172
178
}
173
179
174
180
/** Sets a random seed to have deterministic results. */
175
- def setSeed (seed : Long ): ALS = {
181
+ def setSeed (seed : Long ): this . type = {
176
182
this .seed = seed
177
183
this
178
184
}
179
185
180
- /** If true, do alternating nonnegative least squares. */
181
- private var nonnegative = false
182
-
183
186
/**
184
187
* Set whether the least-squares problems solved at each iteration should have
185
188
* nonnegativity constraints.
186
189
*/
187
- def setNonnegative (b : Boolean ): ALS = {
190
+ def setNonnegative (b : Boolean ): this . type = {
188
191
this .nonnegative = b
189
192
this
190
193
}
191
194
195
+ /**
196
+ * :: DeveloperApi ::
197
+ * Sets storage level for intermediate RDDs (user/product in/out links). The default value is
198
+ * `MEMORY_AND_DISK`. Users can change it to a serialized storage, e.g., `MEMORY_AND_DISK_SER` and
199
+ * set `spark.rdd.compress` to `true` to reduce the space requirement, at the cost of speed.
200
+ */
201
+ @ DeveloperApi
202
+ def setIntermediateDataStorageLevel (storageLevel : StorageLevel ): this .type = {
203
+ this .intermediateDataStorageLevel = storageLevel
204
+ this
205
+ }
206
+
192
207
/**
193
208
* Run ALS with the configured parameters on an input RDD of (user, product, rating) triples.
194
209
* Returns a MatrixFactorizationModel with feature vectors for each user and product.
@@ -441,8 +456,8 @@ class ALS private (
441
456
}, preservesPartitioning = true )
442
457
val inLinks = links.mapValues(_._1)
443
458
val outLinks = links.mapValues(_._2)
444
- inLinks.persist(StorageLevel . MEMORY_AND_DISK )
445
- outLinks.persist(StorageLevel . MEMORY_AND_DISK )
459
+ inLinks.persist(intermediateDataStorageLevel )
460
+ outLinks.persist(intermediateDataStorageLevel )
446
461
(inLinks, outLinks)
447
462
}
448
463
0 commit comments