class_docstr: Models a simple one variable(y = wx) neural network, and a MSE loss function.
class_docstr_tok: ["Models","a","simple","one","variable","(","y","=","wx",")","neural","network",",","and","a","MSE","loss","function","."]
code: def calc_gradient(w: float, values: List[float]) -> float:
      # Calculate what the gradient should be for a given weight and batch of
      # input values.
  
      # model:            yhat = w*x
      # loss:             L = (ytrue - w*x)**2
      # gradient:         dL/dw = -2*x*(ytrue - w*x)
      # let ytrue = x:    dL/dw = -2*x*x*(1-w)
  
      # We know that TensorFlow averages gradients across a batch, so we take
      # the mean of the gradient from each value in `values`.
      return np.mean([-2 * v * v * (1 - w) for v in values])
  
file_path: determined/harness/tests/experiment/fixtures/tf_keras_one_var_model.py
imports: from typing import Any, Dict, List, cast
  import numpy
  import tensorflow
  from tensorflow.keras.layers import Dense
  from tensorflow.keras.losses import mean_squared_error
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.optimizers.legacy import SGD
  from determined import keras
  from tests.experiment.fixtures import keras_cb_checker
label_desc: Use image node_id 5 for calling the OneVarTrial obj's underlying member method code with example usage: obj.calc_gradient(w, values) and returns: np