-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ma_characteristics #47
Open
Maximus2012
wants to merge
20
commits into
main
Choose a base branch
from
ma_characteristics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8263cc8
added volume
Maximus2012 ef1afc1
added depth func
Maximus2012 457e1ca
Merge branch 'main' into ma_characteristics
goruha ac224c2
characteristics refactoring
Maximus2012 dd739c8
Added ma_arighmetic_mean
Maximus2012 9139ba3
Added ma_geometric_mean
Maximus2012 cf3183f
added entropy
Maximus2012 5f87dcb
added average_remoteness
Maximus2012 dbce690
added uniformity
Maximus2012 750806a
added periodicity
Maximus2012 634ce5e
Merge branch 'main' into ma_characteristics
goruha 36df901
test repair, change entropy realisation, added volume documentation
Maximus2012 3d23a1d
added tests for masked array in depth, rewrote docs for volume and depth
Maximus2012 1be7f76
added tests for depth and uniformity, also rewrote uniformity doc and…
Maximus2012 641e413
added tests with masked arrays for entropy, corrected uniformity docs…
Maximus2012 690ef38
added new tests and docs for arigthmetic_mean, average_remoteness, en…
Maximus2012 6cd7f60
Added new tests for average remoteness and geometric mean. Changed ep…
Maximus2012 d8f4a25
geometric mean repair
Maximus2012 836e31d
correction of documentation
Maximus2012 47bfeda
correction of documentation
Maximus2012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import numpy as np | ||
|
||
|
||
def arigthmetic_mean(intervals): | ||
""" | ||
Arithmetic mean is calculated as the sum of | ||
the elements of the sequence divided | ||
by the number of elements in the sequence. | ||
|
||
Parameters | ||
---------- | ||
X: two-dimensional array | ||
Source array sequence. | ||
|
||
Returns | ||
------- | ||
result: array. | ||
|
||
Examples | ||
-------- | ||
|
||
----1---- | ||
>>> X = [ | ||
[1 4 4] | ||
[1 3] | ||
[3 1] | ||
] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[3 2 2] | ||
|
||
----2---- | ||
>>> X = [ | ||
[1 1 4 4] | ||
[3 1 3] | ||
[5 3 1] | ||
] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[2.5 2.333 3] | ||
|
||
----3---- | ||
>>> X = [ | ||
[1 4 4 1] | ||
[1 3 4] | ||
[3 1 2] | ||
] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[2.5 2.66 2] | ||
|
||
----4---- | ||
>>> X = [ | ||
[4 1 3 3] | ||
] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[2.75] | ||
|
||
----5---- | ||
>>> X = [[]] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[0] | ||
|
||
----6---- | ||
>>> X = [[1]] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[1] | ||
|
||
----7---- | ||
>>> X = [ | ||
[1 1 1 1 1] | ||
] | ||
>>> b = arigthmetic_mean(X) | ||
>>> b | ||
[1] | ||
|
||
""" | ||
return np.asanyarray( | ||
[np.sum(line) / len(line) if len(line) != 0 else 0 for line in intervals], | ||
dtype=float, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import numpy as np | ||
|
||
from foapy.characteristics.ma.depth import depth | ||
|
||
|
||
def average_remoteness(intervals): | ||
""" | ||
Calculation of the average remoteness of a sequence: | ||
The average remoteness is calculated as the depth | ||
divided by the number of intervals in the | ||
given congeneric sequence. | ||
|
||
Parameters | ||
---------- | ||
X: two-dimensional array | ||
Source array sequence. | ||
|
||
Returns | ||
------- | ||
result: array. | ||
|
||
Examples | ||
-------- | ||
|
||
----1---- | ||
>>> X = [ | ||
[1 4 4] | ||
[1 3] | ||
[3 1] | ||
] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[1.3333 0.79248 0.79248] | ||
|
||
----2---- | ||
>>> X = [ | ||
[1 1 4 4] | ||
[3 1 3] | ||
[5 3 1] | ||
] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[1 1.05664 1.30229] | ||
|
||
----3---- | ||
>>> X = [ | ||
[1 4 4 1] | ||
[1 3 4] | ||
[3 1 2] | ||
] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[1 1.1949 0.8616] | ||
|
||
----4---- | ||
>>> X = [ | ||
[4 1 3 3] | ||
] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[1.2925] | ||
|
||
----5---- | ||
>>> X = [[]] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[0] | ||
|
||
----6---- | ||
>>> X = [[1]] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[0] | ||
|
||
----7---- | ||
>>> X = [ | ||
[1 1 1 1 1] | ||
] | ||
>>> b = average_remoteness(X) | ||
>>> b | ||
[0] | ||
|
||
""" | ||
size = np.array([len(elem) for elem in intervals]) | ||
depth_seq = depth(intervals) | ||
res = np.divide(depth_seq, size, out=np.zeros_like(depth_seq), where=size != 0) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import numpy as np | ||
|
||
from foapy.characteristics.ma.volume import volume | ||
|
||
|
||
def depth(intervals): | ||
""" | ||
Calculation of the depth of a sequence: | ||
Depth is calculated as the logarithm base 2 (log₂) of the volume, | ||
where the volume is the product of the elements | ||
of the intervals in the sequence. | ||
|
||
Parameters | ||
---------- | ||
X: two-dimensional intervals sequence array | ||
Source array sequence. | ||
|
||
|
||
Returns | ||
------- | ||
result: array. | ||
|
||
Examples | ||
-------- | ||
|
||
----1---- | ||
>>> X = [ | ||
[1 4 4] | ||
[1 3] | ||
[3 1] | ||
] | ||
>>> b = depth(X) | ||
>>> b | ||
[4 1.585 1.585] | ||
|
||
----2---- | ||
>>> X = [ | ||
[1 1 4 4] | ||
[3 1 3] | ||
[5 3 1] | ||
] | ||
>>> b = depth(X) | ||
>>> b | ||
[4 3.1699 3.9069] | ||
|
||
----3---- | ||
>>> X = [ | ||
[1 4 4 1] | ||
[1 3 4] | ||
[3 1 2] | ||
] | ||
>>> b = depth(X) | ||
>>> b | ||
[4 3.585 2.585] | ||
|
||
----4---- | ||
>>> X = [ | ||
[4 1 3 3] | ||
] | ||
>>> b = depth(X) | ||
>>> b | ||
[5.1699] | ||
|
||
----5---- | ||
>>> X = [[]] | ||
>>> b = depth(X) | ||
>>> b | ||
[] | ||
|
||
----6---- | ||
>>> X = [[1]] | ||
>>> b = depth(X) | ||
>>> b | ||
[0] | ||
|
||
----7---- | ||
>>> X = [ | ||
[1 1 1 1 1] | ||
] | ||
>>> b = depth(X) | ||
>>> b | ||
[0] | ||
|
||
""" | ||
return np.asanyarray([np.log2(line) for line in volume(intervals)]) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import numpy as np | ||
|
||
|
||
def geometric_mean(intervals): | ||
""" | ||
Calculation of the geometric mean of a sequence: | ||
The geometric mean is calculated as the nth root | ||
of the product of the elements in the sequence, | ||
where n is the number of elements in the sequence. | ||
|
||
Parameters | ||
---------- | ||
X: two-dimensional array | ||
Source array sequence. | ||
|
||
Returns | ||
------- | ||
result: array. | ||
|
||
Examples | ||
-------- | ||
|
||
----1---- | ||
>>> X = [ | ||
[1 4 4] | ||
[1 3] | ||
[3 1] | ||
] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[2.5198 1.73205 1.73205] | ||
|
||
----2---- | ||
>>> X = [ | ||
[1 1 4 4] | ||
[3 1 3] | ||
[5 3 1] | ||
] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[2 2.08 2.466] | ||
|
||
----3---- | ||
>>> X = [ | ||
[1 4 4 1] | ||
[1 3 4] | ||
[3 1 2] | ||
] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[2 2.28942 1.8171] | ||
|
||
----4---- | ||
>>> X = [ | ||
[4 1 3 3] | ||
] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[2.449489] | ||
|
||
----5---- | ||
>>> X = [[]] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[0] | ||
|
||
----6---- | ||
>>> X = [[1]] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[0] | ||
|
||
----7---- | ||
>>> X = [ | ||
[0 0 0 0 0] | ||
] | ||
>>> b = geometric_mean(X) | ||
>>> b | ||
[0] | ||
|
||
""" | ||
return np.asanyarray( | ||
[ | ||
np.power(np.prod(line), 1 / len(line)) if len(line) != 0 else 0 | ||
for line in intervals | ||
], | ||
dtype=float, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace volume with sum log2