'Update the encoder and decoder weigths and biases.
Args:
step: Time step of training.'

def UpdateParameters(self, step):

    numcases = self.batchsize
    code_layer = self.code_layer
    input_layer = self.input_layer
    encoder = self.encoder
    decoder = self.decoder
    wd = decoder.params['weight']
    bd = input_layer.params['bias']
    z = code_layer.state
    inputs = input_layer.state
    we = encoder.params['weight']
    be = code_layer.params['bias']
    scale = code_layer.params['scale']
    code_approx = code_layer.approximator
    hyp = code_layer.hyperparams
    alpha = hyp.sc_alpha
    beta = hyp.sc_beta
    gamma = hyp.sc_gamma
    enc_hyp = encoder.hyperparams
    dec_hyp = decoder.hyperparams
    deriv = input_layer.deriv
    (momentum, epsilon) = decoder.GetMomentumAndEpsilon(step)
    wd_delta = self.decoder.grad_weight
    wd_delta.mult(momentum)
    wd_delta.add_dot(z, deriv.T, (beta / numcases))
    if dec_hyp.apply_l2_decay:
        wd_delta.add_mult(wd, alpha=dec_hyp.l2_decay)
    (momentum, epsilon) = input_layer.GetMomentumAndEpsilon(step)
    bd_delta = input_layer.grad_bias
    bd_delta.mult(momentum)
    bd_delta.add_sums(deriv, axis=1, mult=(beta / numcases))
    deriv = code_layer.deriv
    code_approx.div_by_col(scale)
    scale_delta = code_layer.grad_scale
    scale_delta.mult(momentum)
    temp = code_layer.temp3
    code_approx.mult(deriv, target=temp)
    scale_delta.add_sums(temp, axis=1, mult=(alpha / numcases))
    code_layer.deriv.mult_by_col(scale)
    code_layer.ComputeDeriv(code_approx)
    deriv = code_layer.deriv
    (momentum, epsilon) = encoder.GetMomentumAndEpsilon(step)
    we_delta = self.encoder.grad_weight
    we_delta.mult(momentum)
    we_delta.add_dot(inputs, deriv.T, (alpha / numcases))
    if enc_hyp.apply_l2_decay:
        we_delta.add_mult(we, alpha=enc_hyp.l2_decay)
    (momentum, epsilon) = code_layer.GetMomentumAndEpsilon(step)
    be_delta = code_layer.grad_bias
    be_delta.mult(momentum)
    be_delta.add_sums(deriv, axis=1, mult=(alpha / numcases))
    scale.add_mult(scale_delta, (- epsilon))
    bd.add_mult(bd_delta, (- epsilon))
    wd.add_mult(wd_delta, (- epsilon))
    be.add_mult(be_delta, (- epsilon))
    we.add_mult(we_delta, (- epsilon))
    if dec_hyp.apply_weight_norm:
        wd.norm_limit(dec_hyp.weight_norm, axis=0)
    if enc_hyp.apply_weight_norm:
        we.norm_limit(enc_hyp.weight_norm, axis=0)
