Skip to content

Commit a9b10b2

Browse files
committed
upgrade to PASTE 1.4.0
fixed compatibility with POT v0.9.0
1 parent f5617b4 commit a9b10b2

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

dist/paste-bio-1.3.0.tar.gz

-15.6 KB
Binary file not shown.

dist/paste-bio-1.4.0.tar.gz

16.4 KB
Binary file not shown.
-13.4 KB
Binary file not shown.
14.3 KB
Binary file not shown.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
anndata>=0.7.6
22
scanpy>=1.7.2
3-
POT>=0.9.0
3+
POT=0.9.0
44
numpy
55
scipy
66
scikit-learn>=0.24.0

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = paste-bio
3-
version = 1.3.0
3+
version = 1.4.0
44
author = Max Land
55
author_email = [email protected]
66
description = A computational method to align and integrate spatial transcriptomics experiments.

src/paste/PASTE.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def center_NMF(W, H, slices, pis, lmbda, n_components, random_seed, dissimilarit
316316
H_new = model.components_
317317
return W_new, H_new
318318

319-
def my_fused_gromov_wasserstein(M, C1, C2, p, q, G_init = None, loss_fun='square_loss', alpha=0.5, armijo=False, log=False,numItermax=200, use_gpu = False, **kwargs):
319+
def my_fused_gromov_wasserstein(M, C1, C2, p, q, G_init = None, loss_fun='square_loss', alpha=0.5, armijo=False, log=False,numItermax=200, tol_rel=1e-9, tol_abs=1e-9, use_gpu = False, **kwargs):
320320
"""
321321
Adapted fused_gromov_wasserstein with the added capability of defining a G_init (inital mapping).
322322
Also added capability of utilizing different POT backends to speed up computation.
@@ -343,9 +343,19 @@ def f(G):
343343

344344
def df(G):
345345
return ot.gromov.gwggrad(constC, hC1, hC2, G)
346+
347+
if loss_fun == 'kl_loss':
348+
armijo = True # there is no closed form line-search with KL
349+
350+
if armijo:
351+
def line_search(cost, G, deltaG, Mi, cost_G, **kwargs):
352+
return ot.optim.line_search_armijo(cost, G, deltaG, Mi, cost_G, nx=nx, **kwargs)
353+
else:
354+
def line_search(cost, G, deltaG, Mi, cost_G, **kwargs):
355+
return solve_gromov_linesearch(G, deltaG, cost_G, C1, C2, M=0., reg=1., nx=nx, **kwargs)
346356

347357
if log:
348-
res, log = ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, log=True, **kwargs)
358+
res, log = ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, line_search, log=True, numItermax=numItermax, stopThr=tol_rel, stopThr2=tol_abs, **kwargs)
349359

350360
fgw_dist = log['loss'][-1]
351361

@@ -355,4 +365,70 @@ def df(G):
355365
return res, log
356366

357367
else:
358-
return ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, **kwargs)
368+
return ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, line_search, numItermax=numItermax, stopThr=tol_rel, stopThr2=tol_abs, **kwargs)
369+
370+
def solve_gromov_linesearch(G, deltaG, cost_G, C1, C2, M, reg,
371+
alpha_min=None, alpha_max=None, nx=None, **kwargs):
372+
"""
373+
Solve the linesearch in the FW iterations
374+
375+
Parameters
376+
----------
377+
378+
G : array-like, shape(ns,nt)
379+
The transport map at a given iteration of the FW
380+
deltaG : array-like (ns,nt)
381+
Difference between the optimal map found by linearization in the FW algorithm and the value at a given iteration
382+
cost_G : float
383+
Value of the cost at `G`
384+
C1 : array-like (ns,ns), optional
385+
Structure matrix in the source domain.
386+
C2 : array-like (nt,nt), optional
387+
Structure matrix in the target domain.
388+
M : array-like (ns,nt)
389+
Cost matrix between the features.
390+
reg : float
391+
Regularization parameter.
392+
alpha_min : float, optional
393+
Minimum value for alpha
394+
alpha_max : float, optional
395+
Maximum value for alpha
396+
nx : backend, optional
397+
If let to its default value None, a backend test will be conducted.
398+
Returns
399+
-------
400+
alpha : float
401+
The optimal step size of the FW
402+
fc : int
403+
nb of function call. Useless here
404+
cost_G : float
405+
The value of the cost for the next iteration
406+
407+
408+
.. _references-solve-linesearch:
409+
References
410+
----------
411+
.. [24] Vayer Titouan, Chapel Laetitia, Flamary Rémi, Tavenard Romain and Courty Nicolas
412+
"Optimal Transport for structured data with application on graphs"
413+
International Conference on Machine Learning (ICML). 2019.
414+
"""
415+
if nx is None:
416+
G, deltaG, C1, C2, M = ot.utils.list_to_array(G, deltaG, C1, C2, M)
417+
418+
if isinstance(M, int) or isinstance(M, float):
419+
nx = ot.backend.get_backend(G, deltaG, C1, C2)
420+
else:
421+
nx = ot.backend.get_backend(G, deltaG, C1, C2, M)
422+
423+
dot = nx.dot(nx.dot(C1, deltaG), C2.T)
424+
a = -2 * reg * nx.sum(dot * deltaG)
425+
b = nx.sum(M * deltaG) - 2 * reg * (nx.sum(dot * G) + nx.sum(nx.dot(nx.dot(C1, G), C2.T) * deltaG))
426+
427+
alpha = ot.optim.solve_1d_linesearch_quad(a, b)
428+
if alpha_min is not None or alpha_max is not None:
429+
alpha = np.clip(alpha, alpha_min, alpha_max)
430+
431+
# the new cost is deduced from the line search quadratic function
432+
cost_G = cost_G + a * (alpha ** 2) + b * alpha
433+
434+
return alpha, 1, cost_G

src/paste_bio.egg-info/PKG-INFO

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: paste-bio
3-
Version: 1.3.0
3+
Version: 1.4.0
44
Summary: A computational method to align and integrate spatial transcriptomics experiments.
55
Home-page: https://github.com/raphael-group/paste
66
Author: Max Land
@@ -31,8 +31,6 @@ You can read full paper [here](https://www.nature.com/articles/s41592-022-01459-
3131

3232
Additional examples and the code to reproduce the paper's analyses can be found [here](https://github.com/raphael-group/paste_reproducibility). Preprocessed datasets used in the paper can be found on [zenodo](https://doi.org/10.5281/zenodo.6334774).
3333

34-
PASTE is actively being worked on with future updates coming.
35-
3634
### Recent News
3735

3836
* PASTE is now published in [Nature Methods](https://www.nature.com/articles/s41592-022-01459-6)!

0 commit comments

Comments
 (0)