Commit 493643b2 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'getting_started_CorrelatedField' into 'NIFTy_6'

Getting started Demo for Correlated Field Model

See merge request !494
parents ad0434e3 20b6b057
Pipeline #75400 passed with stages
in 9 minutes and 8 seconds
...@@ -65,11 +65,16 @@ pages: ...@@ -65,11 +65,16 @@ pages:
before_script: before_script:
- python3 setup.py install --user -f - python3 setup.py install --user -f
run_ipynb: run_ipynb0:
stage: demo_runs stage: demo_runs
script: script:
- jupyter nbconvert --execute --ExecutePreprocessor.timeout=None demos/getting_started_0.ipynb - jupyter nbconvert --execute --ExecutePreprocessor.timeout=None demos/getting_started_0.ipynb
run_ipynb1:
stage: demo_runs
script:
- jupyter nbconvert --execute --ExecutePreprocessor.timeout=None demos/getting_started_4_CorrelatedFields.ipynb
run_getting_started_1: run_getting_started_1:
stage: demo_runs stage: demo_runs
script: script:
...@@ -99,7 +104,7 @@ run_getting_started_3: ...@@ -99,7 +104,7 @@ run_getting_started_3:
run_getting_started_mf: run_getting_started_mf:
stage: demo_runs stage: demo_runs
script: script:
- python3 demos/getting_started_mf.py - python3 demos/getting_started_5_mf.py
artifacts: artifacts:
paths: paths:
- '*.png' - '*.png'
......
...@@ -55,6 +55,10 @@ if __name__ == '__main__': ...@@ -55,6 +55,10 @@ if __name__ == '__main__':
position_space = ift.RGSpace([128, 128]) position_space = ift.RGSpace([128, 128])
# For a detailed showcase of the effects the parameters
# of the CorrelatedField model have on the generated fields,
# see 'getting_started_4_CorrelatedFields.ipynb'.
cfmaker = ift.CorrelatedFieldMaker.make( cfmaker = ift.CorrelatedFieldMaker.make(
offset_mean = 0.0, # 0. offset_mean = 0.0, # 0.
offset_std_mean = 1e-3, # 1e-3 offset_std_mean = 1e-3, # 1e-3
...@@ -62,22 +66,21 @@ if __name__ == '__main__': ...@@ -62,22 +66,21 @@ if __name__ == '__main__':
prefix = '') prefix = '')
fluctuations_dict = { fluctuations_dict = {
# Amplitude of the fluctuations # Amplitude of field fluctuations
'fluctuations_mean': 2.0, # 1.0 'fluctuations_mean': 2.0, # 1.0
'fluctuations_stddev': 1.0, # 1e-2 'fluctuations_stddev': 1.0, # 1e-2
# Smooth variation speed # Exponent of power law power spectrum component
'loglogavgslope_mean': -2.0, # -3.0
'loglogavgslope_stddev': 0.5, # 0.5
# Amplitude of integrated Wiener process power spectrum component
'flexibility_mean': 2.5, # 1.0 'flexibility_mean': 2.5, # 1.0
'flexibility_stddev': 1.0, # 0.5 'flexibility_stddev': 1.0, # 0.5
# How strong the ragged component of the spectrum is # How ragged the integrated Wiener process component is
# (Ratio of Wiener process and integrated Wiener process ?)
'asperity_mean': 0.5, # 0.1 'asperity_mean': 0.5, # 0.1
'asperity_stddev': 0.5, # 0.5 'asperity_stddev': 0.5 # 0.5
# Slope of linear spectrum component
'loglogavgslope_mean': -2.0, # -3.0
'loglogavgslope_stddev': 0.5 # 0.5
} }
cfmaker.add_fluctuations(position_space, **fluctuations_dict) cfmaker.add_fluctuations(position_space, **fluctuations_dict)
...@@ -135,7 +138,7 @@ if __name__ == '__main__': ...@@ -135,7 +138,7 @@ if __name__ == '__main__':
# Plot current reconstruction # Plot current reconstruction
plot = ift.Plot() plot = ift.Plot()
plot.add(signal(KL.position), title="reconstruction") plot.add(signal(KL.position), title="reconstruction")
plot.add([A.force(KL.position), A.force(mock_position)], title="power") plot.add([A.force(mock_position), A.force(KL.position)], title="power")
plot.output(ny=1, ysize=6, xsize=16, plot.output(ny=1, ysize=6, xsize=16,
name=filename.format("loop_{:02d}".format(i))) name=filename.format("loop_{:02d}".format(i)))
...@@ -153,8 +156,8 @@ if __name__ == '__main__': ...@@ -153,8 +156,8 @@ if __name__ == '__main__':
powers = [A.force(s + KL.position) for s in KL.samples] powers = [A.force(s + KL.position) for s in KL.samples]
plot.add( plot.add(
powers + [A.force(KL.position), powers + [A.force(mock_position),
A.force(mock_position)], A.force(KL.position)],
title="Sampled Posterior Power Spectrum", title="Sampled Posterior Power Spectrum",
linewidth=[1.]*len(powers) + [3., 3.]) linewidth=[1.]*len(powers) + [3., 3.])
plot.output(ny=1, nx=3, xsize=24, ysize=6, name=filename_res) plot.output(ny=1, nx=3, xsize=24, ysize=6, name=filename_res)
......
%% Cell type:markdown id: tags:
# Notebook showcasing the NIFTy 6 Correlated Field model
**Skip to `Parameter Showcases` for the meat/veggies ;)**
The field model roughly works like this:
`f = HT( A * zero_mode * xi ) + offset`
`A` is a spectral power field which is constructed from power spectra that hold on subdomains of the target domain.
It is scaled by a zero mode operator and then pointwise multiplied by a gaussian excitation field, yielding
a representation of the field in harmonic space.
It is then transformed into the target real space and a offset added.
The power spectra `A` is constructed of are in turn constructed as the sum of a power law component
and an integrated Wiener process whose amplitude and roughness can be set.
## Setup code
%% Cell type:code id: tags:
``` python
import nifty6 as ift
import matplotlib.pyplot as plt
import numpy as np
ift.random.push_sseq_from_seed(43)