Skip to content

Commit

Permalink
Merge pull request #201 from SwaragThaikkandi/renovate/snyk-actions-d…
Browse files Browse the repository at this point in the history
…igest

Update snyk/actions digest to cdb7600
  • Loading branch information
SwaragThaikkandi authored Sep 8, 2024
2 parents 592cebe + 67f5c91 commit 3469083
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/snyk-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Set up Snyk CLI to check for security issues
# Snyk can be used to break the build when it detects security issues.
# In this case we want to upload the SAST issues to GitHub Code Scanning
uses: snyk/actions/setup@9213221444c2dc9e8b2502c1e857c26d851e84a7
uses: snyk/actions/setup@cdb760004ba9ea4d525f2e043745dfe85bb9077e

# For Snyk Open Source you must first set up the development environment for your application's dependencies
# For example for Node
Expand Down
32 changes: 17 additions & 15 deletions SMdRQA/RQA_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def KNN_MI_vectorized(X, Y, nearest_neighbor=5, dtype=np.float64):
return digamma(n_samples) + digamma(nearest_neighbor) - \
np.mean(digamma(neigh_X + 1)) - np.mean(digamma(neigh_Y + 1))

def KNN_MI_partial_vectorized(X,Y,nearest_neighbor=5, dtype=np.float64):

def KNN_MI_partial_vectorized(X, Y, nearest_neighbor=5, dtype=np.float64):
'''
Function to calculate mutual information between two time series using KNN method for datasets that can't be handled with default binning method. Partially version. Vectorized version is faster, however, if size of the time series is large and number of dimensions are much larger, the resulting matrix can't be stored in the physical memory of the system (RAM) depending on the resource available. In that case this version can be used to use a relatively faster version compared to non-vectorized version
Expand Down Expand Up @@ -286,16 +287,17 @@ def KNN_MI_partial_vectorized(X,Y,nearest_neighbor=5, dtype=np.float64):
dist_Y = dist_Y[mask]

# Compute the maximum of distances for each pair (i, j)
N = np.maximum(dist_X, dist_Y)
N = sorted(np.maximum(dist_X, dist_Y))

# Sort the resulting vector
N.sort()
k_nearest = N[nearest_neighbor - 1]
NX[i] = np.sum(1*(dist_X < k_nearest))
NY[i] = np.sum(1*(dist_Y < k_nearest))
#print('k nearest non vectorized:', k_nearest)
NX[i] = np.sum(1 * (dist_X < k_nearest))
NY[i] = np.sum(1 * (dist_Y < k_nearest))
# print('k nearest non vectorized:', k_nearest)

return digamma(n_samples) + digamma(nearest_neighbor) - \
np.mean(digamma(NX + 1)) - np.mean(digamma(NY + 1))

return digamma(n_samples) + digamma(nearest_neighbor) - np.mean(digamma(NX + 1)) - np.mean(digamma(NY + 1))

def KNN_MI_non_vectorized(X, Y, nearest_neighbor=5):
'''
Expand Down Expand Up @@ -391,7 +393,7 @@ def KNN_MI(
- "sequential" : The algorithm is implemented with for loops instead of vectorization. This could be
significantly slower than the vectorized version. However, if resources (RAM/physical memory) are limited
and can't handle huge matrices, this option should be chosen.
- "partial" : best of both worlds between "vectorized" and "sequential"
dtype : dtype
Expand Down Expand Up @@ -422,21 +424,21 @@ def KNN_MI(
dtype=dtype,
memory_limit=memory_limit)
if method == "auto":
if pv1 == True:
mi = KNN_MI_vectorized(X,Y,nearest_neighbor)
elif (pv1 == False) and (pv2 == True):
mi = KNN_MI_partial_vectorized(X,Y,nearest_neighbor, dtype=dtype)
if pv1:
mi = KNN_MI_vectorized(X, Y, nearest_neighbor)
elif (pv1 == False) and (pv2):
mi = KNN_MI_partial_vectorized(X, Y, nearest_neighbor, dtype=dtype)
elif (pv1 == False) and (pv2 == False):
mi = KNN_MI_non_vectorized(X,Y,nearest_neighbor)
mi = KNN_MI_non_vectorized(X, Y, nearest_neighbor)

elif method == "vectorized":
mi = KNN_MI_vectorized(X, Y, nearest_neighbor, dtype=dtype)

elif method == "sequential":
mi = KNN_MI_non_vectorized(X, Y, nearest_neighbor)

elif method == "partial":
mi = KNN_MI_partial_vectorized(X,Y,nearest_neighbor, dtype=dtype)
mi = KNN_MI_partial_vectorized(X, Y, nearest_neighbor, dtype=dtype)

return mi

Expand Down

0 comments on commit 3469083

Please sign in to comment.