sfa.utils module

class sfa.utils.FrozenClass[source]

Bases: object

sfa.utils.Singleton(_class)[source]
sfa.utils.to_networkx_digraph(A, n2i=None)[source]
sfa.utils.normalize(A, norm_in=True, norm_out=True)[source]
sfa.utils.rand_swap(A, nsamp=10, noself=True, pivots=None, inplace=False)[source]

Randomly rewire the network connections by swapping.

Parameters
Anumpy.ndarray

Adjacency matrix (connection matrix).

nsampint, optional

Number of sampled connections to rewire

noselfbool, optional

Whether to allow self-loop link.

pivotslist, optional

Indices of pivot nodes

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomized matrix. The reference of the given W is returned, when inplace is True.

sfa.utils.rand_flip(A, nsamp=10, pivots=None, inplace=False)[source]

Randomly flip the signs of connections.

Parameters
Anumpy.ndarray

Adjacency matrix (connection matrix).

nsampint, optional

Number of sampled connections to be flipped.

pivotslist, optional

Indices of pivot nodes

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomized matrix. The reference of the given W is returned, when inplace is True.

sfa.utils.rand_weights(W, lb=-3, ub=3, inplace=False)[source]

Randomly sample the weights of connections in W from 10^(lb, ub).

Parameters
Wnumpy.ndarray

Adjacency (connection) or weight matrix.

lbfloat, optional

The 10’s exponent for lower bound

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomly sampled weight matrix. The reference of the given W is returned, when inplace is True.

sfa.utils.rand_structure(A, nswap=10, nflip=10, noself=True, pivots=None, inplace=False)[source]
sfa.utils.get_akey(d)[source]

Get a key from a given dictionary. It returns the first key in d.keys().

Parameters
ddict

Dictionary of objects.

Returns
objobject

First item of iter(d.keys()).

sfa.utils.get_avalue(d)[source]

Get a value from a given dictionary. It returns the value designated by sfa.get_akey().

Parameters
ddict

Dictionary of objects.

Returns
objobject

First item of d[iter(d.keys())].