Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvia Biscoveanu
bilby
Commits
d339a288
Commit
d339a288
authored
6 years ago
by
Gregory Ashton
Browse files
Options
Downloads
Patches
Plain Diff
More flake8 fixes
parent
91648bee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tupak/core/sampler.py
+3
-3
3 additions, 3 deletions
tupak/core/sampler.py
tupak/core/utils.py
+17
-17
17 additions, 17 deletions
tupak/core/utils.py
with
20 additions
and
20 deletions
tupak/core/sampler.py
+
3
−
3
View file @
d339a288
...
...
@@ -1498,9 +1498,9 @@ class Pymc3(Sampler):
"""
try
:
import
theano
import
theano
# noqa
import
theano.tensor
as
tt
from
theano.compile.ops
import
as_op
from
theano.compile.ops
import
as_op
# noqa
except
ImportError
:
raise
ImportError
(
"
Could not import theano
"
)
...
...
@@ -1534,7 +1534,7 @@ class Pymc3(Sampler):
def
grad
(
self
,
inputs
,
g
):
theta
,
=
inputs
return
[
g
[
0
]
*
self
.
logpgrad
(
theta
)]
return
[
g
[
0
]
*
self
.
logpgrad
(
theta
)]
# create theano Op for calculating the gradient of the log likelihood
class
LogLikeGrad
(
tt
.
Op
):
...
...
This diff is collapsed.
Click to expand it.
tupak/core/utils.py
+
17
−
17
View file @
d339a288
...
...
@@ -479,7 +479,7 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
An array of indices in `vals` that are _not_ fixed values and therefore
can have derivatives taken. If `None` then derivatives of all values
are calculated.
Returns
-------
grads: array_like
...
...
@@ -488,10 +488,10 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
if
nonfixedidx
is
None
:
nonfixedidx
=
range
(
len
(
vals
))
if
len
(
nonfixedidx
)
>
len
(
vals
):
raise
ValueError
(
"
To many non-fixed values
"
)
if
max
(
nonfixedidx
)
>=
len
(
vals
)
or
min
(
nonfixedidx
)
<
0
:
raise
ValueError
(
"
Non-fixed indexes contain non-existant indices
"
)
...
...
@@ -503,9 +503,9 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
# set steps
if
abseps
is
None
:
if
isinstance
(
releps
,
float
):
eps
=
np
.
abs
(
vals
)
*
releps
eps
[
eps
==
0.
]
=
releps
# if any values are zero set eps to releps
teps
=
releps
*
np
.
ones
(
len
(
vals
))
eps
=
np
.
abs
(
vals
)
*
releps
eps
[
eps
==
0.
]
=
releps
# if any values are zero set eps to releps
teps
=
releps
*
np
.
ones
(
len
(
vals
))
elif
isinstance
(
releps
,
(
list
,
np
.
ndarray
)):
if
len
(
releps
)
!=
len
(
vals
):
raise
ValueError
(
"
Problem with input relative step sizes
"
)
...
...
@@ -516,7 +516,7 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
raise
RuntimeError
(
"
Relative step sizes are not a recognised type!
"
)
else
:
if
isinstance
(
abseps
,
float
):
eps
=
abseps
*
np
.
ones
(
len
(
vals
))
eps
=
abseps
*
np
.
ones
(
len
(
vals
))
elif
isinstance
(
abseps
,
(
list
,
np
.
ndarray
)):
if
len
(
abseps
)
!=
len
(
vals
):
raise
ValueError
(
"
Problem with input absolute step sizes
"
)
...
...
@@ -539,13 +539,13 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
bvals
=
np
.
copy
(
vals
)
# central difference
fvals
[
i
]
+=
0.5
*
leps
# change forwards distance to half eps
bvals
[
i
]
-=
0.5
*
leps
# change backwards distance to half eps
cdiff
=
(
func
(
fvals
)
-
func
(
bvals
))
/
leps
fvals
[
i
]
+=
0.5
*
leps
# change forwards distance to half eps
bvals
[
i
]
-=
0.5
*
leps
# change backwards distance to half eps
cdiff
=
(
func
(
fvals
)
-
func
(
bvals
))
/
leps
while
1
:
fvals
[
i
]
-=
0.5
*
leps
# remove old step
bvals
[
i
]
+=
0.5
*
leps
fvals
[
i
]
-=
0.5
*
leps
# remove old step
bvals
[
i
]
+=
0.5
*
leps
# change the difference by a factor of two
cureps
*=
epsscale
...
...
@@ -557,19 +557,19 @@ def derivatives(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,
leps
*=
epsscale
# central difference
fvals
[
i
]
+=
0.5
*
leps
# change forwards distance to half eps
bvals
[
i
]
-=
0.5
*
leps
# change backwards distance to half eps
cdiffnew
=
(
func
(
fvals
)
-
func
(
bvals
))
/
leps
fvals
[
i
]
+=
0.5
*
leps
# change forwards distance to half eps
bvals
[
i
]
-=
0.5
*
leps
# change backwards distance to half eps
cdiffnew
=
(
func
(
fvals
)
-
func
(
bvals
))
/
leps
if
cdiffnew
==
cdiff
:
grads
[
count
]
=
cdiff
break
# check whether previous diff and current diff are the same within reltol
rat
=
(
cdiff
/
cdiffnew
)
rat
=
(
cdiff
/
cdiffnew
)
if
np
.
isfinite
(
rat
)
and
rat
>
0.
:
# gradient has not changed sign
if
np
.
abs
(
1.
-
rat
)
<
reltol
:
if
np
.
abs
(
1.
-
rat
)
<
reltol
:
grads
[
count
]
=
cdiffnew
break
else
:
...
...
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