Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor 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
schwede
openstructure
Commits
f7d0f0d8
Commit
f7d0f0d8
authored
14 years ago
by
Tobias Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
corrected some errors in stutil.py and added unit test
parent
fb0c2084
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/base/pymod/stutil.py
+5
-5
5 additions, 5 deletions
modules/base/pymod/stutil.py
modules/base/tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
modules/base/tests/CMakeLists.txt
modules/base/tests/test_stutil.py
+82
-0
82 additions, 0 deletions
modules/base/tests/test_stutil.py
with
88 additions
and
5 deletions
modules/base/pymod/stutil.py
+
5
−
5
View file @
f7d0f0d8
...
...
@@ -45,7 +45,7 @@ def Mean(xs):
"""
if
len
(
xs
)
==
0
:
raise
RuntimeError
(
"
Can
'
t calculate mean of empty sequence
"
)
return
sum
(
xs
)
/
len
(
xs
)
return
float
(
sum
(
xs
)
)
/
len
(
xs
)
@FloatValueExtract
def
Median
(
xs
):
...
...
@@ -86,7 +86,7 @@ def Correl(xs, ys):
sum[(xi-<x>)*(yi-<y>)]
r=----------------------
(n-1)*
sx*sy
sx*sy
where <x>, <y> are the mean of dataset xs and ys, and, sx and sy are the
standard deviations.
...
...
@@ -103,9 +103,9 @@ def Correl(xs, ys):
cross_term
+=
(
x
-
mean_x
)
*
(
y
-
mean_y
)
sigma_x
+=
(
x
-
mean_x
)
**
2
sigma_y
+=
(
y
-
mean_y
)
**
2
sigma_x
=
math
.
sqrt
(
sigma_x
/
len
(
xs
)
)
sigma_y
=
math
.
sqrt
(
sigma_y
/
len
(
ys
))
return
cross_term
/
(
(
len
(
xs
)
-
1
)
*
sigma_x
*
sigma_y
)
sigma_x
=
math
.
sqrt
(
sigma_x
)
sigma_y
=
math
.
sqrt
(
sigma_y
)
return
cross_term
/
(
sigma_x
*
sigma_y
)
def
Histogram
(
xs
,
bounds
,
num_bins
):
bins
=
[
0
for
i
in
range
(
num_bins
)]
...
...
This diff is collapsed.
Click to expand it.
modules/base/tests/CMakeLists.txt
+
1
−
0
View file @
f7d0f0d8
...
...
@@ -2,6 +2,7 @@ set(OST_BASE_UNIT_TESTS
test_generic_property.cc
test_string_ref.cc
test_pod_vector.cc
test_stutil.py
tests.cc
)
...
...
This diff is collapsed.
Click to expand it.
modules/base/tests/test_stutil.py
0 → 100644
+
82
−
0
View file @
f7d0f0d8
import
unittest
from
ost
import
stutil
class
TestStUtils
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
data1
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
-
5
,
-
4
,
-
3
,
-
2
,
-
1
,
1
]
self
.
data2
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
]
self
.
data3
=
[
0.1
,
0.5
,
0.7
,
2.4
,
0.5
,
4.1
,
0.9
,
-
1.1
,
-
0.5
,
0.7
,
-
1.4
,
-
7.5
,
8.5
]
self
.
mean
=
0.5384615385
self
.
mean2
=
0.6076923077
self
.
median
=
1
self
.
median2
=
0.5
self
.
stddev
=
3.3192998478
self
.
stddev2
=
3.4192805223
self
.
minimum
=
-
5
self
.
minimum2
=
-
7.5
self
.
maximum
=
6
self
.
maximum2
=
8.5
self
.
correl
=
-
0.39639313
self
.
correl2
=
-
0.0619291504
def
isSimilar
(
self
,
value
,
reference
,
accuracy
):
if
abs
(
value
-
reference
)
<=
accuracy
:
return
True
return
False
def
testMean
(
self
):
assert
self
.
isSimilar
(
stutil
.
Mean
(
self
.
data1
),
self
.
mean
,
0.001
),
\
"
Mean (%f) does not correspond to precalculated mean (%f)
"
%
\
(
stutil
.
Mean
(
self
.
data1
),
self
.
mean
)
assert
self
.
isSimilar
(
stutil
.
Mean
(
self
.
data3
),
self
.
mean2
,
0.001
),
\
"
Mean (%f) does not correspond to precalculated mean (%f)
"
%
\
(
stutil
.
Mean
(
self
.
data3
),
self
.
mean2
)
def
testMedian
(
self
):
assert
self
.
isSimilar
(
stutil
.
Median
(
self
.
data1
),
self
.
median
,
0.001
),
\
"
Median (%f) does not correspond to precalculated median (%f)
"
%
\
(
stutil
.
Median
(
self
.
data1
),
self
.
median
)
assert
self
.
isSimilar
(
stutil
.
Median
(
self
.
data3
),
self
.
median2
,
0.001
),
\
"
Median (%f) does not correspond to precalculated median (%f)
"
%
\
(
stutil
.
Median
(
self
.
data3
),
self
.
median2
)
def
testStddev
(
self
):
assert
self
.
isSimilar
(
stutil
.
StdDev
(
self
.
data1
),
self
.
stddev
,
0.001
),
\
"
StdDev (%f) does not correspond to precalculated StdDev (%f)
"
%
\
(
stutil
.
StdDev
(
self
.
data1
),
self
.
stddev
)
assert
self
.
isSimilar
(
stutil
.
StdDev
(
self
.
data3
),
self
.
stddev2
,
0.001
),
\
"
StdDev (%f) does not correspond to precalculated StdDev (%f)
"
%
\
(
stutil
.
StdDev
(
self
.
data3
),
self
.
stddev2
)
def
testMinimum
(
self
):
assert
self
.
isSimilar
(
stutil
.
Min
(
self
.
data1
),
self
.
minimum
,
0.001
),
\
"
Minimum (%f) does not correspond to precalculated minimum (%f)
"
%
\
(
stutil
.
Min
(
self
.
data1
),
self
.
minimum
)
assert
self
.
isSimilar
(
stutil
.
Min
(
self
.
data3
),
self
.
minimum2
,
0.001
),
\
"
Minimum (%f) does not correspond to precalculated minimum (%f)
"
%
\
(
stutil
.
Min
(
self
.
data3
),
self
.
minimum2
)
def
testMaximum
(
self
):
assert
self
.
isSimilar
(
stutil
.
Max
(
self
.
data1
),
self
.
maximum
,
0.001
),
\
"
Maximum (%f) does not correspond to precalculated maximum (%f)
"
%
\
(
stutil
.
Max
(
self
.
data1
),
self
.
maximum
)
assert
self
.
isSimilar
(
stutil
.
Max
(
self
.
data3
),
self
.
maximum2
,
0.001
),
\
"
Maximum (%f) does not correspond to precalculated maximum (%f)
"
%
\
(
stutil
.
Max
(
self
.
data3
),
self
.
maximum2
)
def
testCorrel
(
self
):
assert
self
.
isSimilar
(
stutil
.
Correl
(
self
.
data1
,
self
.
data2
),
self
.
correl
,
0.001
),
\
"
Correl (%f) does not correspond to precalculated correl (%f)
"
%
\
(
stutil
.
Correl
(
self
.
data1
,
self
.
data2
),
self
.
correl
)
assert
self
.
isSimilar
(
stutil
.
Correl
(
self
.
data3
,
self
.
data2
),
self
.
correl2
,
0.001
),
\
"
Correl (%f) does not correspond to precalculated correl (%f)
"
%
\
(
stutil
.
Correl
(
self
.
data3
,
self
.
data2
),
self
.
correl2
)
if
__name__
==
"
__main__
"
:
try
:
unittest
.
main
()
except
Exception
,
e
:
print
e
\ No newline at end of file
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