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
8
Merge Requests
8
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
bbf22449
Commit
bbf22449
authored
Jul 03, 2018
by
Martin Reinecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Model.gradient -> Model.jacobian
parent
c15669d0
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
32 additions
and
29 deletions
+32
-29
nifty5/extra/energy_and_model_tests.py
nifty5/extra/energy_and_model_tests.py
+2
-2
nifty5/library/apply_data.py
nifty5/library/apply_data.py
+1
-1
nifty5/library/gaussian_energy.py
nifty5/library/gaussian_energy.py
+7
-5
nifty5/library/poissonian_energy.py
nifty5/library/poissonian_energy.py
+2
-2
nifty5/models/binary_helpers.py
nifty5/models/binary_helpers.py
+4
-4
nifty5/models/constant.py
nifty5/models/constant.py
+2
-2
nifty5/models/linear_model.py
nifty5/models/linear_model.py
+2
-2
nifty5/models/local_nonlinearity.py
nifty5/models/local_nonlinearity.py
+3
-3
nifty5/models/model.py
nifty5/models/model.py
+6
-6
nifty5/models/multi_model.py
nifty5/models/multi_model.py
+2
-1
nifty5/models/variable.py
nifty5/models/variable.py
+1
-1
No files found.
nifty5/extra/energy_and_model_tests.py
View file @
bbf22449
...
...
@@ -30,7 +30,7 @@ def _get_acceptable_model(M):
if
not
np
.
isfinite
(
val
.
sum
()):
raise
ValueError
(
'Initial Model value must be finite'
)
dir
=
from_random
(
"normal"
,
M
.
position
.
domain
)
dirder
=
M
.
gradient
(
dir
)
dirder
=
M
.
jacobian
(
dir
)
dir
*=
val
/
(
dirder
).
norm
()
*
1e-5
# Find a step length that leads to a "reasonable" Model
for
i
in
range
(
50
):
...
...
@@ -82,7 +82,7 @@ def check_value_gradient_consistency(E, tol=1e-8, ntries=100):
if
isinstance
(
E
,
Energy
):
dirder
=
Emid
.
gradient
.
vdot
(
dir
)
/
dirnorm
else
:
dirder
=
Emid
.
gradient
(
dir
)
/
dirnorm
dirder
=
Emid
.
jacobian
(
dir
)
/
dirnorm
numgrad
=
(
E2
.
value
-
val
)
/
dirnorm
if
isinstance
(
E
,
Model
):
xtol
=
tol
*
dirder
.
norm
()
/
np
.
sqrt
(
dirder
.
size
)
...
...
nifty5/library/apply_data.py
View file @
bbf22449
...
...
@@ -5,4 +5,4 @@ def ApplyData(data, var, model_data):
from
..sugar
import
sqrt
sqrt_n
=
DiagonalOperator
(
sqrt
(
var
))
data
=
Constant
(
model_data
.
position
,
data
)
return
sqrt_n
.
inverse
(
model_data
-
data
)
return
sqrt_n
.
inverse
_times
(
model_data
-
data
)
nifty5/library/gaussian_energy.py
View file @
bbf22449
...
...
@@ -49,18 +49,20 @@ class GaussianEnergy(Energy):
def
value
(
self
):
if
self
.
_cov
is
None
:
return
.
5
*
self
.
residual
.
vdot
(
self
.
residual
).
real
return
.
5
*
self
.
residual
.
vdot
(
self
.
_cov
.
inverse
(
self
.
residual
)).
real
return
.
5
*
self
.
residual
.
vdot
(
self
.
_cov
.
inverse_times
(
self
.
residual
)).
real
@
property
@
memo
def
gradient
(
self
):
if
self
.
_cov
is
None
:
return
self
.
_inp
.
gradient
.
adjoint
(
self
.
residual
)
return
self
.
_inp
.
gradient
.
adjoint
(
self
.
_cov
.
inverse
(
self
.
residual
))
return
self
.
_inp
.
jacobian
.
adjoint_times
(
self
.
residual
)
return
self
.
_inp
.
jacobian
.
adjoint_times
(
self
.
_cov
.
inverse_times
(
self
.
residual
))
@
property
@
memo
def
curvature
(
self
):
if
self
.
_cov
is
None
:
return
SandwichOperator
.
make
(
self
.
_inp
.
gradient
,
None
)
return
SandwichOperator
.
make
(
self
.
_inp
.
gradient
,
self
.
_cov
.
inverse
)
return
SandwichOperator
.
make
(
self
.
_inp
.
jacobian
,
None
)
return
SandwichOperator
.
make
(
self
.
_inp
.
jacobian
,
self
.
_cov
.
inverse
)
nifty5/library/poissonian_energy.py
View file @
bbf22449
...
...
@@ -40,11 +40,11 @@ class PoissonianEnergy(Energy):
self
.
_value
=
lamb_val
.
sum
()
-
d
.
vdot
(
log
(
lamb_val
))
if
isnan
(
self
.
_value
):
self
.
_value
=
inf
self
.
_gradient
=
self
.
_lamb
.
gradient
.
adjoint_times
(
1
-
d
/
lamb_val
)
self
.
_gradient
=
self
.
_lamb
.
jacobian
.
adjoint_times
(
1
-
d
/
lamb_val
)
# metric = makeOp(d/lamb_val/lamb_val)
metric
=
makeOp
(
1.
/
lamb_val
)
self
.
_curvature
=
SandwichOperator
.
make
(
self
.
_lamb
.
gradient
,
metric
)
self
.
_curvature
=
SandwichOperator
.
make
(
self
.
_lamb
.
jacobian
,
metric
)
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_lamb
.
at
(
position
),
self
.
_d
)
...
...
nifty5/models/binary_helpers.py
View file @
bbf22449
...
...
@@ -42,7 +42,7 @@ class ScalarMul(Model):
self
.
_factor
=
factor
self
.
_value
=
self
.
_factor
*
self
.
_model
.
value
self
.
_
gradient
=
self
.
_factor
*
self
.
_model
.
gradient
self
.
_
jacobian
=
self
.
_factor
*
self
.
_model
.
jacobian
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_factor
,
self
.
_model
.
at
(
position
))
...
...
@@ -57,7 +57,7 @@ class Add(Model):
self
.
_model2
=
model2
.
at
(
position
)
self
.
_value
=
self
.
_model1
.
value
+
self
.
_model2
.
value
self
.
_
gradient
=
self
.
_model1
.
gradient
+
self
.
_model2
.
gradient
self
.
_
jacobian
=
self
.
_model1
.
jacobian
+
self
.
_model2
.
jacobian
@
staticmethod
def
make
(
model1
,
model2
):
...
...
@@ -87,8 +87,8 @@ class Mul(Model):
self
.
_model2
=
model2
.
at
(
position
)
self
.
_value
=
self
.
_model1
.
value
*
self
.
_model2
.
value
self
.
_
gradient
=
(
makeOp
(
self
.
_model1
.
value
)
*
self
.
_model2
.
gradient
+
makeOp
(
self
.
_model2
.
value
)
*
self
.
_model1
.
gradient
)
self
.
_
jacobian
=
(
makeOp
(
self
.
_model1
.
value
)
*
self
.
_model2
.
jacobian
+
makeOp
(
self
.
_model2
.
value
)
*
self
.
_model1
.
jacobian
)
@
staticmethod
def
make
(
model1
,
model2
):
...
...
nifty5/models/constant.py
View file @
bbf22449
...
...
@@ -32,7 +32,7 @@ class Constant(Model):
-----
Since there is no model-function associated:
- Position has no influence on value.
- There is no
gradient
.
- There is no
Jacobian
.
"""
# TODO Remove position
def
__init__
(
self
,
position
,
constant
):
...
...
@@ -40,7 +40,7 @@ class Constant(Model):
self
.
_constant
=
constant
self
.
_value
=
self
.
_constant
self
.
_
gradient
=
0.
self
.
_
jacobian
=
0.
def
at
(
self
,
position
):
return
self
.
__class__
(
position
,
self
.
_constant
)
nifty5/models/linear_model.py
View file @
bbf22449
...
...
@@ -34,7 +34,7 @@ class LinearModel(Model):
-------
Model with linear Operator applied:
- Model.value = LinOp (inp.value) [key-wise]
-
Gradient = LinOp * inp.gradient
-
Jacobian = LinOp * inp.jacobian
"""
from
..operators.linear_operator
import
LinearOperator
super
(
LinearModel
,
self
).
__init__
(
inp
.
position
)
...
...
@@ -49,7 +49,7 @@ class LinearModel(Model):
self
.
_lin_op
.
_key
)
self
.
_value
=
self
.
_lin_op
(
self
.
_inp
.
value
)
self
.
_
gradient
=
self
.
_lin_op
*
self
.
_inp
.
gradient
self
.
_
jacobian
=
self
.
_lin_op
*
self
.
_inp
.
jacobian
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_inp
.
at
(
position
),
self
.
_lin_op
)
nifty5/models/local_nonlinearity.py
View file @
bbf22449
...
...
@@ -27,7 +27,7 @@ class LocalModel(Model):
"""
Computes nonlinearity(inp)
- LocalModel.value = nonlinearity(value) (pointwise)
- LocalModel.
gradient = Outer Product of gradient
s
- LocalModel.
jacobian = Outer Product of Jacobian
s
Parameters
----------
...
...
@@ -40,9 +40,9 @@ class LocalModel(Model):
self
.
_inp
=
inp
self
.
_nonlinearity
=
nonlinearity
self
.
_value
=
nonlinearity
(
self
.
_inp
.
value
)
d_inner
=
self
.
_inp
.
gradient
d_inner
=
self
.
_inp
.
jacobian
d_outer
=
makeOp
(
self
.
_nonlinearity
.
derivative
(
self
.
_inp
.
value
))
self
.
_
gradient
=
d_outer
*
d_inner
self
.
_
jacobian
=
d_outer
*
d_inner
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_inp
.
at
(
position
),
self
.
_nonlinearity
)
...
...
nifty5/models/model.py
View file @
bbf22449
...
...
@@ -28,7 +28,7 @@ class Model(NiftyMetaBase()):
The Model object is an implementation of a * which knows:
- position in parameterspace. (Field, MulitField)
- value according to its modelfunction A. A(position)
-
gradient of the model
function at the current position.
-
Jacobian of the model
function at the current position.
Parameters
----------
...
...
@@ -37,9 +37,9 @@ class Model(NiftyMetaBase()):
Notes
-----
An instance of the model class knows its position, value and
gradient
.
An instance of the model class knows its position, value and
Jacobian
.
One can 'jump' to a new position, with the help of the 'at' method, whereby
one automatically gets the value and
gradient
of the model. The 'at' method
one automatically gets the value and
Jacobian
of the model. The 'at' method
creates a new instance of the class.
"""
def
__init__
(
self
,
position
):
...
...
@@ -65,7 +65,7 @@ class Model(NiftyMetaBase()):
"""
Field or MultiField: selected location in parameter space.
The location in parameter space where value and
gradient
are
The location in parameter space where value and
Jacobian
are
evaluated.
"""
return
self
.
_position
...
...
@@ -80,11 +80,11 @@ class Model(NiftyMetaBase()):
return
self
.
_value
@
property
def
gradient
(
self
):
def
jacobian
(
self
):
"""
LinearOperator : The derivative of the model at given `position`.
"""
return
self
.
_
gradient
return
self
.
_
jacobian
def
__getitem__
(
self
,
key
):
sel
=
SelectionOperator
(
self
.
value
.
domain
,
key
)
...
...
nifty5/models/multi_model.py
View file @
bbf22449
...
...
@@ -34,7 +34,8 @@ class MultiModel(Model):
if
not
isinstance
(
val
.
domain
,
DomainTuple
):
raise
TypeError
self
.
_value
=
MultiField
({
key
:
val
})
self
.
_gradient
=
MultiAdaptor
(
self
.
value
.
domain
)
*
self
.
_model
.
gradient
self
.
_jacobian
=
(
MultiAdaptor
(
self
.
value
.
domain
)
*
self
.
_model
.
jacobian
)
def
at
(
self
,
position
):
return
self
.
__class__
(
self
.
_model
.
at
(
position
),
self
.
_key
)
nifty5/models/variable.py
View file @
bbf22449
...
...
@@ -32,7 +32,7 @@ class Variable(Model):
super
(
Variable
,
self
).
__init__
(
position
)
self
.
_value
=
position
self
.
_
gradient
=
ScalingOperator
(
1.
,
position
.
domain
)
self
.
_
jacobian
=
ScalingOperator
(
1.
,
position
.
domain
)
def
at
(
self
,
position
):
return
self
.
__class__
(
position
)
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