nlgm.optimizers Module#

class nlgm.optimizers.RandomWalkOptimizer(graph, signatures, start, criterion)[source]#

RandomWalkOptimizer class for optimizing a given objective function using random walk algorithm.

Args:

graph (numpy.ndarray): The adjacency matrix of the graph. signatures (list): List of signatures corresponding to each node in the graph. start (int): The starting node for the random walk. criterion (str): The criterion for optimization.

Attributes:

graph (numpy.ndarray): The adjacency matrix of the graph. start (int): The starting node for the random walk. signatures (list): List of signatures corresponding to each node in the graph. criterion (str): The criterion for optimization.

Methods:

optimize(objective, max_iters, callback=None): Optimizes the objective function using random walk algorithm. normalize_graph(): Normalizes the graph by dividing each row by its sum. optimize_with_backtracking(objective, max_iters, callback=None): Optimizes the objective function using random walk algorithm with backtracking.

normalize_graph()[source]#

Normalizes the graph by dividing each row by its sum.

optimize(objective, max_iters, callback=None)[source]#

Optimizes the objective function using random walk algorithm.

Args:

objective (function): The objective function to be optimized. max_iters (int): The maximum number of iterations for the optimization. callback (function, optional): A callback function to be called after each iteration. Defaults to None.

Returns:

tuple: A tuple containing the best node, metric, and loss.

optimize_with_backtracking(objective, max_iters, callback=None)[source]#

Optimizes the objective function using random walk algorithm with backtracking.

Args:

objective (function): The objective function to be optimized. max_iters (int): The maximum number of iterations for the optimization. callback (function, optional): A callback function to be called after each iteration. Defaults to None.

Returns:

tuple: A tuple containing the best node, metric, and loss.