matrix_SPSA_algorithm.SPSA_gradient#

matrix_SPSA_algorithm.SPSA_gradient(theta: ndarray, initial_trans_matrix: ndarray, C: ndarray, rng: numpy.random.mtrand.RandomState | numpy.random._generator.Generator, i: int, ALGORITHM_PARAMETERS: dict[str, Any]) ndarray#

Calculates the SPSA gradient.

Note that the elements where C=0 have value 0.

Parameters:
  • theta (np.ndarray) – The matrix in the unconstrained space that is optimised.

  • initial_trans_matrix (np.ndarray) – The transition matrix that is optimised.

  • C (np.ndarray) – The binary adjustment matrix.

  • rng (np.random.mtrand.RandomState|np.random._generator.Generator) – A pseudo-random number generator.

  • i (int) – The iteration number.

  • ALGORITHM_PARAMETERS (dict[str, Any]) – The algorithm parameters. Methods that are called within this method require parameters. See these methods for explanations.

Returns:

Y (np.ndarray) – The SPSA gradient.