implementation of entropy algorithm.#2110
Conversation
|
Hey @beqakd, TravisCI finished with status TravisBuddy Request Identifier: 48a2b950-acea-11ea-8245-836d9da6cb4c |
|
This fail is not from my PR! |
maths/entropy.py
Outdated
| """ | ||
| f = open(path_dest, mode="w+", encoding="utf-8") | ||
|
|
||
| my_alphas = create_alpha_array() # create our alpha |
There was a problem hiding this comment.
| my_alphas = create_alpha_array() # create our alpha | |
| my_alphas = list(' ' + ascii_lowercase) |
maths/entropy.py
Outdated
|
|
||
| import sys | ||
| import math | ||
| r = range |
There was a problem hiding this comment.
| r = range | |
| from string import ascii_lowercase |
maths/entropy.py
Outdated
| :param path_dest: | ||
| :return: | ||
| """ | ||
| f = open(path_dest, mode="w+", encoding="utf-8") |
There was a problem hiding this comment.
Do not open the file until you need it. Please move this down to line 47.
maths/entropy.py
Outdated
| my_alphas = create_alpha_array() # create our alpha | ||
| # what is our total sum of probabilities. | ||
| values = my_dic_fir.values() | ||
| all_sum = sum(values) |
There was a problem hiding this comment.
| all_sum = sum(values) | |
| all_sum = sum(my_dic_fir.values()) |
maths/entropy.py
Outdated
| # one length string | ||
| my_fir_sum = 0 | ||
| # for each alpha we go in our dict and if it is in it we calculate entropy | ||
| for _ in my_alphas: |
There was a problem hiding this comment.
Only use _ as a variable name if you are never going to refer to it again. In this case, please replace _ with char.
Or better yet, use for key, value in first_dict.items():. The use of my_ in variable names is not helpful.
maths/entropy.py
Outdated
| sequence_fir = text[_] | ||
| sequence_sec = text[_ : _ + 2] | ||
| # continue | ||
| if sequence_fir not in my_dic_fir: |
There was a problem hiding this comment.
maths/entropy.py
Outdated
| else: | ||
| my_dic_fir[sequence_fir] += 1 | ||
|
|
||
| if sequence_sec not in my_dic_sec: |
There was a problem hiding this comment.
maths/entropy.py
Outdated
|
|
||
| def main(): | ||
| path_src = sys.argv[1] | ||
| path_dest = sys.argv[2] |
There was a problem hiding this comment.
| path_dest = sys.argv[2] | |
| try: | |
| _, path_src, path_dest = sys.argv | |
| except IndexError: | |
| print(f"Usage: {sys.argv[0]} path_src path_dest”) |
maths/entropy.py
Outdated
|
|
||
|
|
||
| # 0x | ||
| def open_file(path_src, path_dest): |
There was a problem hiding this comment.
| def open_file(path_src, path_dest): | |
| def read_dicts_from_file(path_src: str) -> dict, dict: |
- More self-documenting function name
- Remove unused parameter
- Python type hints as discussed in CONTRIBUTING.md
maths/entropy.py
Outdated
| in second dictionary it puts two len strings. | ||
| :param path_src: | ||
| :param path_dest: | ||
| :return: |
There was a problem hiding this comment.
| :return: | |
| :return: dict, dict |
Yes but not surprising because this PR contains no tests. |
|
Will do changes! |
|
@cclauss All changes done! Tests added. I think its cool now. |
|
Hey @beqakd, TravisCI finished with status TravisBuddy Request Identifier: 3bd22640-b003-11ea-ae15-c70b0cf57a1c |
Travis tests have failedHey @beqakd, TravisBuddy Request Identifier: 02f95b10-b006-11ea-ae15-c70b0cf57a1c |
* implementation of entropy algorithm. * add tests, fix requested changes * open_file() --> analyze_text() * Create bidirectional_breadth_first_search.py * # type: ignore Co-authored-by: Christian Clauss <cclauss@me.com>
Wrote implementation of entropy algorithm.
Checklist:
Fixes: #{$ISSUE_NO}.