
Questions
Consider a simple function \(R(\beta) = sin(\beta) + \frac{\beta}{10}\).
- Create an R function
cost that returns the function value for some argument beta. (hint: use the sin() function)
- Draw a graph of this function over the range \(\beta \in [-6, 6]\). (not tested)
- What is the derivative of this function?
Create an R function
cost_deriv that returns the derivative for some argument beta. (hint: \(sin'(x) = cos(x)\), i.e. cos() function)
- Create an R function
gradient_descent with arguments num_iters, learning_rate, and init_value.
The function performs gradient descent for num_iters iterations, starting from the initial value init_value, using a learning rate learning_rate.
The function should return the vector of betas of length num_iters + 1
- Given \(\beta^0 = 2.3\), run gradient descent for 50 iterations to find a local minimum of \(R(\beta)\) using a learning rate of \(\rho = 0.1\).
Store the vector in
beta_vec1.
- Show each of \(\beta^0, \beta^1, \dots\) in your plot, as well as the answer. (not tested)
- Repeat with \(\beta^0 = 1.4\). This time, use 60 iterations and store the vector in
beta_vec2.
- Show each of \(\beta^0, \beta^1, \dots\) in your plot, as well as the answer. (not tested)
- MC1: Which one of the 2 initializations ends up in the global optimum?
- 1) \(\beta^0 = 2.3\)
- 2) \(\beta^0 = 1.4\)