Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
esde
machine-learning
MLAir
Commits
38849c46
Commit
38849c46
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
loss function is implemented with docs and test,
#5
parent
e5616b9b
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!9
new version v0.2.0
,
!7
l_p_loss and lrdecay implementation
Checking pipeline status
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers.py
+7
-1
7 additions, 1 deletion
src/helpers.py
test/test_helpers.py
+6
-2
6 additions, 2 deletions
test/test_helpers.py
with
13 additions
and
3 deletions
src/helpers.py
+
7
−
1
View file @
38849c46
...
...
@@ -14,7 +14,13 @@ def to_list(arg):
return
arg
def
l_p_loss
(
power
):
def
l_p_loss
(
power
:
int
):
"""
Calculate the L<p> loss for given power p. L1 (p=1) is equal to mean absolute error (MAE), L2 (p=2) is to mean
squared error (MSE), ...
:param power: set the power of the error calculus
:return: loss for given power
"""
def
loss
(
y_true
,
y_pred
):
return
K
.
mean
(
K
.
pow
(
K
.
abs
(
y_pred
-
y_true
),
power
),
axis
=-
1
)
return
loss
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers.py
+
6
−
2
View file @
38849c46
...
...
@@ -13,5 +13,9 @@ class TestLoss:
model
=
keras
.
Sequential
()
model
.
add
(
keras
.
layers
.
Lambda
(
lambda
x
:
x
,
input_shape
=
(
None
,
)))
model
.
compile
(
optimizer
=
keras
.
optimizers
.
Adam
(),
loss
=
l_p_loss
(
2
))
hist
=
model
.
fit
(
np
.
array
([
1
,
0
]),
np
.
array
([
1
,
1
]),
epochs
=
1
)
assert
hist
.
history
[
'
loss
'
][
0
]
==
0.5
hist
=
model
.
fit
(
np
.
array
([
1
,
0
,
2
,
0.5
]),
np
.
array
([
1
,
1
,
0
,
0.5
]),
epochs
=
1
)
assert
hist
.
history
[
'
loss
'
][
0
]
==
1.25
model
.
compile
(
optimizer
=
keras
.
optimizers
.
Adam
(),
loss
=
l_p_loss
(
3
))
hist
=
model
.
fit
(
np
.
array
([
1
,
0
,
-
2
,
0.5
]),
np
.
array
([
1
,
1
,
0
,
0.5
]),
epochs
=
1
)
assert
hist
.
history
[
'
loss
'
][
0
]
==
2.25
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