# How should I use stochastic gradient descent when I have two sets of data?

In social recommender system problems, we have two sets of data, one the rating data denoted as $R$ and the other social data denoted as $T$, most of the papers end at an objective function over these two sets of data, something like this:

$$\text{Minimize} J = \lvert \lvert R - U^TV \rvert \rvert^2 + \beta ||T - U^TZ|| + \lambda(||U||^2 + ||V||^2 + ||Z||^2)$$ Where the first term is for rating data $R$ and the second term is for social data $T$

I have came up with the following code for training, can anyone tell me if I am doing wrong? or should I alternate between social data and rating data and update parameters in that way?

def iterate():
for (u, i) in rating:
// the gradient term is computed by the first term of objective function and regularization part
// update U,
// update V,
for (u, v) in social_data:
// the gradient term is computed by the second term of objective function and regularization part
// update U
// update Z


## 1 Answer

Yes, this is a bad idea. You want to alternate between social data and rating data examples. If you alternate the datasets instead of alternating each example, then the learned weights will probably not converge.

You can imagine if you trained a neural network to classify dogs and cats, but fed all the dog images first, then all the cat images, then back to dog images, etc, then the network would go back and forth between classifying everything as dogs and classifying everything as cats. Same idea here.