Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
ift
NIFTy
Commits
8784c5f5
Commit
8784c5f5
authored
4 years ago
by
Vincent Eberle
Browse files
Options
Downloads
Patches
Plain Diff
add loc and scale
parent
a1bd1b6b
No related branches found
No related tags found
1 merge request
!599
Laplace distribution operator for L1 regularisation
Pipeline
#93859
passed
4 years ago
Stage: build_docker
Stage: test
Stage: demo_runs
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/library/special_distributions.py
+13
-4
13 additions, 4 deletions
src/library/special_distributions.py
with
13 additions
and
4 deletions
src/library/special_distributions.py
+
13
−
4
View file @
8784c5f5
...
...
@@ -163,16 +163,25 @@ class LaplaceOperator(Operator):
"""
Transforms a Gaussian with uni covariance and zero mean to a Laplace distribution
via a uniform distribution.
# VE TODO implement sigma
Parameters
-----------
domain : Domain, tuple of Domain or DomainTuple
The domain on which the field shall be defined. This is at the same
time the domain and the target of the operator.
loc : float
scale : float
"""
def
__init__
(
self
,
domain
):
def
__init__
(
self
,
domain
,
loc
=
0
,
scale
=
1
):
self
.
_target
=
self
.
_domain
=
DomainTuple
.
make
(
domain
)
self
.
_loc
=
float
(
loc
)
self
.
_scale
=
float
(
scale
)
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
lin
=
x
.
jac
is
not
None
xval
=
x
.
val
.
val
if
lin
else
x
.
val
res
=
Field
(
self
.
_target
,
laplace
.
_
ppf
(
norm
.
_cdf
(
xval
)))
res
=
Field
(
self
.
_target
,
laplace
.
ppf
(
norm
.
_cdf
(
xval
)
,
self
.
_loc
,
self
.
_scale
))
if
not
lin
:
return
res
jac
=
makeOp
(
Field
(
self
.
domain
,
self
.
_jac_func
(
norm
.
_cdf
(
xval
))
*
norm
.
_pdf
(
xval
)))
...
...
@@ -183,5 +192,5 @@ class LaplaceOperator(Operator):
return
Field
(
x
.
domain
,
res
)
def
_jac_func
(
self
,
x
):
res
=
np
.
where
(
x
>
0.5
,
(
1
/
(
1
-
x
)),
(
1
/
x
))
res
=
self
.
_scale
*
np
.
where
(
x
>
0.5
,
(
1
/
(
1
-
x
)),
(
1
/
x
))
return
res
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