Skip to content

Commit

Permalink
initializer update
Browse files Browse the repository at this point in the history
  • Loading branch information
selmanozleyen committed Dec 10, 2024
1 parent 5b9d4e0 commit 1e3a531
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions examples/solvers/200_linear_problems_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"outputs": [],
"source": [
"from moscot import datasets\n",
"from moscot.problems.generic import SinkhornProblem"
"from moscot.problems.generic import SinkhornProblem\n",
"from ott.initializers.linear import initializers_lr as init_lr_lib"
]
},
{
Expand Down Expand Up @@ -105,6 +106,7 @@
"output_type": "stream",
"text": [
"\u001b[34mINFO \u001b[0m Computing pca with `\u001b[33mn_comps\u001b[0m=\u001b[1;36m30\u001b[0m` for `xy` using `adata.X` \n",
"\u001b[34mINFO \u001b[0m Solving `\u001b[1;36m1\u001b[0m` problems \n",
"\u001b[34mINFO \u001b[0m Solving problem OTProblem\u001b[1m[\u001b[0m\u001b[33mstage\u001b[0m=\u001b[32m'prepared'\u001b[0m, \u001b[33mshape\u001b[0m=\u001b[1m(\u001b[0m\u001b[1;36m20\u001b[0m, \u001b[1;36m20\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m. \n"
]
}
Expand All @@ -114,7 +116,7 @@
"sp = sp.prepare(key=\"day\")\n",
"\n",
"ik = {\"min_iterations\": 5, \"max_iterations\": 200}\n",
"sp = sp.solve(epsilon=0, rank=3, initializer=\"k-means\", initializer_kwargs=ik)"
"sp = sp.solve(epsilon=0, rank=3, initializer=init_lr_lib.KMeansInitializer(rank=3), initializer_kwargs=ik)"
]
},
{
Expand Down Expand Up @@ -145,6 +147,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[34mINFO \u001b[0m Solving `\u001b[1;36m1\u001b[0m` problems \n",
"\u001b[34mINFO \u001b[0m Solving problem OTProblem\u001b[1m[\u001b[0m\u001b[33mstage\u001b[0m=\u001b[32m'solved'\u001b[0m, \u001b[33mshape\u001b[0m=\u001b[1m(\u001b[0m\u001b[1;36m20\u001b[0m, \u001b[1;36m20\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m. \n",
"\u001b[31mWARNING \u001b[0m Solver did not converge \n"
]
Expand Down Expand Up @@ -179,13 +182,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[34mINFO \u001b[0m Solving `\u001b[1;36m1\u001b[0m` problems \n",
"\u001b[34mINFO \u001b[0m Solving problem OTProblem\u001b[1m[\u001b[0m\u001b[33mstage\u001b[0m=\u001b[32m'solved'\u001b[0m, \u001b[33mshape\u001b[0m=\u001b[1m(\u001b[0m\u001b[1;36m20\u001b[0m, \u001b[1;36m20\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m. \n",
"\u001b[31mWARNING \u001b[0m Solver did not converge \n"
]
}
],
"source": [
"sp = sp.solve(epsilon=0, rank=3, initializer=\"random\", max_iterations=30, gamma=1000)"
"sp = sp.solve(epsilon=0, rank=3, initializer=init_lr_lib.RandomInitializer(rank=3), max_iterations=30, gamma=1000)"
]
},
{
Expand All @@ -198,12 +202,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[34mINFO \u001b[0m Solving problem OTProblem\u001b[1m[\u001b[0m\u001b[33mstage\u001b[0m=\u001b[32m'solved'\u001b[0m, \u001b[33mshape\u001b[0m=\u001b[1m(\u001b[0m\u001b[1;36m20\u001b[0m, \u001b[1;36m20\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m. \n"
"\u001b[34mINFO \u001b[0m Solving `\u001b[1;36m1\u001b[0m` problems \n",
"\u001b[34mINFO \u001b[0m Solving problem OTProblem\u001b[1m[\u001b[0m\u001b[33mstage\u001b[0m=\u001b[32m'solved'\u001b[0m, \u001b[33mshape\u001b[0m=\u001b[1m(\u001b[0m\u001b[1;36m20\u001b[0m, \u001b[1;36m20\u001b[0m\u001b[1m)\u001b[0m\u001b[1m]\u001b[0m. \n",
"\u001b[31mWARNING \u001b[0m Solver did not converge \n"
]
}
],
"source": [
"sp = sp.solve(epsilon=0, rank=3, initializer=\"random\", max_iterations=30, gamma=10)"
"sp = sp.solve(epsilon=0, rank=3, initializer=init_lr_lib.RandomInitializer(rank=3), max_iterations=30, gamma=10)"
]
},
{
Expand Down Expand Up @@ -233,7 +239,7 @@
"kernelspec": {
"display_name": "moscot",
"language": "python",
"name": "moscot"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -245,7 +251,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion tutorials/500_spatiotemporal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
"source": [
"As the data is large, we use low-rank optimal transport to decrease the computational complexity {cite}`scetbon:21a`. \n",
"\n",
"To solve the problem we pass the following arguments, `alpha` (in $(0, 1]$), which defines the influence of the spatial coordinates as opposed to the single-cell data. `epsilon`, the entropy parameter, and `initializer='rank2'` to improve the speed of convergence.\n",
"To solve the problem we pass the following arguments, `alpha` (in $(0, 1]$), which defines the influence of the spatial coordinates as opposed to the single-cell data and `epsilon`, the entropy parameter to improve the speed of convergence.\n",
"\n",
":::{seealso}\n",
"- See {doc}`../examples/solvers/200_linear_problems_advanced` on how to modify low-rank parameters. \n",
Expand Down

0 comments on commit 1e3a531

Please sign in to comment.