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
I
IMAGINE
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
IMAGINE
Commits
c98ebc8e
Commit
c98ebc8e
authored
Dec 13, 2017
by
Theo Steininger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored simple likelihood.
parent
41320f6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
19 deletions
+25
-19
imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py
...ne/likelihoods/ensemble_likelihood/ensemble_likelihood.py
+3
-13
imagine/likelihoods/likelihood/likelihood.py
imagine/likelihoods/likelihood/likelihood.py
+11
-0
imagine/likelihoods/simple_likelihood/simple_likelihood.py
imagine/likelihoods/simple_likelihood/simple_likelihood.py
+11
-6
No files found.
imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py
View file @
c98ebc8e
...
...
@@ -16,15 +16,6 @@ class EnsembleLikelihood(Likelihood):
data_covariance
=
data_covariance
.
val
.
get_full_data
()
self
.
data_covariance
=
data_covariance
def
_strip_data
(
self
,
data
):
# if the first element in the domain tuple is a FieldArray we must
# extract the data
if
isinstance
(
data
.
domain
[
0
],
FieldArray
):
data
=
Field
(
domain
=
data
.
domain
[
1
:],
val
=
data
.
val
.
get_full_data
()[
0
],
distribution_strategy
=
'not'
)
return
data
def
__call__
(
self
,
observable
):
field
=
observable
[
self
.
observable_name
]
return
self
.
_process_simple_field
(
field
,
...
...
@@ -58,7 +49,6 @@ class EnsembleLikelihood(Likelihood):
rho
=
1
else
:
rho
=
np
.
min
([
1
,
numerator
/
denominator
])
self
.
logger
.
debug
(
"rho: %f = %f / %f"
%
(
rho
,
numerator
,
denominator
))
# rescale U half/half
...
...
@@ -68,7 +58,7 @@ class EnsembleLikelihood(Likelihood):
self
.
logger
.
info
((
'rho*mu'
,
rho
*
mu
,
'rho'
,
rho
,
'mu'
,
mu
,
'al
hp
a'
,
alpha
))
'al
ph
a'
,
alpha
))
A_diagonal_val
+=
rho
*
mu
a_u_val
=
u_val
/
A_diagonal_val
...
...
@@ -82,7 +72,7 @@ class EnsembleLikelihood(Likelihood):
# If the data was incomplete, i.e. contains np.NANs, set those values
# to zero.
c
.
val
.
data
=
np
.
nan_to_num
(
c
.
val
.
data
)
c
=
np
.
nan_to_num
(
c
)
# assuming that A == A^dagger, this can be shortend
# a_c = A.inverse_times(c)
# u_a_c = a_c.dot(U, spaces=1)
...
...
@@ -94,7 +84,7 @@ class EnsembleLikelihood(Likelihood):
# Pure NIFTy is
# u_a_c = c.dot(a_u, spaces=1)
# u_a_c_val = u_a_c.val.get_full_data()
c_val
=
c
.
val
.
get_full_data
()
c_val
=
c
u_a_c_val
=
np
.
einsum
(
c_val
,
[
1
],
a_u_val
,
[
0
,
1
])
first_summand_val
=
c_val
/
A_diagonal_val
...
...
imagine/likelihoods/likelihood/likelihood.py
View file @
c98ebc8e
...
...
@@ -4,8 +4,19 @@ import abc
from
keepers
import
Loggable
from
nifty
import
FieldArray
class
Likelihood
(
Loggable
,
object
):
@
abc
.
abstractmethod
def
__call__
(
self
,
observables
):
raise
NotImplementedError
def
_strip_data
(
self
,
data
):
# if the first element in the domain tuple is a FieldArray we must
# extract the data
if
isinstance
(
data
.
domain
[
0
],
FieldArray
):
data
=
data
.
val
.
get_full_data
()[
0
]
else
:
data
=
data
.
val
.
get_full_data
()
return
data
imagine/likelihoods/simple_likelihood/simple_likelihood.py
View file @
c98ebc8e
# -*- coding: utf-8 -*-
import
numpy
as
np
from
nifty
import
Field
from
imagine.likelihoods.likelihood
import
Likelihood
class
SimpleLikelihood
(
Likelihood
):
def
__init__
(
self
,
measured_data
,
data_covariance
_operator
=
None
):
def
__init__
(
self
,
measured_data
,
data_covariance
=
None
):
self
.
measured_data
=
measured_data
self
.
data_covariance_operator
=
data_covariance_operator
if
isinstance
(
data_covariance
,
Field
):
data_covariance
=
data_covariance
.
val
.
get_full_data
()
self
.
data_covariance
=
data_covariance
def
__call__
(
self
,
observable
):
data
=
self
.
measured_data
.
val
.
get_full_data
()
data
=
self
.
measured_data
obs_mean
=
observable
.
ensemble_mean
().
val
.
get_full_data
()
diff
=
data
-
obs_mean
if
self
.
data_covariance
_operator
is
not
None
:
right
=
self
.
data_covariance_operator
.
inverse_times
(
diff
)
if
self
.
data_covariance
is
not
None
:
right
=
diff
/
self
.
data_covariance_operator
else
:
right
=
diff
return
-
0.5
*
diff
.
conjugate
().
vdot
(
right
)
return
-
0.5
*
np
.
vdot
(
diff
,
right
)
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