matrix_algorithms.run_matrix_algorithm_improved_memory#

matrix_algorithms.run_matrix_algorithm_improved_memory(M: ndarray, C: ndarray, start_time_algorithm: datetime, rng: numpy.random.mtrand.RandomState | numpy.random._generator.Generator, ALGORITHM_PARAMETERS: dict[str, Any]) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]#

Runs SM-SPSA “memory optimised” on a transition matrix and binary matrix C.

The main difference between the “normal” and “memory optimised” version of the algorithm is that, in case of the memory optimised version, not all matrices are stored for each iteration. Instead, only the matrices of the last iteration are stored. This version is especially useful for large networks.

Parameters:
  • M (np.ndarray) – The transition matrix that is optimised.

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

  • start_time_algorithm (datetime.datetime) – The start time of the algorithm.

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

  • ALGORITHM_PARAMETERS (dict[str, Any]) – The algorithm parameters. The parameters DECR_NR_OBJ_EVAL, NR_ITERATIONS, MAXIMISE_OBJECTIVE, EPSILON, OBJ_EVAL_ITERATION, USE_TIME_LIMIT and TIME_LIMIT_SEC are at least necessary. See main.py for parameter explanations. Note that methods that are called within this method may require more parameters. Note that NR_ITERATIONS is set in the methods of run_algorithm.py.

Returns:

  • Y_grad (np.ndarray) – The gradient estimate at the last iteration.

  • current_theta (np.ndarray) – The matrix in the unconstrained space at the last iteration.

  • current_transition_matrix (np.ndarray) – The transition matrix in the stochastic matrix space at the last iteration.

  • current_stationary_distribution (np.ndarray) – The stationary distribution of all nodes at the last iteration.

  • objective_values (np.ndarray) – The objective value at each iteration or at each OBJ_EVAL_ITERATION th iteration if DECR_NR_OBJ_EVAL=True. Note that the last objective value is the objective value of the last OBJ_EVAL_ITERATION th iteration if USE_TIME_LIMIT=True and the optimisation has not finished before the time limit has passed, i.e., the objective value is not calculated at the specific iteration the time limit has passed if that iteration is not divisible by OBJ_EVAL_ITERATION.