-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework project structure, update arguments, update math.
- Loading branch information
Dmitry
committed
Nov 17, 2022
1 parent
a60e775
commit ca478cd
Showing
15 changed files
with
864 additions
and
82 deletions.
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,3 @@ | ||
/tmp/ | ||
/test/.pytest_cache/ | ||
*.json |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
FROM python:3.8.6 | ||
FROM python:3.9.15 | ||
|
||
ADD src /src | ||
ADD test /test | ||
ADD calculate_ephemerality.py / | ||
ADD ephemerality.py / | ||
ADD requirements.txt / | ||
ADD _version.py / | ||
ADD setup.py / | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
ENTRYPOINT ["python", "calculate_ephemerality.py"] | ||
ENTRYPOINT ["python", "ephemerality.py"] |
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
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 @@ | ||
__version__ = "1.0.0" |
This file was deleted.
Oops, something went wrong.
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,89 @@ | ||
from _version import __version__ | ||
import sys | ||
import json | ||
import argparse | ||
import numpy as np | ||
from src import compute_ephemeralities | ||
|
||
|
||
HELP_INFO = "" | ||
|
||
|
||
def init_argparse() -> argparse.ArgumentParser: | ||
parser = argparse.ArgumentParser( | ||
usage="%(prog)s [FREQUENCY_VECTOR] [-h] [-v] [-i INPUT_FILE] [-o OUTPUT_FILE.json] [-t THRESHOLD]...", | ||
description="Calculate ephemerality for a given vector of frequencies." | ||
) | ||
parser.add_argument( | ||
"-v", "--version", action="version", | ||
version=f"{parser.prog} version {__version__}" | ||
) | ||
parser.add_argument( | ||
"-p", "--print", action="store_true", | ||
help="If output file is provided, forces the results to still be printed to stdout." | ||
) | ||
parser.add_argument( | ||
"-i", "--input", action="store", | ||
help="Path to the input csv file. If not specified, will use the command line arguments " | ||
"(delimited either by commas or spaces)." | ||
) | ||
parser.add_argument( | ||
"-o", "--output", action="store", | ||
help="Path to the output json file. If not specified, will output ephemerality values to stdout in the" | ||
" following format separated by a space: \"EPH_ORIG EPH_ORIG_SPAN EPH_FILT EPH_FILT_SPAN EPH_SORT " | ||
"EPH_SORT_SPAN\"" | ||
) | ||
parser.add_argument( | ||
"-t", "--threshold", action="store", default=0.8, | ||
help="Threshold value for ephemerality computations. Defaults to 0.8." | ||
) | ||
parser.add_argument( | ||
'frequencies', | ||
help='frequency vector (if the input file is not specified)', | ||
nargs='*' | ||
) | ||
return parser | ||
|
||
|
||
def print_ephemeralities(ephemerality_list: list[dict]): | ||
for ephemeralities in ephemerality_list: | ||
print(f"{ephemeralities['ephemerality_original']} {ephemeralities['ephemerality_original_span']} " | ||
f"{ephemeralities['ephemerality_filtered']} {ephemeralities['ephemerality_filtered_span']} " | ||
f"{ephemeralities['ephemerality_sorted']} {ephemeralities['ephemerality_sorted_span']}") | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = init_argparse() | ||
args = parser.parse_args() | ||
|
||
frequency_vectors = list() | ||
|
||
if args.input: | ||
with open(args.input, 'r') as f: | ||
for line in f.readlines(): | ||
if line.strip(): | ||
frequency_vectors.append(np.array(line.split(','), dtype=float)) | ||
else: | ||
if len(args.frequencies) > 1: | ||
frequency_vectors.append(np.array(args.frequencies, dtype=float)) | ||
elif len(args.frequencies) == 1: | ||
if ' ' in args.frequencies[0]: | ||
frequency_vectors.append(np.array(args.frequencies[0].split(' '), dtype=float)) | ||
else: | ||
frequency_vectors.append(np.array(args.frequencies[0].split(','), dtype=float)) | ||
else: | ||
sys.exit('No input provided!') | ||
|
||
threshold = float(args.threshold) | ||
|
||
ephemerality_list = list() | ||
for frequency_vector in frequency_vectors: | ||
ephemerality_list.append(compute_ephemeralities(frequency_vector=frequency_vector, threshold=threshold)) | ||
|
||
if args.output: | ||
with open(args.output, 'w+') as f: | ||
json.dump(ephemerality_list, f, indent=2) | ||
if args.print: | ||
print_ephemeralities(ephemerality_list) | ||
else: | ||
print_ephemeralities(ephemerality_list) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
numpy==1.20.3 | ||
numpy==1.21.5 |
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,30 @@ | ||
import os | ||
from setuptools import setup | ||
import re | ||
|
||
VERSION_FILE = "_version.py" | ||
VERSION_REGEX = r"^__version__ = ['\"]([^'\"]*)['\"]" | ||
|
||
|
||
def read(file_name): | ||
return open(os.path.join(os.path.dirname(__file__), file_name)).read() | ||
|
||
|
||
version_lines = open(VERSION_FILE, 'r').read() | ||
match = re.search(VERSION_REGEX, version_lines, re.M) | ||
if match: | ||
version = match.group(1) | ||
else: | ||
raise RuntimeError("Unable to find version string in %s." % (VERSION_FILE,)) | ||
|
||
setup( | ||
name='ephemerality', | ||
version=version, | ||
packages=['src', 'test'], | ||
url='https://github.com/HPAI-BSC/ephemerality', | ||
license='MIT', | ||
author='HPAI BSC', | ||
author_email='[email protected]', | ||
description='Module for computing ephemerality metrics of temporal arrays.', | ||
long_description=read('README.md') | ||
) |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from src.ephemerality import compute_ephemerality_measures | ||
from src.ephemerality_computation import compute_ephemeralities | ||
|
||
__all__ = ['compute_ephemerality_measures'] | ||
__all__ = ['compute_ephemeralities'] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.