Skip to content

Commit

Permalink
test repair, change entropy realisation, added volume documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximus2012 committed Nov 28, 2024
1 parent 634ce5e commit 36df901
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/foapy/characteristics/ma/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def entropy(intervals):
"""

return np.asanyarray([np.log2(line.mean()) for line in intervals])
return np.asanyarray([np.log2(np.average(line)) for line in intervals])
66 changes: 45 additions & 21 deletions src/foapy/characteristics/ma/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def volume(intervals):
Parameters
----------
X: two-dimensional array
X: two-dimensional intervals sequence array
Source array sequence.
Returns
Expand All @@ -19,46 +19,70 @@ def volume(intervals):
--------
----1----
>>> a = ["B", "B", "A", "A", "C", "B", "A", "C", "C", "B"]
>>> b = volume(X, binding.start, mode.lossy)
>>> a = [
[0 0 -- -- -- 0 -- -- -- 0]
[-- -- 1 1 -- -- 1 -- -- --]
[-- -- -- -- 2 -- -- 2 2 --]
]
>>> b = volume(a)
>>> b
[16 3 3]
----2----
>>> a = ["B", "B", "A", "A", "C", "B", "A", "C", "C", "B"]
>>> b = volume(X, binding.start, mode.normal)
>>> a = [
[1 1 4 4]
[3 1 3]
[5 3 1]
]
>>> b = volume(a)
>>> b
[16 12 6]
[16 9 15]
----3----
>>> a = ["B", "B", "A", "A", "C", "B", "A", "C", "C", "B"]
>>> b = volume(X, binding.end, mode.normal)
>>> a = [
[1 4 4 1]
[1 3 4]
[3 1 2]
]
>>> b = volume(a)
>>> b
[16 36 30]
[16 12 6]
----4----
>>> a = ["B", "B", "A", "A", "C", "B", "A", "C", "C", "B"]
>>> b = volume(X, binding.start, mode.redundant)
>>> a = [
[-- -- -- 1 1 -- -- 1 -- --]
]
>>> b = volume(a)
>>> b
[16 36 30]
[6]
----5----
>>> a = ["B", "B", "A", "A", "C", "B", "A", "C", "C", "B"]
>>> b = volume(X, binding.start, mode.cycle)
>>> a = [--]
>>> b = volume(a)
>>> b
[16 18 18]
[]
----6----
>>> a = ["B", "A"]
>>> b = volume(X, binding.start, mode.lossy)
>>> a = ["B"]
>>> b = volume(a)
>>> b
[1 1]
[1]
----7----
>>> a = ["B", "A", "C", "D"]
>>> b = volume(X, binding.start, mode.lossy)
>>> a = [
[1 1 1 1 1]
]
>>> b = volume(a)
>>> b
[1 1 1 1]
[1]
----8----
>>> a = [
[]
]
>>> b = volume(a)
>>> b
[]
"""

return np.asanyarray([np.prod(line) for line in intervals])
2 changes: 1 addition & 1 deletion tests/test_characteristics/test_ma_arighmetic_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_calculate_start_redunant_depth(self):
intervals_seq = intervals(
order_seq, binding_constant.start, mode_constant.lossy
)
expected = np.array([1.5, 2]) # incorrect test
expected = np.array([2])
exists = arigthmetic_mean(intervals_seq)
epsilon = 0.01
print(exists)
Expand Down
57 changes: 44 additions & 13 deletions tests/test_characteristics/test_ma_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,48 @@ def test_calculate_start_lossy_empty_values_volume(self):
exists = volume(intervals_seq)
assert_equal(expected, exists)

# def test_calculate_start_redunant_values_with_mask(self):
# X = ['B','B','B','A','A','B','B','A','B','B']
# mask = [1, 1, 1, 0, 0, 1, 1, 0, 1, 1]
# masked_X = ma.masked_array(X, mask)
# order_seq = order(masked_X)
# print(order_seq)
# intervals_seq = intervals(
# order_seq, binding_constant.start, mode_constant.redundant
# )
def test_calculate_start_redunant_values_with_mask(self):
X = ["B", "B", "B", "A", "A", "B", "B", "A", "B", "B"]
mask = [1, 1, 1, 0, 0, 1, 1, 0, 1, 1]
masked_X = ma.masked_array(X, mask)
order_seq = order(masked_X)
intervals_seq = intervals(
order_seq, binding_constant.start, mode_constant.redundant
)
expected = np.array([36])
exists = volume(intervals_seq)
assert_equal(expected, exists)

def test_calulate_normal_with_the_same_values(self):
X = ["A", "A", "A", "A", "A"]
masked_X = ma.masked_array(X)
order_seq = order(masked_X)
intervals_seq = intervals(
order_seq, binding_constant.start, mode_constant.normal
)
expected = np.array([1])
exists = volume(intervals_seq)
assert_equal(expected, exists)

# expected = np.array([36]) # incorrect test res [6, 36]
# exists = volume(intervals_seq)
# print(exists)
# assert_equal(expected, exists)
def test_calculate_start_cycle_with_masked_single_value(self):
X = ["A"]
mask = [1]
masked_X = ma.masked_array(X, mask)
order_seq = order(masked_X)
intervals_seq = intervals(
order_seq, binding_constant.start, mode_constant.cycle
)
expected = np.array([])
exists = volume(intervals_seq)
assert_equal(expected, exists)

def test_calculate_start_cycle_with_single_value(self):
X = ["A"]
masked_X = ma.masked_array(X)
order_seq = order(masked_X)
intervals_seq = intervals(
order_seq, binding_constant.start, mode_constant.cycle
)
expected = np.array([1])
exists = volume(intervals_seq)
assert_equal(expected, exists)

0 comments on commit 36df901

Please sign in to comment.