Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
13
Merge Requests
13
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
54b34fbe
Commit
54b34fbe
authored
Jul 02, 2018
by
Martin Reinecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more adjustments
parent
5de1cebf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
20 deletions
+14
-20
demos/getting_started_2.py
demos/getting_started_2.py
+2
-1
demos/getting_started_3.py
demos/getting_started_3.py
+1
-2
nifty5/energies/hamiltonian.py
nifty5/energies/hamiltonian.py
+6
-9
nifty5/minimization/descent_minimizer.py
nifty5/minimization/descent_minimizer.py
+3
-6
nifty5/operators/linear_operator.py
nifty5/operators/linear_operator.py
+2
-2
No files found.
demos/getting_started_2.py
View file @
54b34fbe
...
...
@@ -79,7 +79,8 @@ if __name__ == '__main__':
minimizer
=
ift
.
RelaxedNewton
(
ic_newton
)
# Minimize the Hamiltonian
H
=
ift
.
Hamiltonian
(
likelihood
,
ic_cg
)
H
=
ift
.
Hamiltonian
(
likelihood
)
H
=
H
.
makeInvertible
(
ic_cg
)
H
,
convergence
=
minimizer
(
H
)
# Plot results
...
...
demos/getting_started_3.py
View file @
54b34fbe
...
...
@@ -64,8 +64,7 @@ if __name__ == '__main__':
minimizer
=
ift
.
RelaxedNewton
(
ic_newton
)
# build model Hamiltonian
H
=
ift
.
Hamiltonian
(
likelihood
,
ic_cg
,
iteration_controller_sampling
=
ic_sampling
)
H
=
ift
.
Hamiltonian
(
likelihood
,
ic_sampling
)
INITIAL_POSITION
=
ift
.
from_random
(
'normal'
,
H
.
position
.
domain
)
position
=
INITIAL_POSITION
...
...
nifty5/energies/hamiltonian.py
View file @
54b34fbe
...
...
@@ -19,25 +19,23 @@
from
..library.gaussian_energy
import
GaussianEnergy
from
..minimization.energy
import
Energy
from
..models.variable
import
Variable
from
..operators
import
InversionEnabler
,
SamplingEnabler
from
..operators
.sampling_enabler
import
SamplingEnabler
from
..utilities
import
memo
class
Hamiltonian
(
Energy
):
def
__init__
(
self
,
lh
,
iteration_controller
,
iteration_controller_sampling
=
None
):
def
__init__
(
self
,
lh
,
iteration_controller_sampling
=
None
):
"""
lh: Likelihood (energy object)
prior:
"""
super
(
Hamiltonian
,
self
).
__init__
(
lh
.
position
)
self
.
_lh
=
lh
self
.
_ic
=
iteration_controller
self
.
_ic_samp
=
iteration_controller_sampling
self
.
_prior
=
GaussianEnergy
(
Variable
(
self
.
position
))
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_lh
.
at
(
position
),
self
.
_ic
,
self
.
_ic
_samp
)
return
self
.
__class__
(
self
.
_lh
.
at
(
position
),
self
.
_ic_samp
)
@
property
@
memo
...
...
@@ -54,11 +52,10 @@ class Hamiltonian(Energy):
def
curvature
(
self
):
prior_curv
=
self
.
_prior
.
curvature
if
self
.
_ic_samp
is
None
:
c
=
self
.
_lh
.
curvature
+
prior_curv
return
self
.
_lh
.
curvature
+
prior_curv
else
:
c
=
SamplingEnabler
(
self
.
_lh
.
curvature
,
prior_curv
.
inverse
,
self
.
_ic_samp
,
prior_curv
.
inverse
)
return
InversionEnabler
(
c
,
self
.
_ic
,
prior_curv
)
return
SamplingEnabler
(
self
.
_lh
.
curvature
,
prior_curv
.
inverse
,
self
.
_ic_samp
,
prior_curv
.
inverse
)
def
__str__
(
self
):
res
=
'Likelihood:
\t
{:.2E}
\n
'
.
format
(
self
.
_lh
.
value
)
...
...
nifty5/minimization/descent_minimizer.py
View file @
54b34fbe
...
...
@@ -80,12 +80,9 @@ class DescentMinimizer(Minimizer):
return
energy
,
controller
.
CONVERGED
# compute a step length that reduces energy.value sufficiently
try
:
new_energy
,
success
=
self
.
line_searcher
.
perform_line_search
(
energy
=
energy
,
pk
=
self
.
get_descent_direction
(
energy
),
f_k_minus_1
=
f_k_minus_1
)
except
ValueError
:
return
energy
,
controller
.
ERROR
new_energy
,
success
=
self
.
line_searcher
.
perform_line_search
(
energy
=
energy
,
pk
=
self
.
get_descent_direction
(
energy
),
f_k_minus_1
=
f_k_minus_1
)
if
not
success
:
self
.
reset
()
...
...
nifty5/operators/linear_operator.py
View file @
54b34fbe
...
...
@@ -274,9 +274,9 @@ class LinearOperator(NiftyMetaBase()):
def
_check_mode
(
self
,
mode
):
if
not
self
.
_validMode
[
mode
]:
raise
Value
Error
(
"invalid operator mode specified"
)
raise
NotImplemented
Error
(
"invalid operator mode specified"
)
if
mode
&
self
.
capability
==
0
:
raise
Value
Error
(
"requested operator mode is not supported"
)
raise
NotImplemented
Error
(
"requested operator mode is not supported"
)
def
_check_input
(
self
,
x
,
mode
):
self
.
_check_mode
(
mode
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment