Notice that we update the warping function gradients here.
960878
def parameters_changed(self):
        
        self.Y_normalized[:] = self.transform_data()
        super(WarpedGP, self).parameters_changed()
        Kiy = self.posterior.woodbury_vector.flatten()
        self.warping_function.update_grads(self.Y_untransformed, Kiy)
564418
private Pair<Gradient, INDArray> getGradientsAndDelta(INDArray preOut, LayerWorkspaceMgr workspaceMgr) {
        // delta calculation
        ILossFunction lossFunction = layerConf().getLossFn();
        INDArray delta = lossFunction.computeGradient(getLabels2d(), preOut, layerConf().getActivationFn(), maskArray);

        // grab the empty gradient
        Gradient gradient = new DefaultGradient();

        delta = workspaceMgr.leverageTo(ArrayType.ACTIVATION_GRAD, delta);
        return new Pair<>(gradient, delta);
    }
623554
def update_gradients_full(self, dL_dK, X, X2=None):
        """"""
        if X2 is None:
            X2 = X

        base = np.pi * (X[:, None, :] - X2[None, :, :]) / self.period

        sin_base = np.sin( base )
        exp_dist = np.exp( -0.5* np.sum( np.square(  sin_base / self.lengthscale ), axis = -1 ) )

        dwl = self.variance * (1.0/np.square(self.lengthscale)) * sin_base*np.cos(base) * (base / self.period)

        dl = self.variance * np.square( sin_base) / np.power( self.lengthscale, 3)

        self.variance.gradient = np.sum(exp_dist * dL_dK)
        #target[0] += np.sum( exp_dist * dL_dK)

        if self.ARD1: # different periods
            self.period.gradient = (dwl * exp_dist[:,:,None] * dL_dK[:, :, None]).sum(0).sum(0)
        else:  # same period
            self.period.gradient = np.sum(dwl.sum(-1) * exp_dist * dL_dK)

        if self.ARD2: # different lengthscales
            self.lengthscale.gradient = (dl * exp_dist[:,:,None] * dL_dK[:, :, None]).sum(0).sum(0)
        else: # same lengthscales
            self.lengthscale.gradient = np.sum(dl.sum(-1) * exp_dist * dL_dK)
313326
function regularizeL2(weights, gradientCount, stepSize, regParam) {
  const [gradient, count] = gradientCount;

  for (let i = 0; i < gradient.length; i++) {
    let grad = (gradient[i] || 0) / count;
    weights[i] = weights[i] || 0;
    weights[i] -= stepSize * (grad + regParam * weights[i]);
  }
}
1041607
function toGradientData(v1, v2, v3, v4, v5) {
    var startColor, endColor, type, rotation, spread, d;
    var data = {};

    if (arguments.length === 1) { // The argument is a dictionary or undefined.
        d = v1 || {};
        startColor = d.startColor;
        endColor = d.endColor;
        type = d.type;
        rotation = d.rotation;
        spread = d.spread;
    } else if (arguments.length >= 2) { // The first two arguments are a start color and an end color.
        startColor = v1;
        endColor = v2;
        type = 'linear';
        rotation = 0;
        spread = 0;
        if (arguments.length === 3) {
            if (typeof v3 === 'string') { // The type can be either linear or radial.
                type = v3;
            } else if (typeof v3 === 'number') { // The type is implicitly linear and the third argument is the rotation angle.
                rotation = v3;
            }
        } else if (arguments.length === 4) {
            if (typeof v3 === 'number') { // The type is implicitly linear and the third/forth arguments are the rotation angle and gradient spread.
                rotation = v3;
                spread = v4;
            } else if (v3 === 'linear') { // The type is explicitly linear and the forth argument is the rotation angle.
                rotation = v4;
            } else if (v3 === 'radial') { // The type is explicitly radial and the forth argument is the gradient spread.
                type = v3;
                spread = v4;
            } else {
                throw new Error('Wrong argument provided: ' + v3);
            }
        } else if (arguments.length === 5) { // Type, rotation (unused in case of radial type gradient), and gradient spread.
            type = v3;
            rotation = v4;
            spread = v5;
        }
    }

    if (!startColor && startColor !== 0) {
        throw new Error('No startColor was given.');
    }
    if (!endColor && endColor !== 0) {
        throw new Error('No endColor was given.');
    }

    try {
        data.startColor = toColor(startColor);
    } catch (e1) {
        throw new Error('startColor is not a valid color: ' + startColor);
    }

    try {
        data.endColor = toColor(endColor);
    } catch (e2) {
        throw new Error('endColor is not a valid color: ' + endColor);
    }

    if (type === undefined) {
        type = 'linear';
    }
    if (type !== 'linear' && type !== 'radial') {
        throw new Error('Unknown gradient type: ' + type);
    }

    data.type = type;

    if (spread === undefined) {
        spread = 0;
    }
    if (typeof spread !== 'number') {
        throw new Error('Spread value is not a number: ' + spread);
    }

    if (type === 'linear') {
        if (rotation === undefined) {
            rotation = 0;
        }
        if (typeof rotation !== 'number') {
            throw new Error('Rotation value is not a number: ' + rotation);
        }
        data.rotation = rotation;
    }

    data.spread = clamp(spread, 0, 0.99);

    return data;
}
1336657
@Override
	protected boolean updateDerivates() {
		functionGradientHessian(x,sameStateAsCost,gradient,hessian);

		if( config.hessianScaling ) {
			computeHessianScaling();
			applyHessianScaling();
		}

		// Convergence should be tested on scaled variables to remove their arbitrary natural scale
		// from influencing convergence
		if( checkConvergenceGTest(gradient)) {
			if( verbose != null ) {
				verbose.println("Converged g-test");
			}
			return true;
		}

		gradientNorm = NormOps_DDRM.normF(gradient);
		if(UtilEjml.isUncountable(gradientNorm))
			throw new OptimizationException("Uncountable. gradientNorm="+gradientNorm);

		parameterUpdate.initializeUpdate();
		return false;
	}
