Skip to content
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

Sourcery refactored master branch #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions tspex/core/auxiliary_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def dpm(vector):
"""

n = len(vector)
dispersion_measure = np.std(vector, ddof=1) * np.sqrt(n)
return dispersion_measure
return np.std(vector, ddof=1) * np.sqrt(n)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function dpm refactored with the following changes:

  • Inline variable that is only used once



def tukey_biweight(vector, c=5, epsilon=1e-4):
Expand Down Expand Up @@ -76,8 +75,7 @@ def tukey_biweight(vector, c=5, epsilon=1e-4):
i = np.abs(u) > 1
w = (1 - u ** 2) ** 2
w[i] = 0
tbi = np.sum(w * vector) / np.sum(w)
return tbi
return np.sum(w * vector) / np.sum(w)
Comment on lines -79 to +78
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function tukey_biweight refactored with the following changes:

  • Inline variable that is only used once



def entropy(vector):
Expand Down Expand Up @@ -106,8 +104,7 @@ def entropy(vector):
else:
p = vector / np.sum(vector)
p = p[np.nonzero(p)[0]]
h = -1 * np.dot(p, np.log2(p))
return h
return -1 * np.dot(p, np.log2(p))
Comment on lines -109 to +107
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function entropy refactored with the following changes:

  • Inline variable that is only used once



def roku(vector):
Expand Down Expand Up @@ -136,8 +133,7 @@ def roku(vector):

tbi = tukey_biweight(vector)
vector_p = np.abs(vector - tbi)
h = entropy(vector_p)
return h
return entropy(vector_p)
Comment on lines -139 to +136
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function roku refactored with the following changes:

  • Inline variable that is only used once



def js_distance(p, q):
Expand Down Expand Up @@ -168,5 +164,4 @@ def js_distance(p, q):
left = entropy((p + q) / 2)
right = (entropy(p) + entropy(q)) / 2
js = left - right
jsd = np.sqrt(js)
return jsd
return np.sqrt(js)
Comment on lines -171 to +167
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function js_distance refactored with the following changes:

  • Inline variable that is only used once

30 changes: 10 additions & 20 deletions tspex/core/specificity_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def counts(vector, **kwargs):
if cts == 0:
return 0.0
else:
cts_transformed = (1 - (cts / n)) * (n / (n - 1))
return cts_transformed
return (1 - (cts / n)) * (n / (n - 1))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function counts refactored with the following changes:

  • Inline variable that is only used once



def tau(vector, **kwargs):
Expand Down Expand Up @@ -110,8 +109,7 @@ def tau(vector, **kwargs):
else:
n = len(vector)
vector_r = vector / np.max(vector)
tau_index = np.sum(1 - vector_r) / (n - 1)
return tau_index
return np.sum(1 - vector_r) / (n - 1)
Comment on lines -113 to +112
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function tau refactored with the following changes:

  • Inline variable that is only used once



def gini(vector, **kwargs):
Expand Down Expand Up @@ -149,8 +147,7 @@ def gini(vector, **kwargs):
index = np.arange(1, n + 1)
gini_coefficient = (np.sum((2 * index - n - 1) * vector)) / (n * np.sum(vector))
if transform:
transformed_gini_coefficient = gini_coefficient * (n / (n - 1))
return transformed_gini_coefficient
return gini_coefficient * (n / (n - 1))
Comment on lines -152 to +150
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gini refactored with the following changes:

  • Inline variable that is only used once

else:
return gini_coefficient

Expand Down Expand Up @@ -187,8 +184,7 @@ def simpson(vector, **kwargs):
simpson_index = np.sum(p ** 2)
if transform:
min_simpson = 1 / len(vector)
transformed_simpson_index = (simpson_index - min_simpson) / (1 - min_simpson)
return transformed_simpson_index
return (simpson_index - min_simpson) / (1 - min_simpson)
Comment on lines -190 to +187
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function simpson refactored with the following changes:

  • Inline variable that is only used once

else:
return simpson_index

Expand Down Expand Up @@ -227,8 +223,7 @@ def shannon_specificity(vector, **kwargs):
n = len(vector)
ss = np.log2(n) - entropy(vector)
if transform:
ss_transformed = ss / np.log2(n)
return ss_transformed
return ss / np.log2(n)
Comment on lines -230 to +226
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function shannon_specificity refactored with the following changes:

  • Inline variable that is only used once

else:
return ss

Expand Down Expand Up @@ -271,8 +266,7 @@ def roku_specificity(vector, **kwargs):
n = len(vector)
rs = np.log2(n) - roku(vector)
if transform:
rs_transformed = rs / np.log2(n)
return rs_transformed
return rs / np.log2(n)
Comment on lines -274 to +269
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function roku_specificity refactored with the following changes:

  • Inline variable that is only used once

else:
return rs

Expand Down Expand Up @@ -303,8 +297,7 @@ def tsi(vector, **kwargs):
if not np.any(vector):
return 0.0
else:
tissue_specificity_index = vector / np.sum(vector)
return tissue_specificity_index
return vector / np.sum(vector)
Comment on lines -306 to +300
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function tsi refactored with the following changes:

  • Inline variable that is only used once



def zscore(vector, **kwargs):
Expand Down Expand Up @@ -342,8 +335,7 @@ def zscore(vector, **kwargs):
zs = (vector - np.mean(vector)) / std
if transform:
max_zs = (n - 1) / np.sqrt(n)
zs_transformed = (zs + max_zs) / (2 * max_zs)
return zs_transformed
return (zs + max_zs) / (2 * max_zs)
Comment on lines -345 to +338
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function zscore refactored with the following changes:

  • Inline variable that is only used once

else:
return zs

Expand Down Expand Up @@ -407,8 +399,7 @@ def spm_dpm(vector, **kwargs):
"""

spm_vector = spm(vector)
spm_dispersion = dpm(spm_vector)
return spm_dispersion
return dpm(spm_vector)
Comment on lines -410 to +402
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function spm_dpm refactored with the following changes:

  • Inline variable that is only used once



def js_specificity(vector, **kwargs):
Expand Down Expand Up @@ -475,5 +466,4 @@ def js_specificity_dpm(vector, **kwargs):
"""

js_vector = js_specificity(vector)
js_specificity_dispersion = dpm(js_vector)
return js_specificity_dispersion
return dpm(js_vector)
Comment on lines -478 to +469
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function js_specificity_dpm refactored with the following changes:

  • Inline variable that is only used once