plot

Questions

Consider a simple function \(R(\beta) = sin(\beta) + \frac{\beta}{10}\).

  1. Create an R function cost that returns the function value for some argument beta. (hint: use the sin() function)
  2. Draw a graph of this function over the range \(\beta \in [-6, 6]\). (not tested)
  3. 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)
  4. 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
  5. 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.
  6. Show each of \(\beta^0, \beta^1, \dots\) in your plot, as well as the answer. (not tested)
  7. Repeat with \(\beta^0 = 1.4\). This time, use 60 iterations and store the vector in beta_vec2.
  8. Show each of \(\beta^0, \beta^1, \dots\) in your plot, as well as the answer. (not tested)