Kernel¶
Compute graph kernels.
- diffupy.kernels.diffusion_kernel(graph: networkx.classes.graph.Graph, sigma2: float = 1, normalized: bool = True) → diffupy.matrix.Matrix[source]¶
Compute the classical diffusion kernel that involves matrix exponentiation.
It has a “bandwidth” parameter sigma^2 that controls the extent of the spreading. Quoting [Smola, 2003]: k(x1,x2) can be visualized as the quantity of some substance that would accumulate at vertex x2 after a given amount of time if we injected the substance at vertex x1 and let it diffuse through the graph along the edges.
This kernel can be computed using both the unnormalised and normalised graph Laplacian. :param graph: A graph :param sigma2: Controls the extent of the spreading. :param normalized: Indicates if Laplacian transformation is normalized or not. :return: Laplacian representation of the graph
- diffupy.kernels.compute_time_kernel(graph: networkx.classes.graph.Graph, normalized: bool = False) → diffupy.matrix.Matrix[source]¶
Compute the commute-time kernel, which is the expected time of going back and forth between a couple of nodes.
If the network is connected, then the commuted time kernel will be totally dense, therefore reflecting global properties of the network. For further details, see [Yen, 2007]. This kernel can be computed using both the unnormalised and normalised graph Laplacian.
- Parameters
graph – A graph
normalized – Indicates if Laplacian transformation is normalized or not.
- Returns
Laplacian representation of the graph.
- diffupy.kernels.inverse_cosine_kernel(graph: networkx.classes.graph.Graph) → diffupy.matrix.Matrix[source]¶
Compute the inverse cosine kernel, which is based on a cosine transform on the spectrum of the normalized LM.
Quoting [Smola, 2003]: the inverse cosine kernel treats lower complexity functions almost equally, with a significant reduction in the upper end of the spectrum.
This kernel is computed using the normalised graph Laplacian.
- Parameters
graph – A graph
- Returns
Laplacian representation of the graph
- diffupy.kernels.regularised_laplacian_kernel(graph: networkx.classes.graph.Graph, sigma2: float = 1, add_diag: int = 1, normalized: bool = False) → diffupy.matrix.Matrix[source]¶
Compute the regularised Laplacian kernel, which is a standard in biological networks.
The regularised Laplacian kernel arises in numerous situations, such as the finite difference formulation of the diffusion equation and in Gaussian process estimation. Sticking to the heat diffusion model, this function allows to control the constant terms summed to the diagonal through add_diag, i.e. the strength of the leaking in each node. If a node has diagonal term of 0, it is not allowed to disperse heat. The larger the diagonal term of a node, the stronger the first order heat dispersion in it, provided that it is positive. Every connected component in the graph should be able to disperse heat, i.e. have at least a node i with add_diag[i] > 0. If this is not the case, the result diverges. More details on the parameters can be found in [Smola, 2003]. This kernel can be computed using both the unnormalised and normalised graph Laplacian.
- Parameters
graph – A graph
a – regularising summed to the spectrum. Spectrum of the normalised Laplacian matrix.
p – p-step kernels can be cheaper to compute and have been successful in biological tasks.
- Returns
Laplacian representation of the graph.
- diffupy.kernels.p_step_kernel(graph: networkx.classes.graph.Graph, a: int = 2, p: int = 5) → diffupy.matrix.Matrix[source]¶
Compute the inverse cosine kernel, which is based on a cosine transform on the spectrum of the normalized LM.
This kernel is more focused on local properties of the nodes, because random walks are limited in terms of length. Therefore, if p is small, only a fraction of the values k(x1,x2) will be non-null if the network is sparse [Smola, 2003]. The parameter a is a regularising term that is summed to the spectrum of the normalised Laplacian matrix, and has to be 2 or greater. The p-step kernels can be cheaper to compute and have been successful in biological tasks, see the benchmark in [Valentini, 2014].
- Parameters
graph – A graph
a – regularising summed to the spectrum. Spectrum of the normalised Laplacian matrix.
p – p-step kernels can be cheaper to compute and have been successful in biological tasks.
- Returns
Laplacian representation of the graph.