gradnet.gradnet.SparseParameterization

class gradnet.gradnet.SparseParameterization(*, num_nodes, budget, edge_index, cost_p_sum, delta_sign='nonnegative', directed=False, strict_budget=False, cost_aggr_norm=1, rand_init_weights=True, dtype=None, device=None)[source]

Sparse, edge-list parameterization for masked adjacencies.

This backend stores a 1D trainable vector of length E (active edges) and constructs a sparse COO tensor for the delta matrix. In directed=False mode, only (i < j) edges are parameterized and mirrored on output.

Construct a sparse edge-list parameterization.

Parameters:
  • num_nodes (int) – Number of nodes N (matrix dimension).

  • budget (float | None) – Target cost-weighted p-norm of the perturbation. If None, skip normalization.

  • edge_index (torch.Tensor) – Integer tensor of shape (2, E) giving the edge list. When directed=False, edges must satisfy i < j.

  • cost_p_sum (torch.Tensor) – Positive tensor of shape (E,) containing, for each edge, the sum of costs to the power p used in the normalization. For directed=False this is typically |c_ij|^p + |c_ji|^p; for directed, |c_ij|^p.

  • delta_sign (str, optional) – Sign constraint for the perturbation. One of {"free", "nonnegative", "nonpositive"}.

  • directed (bool, optional) – If False, mirror (i, j) entries to (j, i) when building the sparse matrix.

  • strict_budget (bool, optional) – If True, always scale up/down to the exact budget; if False, scale down only.

  • cost_aggr_norm (int, optional) – Aggregation norm p for the cost-weighted p-norm.

  • rand_init_weights (bool | float, optional) – Initialization mix coefficient a. Cast to float and clamped to [0,1]. Raw edge weights are set to (1 - a) * base + a * U(0,1), where base is ones for strict budget mode and zeros otherwise.

  • dtype (torch.dtype | None, optional) – Parameter/buffer dtype. If omitted, inferred from cost_p_sum.

  • device (torch.device | None, optional) – Parameter/buffer device. If omitted, inferred from edge_index.

Methods

extra_repr()

Return the extra representation of the module.

forward([noise_amplitude])

Project raw edge weights to a sparse, normalized delta.

renorm_params()

Scale raw edge parameters to a backend-aligned constant norm.

set_initial_state(delta_adj_raw_0)

Set the internal raw edge weights and re-normalize.

Attributes

device

dtype

training