Skip to content

Commit 92e0929

Browse files
authored
Merge pull request #79 from CUQI-DTU/sprint22_update_components
Sprint22 update notebooks to reflect the change to get_components
2 parents 8453b39 + 38d1b04 commit 92e0929

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

training/CUQIpy-CIL/demo_CT.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
"metadata": {},
8585
"outputs": [],
8686
"source": [
87-
"A, y_data, info = cuqipy_cil.testproblem.ParallelBeam2D.get_components(\n",
87+
"A, y_data, info = cuqipy_cil.testproblem.ParallelBeam2D(\n",
8888
" im_size=(90, 90),\n",
8989
" det_count=128,\n",
9090
" angles=np.linspace(0, np.pi, 90),\n",
9191
" phantom=\"shepp-logan\"\n",
92-
")"
92+
").get_components()"
9393
]
9494
},
9595
{

training/CUQIpy-PyTorch/HMC.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@
763763
"metadata": {},
764764
"outputs": [],
765765
"source": [
766-
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D.get_components(dim=50, phantom=\"sinc\")\n",
766+
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D(dim=50, phantom=\"sinc\").get_components()\n",
767767
"\n",
768768
"# CUQIpy Bayesian model\n",
769769
"x = cuqi.distribution.Gaussian(np.zeros(A.domain_dim), cov=0.2)\n",
@@ -792,7 +792,7 @@
792792
"outputs": [],
793793
"source": [
794794
"# CUQIpy test problem\n",
795-
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D.get_components(dim=50, phantom=\"sinc\")\n",
795+
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D(dim=50, phantom=\"sinc\").get_components()\n",
796796
"\n",
797797
"# Add forward model to PyTorch automatic differentiation framework\n",
798798
"A = cuqipy_pytorch.model.add_to_autograd(A)\n",
@@ -831,7 +831,7 @@
831831
"outputs": [],
832832
"source": [
833833
"# CUQIpy test problem\n",
834-
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D.get_components(dim=50, phantom=\"sinc\")\n",
834+
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D(dim=50, phantom=\"sinc\").get_components()\n",
835835
"\n",
836836
"# CUQIpy Bayesian model\n",
837837
"x = cuqi.distribution.Gaussian(np.zeros(A.domain_dim), cov=0.2)\n",
@@ -859,7 +859,7 @@
859859
"outputs": [],
860860
"source": [
861861
"# CUQIpy test problem\n",
862-
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D.get_components(dim=50, phantom=\"sinc\")\n",
862+
"A, y_data, probinfo = cuqi.testproblem.Deconvolution1D(dim=50, phantom=\"sinc\").get_components()\n",
863863
"\n",
864864
"# Add forward model to PyTorch automatic differentiation framework\n",
865865
"A = cuqipy_pytorch.model.add_to_autograd(A)\n",

training/Exercise01_Minimal_UQ.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"metadata": {},
117117
"outputs": [],
118118
"source": [
119-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")"
119+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()"
120120
]
121121
},
122122
{
@@ -276,7 +276,7 @@
276276
"metadata": {},
277277
"outputs": [],
278278
"source": [
279-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")"
279+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()"
280280
]
281281
},
282282
{
@@ -320,7 +320,7 @@
320320
"source": [
321321
"and their calling signature is the same as for the `Deconvolution1D` problem, e.g. \n",
322322
"```\n",
323-
"model, data, probInfo = Heat1D.get_components()\n",
323+
"model, data, probInfo = Heat1D().get_components()\n",
324324
"```\n",
325325
"Input arguments vary and default values are provided if left empty. Instead of checking the onlinen docs, calling help of each testproblem, e.g., `help(Heat1D)` will also describe the test problem and the inputs it accepts"
326326
]
@@ -658,7 +658,7 @@
658658
"metadata": {},
659659
"outputs": [],
660660
"source": [
661-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"square\", PSF_param=5)"
661+
"A, y_data, probInfo = Deconvolution1D(phantom=\"square\", PSF_param=5).get_components()"
662662
]
663663
},
664664
{

training/Exercise03_Forward_Models.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"model1, data1, probInfo1 = cuqi.testproblem.Deconvolution1D.get_components(dim=64, phantom=\"sinc\")"
86+
"model1, data1, probInfo1 = cuqi.testproblem.Deconvolution1D(dim=64, phantom=\"sinc\").get_components()"
8787
]
8888
},
8989
{
@@ -201,7 +201,7 @@
201201
"metadata": {},
202202
"outputs": [],
203203
"source": [
204-
"model2, data2, probInfo2 = cuqi.testproblem.Deconvolution2D.get_components()"
204+
"model2, data2, probInfo2 = cuqi.testproblem.Deconvolution2D().get_components()"
205205
]
206206
},
207207
{
@@ -301,7 +301,7 @@
301301
"metadata": {},
302302
"outputs": [],
303303
"source": [
304-
"modelH, dataH, probInfoH = cuqi.testproblem.Heat1D.get_components()"
304+
"modelH, dataH, probInfoH = cuqi.testproblem.Heat1D().get_components()"
305305
]
306306
},
307307
{
@@ -422,7 +422,7 @@
422422
"metadata": {},
423423
"outputs": [],
424424
"source": [
425-
"A,_,probInfo = cuqi.testproblem.Deconvolution1D.get_components(dim=64, phantom=\"sinc\")\n",
425+
"A,_,probInfo = cuqi.testproblem.Deconvolution1D(dim=64, phantom=\"sinc\").get_components()\n",
426426
"x_exact = probInfo.exactSolution"
427427
]
428428
},
@@ -733,7 +733,7 @@
733733
"outputs": [],
734734
"source": [
735735
"n = 64\n",
736-
"A, _, probInfo = cuqi.testproblem.Deconvolution1D.get_components(dim=n, phantom=\"sinc\")\n",
736+
"A, _, probInfo = cuqi.testproblem.Deconvolution1D(dim=n, phantom=\"sinc\").get_components()\n",
737737
"x_exact = probInfo.exactSolution"
738738
]
739739
},

training/Exercise04_Bayesian_Inverse_Problems.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"outputs": [],
147147
"source": [
148148
"# Load forward model, data and problem information\n",
149-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")\n",
149+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()\n",
150150
"\n",
151151
"# For convenience, we define the dimension of the domain of A\n",
152152
"n = A.domain_dim\n",
@@ -380,6 +380,7 @@
380380
{
381381
"attachments": {},
382382
"cell_type": "markdown",
383+
"id": "09194832",
383384
"metadata": {},
384385
"source": [
385386
"For the purpose of this notebook we are not going to dive further into the details of the joint distribution, and simply use it to define the posterior."
@@ -640,7 +641,7 @@
640641
"outputs": [],
641642
"source": [
642643
"# Deterministic forward model\n",
643-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")\n",
644+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()\n",
644645
"\n",
645646
"# Distributions for each parameter\n",
646647
"x = GMRF(np.zeros(A.domain_dim), 50)\n",
@@ -703,7 +704,7 @@
703704
"# You can modify this code or write your own from scratch\n",
704705
"\n",
705706
"# 1. Forward model and data\n",
706-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")\n",
707+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()\n",
707708
"\n",
708709
"# 2. Distributions\n",
709710
"x = GMRF(np.zeros(A.domain_dim), 50) # Try e.g. LMRF or CMRF (also update parameters!)\n",
@@ -755,7 +756,7 @@
755756
"# We redefine in case something was changed\n",
756757
"\n",
757758
"# Deterministic forward model\n",
758-
"A, y_data, probInfo = Deconvolution1D.get_components(phantom=\"sinc\")\n",
759+
"A, y_data, probInfo = Deconvolution1D(phantom=\"sinc\").get_components()\n",
759760
"\n",
760761
"# Distributions for each parameter\n",
761762
"x = GMRF(np.zeros(A.domain_dim), 50)\n",
@@ -838,7 +839,7 @@
838839
"name": "python",
839840
"nbconvert_exporter": "python",
840841
"pygments_lexer": "ipython3",
841-
"version": "3.8.5"
842+
"version": "3.11.4"
842843
},
843844
"vscode": {
844845
"interpreter": {

training/Exercise05_PDE.ipynb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"source": [
154154
"While it is possible to create a PDE model from scratch, for this notebook we use the `Heat1D` test problem that is already implemented in CUQIpy.\n",
155155
"\n",
156-
"We load `Heat1D` using the `get_components` method. We can explore `Heat1D` initialization parameters (which are the same parameters that can be passed to `get_components` method) by calling `Heat1D?`. "
156+
"We may extract components of a `Heat1D` instance by calling the `get_components` method."
157157
]
158158
},
159159
{
@@ -162,12 +162,12 @@
162162
"metadata": {},
163163
"outputs": [],
164164
"source": [
165-
"model, data, problemInfo = Heat1D.get_components(\n",
165+
"model, data, problemInfo = Heat1D(\n",
166166
" dim=N, \n",
167167
" endpoint=L, \n",
168168
" max_time=T, \n",
169169
" exactSolution=myExactSolution\n",
170-
")"
170+
").get_components()"
171171
]
172172
},
173173
{
@@ -307,12 +307,12 @@
307307
"N = 30 # Number of finite difference nodes \n",
308308
"L = 1 # Length of the domain\n",
309309
"T = 0.02 # Final time\n",
310-
"model, data, problemInfo = Heat1D.get_components(\n",
310+
"model, data, problemInfo = Heat1D(\n",
311311
" dim=N, \n",
312312
" endpoint=L, \n",
313313
" max_time=T, \n",
314314
" exactSolution=myExactSolution\n",
315-
")"
315+
").get_components()"
316316
]
317317
},
318318
{
@@ -504,9 +504,9 @@
504504
"source": [
505505
"One way to improve the solution of this Bayesian problem is to use better prior information. Here we assume the prior is a step function with three pieces (which is exactly how we created the exact solution). This also makes the Bayesian problem simpler because now we only have three Bayesian parameters to infer.\n",
506506
"\n",
507-
"To test this case we pass `field_type='Step'` to `Heat1D.get_components`, which creates a `StepExpansion` domain geometry for the model during initializing the `Heat1D` test problem. It is also possible to change the domain geometry manually after initializing the test problem, but we will not do that here. \n",
507+
"To test this case we pass `field_type='Step'` to the constructor of `Heat1D`, which creates a `StepExpansion` domain geometry for the model during initializing the `Heat1D` test problem. It is also possible to change the domain geometry manually after initializing the test problem, but we will not do that here. \n",
508508
"\n",
509-
"The `Heat1D.get_components` parameter `field_params` is a dictionary that is used to pass keyword arguments that the underlying domain field geometry accepts. For example `StepExpansion` has a keyword argument `n_steps` and thus we can set `field_params={'n_steps': 3}`."
509+
"The parameter `field_params` is a dictionary that is used to pass keyword arguments that the underlying domain field geometry accepts. For example `StepExpansion` has a keyword argument `n_steps` and thus we can set `field_params={'n_steps': 3}`."
510510
]
511511
},
512512
{
@@ -517,14 +517,14 @@
517517
"source": [
518518
"n_steps = 3 # number of steps in the step expansion domain geometry\n",
519519
"N = 30\n",
520-
"model, data, problemInfo = Heat1D.get_components(\n",
520+
"model, data, problemInfo = Heat1D(\n",
521521
" dim=N,\n",
522522
" endpoint=L,\n",
523523
" max_time=T,\n",
524524
" field_type=\"Step\",\n",
525525
" field_params={\"n_steps\": n_steps},\n",
526526
" exactSolution=myExactSolution,\n",
527-
")\n"
527+
").get_components()\n"
528528
]
529529
},
530530
{
@@ -736,7 +736,7 @@
736736
"metadata": {},
737737
"source": [
738738
"#### Try it yourself (optional):\n",
739-
"* For this step function parametrization, try to enforce positivity of prior and the posterior samples via log parametrization which can be done by passing `map = lambda x : np.exp(x)` to the `Heat1D.get_components` method. Then run the Metropolis Hastings sampler again (similar to part 3)."
739+
"* For this step function parametrization, try to enforce positivity of prior and the posterior samples via log parametrization which can be done by initialing `Heat1D` with `map = lambda x : np.exp(x)`. Then run the Metropolis Hastings sampler again (similar to part 3)."
740740
]
741741
},
742742
{
@@ -815,14 +815,14 @@
815815
"metadata": {},
816816
"outputs": [],
817817
"source": [
818-
"model, data, problemInfo = Heat1D.get_components(\n",
818+
"model, data, problemInfo = Heat1D(\n",
819819
" dim=N,\n",
820820
" endpoint=L,\n",
821821
" max_time=T,\n",
822822
" field_type=\"Step\",\n",
823823
" field_params={\"n_steps\": n_steps},\n",
824824
" observation_grid_map=observation_nodes,\n",
825-
")\n"
825+
").get_components()\n"
826826
]
827827
},
828828
{
@@ -964,12 +964,12 @@
964964
"outputs": [],
965965
"source": [
966966
"N = 35\n",
967-
"model, data, problemInfo = Heat1D.get_components(\n",
967+
"model, data, problemInfo = Heat1D(\n",
968968
" dim=N,\n",
969969
" endpoint=L,\n",
970970
" max_time=T,\n",
971971
" field_type=\"KL\"\n",
972-
")\n"
972+
").get_components()\n"
973973
]
974974
},
975975
{

training/Exercise06_Gibbs.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279
"outputs": [],
280280
"source": [
281281
"# Model and data\n",
282-
"A, y_data, probinfo = Deconvolution1D.get_components(phantom='sinc', noise_std=0.005, PSF_param=6)\n",
282+
"A, y_data, probinfo = Deconvolution1D(phantom='sinc', noise_std=0.005, PSF_param=6).get_components()\n",
283283
"\n",
284284
"# Get dimension of signal\n",
285285
"n = A.domain_dim\n",
@@ -682,7 +682,7 @@
682682
"outputs": [],
683683
"source": [
684684
"# Deterministic forward model + data\n",
685-
"A, y_data, probinfo = Deconvolution1D.get_components(phantom='square')\n",
685+
"A, y_data, probinfo = Deconvolution1D(phantom='square').get_components()\n",
686686
"\n",
687687
"# Bayesian model\n",
688688
"d = Gamma(1, 1e-4)\n",
@@ -943,7 +943,7 @@
943943
"name": "python",
944944
"nbconvert_exporter": "python",
945945
"pygments_lexer": "ipython3",
946-
"version": "3.11.5"
946+
"version": "3.11.4"
947947
},
948948
"vscode": {
949949
"interpreter": {

0 commit comments

Comments
 (0)