graphdot.microkernel package¶
Microkernels are positive-semidefinite functions between individual nodes and edges of graphs.
-
class
graphdot.microkernel.
MicroKernel
[source]¶ Bases:
abc.ABC
The abstract base class for all microkernels.
-
__add__
(k)[source]¶ Implements the additive kernel composition semantics, i.e. expression
k1 + k2
creates \(k_+(a, b) = k_1(a, b) + k_2(a, b)\)
-
__call__
(i, j, jac=False)[source]¶ Evaluates the kernel.
Parameters: - j (i,) – Inputs to the kernel.
- jac (Boolean) – Whether or not to return the gradient of the kernel with respect to kernel hyperparameters alongside the kernel value.
Returns: - k_ij (scalar) – The value of the kernel as evaluated on i and j.
- jacobian (1D ndarray) – The gradient of the kernel with regard to hyperparameters.
-
__mul__
(k)[source]¶ Implements the multiplicative kernel composition semantics, i.e. expression
k1 * k2
creates \(k_\times(a, b) = k_1(a, b) \times k_2(a, b)\)
-
bounds
¶ A list of 2-tuples for the lower and upper bounds of each kernel hyperparameter.
-
static
from_sympy
(name, desc, expr, vars, *hyperparameter_specs, minmax=(0, 1))[source]¶ Create a pairwise kernel class from a SymPy expression.
Parameters: - name (str) – The name of the kernel. Must be a valid Python identifier.
- desc (str) – A human-readable description of the kernel. Will be used to build the docstring of the returned kernel class.
- expr (str or SymPy expression) – Expression of the kernel in SymPy format.
- vars (2-tuple of str or SymPy symbols) – The input variables of the kernel as shown up in the expression. A kernel must have exactly 2 input variables. All other symbols that show up in its expression should be regarded as hyperparameters.
- hyperparameter_specs (list of hyperparameter specifications in one of) –
- formats below (the) – symbol,(symbol,),(symbol, dtype),(symbol, dtype, description),(symbol, dtype, lower_bound, upper_bound),(symbol, dtype, lower_bound, upper_bound, description),
If a default set of lower and upper bounds are not defined here, then it must be specified explicitly during kernel object creation, using arguments as specified in the kernel class’s docstring.
-
gen_expr
(x, y, theta_scope='')[source]¶ Generate the C++ expression for evaluating the kernel and its partial derivatives.
Parameters: - y (x,) – Name of the input variables.
- theta_scope (str) – The scope in which the hyperparameters is located.
Returns: - expr (str) – A C++ expression that evaluates the kernel.
- jac_expr (list of strs) – C++ expressions that evaluate the derivative of the kernel.
-
minmax
¶ A 2-tuple of the minimum and maximum values that the kernel could take.
-
name
¶ Name of the kernel.
-
normalized
¶ A normalized version of the original kernel using the dot product formula: :py:math:`k^\mathrm{normalized}(i, j) = \frac{k(i, j)}{\sqrt{k(i, i) k(j, j)}}`.
-
theta
¶ A tuple of all the kernel hyperparameters.
-
-
class
graphdot.microkernel.
Product
¶ Bases:
graphdot.microkernel.product.Product
-
dtype
= dtype([], align=True)¶
-
state
¶
-
-
graphdot.microkernel.
Constant
(c, c_bounds='fixed')[source]¶ Creates a no-op microkernel that returns a constant value, i.e. \(k_\mathrm{c}(\cdot, \cdot) \equiv constant\). This kernel is often mutliplied with other microkernels as an adjustable weight.
Parameters: c (float > 0) – The constant value.
-
graphdot.microkernel.
KroneckerDelta
(h, h_bounds=(0.001, 1))[source]¶ Creates a Kronecker delta microkernel that returns either 1 or h depending on whether two features compare equal, i.e. \(k_\delta(i, j) = \begin{cases} 1, i = j \\ h, otherwise \end{cases}\).
Parameters: - h (float in (0, 1)) – The value of the microkernel when two features do not compare equal.
- h_bounds (tuple or "fixed") – If tuple, contains the lower and upper bounds that h is allowed to vary during hyperparameter optimization. If “fixed”, the hyperparameter will not be optimized during training.
-
graphdot.microkernel.
SquareExponential
¶ alias of
graphdot.microkernel._base._from_sympy.<locals>.uKernel
-
graphdot.microkernel.
RationalQuadratic
¶ alias of
graphdot.microkernel._base._from_sympy.<locals>.uKernel
-
graphdot.microkernel.
Normalize
(kernel: graphdot.microkernel._base.MicroKernel)[source]¶ Normalize the value range of a microkernel to [0, 1] using the cosine of angle formula: \(k_{normalized}(x, y) = \frac{k(x, y)} {\sqrt{k(x, x) k(y, y)}}\).
Parameters: kernel – The microkernel to be normalized.
-
graphdot.microkernel.
Composite
(oper, **kw_kernels)[source]¶ Creates a microkernel on multiple features, which uses a reduction operator to combine the outputs of multiple microkernels on individual features. \(k_\mathrm{composite}(X, Y; \mathrm{op}) = k_{a_1}(X_{a_1}, Y_{a_1})\,\mathrm{op}\,k_{a_2}(X_{a_2}, Y_{a_2})\, \mathrm{op}\,\ldots\)
Parameters: - oper (str) – A reduction operator. Due to positive definiteness requirements, the available options are currently limited to ‘+’, ‘*’.
- kw_kernels (dict of attribute=kernel pairs) – The kernels can be any microkernels and their compositions as defined in this module, while features should be strings that represent valid Python/C++ identifiers.
-
graphdot.microkernel.
TensorProduct
(**kw_kernels)[source]¶ Alias of Composite(‘*’, **kw_kernels). \(k_\otimes(X, Y) = \prod_{a \in \mathrm{features}} k_a(X_a, Y_a)\)
-
graphdot.microkernel.
Additive
(**kw_kernels)[source]¶ Alias of Composite(‘+’, **kw_kernels). \(k_\oplus(X, Y) = \sum_{a \in \mathrm{features}} k_a(X_a, Y_a)\)
-
graphdot.microkernel.
Convolution
(kernel: graphdot.microkernel._base.MicroKernel, mean=True)[source]¶ Creates a convolutional microkernel, which averages evaluations of a base microkernel between pairs of elements of two variable-length feature sequences.
Parameters: - kernel (MicroKernel) – The base kernel can be any elementary or composite microkernels, while the attribute to be convolved should be sequences.
- mean (bool) – If True, return the arithmetic mean of the kernel evaluations, i.e. \(k_{conv}(X, Y) = \frac{\sum_{x \in X} \sum_{y \in Y} k_{base}(x, y)}{|X||Y|}\). Otherwise, return the sum of the kernel evaluations, i.e. \(k_{conv}(X, Y) = \sum_{x \in X} \sum_{y \in Y} k_{base}(x, y)\). Thus, this serves as a means of normalization beyonds the dot product based one.
-
graphdot.microkernel.
DotProduct
()[source]¶ Creates a dot product microkernel, which computes the inner product between two vector-valued features.
Parameters: kernel does not have any tunable hyperparameters. (This) –
Submodules¶
- graphdot.microkernel.additive module
- graphdot.microkernel.composite module
- graphdot.microkernel.convolution module
- graphdot.microkernel.dotproduct module
- graphdot.microkernel.kronecker_delta module
- graphdot.microkernel.product module
- graphdot.microkernel.rational_quadratic module
- graphdot.microkernel.square_exponential module
- graphdot.microkernel.tensor_product module