local2global.utils.WeightedAlignmentProblem¶
- class WeightedAlignmentProblem[source]¶
Bases:
local2global.utils.AlignmentProblem
Variant of the local2global algorithm where patch edges are weighted according to the number of nodes in the overlap.
- __init__(patches: List[local2global.utils.Patch], patch_edges=None, min_overlap=None, copy_data=True, self_loops=False, verbose=False)¶
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
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
AlignmentProblem
from 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 weight for 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()
, andtranslate_patches()
)verbose
print debug output if True
- calc_synchronised_rotations()¶
Compute the orthogonal transformations that best align the patches
- calc_synchronised_scales(max_scale=100000000.0)¶
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
- calc_synchronised_translations()¶
Compute translations that best align the patches
- get_aligned_embedding(scale=False, realign=False)¶
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
- classmethod load(filename)¶
restore
AlignmentProblem
from patch file- Parameters
filename – path to patch file
- mean_embedding()¶
Compute node embeddings as the centroid over patch embeddings
- rotate_patches(rotations=None)¶
align the rotation/reflection of all patches
- Parameters
rotations – If provided, apply the given transformations instead of synchronizing patch rotations
- save_embedding(filename)¶
save aligned embedding to json file
- Parameters
filename – output filename
- save_patches(filename)¶
save patch embeddings to json file :param filename: path to output file
- scale_patches(scale_factors=None)¶
Synchronise scales of the embeddings for each patch
- Parameters
scale_factors – if provided apply the given scales instead of synchronising
- translate_patches(translations=None)¶
align the patches by translation
- Parameters
translations – If provided, apply the given translations instead of synchronizing