topobench.transforms.liftings.graph2simplicial.latentclique_lifting module#

This module implements the LatentCliqueLifting class, which lifts graphs to simplicial complexes.

class Graph2SimplicialLifting(complex_dim=2, **kwargs)#

Bases: GraphLifting

Abstract class for lifting graphs to simplicial complexes.

Parameters:
complex_dimint, optional

The maximum dimension of the simplicial complex to be generated. Default is 2.

**kwargsoptional

Additional arguments for the class.

__init__(complex_dim=2, **kwargs)#
class LatentCliqueLifting(edge_prob_mean=0.9, edge_prob_var=0.05, it=20, init='edges', do_gibbs=False, **kwargs)#

Bases: Graph2SimplicialLifting

Lift graphs to cell complexes by identifying the cycles as 2-cells.

Parameters:
edge_prob_meanfloat = 0.9

Mean of the prior distribution of pie ~ Beta where edge_prob_mean must be in (0, 1). When edge_prob_mean is one, the value of edge_prob is fixed and not sampled.

edge_prob_varfloat = 0.05

Uncertainty of the prior distribution of pie ~ Beta(a, b) where edge_prob_var must be in [0, inf). When edge_prob_var is zero, the value of edge_prob is fixed and not sampled. It is require dthat edge_prob_var < edge_prob_mean * (1 - edge_prob_mean). When this is not the case the value of edge_prob_var is set to edge_prob_mean * (1 - edge_prob_mean) - 1e-6.

itint, optional

Number of iterations for sampling, by default None.

initstr, optional

Initialization method for the clique cover matrix, by default “edges”.

do_gibbsbool, optional

Whether to perform Gibbs sampling, by default False.

**kwargsoptional

Additional arguments for the class.

__init__(edge_prob_mean=0.9, edge_prob_var=0.05, it=20, init='edges', do_gibbs=False, **kwargs)#
lift_topology(data, verbose=True)#

Find the cycles of a graph and lifts them to 2-cells.

Parameters:
datatorch_geometric.data.Data

The input data to be lifted.

verbosebool, optional

Whether to display verbose output, by default False.

Returns:
dict

The lifted topology.

class SimplicialCliqueLifting(**kwargs)#

Bases: Graph2SimplicialLifting

Lift graphs to simplicial complex domain.

The algorithm creates simplices by identifying the cliques and considering them as simplices of the same dimension.

Parameters:
**kwargsoptional

Additional arguments for the class.

__init__(**kwargs)#
lift_topology(data)#

Lift the topology of a graph to a simplicial complex.

Parameters:
datatorch_geometric.data.Data

The input data to be lifted.

Returns:
dict

The lifted topology.

tqdm#

alias of tqdm_asyncio

logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False)#

Compute the log of the sum of exponentials of input elements.

Parameters:
aarray_like

Input array.

axisNone or int or tuple of ints, optional

Axis or axes over which the sum is taken. By default axis is None, and all elements are summed.

Added in version 0.11.0.

barray-like, optional

Scaling factor for exp(a) must be of the same shape as a or broadcastable to a. These values may be negative in order to implement subtraction.

Added in version 0.12.0.

keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array.

Added in version 0.15.0.

return_signbool, optional

If this is set to True, the result will be a pair containing sign information; if False, results that are negative will be returned as NaN. Default is False (no sign information).

Added in version 0.16.0.

Returns:
resndarray

The result, np.log(np.sum(np.exp(a))) calculated in a numerically more stable way. If b is given then np.log(np.sum(b*np.exp(a))) is returned. If return_sign is True, res contains the log of the absolute value of the argument.

sgnndarray

If return_sign is True, this will be an array of floating-point numbers matching res containing +1, 0, -1 (for real-valued inputs) or a complex phase (for complex inputs). This gives the sign of the argument of the logarithm in res. If return_sign is False, only one result is returned.

Notes

NumPy has a logaddexp function which is very similar to logsumexp, but only handles two arguments. logaddexp.reduce is similar to this function, but may be less stable.

The logarithm is a multivalued function: for each \(x\) there is an infinite number of \(z\) such that \(exp(z) = x\). The convention is to return the \(z\) whose imaginary part lies in \((-pi, pi]\).

logsumexp has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

n/a

CuPy

n/a

PyTorch

JAX

Dask

n/a

See Support for the array API standard for more information.

Examples

>>> import numpy as np
>>> from scipy.special import logsumexp
>>> a = np.arange(10)
>>> logsumexp(a)
9.4586297444267107
>>> np.log(np.sum(np.exp(a)))
9.4586297444267107

With weights

>>> a = np.arange(10)
>>> b = np.arange(10, 0, -1)
>>> logsumexp(a, b=b)
9.9170178533034665
>>> np.log(np.sum(b*np.exp(a)))
9.9170178533034647

Returning a sign flag

>>> logsumexp([1,2],b=[1,-1],return_sign=True)
(1.5413248546129181, -1.0)

Notice that logsumexp does not directly support masked arrays. To use it on a masked array, convert the mask into zero weights:

>>> a = np.ma.array([np.log(2), 2, np.log(3)],
...                  mask=[False, True, False])
>>> b = (~a.mask).astype(int)
>>> logsumexp(a.data, b=b), np.log(5)
1.6094379124341005, 1.6094379124341005