232860
function regularizeNone(weights, gradientCount) {
  const [gradient, count] = gradientCount;

  for (let i = 0; i < gradient.length; i++) {
    let grad = (gradient[i] || 0) / count;
    weights[i] = (weights[i] || 0) - grad;
  }
}
537326
def update_columns_dict(self, kwargs):
        
        super(Mesh, self).update_columns_dict(kwargs)

        # if kwargs.get('vnormals', None) is not None or kwargs.get('tnormals', None) is not None:
            # self._compute_mus()
        if kwargs.get('triangles', None) is not None:
            # reset visibilities and velocities so that they are reset
            # when next queried
            self.update_columns(visibilities=None, velocities=None)
1127879
protected void updateCurrent(ImagePyramid<I> image) {
		this.currentImage = image;
		for( int i = 0; i < image.getNumLayers(); i++ ) {
			gradient.process(image.getLayer(i), currentDerivX[i], currentDerivY[i]);
		}
	}
707875
def _update(self):
        

        """

        # Step 1 from alg.10.7.
        self._grad.get_grad(self._z_old)
        y_old = self._z_old - self._beta * self._grad.grad

        # Step 2 from alg.10.7.
        self._x_new = self._prox.op(y_old, extra_factor=self._beta)

        # Step 5 from alg.10.7.
        self._z_new = self._x_old + self._lambda * (self._x_new - self._x_old)

        # Restarting step from alg.4-5 in [L2018]
        if self._is_restart(self._z_old, self._x_new, self._x_old):
            self._z_new = self._x_new

        # Update old values for next iteration.
        np.copyto(self._x_old, self._x_new)
        np.copyto(self._z_old, self._z_new)

        # Update parameter values for next iteration.
        self._update_param()

        # Test cost function for convergence.
        if self._cost_func:
            self.converge = self.any_convergence_flag() or \
                            self._cost_func.get_cost(self._x_new)
1338767
def approximate_gradient(decision_function, sample, num_evals,
                         delta, constraint, shape, clip_min, clip_max):
  
  # Generate random vectors.
  noise_shape = [num_evals] + list(shape)
  if constraint == 'l2':
    rv = np.random.randn(*noise_shape)
  elif constraint == 'linf':
    rv = np.random.uniform(low=-1, high=1, size=noise_shape)

  axis = tuple(range(1, 1 + len(shape)))
  rv = rv / np.sqrt(np.sum(rv ** 2, axis=axis, keepdims=True))
  perturbed = sample + delta * rv
  perturbed = clip_image(perturbed, clip_min, clip_max)
  rv = (perturbed - sample) / delta

  # query the model.
  decisions = decision_function(perturbed)
  decision_shape = [len(decisions)] + [1] * len(shape)
  fval = 2 * decisions.astype(np_dtype).reshape(decision_shape) - 1.0

  # Baseline subtraction (when fval differs)
  if np.mean(fval) == 1.0:  # label changes.
    gradf = np.mean(rv, axis=0)
  elif np.mean(fval) == -1.0:  # label not change.
    gradf = - np.mean(rv, axis=0)
  else:
    fval = fval - np.mean(fval)
    gradf = np.mean(fval * rv, axis=0)

  # Get the gradient direction.
  gradf = gradf / np.linalg.norm(gradf)

  return gradf
1232612
def adjust_distributions_using_gradient
      return if @recent_scores.length < 3
      vx = (1..@recent_scores.length).to_a.to_numeric
      vy = @recent_scores.reverse.to_numeric
      r = Statsample::Regression::Simple.new_from_vectors(vx,vy)
      slope = r.b
      if slope > 0
        @distributions.each_pair { |k, d| d.tighten slope }
      elsif slope < 0
        @distributions.each_pair { |k, d| d.loosen slope }
      end
    end
513363
def update_gradients_full(self, dL_dK, X, X2=None):
        """"""
        dvar, dw, db = self._comp_grads(dL_dK, X, X2)[:3]
        self.variance.gradient = dvar
        self.weight_variance.gradient = dw
        self.bias_variance.gradient = db
507642
protected void computeGradient(AffinityMatrix pij, double[][] qij, double qij_isum, double[][] sol, double[] meta) {
    final int dim3 = dim * 3;
    int size = pij.size();
    for(int i = 0, off = 0; i < size; i++, off += dim3) {
      final double[] sol_i = sol[i], qij_i = qij[i];
      Arrays.fill(meta, off, off + dim, 0.); // Clear gradient only
      for(int j = 0; j < size; j++) {
        if(i == j) {
          continue;
        }
        final double[] sol_j = sol[j];
        final double qij_ij = qij_i[j];
        // Qij after scaling!
        final double q = MathUtil.max(qij_ij * qij_isum, MIN_QIJ);
        double a = 4 * (pij.get(i, j) - q); // SNE gradient
        for(int k = 0; k < dim; k++) {
          meta[off + k] += a * (sol_i[k] - sol_j[k]);
        }
      }
    }
  }
668129
def clip_gradients(batch_result, model, max_grad_norm):
    
    if max_grad_norm is not None:
        grad_norm = torch.nn.utils.clip_grad_norm_(
            filter(lambda p: p.requires_grad, model.parameters()),
            max_norm=max_grad_norm
        )
    else:
        grad_norm = 0.0

    batch_result['grad_norm'] = grad_norm
267468
public static
	void gradient_noborder(GrayF32 ii , double tl_x , double tl_y , double samplePeriod ,
						   int regionSize , double kernelWidth ,
						   float[] derivX , float[] derivY )
	{
		ImplSurfDescribeOps.gradientInner(ii,tl_x,tl_y,samplePeriod,regionSize, kernelWidth, derivX,derivY);
	}
1004459
private int gradientUpdate(List<TensorBuilder> factors,
      List<TensorBuilder> unaryFactors, double stepSize) {
    // The best assignment, as computed from only the unary factors.
    int[] variableNums = new int[unaryFactors.size()];
    int[] variableSizes = new int[unaryFactors.size()];
    int[] variableValues = new int[unaryFactors.size()];
    locallyDecodeFactors(unaryFactors, variableNums, variableSizes, variableValues);

    // Identify where unary factors disagree with larger factors to compute the
    // subgradient.
    List<Integer> variableDisagreementList = Lists.newArrayList();
    List<Integer> factorDisagreementList = Lists.newArrayList();
    List<Integer> factorValueList = Lists.newArrayList();
    for (int i = 0; i < factors.size(); i++) {
      TensorBuilder factor = factors.get(i);
      int[] bestFactorValues = factor.keyNumToDimKey(factor.getLargestValues(1)[0]);
      int[] factorVariableNums = factor.getDimensionNumbers();

      for (int j = 0; j < factorVariableNums.length; j++) {
        int index = Arrays.binarySearch(variableNums, factorVariableNums[j]);
        if (bestFactorValues[j] != variableValues[index]) {
          // Factor and unary assignments disagree on variableNums[index].
          // Store the disagreement, used later to compute the subgradient.
          variableDisagreementList.add(index);
          factorDisagreementList.add(i);
          factorValueList.add(bestFactorValues[j]);

          /*
          System.out.println("Disagreement " + Arrays.toString(factorVariableNums) + "=" + Arrays.toString(bestFactorValues) + ", "
              + variableNums[index] + "=" + variableValues[index]);
              */
        }
      }
    }

    // Update the factor lagrange multipliers based on the disagreements.
    // For each disagreement, the subgradient update decreases the weight of
    // each factor's maximum weight assignment, and increases the weight of
    // the disagreeing factor's maximum weight assignment.
    for (int i = 0; i < variableDisagreementList.size(); i++) {
      int variableIndex = variableDisagreementList.get(i);
      int factorNum = factorDisagreementList.get(i);

      TensorBuilder factor = factors.get(factorNum);
      TensorBuilder unaryFactor = unaryFactors.get(variableIndex);

      int variableNum = variableNums[variableIndex];
      int variableSize = variableSizes[variableIndex];
      int bestFactorValue = factorValueList.get(i);
      int bestUnaryValue = variableValues[variableIndex];

      SparseTensor unaryGradient = SparseTensor.singleElement(new int[] { variableNum },
          new int[] { variableSize }, new int[] { bestUnaryValue }, 1);
      SparseTensor factorGradient = SparseTensor.singleElement(new int[] { variableNum },
          new int[] { variableSize }, new int[] { bestFactorValue }, 1);

      unaryFactor.incrementWithMultiplier(unaryGradient, -1.0 * stepSize);
      unaryFactor.incrementWithMultiplier(factorGradient, stepSize);
      factor.incrementWithMultiplier(unaryGradient, stepSize);
      factor.incrementWithMultiplier(factorGradient, -1.0 * stepSize);
    }

    return variableDisagreementList.size();
  }