public class Als extends Object implements ComputeFunction<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage>
Modifier and Type | Class and Description |
---|---|
class |
Als.InitItemsComputation
This computation class is used to initialize the factors of the item nodes
in the second superstep.
|
class |
Als.InitUsersComputation
This computation class is used to initialize the factors of the user nodes
in the very first superstep, and send the first updates to the item nodes.
|
ComputeFunction.Aggregators, ComputeFunction.Callback<K,VV,EV,Message>, ComputeFunction.InitCallback, ComputeFunction.MasterCallback, ComputeFunction.ReadAggregators, ComputeFunction.ReadWriteAggregators
Modifier and Type | Field and Description |
---|---|
static String |
ITERATIONS
Keyword for parameter setting the number of iterations.
|
static int |
ITERATIONS_DEFAULT
Default value for ITERATIONS.
|
static String |
LAMBDA
Keyword for parameter setting the regularization parameter LAMBDA.
|
static float |
LAMBDA_DEFAULT
Default value for LABDA.
|
static String |
RANDOM_SEED
Random seed.
|
static Long |
RANDOM_SEED_DEFAULT
Default random seed
|
static String |
RMSE_AGGREGATOR
Aggregator used to compute the RMSE
|
static String |
RMSE_TARGET
RMSE target to reach.
|
static float |
RMSE_TARGET_DEFAULT
Default value of RMSE target.
|
static String |
VECTOR_SIZE
Keyword for parameter setting the Latent Vector Size.
|
static int |
VECTOR_SIZE_DEFAULT
Default value for vector size.
|
Constructor and Description |
---|
Als() |
Modifier and Type | Method and Description |
---|---|
void |
compute(int superstep,
VertexWithValue<CfLongId,org.jblas.FloatMatrix> vertex,
Iterable<FloatMatrixMessage> messages,
Iterable<EdgeWithValue<CfLongId,Float>> edges,
ComputeFunction.Callback<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage> cb)
The function for computing a new vertex value or sending messages to the next superstep.
|
protected long |
getTotalNumEdges(ComputeFunction.ReadAggregators aggregators) |
void |
init(Map<String,?> configs,
ComputeFunction.InitCallback cb)
Initialize the ComputeFunction, this is the place to register aggregators.
|
void |
masterCompute(int superstep,
ComputeFunction.MasterCallback cb)
A function for performing sequential computations between supersteps.
|
void |
preSuperstep(int superstep,
ComputeFunction.Aggregators aggregators)
Prepare for computation.
|
void |
superstepCompute(int superstep,
VertexWithValue<CfLongId,org.jblas.FloatMatrix> vertex,
Iterable<FloatMatrixMessage> messages,
Iterable<EdgeWithValue<CfLongId,Float>> edges,
ComputeFunction.Callback<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage> cb)
Main ALS compute method.
|
protected void |
updateValue(org.jblas.FloatMatrix value,
org.jblas.FloatMatrix mat_M,
org.jblas.FloatMatrix mat_R,
float lambda) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
postSuperstep
public static final String RMSE_TARGET
public static final float RMSE_TARGET_DEFAULT
public static final String ITERATIONS
public static final int ITERATIONS_DEFAULT
public static final String LAMBDA
public static final float LAMBDA_DEFAULT
public static final String VECTOR_SIZE
public static final int VECTOR_SIZE_DEFAULT
public static final String RANDOM_SEED
public static final Long RANDOM_SEED_DEFAULT
public static final String RMSE_AGGREGATOR
public void preSuperstep(int superstep, ComputeFunction.Aggregators aggregators)
ComputeFunction
preSuperstep
in interface ComputeFunction<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage>
superstep
- the superstepaggregators
- the aggregatorspublic void superstepCompute(int superstep, VertexWithValue<CfLongId,org.jblas.FloatMatrix> vertex, Iterable<FloatMatrixMessage> messages, Iterable<EdgeWithValue<CfLongId,Float>> edges, ComputeFunction.Callback<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage> cb)
It updates the current latent vector based on ALS:
A = M * M^T + LAMBDA * N * E
V = M * R
A * U = V, then solve for U
where
R: column vector with ratings by this user
M: item features for items rated by this user with dimensions |F|x|R|
M^T: transpose of M with dimensions |R|x|F|
N: number of ratings of this user
E: identity matrix with dimensions |F|x|F|
superstep
- the count of the current superstepvertex
- the current vertex with its valuemessages
- a Map of the source vertex and the message sent from the previous superstepedges
- the adjacent edges with their valuescb
- a callback for setting a new vertex value or sending messages to the next superstepprotected void updateValue(org.jblas.FloatMatrix value, org.jblas.FloatMatrix mat_M, org.jblas.FloatMatrix mat_R, float lambda)
public final void init(Map<String,?> configs, ComputeFunction.InitCallback cb)
ComputeFunction
init
in interface ComputeFunction<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage>
configs
- configuration parameterscb
- a callback for registering aggregatorspublic final void masterCompute(int superstep, ComputeFunction.MasterCallback cb)
ComputeFunction
masterCompute
in interface ComputeFunction<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage>
superstep
- the superstepcb
- a callback for writing to aggregators or halting the computationpublic void compute(int superstep, VertexWithValue<CfLongId,org.jblas.FloatMatrix> vertex, Iterable<FloatMatrixMessage> messages, Iterable<EdgeWithValue<CfLongId,Float>> edges, ComputeFunction.Callback<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage> cb)
ComputeFunction
compute
in interface ComputeFunction<CfLongId,org.jblas.FloatMatrix,Float,FloatMatrixMessage>
superstep
- the count of the current superstepvertex
- the current vertex with its valuemessages
- a Map of the source vertex and the message sent from the previous superstepedges
- the adjacent edges with their valuescb
- a callback for setting a new vertex value or sending messages to the next superstepprotected long getTotalNumEdges(ComputeFunction.ReadAggregators aggregators)
Copyright © 2020. All rights reserved.