local2global.utils.AlignmentProblem

class AlignmentProblem[source]

Bases: object

Implements the standard local2global algorithm using an unweighted patch graph

__init__(patches: List[local2global.utils.Patch], patch_edges=None, min_overlap=None, copy_data=True, self_loops=False, verbose=False)[source]

Initialise the alignment problem with a list of patches

Parameters
  • patches – List of patches to synchronise

  • patch_edges – if provided, only compute relative transformations for given patch edges (all pairs of patches with at least min_overlap points in common are included by default)

  • min_overlap (int) – minimum number of points in the overlap required for two patches to be considered connected (defaults to dim+1) where dim is the embedding dimension of the patches

  • copy_data (bool) – if True, input patches are copied (default: True)

  • self_loops (bool) – if True, self-loops from a patch to itself are included in the synchronisation problem (default: False)

  • verbose (bool) – if True print diagnostic information (default: False)

Methods

__init__

Initialise the alignment problem with a list of patches

calc_synchronised_rotations

Compute the orthogonal transformations that best align the patches

calc_synchronised_scales

Compute the scaling transformations that best align the patches

calc_synchronised_translations

Compute translations that best align the patches

get_aligned_embedding

Return the aligned embedding

load

restore AlignmentProblem from patch file

mean_embedding

Compute node embeddings as the centroid over patch embeddings

rotate_patches

align the rotation/reflection of all patches

save_embedding

save aligned embedding to json file

save_patches

save patch embeddings to json file :param filename: path to output file

scale_patches

Synchronise scales of the embeddings for each patch

translate_patches

align the patches by translation

weight

Compute the weighting factor for a pair of patches

Attributes

dim

embedding dimension

n_nodes

total number of nodes

n_patches

number of patches

rotations

tracks orthogonal transformations applied to patches (updated by rotate_patches())

scales

tracks scale transformations applied to patches (updated by scale_patches())

shifts

tracks translation transformations applied to patches (updated by scale_patches(), rotate_patches(), and translate_patches())

verbose

print debug output if True

weight(i, j)[source]

Compute the weighting factor for a pair of patches

Parameters
  • i – First patch index

  • j – Second patch index

Returns

1

Override this in subclasses for weighted alignment

scale_patches(scale_factors=None)[source]

Synchronise scales of the embeddings for each patch

Parameters

scale_factors – if provided apply the given scales instead of synchronising

calc_synchronised_scales(max_scale=100000000.0)[source]

Compute the scaling transformations that best align the patches

Parameters

max_scale – maximum allowed scale (all scales are clipped to the range [1/max_scale, max_scale]) (default: 1e8)

Returns

list of scales

rotate_patches(rotations=None)[source]

align the rotation/reflection of all patches

Parameters

rotations – If provided, apply the given transformations instead of synchronizing patch rotations

calc_synchronised_rotations()[source]

Compute the orthogonal transformations that best align the patches

translate_patches(translations=None)[source]

align the patches by translation

Parameters

translations – If provided, apply the given translations instead of synchronizing

calc_synchronised_translations()[source]

Compute translations that best align the patches

mean_embedding()[source]

Compute node embeddings as the centroid over patch embeddings

get_aligned_embedding(scale=False, realign=False)[source]

Return the aligned embedding

Parameters
  • scale (bool) – if True, rescale patches (default: False)

  • realign (bool) – if True, recompute aligned embedding even if it already exists (default: False)

Returns

n_nodes x dim numpy array of embedding coordinates

save_patches(filename)[source]

save patch embeddings to json file :param filename: path to output file

classmethod load(filename)[source]

restore AlignmentProblem from patch file

Parameters

filename – path to patch file

save_embedding(filename)[source]

save aligned embedding to json file

Parameters

filename – output filename