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
4bd1fa25
Commit
4bd1fa25
authored
3 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
new helper relative round
parent
ad2450a2
No related branches found
No related tags found
5 merge requests
!432
IOA works now also with xarray and on identical data, IOA is included in...
,
!431
Resolve "release v2.1.0"
,
!430
update recent developments
,
!420
Resolve "disable/enable early stopping"
,
!419
Resolve "loss plot with best result marker"
Pipeline
#100499
passed
3 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlair/helpers/helpers.py
+15
-0
15 additions, 0 deletions
mlair/helpers/helpers.py
test/test_helpers/test_helpers.py
+34
-1
34 additions, 1 deletion
test/test_helpers/test_helpers.py
with
49 additions
and
1 deletion
mlair/helpers/helpers.py
+
15
−
0
View file @
4bd1fa25
...
...
@@ -122,6 +122,21 @@ def float_round(number: float, decimals: int = 0, round_type: Callable = math.ce
return
round_type
(
number
*
multiplier
)
/
multiplier
def
relative_round
(
x
:
float
,
sig
:
int
)
->
float
:
"""
Round small numbers according to given
"
significance
"
.
Example: relative_round(0.03112, 2) -> 0.031, relative_round(0.03112, 1) -> 0.03
:params x: number to round
:params sig:
"
significance
"
to determine number of decimals
:return: rounded number
"""
assert
sig
>=
1
return
round
(
x
,
sig
-
int
(
np
.
floor
(
np
.
log10
(
abs
(
x
))))
-
1
)
def
remove_items
(
obj
:
Union
[
List
,
Dict
,
Tuple
],
items
:
Any
):
"""
Remove item(s) from either list, tuple or dictionary.
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers/test_helpers.py
+
34
−
1
View file @
4bd1fa25
...
...
@@ -15,7 +15,7 @@ import string
from
mlair.helpers
import
to_list
,
dict_to_xarray
,
float_round
,
remove_items
,
extract_value
,
select_from_dict
,
sort_like
from
mlair.helpers
import
PyTestRegex
from
mlair.helpers
import
Logger
,
TimeTracking
from
mlair.helpers.helpers
import
is_xarray
,
convert2xrda
from
mlair.helpers.helpers
import
is_xarray
,
convert2xrda
,
relative_round
class
TestToList
:
...
...
@@ -171,6 +171,39 @@ class TestFloatRound:
assert
float_round
(
-
34.9221
,
0
)
==
-
34.
class
TestRelativeRound
:
def
test_relative_round_big_numbers
(
self
):
assert
relative_round
(
101
,
1
)
==
100
assert
relative_round
(
99
,
1
)
==
100
assert
relative_round
(
105
,
2
)
==
100
assert
relative_round
(
106
,
2
)
==
110
assert
relative_round
(
106
,
3
)
==
106
def
test_relative_round_float_numbers
(
self
):
assert
relative_round
(
101.2033
,
4
)
==
101.2
assert
relative_round
(
101.2033
,
5
)
==
101.2
assert
relative_round
(
101.2033
,
6
)
==
101.203
def
test_relative_round_small_numbers
(
self
):
assert
relative_round
(
0.03112
,
2
)
==
0.031
assert
relative_round
(
0.03112
,
1
)
==
0.03
assert
relative_round
(
0.031126
,
4
)
==
0.03113
def
test_relative_round_negative_numbers
(
self
):
assert
relative_round
(
-
101.2033
,
5
)
==
-
101.2
assert
relative_round
(
-
106
,
2
)
==
-
110
assert
relative_round
(
-
0.03112
,
2
)
==
-
0.031
assert
relative_round
(
-
0.03112
,
1
)
==
-
0.03
assert
relative_round
(
-
0.031126
,
4
)
==
-
0.03113
def
test_relative_round_wrong_significance
(
self
):
with
pytest
.
raises
(
AssertionError
):
relative_round
(
300
,
-
1
)
with
pytest
.
raises
(
TypeError
):
relative_round
(
300
,
1.1
)
class
TestSelectFromDict
:
@pytest.fixture
...
...
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