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 thedeltamatrix. Indirected=Falsemode, 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. Whendirected=False, edges must satisfyi < j.cost_p_sum (torch.Tensor) – Positive tensor of shape
(E,)containing, for each edge, the sum of costs to the powerpused in the normalization. Fordirected=Falsethis 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; ifFalse, scale down only.cost_aggr_norm (int, optional) – Aggregation norm
pfor 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), wherebaseis 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
devicedtypetraining