hnccorr.graph module

HNCcorr components related to the similarity graph.

class hnccorr.graph.CorrelationEmbedding(patch)[source]

Bases: object

Computes correlation feature vector for each pixel.

Embedding provides a representation of a pixel in terms of feature vector. The feature vector for the CorrelationEmbedding is a vector of pairwise correlations to each (or some) pixel in the patch.

If the correlation is not defined due to a pixel with zero variance, then the corelation is set to zero.

Variables

embedding (np.array) – (D, N_1, N_2, ..) array of pairwise correlations, where D is the dimension of the embedding and N_1, N_2, .. are the pixel shape of the patch.

__init__(patch)[source]

Initializes a CorrelationEmbedding object.

See class description for details.

Parameters

patch (Patch) – Subregion of movie for which the correlation embedding is computed.

get_vector(pixel)[source]

Retrieve feature vector of pixel.

Parameters

pixel (tuple) – Coordinate of pixel.

Returns

Feature vector of pixel.

Return type

np.array

class hnccorr.graph.GraphConstructor(edge_selector, weight_function)[source]

Bases: object

Graph constructor over a set of pixels.

Constructs a similarity graph over the set of pixels in a patch. Edges are selected by an edge_selector and the similarity weight associated with each edge is computed with the weight_function. Edge weights are stored under the attribute weight.

A directed graph is used for efficiency. That is, arcs (i,j) and (j,i) are used to represent edge [i,j].

Variables
  • _edge_selector (EdgeSelector) – Object that constructs the edge set of the graph.

  • _weight_function (function) – Function that computes the edge weight between two pixels. The function should take as input two 1-dimensional numpy arrays, representing the feature vectors of the two pixels. The function should return a float between 0 and 1.

__init__(edge_selector, weight_function)[source]

Initializes a graph constructor.

construct(patch, embedding)[source]

Constructs similarity graph for a given patch.

See class description.

Parameters
  • patch (Patch) – Defines subregion and pixel set for the graph.

  • embedding (CorrelationEmbedding) – Provides feature vectors associated with each pixel in the patch.

Returns

Similarity graph over pixels in patch.

Return type

nx.DiGraph

class hnccorr.graph.SparseComputationEmbeddingWrapper(dim_low, distance, dimension_reducer=None)[source]

Bases: object

Wrapper for SparseComputation that accepts an embedding.

Variables

_sc (SparseComputation) – SparseComputation object.

__init__(dim_low, distance, dimension_reducer=None)[source]

Initializes a SparseComputationEmbeddingWrapper instance.

Parameters
  • dim_low (int) – Dimension of the low-dimensional space in sparse computation.

  • distance (float) – 1 / grid_resolution. Defines the size of the grid blocks in sparse computation.

  • dimension_reducer (DimReducer) – Provides dimension reduction for sparse computation. By default, approximate principle component analysis is used.

Returns

SparseComputationEmbeddingWrapper

select_edges(embedding)[source]

Selects relevant pairwise similarities with sparse computation.

Determines the set of relevant pairwise similarities based on the sparse computation algorithm. See sparse computation for details. Pixel coordinates are with respect to the index of the embedding.

Parameters

embedding (CorrelationEmbedding) – Embedding of pixels into feature vectors.

Returns

List of relevant pixel pairs.

Return type

list(tuple)

hnccorr.graph.exponential_distance_decay(feature_vec1, feature_vec2, alpha)[source]

Computes exp(- alpha / n || x_1 - x_2 ||^2_2) for x_1, x_2 in R^n.