Loading...
Loading...
You are given a 2d list of integers x with n rows and d columns, a list of doubles y with n entries, a list of integers indices, a list of doubles initial with d entries, and a double eta. Row x[i] holds the features of datapoint i, y[i] is its target value, initial is the starting value of the weight vector t, and eta is the step size.
For a weight vector t, the loss of datapoint i is (1/2) * (x[i] . t - y[i]) ** 2, where x[i] . t is the sum of x[i][j] * t[j] over all j. The loss of t is the sum of the losses of all n datapoints.
Consider an operation where you pick a datapoint j and replace t with t - eta * grad(t) where grad(t) = (x[j] . t - y[j]) * x[j] is the gradient of the loss for datapoint j with parameters t. Starting from t = initial, perform this operation indices.length times, using j = indices[k] on the k-th step (counting from 0).
Return the loss of the final weight vector.
x.length ≤20x[i].length ≤3x[i].length = initial.length for every ix[i][j] ≤5y.length = x.lengthy[i] ≤10indices.length ≤500indices[i] < x.lengthinitial[j] ≤1eta $\leq 0.01`One step on the only datapoint gives t = 0.04. The loss is (1/2) * (0.04 - 2) ** 2 = 1.9208.
The two steps give t = [0.02, 0.04]. The datapoint losses are 0.4802 and 1.9208, so the total is 2.401.
After two updates t = [0.0784, 0.0784], and (1/2) * (0.1568 - 2) ** 2 = 1.69869312.