local2global.utils.AlignmentProblem¶
- class AlignmentProblem[source]¶
Bases:
objectImplements 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_overlappoints 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
Initialise the alignment problem with a list of patches
Compute the orthogonal transformations that best align the patches
Compute the scaling transformations that best align the patches
Compute translations that best align the patches
Return the aligned embedding
restore
AlignmentProblemfrom patch fileCompute node embeddings as the centroid over patch embeddings
align the rotation/reflection of all patches
save aligned embedding to json file
save patch embeddings to json file :param filename: path to output file
Synchronise scales of the embeddings for each patch
align the patches by translation
Compute the weighting factor for a pair of patches
Attributes
dimembedding dimension
n_nodestotal number of nodes
n_patchesnumber of patches
rotationstracks orthogonal transformations applied to patches (updated by
rotate_patches())scalestracks scale transformations applied to patches (updated by
scale_patches())shiftstracks translation transformations applied to patches (updated by
scale_patches(),rotate_patches(), andtranslate_patches())verboseprint 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
- 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