sf.apps.similarity¶
Tools to construct graph kernels from GBS.
The graph kernel is built by mapping GBS samples from each graph to a feature vector. Similarity between graphs can then be determined by calculating the overlap between these vectors.
The functionality here is based upon the research papers: [50][51][52].
See also
Coarsegraining GBS samples¶
GBS feature vectors can be composed of probabilities of coarsegrained combinations of elementary samples. We consider two coarse grainings:
Orbits: Combine all samples that can be made identical under permutation. Orbits are written simply as a sorting of integer photon number samples in nonincreasing order with the zeros at the end removed. For example,
[1, 1, 2, 0]
and[2, 1, 0, 1]
both belong to the[2, 1, 1]
orbit.Events: Combine all \(k\)photon orbits where the maximum photon count in any mode does not exceed a fixed value \(n_{\max}\) into an event \(E_{k, n_{\max}}\). For example, orbits
[2, 1]
,[1, 1, 1]
are part of the \(E_{k=3, n_{\max}=2}\) event, while orbit[3]
is not.
This module provides the following tools for dealing with coarsegrained orbits and events.
Creating a feature vector¶
A feature vector of a graph can be created by choosing a collection of orbits or events and evaluating their probabilities with respect to GBS with the embedded graph. These probabilities are then selected to be elements of the feature vector. Evaluating the probabilities of orbits or events can be achieved through two approaches:
Direct sampling: infer the probability of orbits or events from a set of sample data.
Monte Carlo approximation: generate samples within a given orbit or event and use them to approximate the probability.
In the direct sampling approach, \(N\) samples are taken from GBS with the embedded graph. The number that fall within a given orbit or event \(E\) are counted, resulting in the count \(c_{E}\). The probability \(p(E)\) of an orbit or event is then approximated as:
To perform a Monte Carlo estimation of the probability of an orbit or event \(E\),
several samples from \(E\) are drawn uniformly at random using orbit_to_sample()
or
event_to_sample()
. Suppose \(N\) samples \(\{S_{1}, S_{2}, \ldots , S_{N}\}\) are
generated. For each sample, this function calculates the probability \(p(S_i)\) of observing
that sample from a GBS device programmed according to the input graph and mean photon number. The
sum of the probabilities is then rescaled according to the cardinality \(E\) and the total
number of samples:
The sample mean of this sum is an estimate of the rescaled probability \(p(E)\).
This module provides functions to evaluate the probability of orbits and events through Monte Carlo approximation.
Similar to the sample()
function, the MC estimators include a loss
argument
to specify the proportion of photons lost in the simulated GBS device.
One canonical method of constructing a feature vector is to pick event probabilities \(p_{k} := p_{E_{k, n_{\max}}}\) with all events \(E_{k, n_{\max}}\) having a maximum photon count \(n_{\max}\) in each mode. If \(\mathbf{k}\) is the vector of selected events, the resultant feature vector is
This module allows for such feature vectors to be calculated using both the direct sampling and Monte Carlo approximation methods.
Functions

Gives the number of samples belonging to the input event. 

Generates a sample selected uniformly at random from the specified event. 

Calculates feature vector using Monte Carlo estimation of event probabilities according to the input graph. 

Calculates feature vector with respect to input samples. 

Gives the number of samples belonging to the input orbit. 

Generates a sample selected uniformly at random from the specified orbit. 

Generate all the possible orbits for a given photon number. 

Gives a Monte Carlo estimate of the GBS probability of a given event according to the input graph. 

Gives a Monte Carlo estimate of the GBS probability of a given orbit according to the input graph. 

Provides the event corresponding to a given sample. 

Provides the orbit corresponding to a given sample. 
Contents
Downloads