Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container Registry
Model registry
Operate
Environments
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
lscsoft
bilby
Commits
9a4dbfbc
Commit
9a4dbfbc
authored
6 years ago
by
Moritz Huebner
Browse files
Options
Downloads
Patches
Plain Diff
Moritz Huebner: Refined some __repr__ stuff
parent
b135d405
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tupak/prior.py
+14
-24
14 additions, 24 deletions
tupak/prior.py
with
14 additions
and
24 deletions
tupak/prior.py
+
14
−
24
View file @
9a4dbfbc
...
...
@@ -72,40 +72,32 @@ class Prior(object):
def
__repr__
(
self
):
return
self
.
subclass_repr_helper
()
def
subclass_repr_helper
(
self
,
subclass_
key
s
=
list
(),
subclass_names
=
list
()):
def
subclass_repr_helper
(
self
,
subclass_
arg
s
=
list
(),
subclass_names
=
list
()):
prior_name
=
self
.
__class__
.
__name__
keys
=
[
'
name
'
,
'
latex_label
'
,
'
minimum
'
,
'
maximum
'
]
keys
.
extend
(
subclass_keys
)
names
=
[
'
name
'
,
'
latex_label
'
,
'
minimum
'
,
'
maximum
'
]
names
.
extend
(
subclass_names
)
args
=
self
.
repr_format_helper
(
keys
,
names
)
args
=
[
'
name
'
,
'
latex_label
'
,
'
minimum
'
,
'
maximum
'
]
args
.
extend
(
subclass_args
)
args
=
self
.
repr_format_helper
(
args
)
return
"
{}({})
"
.
format
(
prior_name
,
args
)
def
repr_format_helper
(
self
,
keys
,
names
):
def
repr_format_helper
(
self
,
keys
):
string_keys
=
[]
string_names
=
[]
non_string_keys
=
[]
non_string_names
=
[]
property_names
=
[
p
for
p
in
dir
(
self
.
__class__
)
if
isinstance
(
getattr
(
self
.
__class__
,
p
),
property
)]
dict_with_properties
=
self
.
__dict__
.
copy
()
for
key
in
property_names
:
dict_with_properties
[
key
]
=
getattr
(
self
,
key
)
for
key
,
name
in
zip
(
keys
,
names
)
:
for
key
in
keys
:
if
isinstance
(
dict_with_properties
[
key
],
str
):
string_keys
.
append
(
key
)
string_names
.
append
(
name
)
else
:
non_string_keys
.
append
(
key
)
non_string_names
.
append
(
name
)
args
=
'
,
'
.
join
([
'
{}={}
'
.
format
(
name
,
'
\"
'
+
dict_with_properties
[
key
]
+
'
\"
'
)
for
key
,
name
in
zip
(
string_keys
,
string_names
)])
args
=
'
,
'
.
join
([
'
{}={}
'
.
format
(
key
,
'
\"
'
+
dict_with_properties
[
key
]
+
'
\"
'
)
for
key
in
string_keys
])
if
len
(
string_keys
)
>
0
:
args
=
args
+
'
,
'
args
=
args
+
'
,
'
.
join
([
'
{}={}
'
.
format
(
name
,
dict_with_properties
[
key
])
for
key
,
name
in
zip
(
non_string_keys
,
non_string_names
)])
args
=
args
+
'
,
'
.
join
([
'
{}={}
'
.
format
(
key
,
dict_with_properties
[
key
])
for
key
in
non_string_keys
])
return
args
@property
...
...
@@ -192,7 +184,7 @@ class DeltaFunction(Prior):
return
0
def
__repr__
(
self
):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
keys
=
[
'
peak
'
],
subclass_name
s
=
[
'
peak
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
arg
s
=
[
'
peak
'
])
class
PowerLaw
(
Prior
):
...
...
@@ -232,7 +224,7 @@ class PowerLaw(Prior):
return
self
.
alpha
*
np
.
log
(
val
)
*
np
.
log
(
normalising
)
*
in_prior
def
__repr__
(
self
):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
keys
=
[
'
alpha
'
],
subclass_name
s
=
[
'
alpha
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
arg
s
=
[
'
alpha
'
])
class
Uniform
(
PowerLaw
):
...
...
@@ -331,7 +323,7 @@ class Gaussian(Prior):
return
-
0.5
*
((
self
.
mu
-
val
)
**
2
/
self
.
sigma
**
2
+
np
.
log
(
2
*
np
.
pi
*
self
.
sigma
**
2
))
def
__repr__
(
self
):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
keys
=
[
'
mu
'
,
'
sigma
'
],
subclass_name
s
=
[
'
mu
'
,
'
sigma
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
arg
s
=
[
'
mu
'
,
'
sigma
'
])
class
TruncatedGaussian
(
Prior
):
...
...
@@ -367,7 +359,7 @@ class TruncatedGaussian(Prior):
2
*
np
.
pi
)
**
0.5
/
self
.
sigma
/
self
.
normalisation
*
in_prior
def
__repr__
(
self
):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
keys
=
[
'
mu
'
,
'
sigma
'
],
subclass_name
s
=
[
'
mu
'
,
'
sigma
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
arg
s
=
[
'
mu
'
,
'
sigma
'
])
class
Interped
(
Prior
):
...
...
@@ -399,7 +391,7 @@ class Interped(Prior):
return
rescaled
def
__repr__
(
self
):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
keys
=
[
'
xx
'
,
'
yy
'
],
subclass_name
s
=
[
'
xx
'
,
'
yy
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_
arg
s
=
[
'
xx
'
,
'
yy
'
])
@property
def
minimum
(
self
):
...
...
@@ -453,9 +445,7 @@ class FromFile(Interped):
logging
.
warning
(
r
"
x\tp(x)
"
)
def
__repr__
(
self
,
subclass_keys
=
list
(),
subclass_names
=
list
()):
return
Prior
.
subclass_repr_helper
(
self
,
subclass_keys
=
[
'
xx
'
,
'
yy
'
,
'
id
'
],
subclass_names
=
[
'
xx
'
,
'
yy
'
,
'
id
'
])
return
Prior
.
subclass_repr_helper
(
self
,
subclass_args
=
[
'
xx
'
,
'
yy
'
,
'
id
'
])
class
UniformComovingVolume
(
FromFile
):
...
...
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