Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tutorial_nifty_resolve
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ift
tutorial_nifty_resolve
Commits
c720aeae
Commit
c720aeae
authored
2 years ago
by
Philipp Frank
Browse files
Options
Downloads
Patches
Plain Diff
make evidences an array
parent
51697157
No related branches found
No related tags found
1 merge request
!5
make evidences an array
Pipeline
#148607
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo_poisson.ipynb
+4
-4
4 additions, 4 deletions
demo_poisson.ipynb
demo_poisson_solution.ipynb
+5
-5
5 additions, 5 deletions
demo_poisson_solution.ipynb
with
9 additions
and
9 deletions
demo_poisson.ipynb
+
4
−
4
View file @
c720aeae
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
"from utils import plot_2D, load_psf, geovi_sampling, plot_posterior\n",
"from utils import plot_2D, load_psf, geovi_sampling, plot_posterior\n",
"\n",
"\n",
"ift.random.push_sseq_from_seed(42)\n",
"ift.random.push_sseq_from_seed(42)\n",
"evidences =
[]
"
"evidences =
np.zeros(3)
"
]
]
},
},
{
{
...
@@ -74,7 +74,7 @@
...
@@ -74,7 +74,7 @@
"\n",
"\n",
"\n",
"\n",
"print(evidence)\n",
"print(evidence)\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[0]
= evidence"
]
]
},
},
{
{
...
@@ -88,7 +88,7 @@
...
@@ -88,7 +88,7 @@
"# Inference model 2\n",
"# Inference model 2\n",
"\n",
"\n",
"\n",
"\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[1]
= evidence"
]
]
},
},
{
{
...
@@ -149,7 +149,7 @@
...
@@ -149,7 +149,7 @@
"source": [
"source": [
"# Inference model 3\n",
"# Inference model 3\n",
"\n",
"\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[2]
= evidence"
]
]
},
},
{
{
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Nifty tutorial for Poisson count data
Nifty tutorial for Poisson count data
=====================================
=====================================
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Setup
Setup
-----
-----
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
nifty8
as
ift
import
nifty8
as
ift
from
utils
import
plot_2D
,
load_psf
,
geovi_sampling
,
plot_posterior
from
utils
import
plot_2D
,
load_psf
,
geovi_sampling
,
plot_posterior
ift
.
random
.
push_sseq_from_seed
(
42
)
ift
.
random
.
push_sseq_from_seed
(
42
)
evidences
=
[]
evidences
=
np
.
zeros
(
3
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Load data and visualize
# Load data and visualize
data
=
np
.
load
(
'
data/poisson.npz
'
)
data
=
np
.
load
(
'
data/poisson.npz
'
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
position_space
=
ift
.
RGSpace
([
128
,
128
])
position_space
=
ift
.
RGSpace
([
128
,
128
])
# Homogeneous poisson process
# Homogeneous poisson process
print
(
model1
)
print
(
model1
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Set up likelihood & PSF
# Set up likelihood & PSF
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Inference model 1
# Inference model 1
print
(
evidence
)
print
(
evidence
)
evidences
+
=
[
evidence
,
]
evidences
[
0
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Independent poisson process
# Independent poisson process
# Inference model 2
# Inference model 2
evidences
+
=
[
evidence
,
]
evidences
[
1
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Compare evidence
# Compare evidence
print
(
evidences
)
print
(
evidences
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Diffuse poisson process
# Diffuse poisson process
args
=
{
args
=
{
'
offset_mean
'
:
.
5
,
'
offset_mean
'
:
.
5
,
'
offset_std
'
:
(
1.
,
1E-5
),
'
offset_std
'
:
(
1.
,
1E-5
),
# Amplitude of field fluctuations
# Amplitude of field fluctuations
'
fluctuations
'
:
(
1.5
,
0.5
),
# 1.0, 1e-2
'
fluctuations
'
:
(
1.5
,
0.5
),
# 1.0, 1e-2
# Exponent of power law power spectrum component
# Exponent of power law power spectrum component
'
loglogavgslope
'
:
(
-
4.
,
1
),
# -6.0, 1
'
loglogavgslope
'
:
(
-
4.
,
1
),
# -6.0, 1
# Amplitude of integrated Wiener process power spectrum component
# Amplitude of integrated Wiener process power spectrum component
'
flexibility
'
:
(
1.
,
0.2
),
# 2.0, 1.0
'
flexibility
'
:
(
1.
,
0.2
),
# 2.0, 1.0
# How ragged the integrated Wiener process component is
# How ragged the integrated Wiener process component is
'
asperity
'
:
(
0.1
,
0.01
),
# 0.1, 0.5
'
asperity
'
:
(
0.1
,
0.01
),
# 0.1, 0.5
# Name of the input keys
# Name of the input keys
'
prefix
'
:
'
diffuse
'
'
prefix
'
:
'
diffuse
'
}
}
correlated_field
=
ift
.
SimpleCorrelatedField
(
position_space
,
**
args
)
correlated_field
=
ift
.
SimpleCorrelatedField
(
position_space
,
**
args
)
pspec
=
correlated_field
.
power_spectrum
pspec
=
correlated_field
.
power_spectrum
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Prior samples
# Prior samples
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Inference model 3
# Inference model 3
evidences
+
=
[
evidence
,
]
evidences
[
2
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Compare evidence
# Compare evidence
print
(
evidences
)
print
(
evidences
)
print
(
evidences
-
evidences
[
-
1
])
print
(
evidences
-
evidences
[
-
1
])
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Posterior visualization
Posterior visualization
-----------------------
-----------------------
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
plot_posterior
(
samples
,
data
,
model3
,
diffuse
,
model2
,
pspec
)
plot_posterior
(
samples
,
data
,
model3
,
diffuse
,
model2
,
pspec
)
```
```
...
...
This diff is collapsed.
Click to expand it.
demo_poisson_solution.ipynb
+
5
−
5
View file @
c720aeae
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
"from utils import plot_2D, load_psf, geovi_sampling, plot_posterior\n",
"from utils import plot_2D, load_psf, geovi_sampling, plot_posterior\n",
"\n",
"\n",
"ift.random.push_sseq_from_seed(42)\n",
"ift.random.push_sseq_from_seed(42)\n",
"evidences =
[]
"
"evidences =
np.zeros(3)
"
]
]
},
},
{
{
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
"samples, evidence = geovi_sampling(likelihood @ model1)\n",
"samples, evidence = geovi_sampling(likelihood @ model1)\n",
"plot_2D(samples.average(model1).val, 'model1 posterior mean')\n",
"plot_2D(samples.average(model1).val, 'model1 posterior mean')\n",
"print(evidence)\n",
"print(evidence)\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[0]
= evidence"
]
]
},
},
{
{
...
@@ -100,7 +100,7 @@
...
@@ -100,7 +100,7 @@
"samples, evidence = geovi_sampling(likelihood @ model2)\n",
"samples, evidence = geovi_sampling(likelihood @ model2)\n",
"plot_2D(samples.average(model2).val, 'model2 posterior mean')\n",
"plot_2D(samples.average(model2).val, 'model2 posterior mean')\n",
"print(evidence)\n",
"print(evidence)\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[1]
= evidence"
]
]
},
},
{
{
...
@@ -110,7 +110,7 @@
...
@@ -110,7 +110,7 @@
"outputs": [],
"outputs": [],
"source": [
"source": [
"# Compare evidence\n",
"# Compare evidence\n",
"print(evidences)"
"print(evidences
[:2]
)"
]
]
},
},
{
{
...
@@ -169,7 +169,7 @@
...
@@ -169,7 +169,7 @@
"samples, evidence = geovi_sampling(likelihood @ model3)\n",
"samples, evidence = geovi_sampling(likelihood @ model3)\n",
"plot_2D(samples.average(model3).val, 'model3 posterior mean')\n",
"plot_2D(samples.average(model3).val, 'model3 posterior mean')\n",
"print(evidence)\n",
"print(evidence)\n",
"evidences
+
=
[
evidence
, ]
"
"evidences
[2]
= evidence"
]
]
},
},
{
{
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Nifty tutorial for Poisson count data
Nifty tutorial for Poisson count data
=====================================
=====================================
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Setup
Setup
-----
-----
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
nifty8
as
ift
import
nifty8
as
ift
from
utils
import
plot_2D
,
load_psf
,
geovi_sampling
,
plot_posterior
from
utils
import
plot_2D
,
load_psf
,
geovi_sampling
,
plot_posterior
ift
.
random
.
push_sseq_from_seed
(
42
)
ift
.
random
.
push_sseq_from_seed
(
42
)
evidences
=
[]
evidences
=
np
.
zeros
(
3
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Load data and visualize
# Load data and visualize
data
=
np
.
load
(
'
data/poisson.npz
'
)
data
=
np
.
load
(
'
data/poisson.npz
'
)
print
(
data
[
'
data
'
].
shape
)
print
(
data
[
'
data
'
].
shape
)
plot_2D
(
data
[
'
data
'
],
'
Data
'
)
plot_2D
(
data
[
'
data
'
],
'
Data
'
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
position_space
=
ift
.
RGSpace
([
128
,
128
])
position_space
=
ift
.
RGSpace
([
128
,
128
])
# Homogeneous poisson process
# Homogeneous poisson process
projection
=
ift
.
VdotOperator
(
ift
.
full
(
position_space
,
1.
)).
adjoint
projection
=
ift
.
VdotOperator
(
ift
.
full
(
position_space
,
1.
)).
adjoint
model1
=
ift
.
FieldAdapter
(
projection
.
domain
,
'
hom
'
)
model1
=
ift
.
FieldAdapter
(
projection
.
domain
,
'
hom
'
)
model1
=
ift
.
exp
(
5.
*
model1
)
model1
=
ift
.
exp
(
5.
*
model1
)
model1
=
projection
@
model1
model1
=
projection
@
model1
print
(
model1
)
print
(
model1
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Set up likelihood & PSF
# Set up likelihood & PSF
d
=
ift
.
makeField
(
position_space
,
data
[
'
data
'
])
d
=
ift
.
makeField
(
position_space
,
data
[
'
data
'
])
likelihood
=
ift
.
PoissonianEnergy
(
d
)
likelihood
=
ift
.
PoissonianEnergy
(
d
)
PSF_op
,
psf
=
load_psf
(
position_space
)
PSF_op
,
psf
=
load_psf
(
position_space
)
plot_2D
(
psf
,
'
PSF
'
)
plot_2D
(
psf
,
'
PSF
'
)
likelihood
=
likelihood
@
PSF_op
likelihood
=
likelihood
@
PSF_op
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Inference model 1
# Inference model 1
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model1
)
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model1
)
plot_2D
(
samples
.
average
(
model1
).
val
,
'
model1 posterior mean
'
)
plot_2D
(
samples
.
average
(
model1
).
val
,
'
model1 posterior mean
'
)
print
(
evidence
)
print
(
evidence
)
evidences
+
=
[
evidence
,
]
evidences
[
0
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Independent poisson process
# Independent poisson process
model2
=
ift
.
InverseGammaOperator
(
position_space
,
2.
,
3.
).
ducktape
(
'
independent
'
)
model2
=
ift
.
InverseGammaOperator
(
position_space
,
2.
,
3.
).
ducktape
(
'
independent
'
)
# Inference model 2
# Inference model 2
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model2
)
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model2
)
plot_2D
(
samples
.
average
(
model2
).
val
,
'
model2 posterior mean
'
)
plot_2D
(
samples
.
average
(
model2
).
val
,
'
model2 posterior mean
'
)
print
(
evidence
)
print
(
evidence
)
evidences
+
=
[
evidence
,
]
evidences
[
1
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Compare evidence
# Compare evidence
print
(
evidences
)
print
(
evidences
[:
2
]
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Diffuse poisson process
# Diffuse poisson process
args
=
{
args
=
{
'
offset_mean
'
:
.
5
,
'
offset_mean
'
:
.
5
,
'
offset_std
'
:
(
1.
,
1E-5
),
'
offset_std
'
:
(
1.
,
1E-5
),
# Amplitude of field fluctuations
# Amplitude of field fluctuations
'
fluctuations
'
:
(
1.5
,
0.5
),
# 1.0, 1e-2
'
fluctuations
'
:
(
1.5
,
0.5
),
# 1.0, 1e-2
# Exponent of power law power spectrum component
# Exponent of power law power spectrum component
'
loglogavgslope
'
:
(
-
4.
,
1
),
# -6.0, 1
'
loglogavgslope
'
:
(
-
4.
,
1
),
# -6.0, 1
# Amplitude of integrated Wiener process power spectrum component
# Amplitude of integrated Wiener process power spectrum component
'
flexibility
'
:
(
1.
,
0.2
),
# 2.0, 1.0
'
flexibility
'
:
(
1.
,
0.2
),
# 2.0, 1.0
# How ragged the integrated Wiener process component is
# How ragged the integrated Wiener process component is
'
asperity
'
:
(
0.1
,
0.01
),
# 0.1, 0.5
'
asperity
'
:
(
0.1
,
0.01
),
# 0.1, 0.5
# Name of the input keys
# Name of the input keys
'
prefix
'
:
'
diffuse
'
'
prefix
'
:
'
diffuse
'
}
}
correlated_field
=
ift
.
SimpleCorrelatedField
(
position_space
,
**
args
)
correlated_field
=
ift
.
SimpleCorrelatedField
(
position_space
,
**
args
)
pspec
=
correlated_field
.
power_spectrum
pspec
=
correlated_field
.
power_spectrum
diffuse
=
correlated_field
.
exp
()
diffuse
=
correlated_field
.
exp
()
model3
=
diffuse
+
model2
model3
=
diffuse
+
model2
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Prior samples
# Prior samples
pl
=
ift
.
Plot
()
pl
=
ift
.
Plot
()
for
_
in
range
(
9
):
for
_
in
range
(
9
):
pl
.
add
(
model3
(
ift
.
from_random
(
model3
.
domain
)))
pl
.
add
(
model3
(
ift
.
from_random
(
model3
.
domain
)))
pl
.
output
()
pl
.
output
()
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Inference model 3
# Inference model 3
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model3
)
samples
,
evidence
=
geovi_sampling
(
likelihood
@
model3
)
plot_2D
(
samples
.
average
(
model3
).
val
,
'
model3 posterior mean
'
)
plot_2D
(
samples
.
average
(
model3
).
val
,
'
model3 posterior mean
'
)
print
(
evidence
)
print
(
evidence
)
evidences
+
=
[
evidence
,
]
evidences
[
2
]
=
evidence
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Compare evidence
# Compare evidence
print
(
evidences
)
print
(
evidences
)
print
(
evidences
-
evidences
[
-
1
])
print
(
evidences
-
evidences
[
-
1
])
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Posterior visualization
Posterior visualization
-----------------------
-----------------------
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
plot_posterior
(
samples
,
data
,
model3
,
diffuse
,
model2
,
pspec
)
plot_posterior
(
samples
,
data
,
model3
,
diffuse
,
model2
,
pspec
)
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment