Skip to content

Commit fcd9029

Browse files
authored
Merge pull request #13 from spatial-model-editor/add_multiple_model_fitting_example_notebook
Add initial multiple model parameter fitting example notebook
2 parents a07c217 + bd47881 commit fcd9029

File tree

7 files changed

+1229
-16
lines changed

7 files changed

+1229
-16
lines changed

2d-toy-model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
"name": "python",
418418
"nbconvert_exporter": "python",
419419
"pygments_lexer": "ipython3",
420-
"version": "3.10.0"
420+
"version": "3.13.1"
421421
}
422422
},
423423
"nbformat": 4,

3d-model-parameter-fitting.xml

Lines changed: 602 additions & 0 deletions
Large diffs are not rendered by default.

3d-toy-model.ipynb

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,50 @@
638638
]
639639
},
640640
{
641-
"cell_type": "markdown",
641+
"cell_type": "code",
642+
"execution_count": null,
642643
"id": "26",
644+
"metadata": {
645+
"slideshow": {
646+
"slide_type": "subslide"
647+
}
648+
},
649+
"outputs": [],
650+
"source": [
651+
"def geometry_image(n_pixels):\n",
652+
" # generate a segmented image containing one randomly distributed, sized and deformed sphere\n",
653+
" max_radius = n_pixels / 3\n",
654+
" max_deform = 1.2\n",
655+
" voxels = np.zeros((n_pixels, n_pixels, n_pixels), dtype=np.uint16)\n",
656+
" center = np.random.randint(2, n_pixels - 2, 3)\n",
657+
" nuclear_radius = np.random.randint(1, max_radius / 2)\n",
658+
" cell_radius = np.random.randint(1.5 * nuclear_radius, max_radius)\n",
659+
" deformation = np.random.uniform(1 / max_deform, max_deform, 3)\n",
660+
" voxels[sphere_mask(voxels.shape, center, cell_radius, deformation)] = 2\n",
661+
" voxels[sphere_mask(voxels.shape, center, nuclear_radius, deformation)] = 1\n",
662+
" return voxels"
663+
]
664+
},
665+
{
666+
"cell_type": "code",
667+
"execution_count": null,
668+
"id": "27",
669+
"metadata": {
670+
"slideshow": {
671+
"slide_type": "subslide"
672+
}
673+
},
674+
"outputs": [],
675+
"source": [
676+
"img = geometry_image(30)\n",
677+
"plot3D(\n",
678+
" img, [\"Geometry image (voxel)\", \"Geometry image (surface)\"], threshold_value=[1, 0]\n",
679+
").show()"
680+
]
681+
},
682+
{
683+
"cell_type": "markdown",
684+
"id": "28",
643685
"metadata": {
644686
"editable": true,
645687
"slideshow": {
@@ -659,7 +701,7 @@
659701
{
660702
"cell_type": "code",
661703
"execution_count": null,
662-
"id": "27",
704+
"id": "29",
663705
"metadata": {
664706
"slideshow": {
665707
"slide_type": "subslide"
@@ -673,7 +715,7 @@
673715
{
674716
"cell_type": "code",
675717
"execution_count": null,
676-
"id": "28",
718+
"id": "30",
677719
"metadata": {
678720
"editable": true,
679721
"slideshow": {
@@ -689,7 +731,7 @@
689731
{
690732
"cell_type": "code",
691733
"execution_count": null,
692-
"id": "29",
734+
"id": "31",
693735
"metadata": {
694736
"editable": true,
695737
"slideshow": {
@@ -705,7 +747,7 @@
705747
{
706748
"cell_type": "code",
707749
"execution_count": null,
708-
"id": "30",
750+
"id": "32",
709751
"metadata": {
710752
"slideshow": {
711753
"slide_type": "subslide"
@@ -726,7 +768,7 @@
726768
},
727769
{
728770
"cell_type": "markdown",
729-
"id": "31",
771+
"id": "33",
730772
"metadata": {
731773
"editable": true,
732774
"slideshow": {
@@ -744,7 +786,7 @@
744786
{
745787
"cell_type": "code",
746788
"execution_count": null,
747-
"id": "32",
789+
"id": "34",
748790
"metadata": {
749791
"editable": true,
750792
"slideshow": {
@@ -759,7 +801,7 @@
759801
},
760802
{
761803
"cell_type": "markdown",
762-
"id": "33",
804+
"id": "35",
763805
"metadata": {
764806
"editable": true,
765807
"slideshow": {
@@ -774,7 +816,7 @@
774816
{
775817
"cell_type": "code",
776818
"execution_count": null,
777-
"id": "34",
819+
"id": "36",
778820
"metadata": {
779821
"slideshow": {
780822
"slide_type": "subslide"
@@ -795,7 +837,7 @@
795837
{
796838
"cell_type": "code",
797839
"execution_count": null,
798-
"id": "35",
840+
"id": "37",
799841
"metadata": {
800842
"slideshow": {
801843
"slide_type": "subslide"
@@ -815,7 +857,7 @@
815857
{
816858
"cell_type": "code",
817859
"execution_count": null,
818-
"id": "36",
860+
"id": "38",
819861
"metadata": {
820862
"slideshow": {
821863
"slide_type": "subslide"
@@ -835,7 +877,7 @@
835877
{
836878
"cell_type": "code",
837879
"execution_count": null,
838-
"id": "37",
880+
"id": "39",
839881
"metadata": {
840882
"slideshow": {
841883
"slide_type": "subslide"
@@ -854,7 +896,7 @@
854896
],
855897
"metadata": {
856898
"kernelspec": {
857-
"display_name": ".venv",
899+
"display_name": "Python 3 (ipykernel)",
858900
"language": "python",
859901
"name": "python3"
860902
},
@@ -868,7 +910,7 @@
868910
"name": "python",
869911
"nbconvert_exporter": "python",
870912
"pygments_lexer": "ipython3",
871-
"version": "3.12.3"
913+
"version": "3.13.1"
872914
}
873915
},
874916
"nbformat": 4,

3d-toy-model.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<options>
1717
<cereal_class_version>0</cereal_class_version>
1818
<dune>
19-
<cereal_class_version>0</cereal_class_version>
19+
<cereal_class_version>1</cereal_class_version>
2020
<discretization>0</discretization>
2121
<integrator>alexander_2</integrator>
2222
<dt>0.10000000000000001</dt>
@@ -27,6 +27,7 @@
2727
<writeVTKfiles>false</writeVTKfiles>
2828
<newtonRelErr>1e-08</newtonRelErr>
2929
<newtonAbsErr>9.9999999999999998e-13</newtonAbsErr>
30+
<linearSolver>RestartedGMRes</linearSolver>
3031
</dune>
3132
<pixel>
3233
<cereal_class_version>0</cereal_class_version>
@@ -172,6 +173,8 @@
172173
<parameter id="A_membrane_diffusionConstant" value="1" units="diffusion_constant_units" constant="true">
173174
<spatial:diffusionCoefficient spatial:variable="A_membrane" spatial:type="isotropic"/>
174175
</parameter>
176+
<parameter id="k1" name="k1" value="1" constant="true"/>
177+
<parameter id="k2" name="k2" value="1" constant="true"/>
175178
</listOfParameters>
176179
<listOfReactions>
177180
<reaction id="Outside_to_membrane" name="Outside to membrane" reversible="true" compartment="outside_membrane_membrane" spatial:isLocal="true">
@@ -186,6 +189,7 @@
186189
<apply>
187190
<times/>
188191
<cn type="e-notation"> 1 <sep/> -14 </cn>
192+
<ci> k1 </ci>
189193
<apply>
190194
<plus/>
191195
<apply>
@@ -210,6 +214,7 @@
210214
<apply>
211215
<times/>
212216
<cn type="e-notation"> 1 <sep/> -14 </cn>
217+
<ci> k2 </ci>
213218
<apply>
214219
<plus/>
215220
<apply>

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ A 3d toy model starting from 3d segmented cells
1616
- [Jupyter notebook](https://github.com/spatial-model-editor/toy-models/blob/main/3d-toy-model.ipynb)
1717
- [SBML model](https://spatial-model-editor.github.io/toy-models/3d-toy-model.xml)
1818

19+
## 3d multiple model parameter fitting
20+
21+
Fitting parameters to multiple 3d toy models
22+
23+
- [Online slides (generated from jupyter notebook below)](https://spatial-model-editor.github.io/toy-models/multiple-model-parameter-fitting.slides.html)
24+
- [Jupyter notebook](https://github.com/spatial-model-editor/toy-models/blob/main/multiple-model-parameter-fitting.ipynb)
25+
- [SBML model](https://spatial-model-editor.github.io/toy-models/3d-model-parameter-fitting.xml)
26+
1927
The SBML models can be opened, modified and simulated using [Spatial Model Editor](https://spatial-model-editor.github.io/)

0 commit comments

Comments
 (0)