Skip to content

Commit

Permalink
The entropy simliarity will be 0 or 1 if it's less than 0 or higher t…
Browse files Browse the repository at this point in the history
…han 1.

This helps for some round error for float number calculation.
  • Loading branch information
YuanyueLi committed Sep 16, 2024
1 parent 3e592da commit c7fa950
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion languages/c/SpectralEntropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ float calculate_unweighted_entropy_similarity(
b++;
}
}
return similarity / 2;
similarity = similarity / 2;
if (similarity < 0) {
similarity = 0;
}elif(similarity > 1) {
similarity = 1;
}
return similarity;
}

// Calculate entropy similarity
Expand Down
4 changes: 4 additions & 0 deletions ms_entropy/spectra/entropy_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ cpdef float cy_calculate_entropy_similarity(
float
The entropy similarity between the two spectra.
"""
if len(peaks_a) == 0 or len(peaks_b) == 0:
return 0.0
cdef np.ndarray[float32, ndim=2] peaks_a_np = np.array(peaks_a, dtype=np.float32, copy=True, order="C")
cdef np.ndarray[float32, ndim=2] peaks_b_np = np.array(peaks_b, dtype=np.float32, copy=True, order="C")

Expand Down Expand Up @@ -248,6 +250,8 @@ cpdef float cy_calculate_unweighted_entropy_similarity(
float
The unweighted entropy similarity between the two spectra.
"""
if len(peaks_a) == 0 or len(peaks_b) == 0:
return 0.0
cdef np.ndarray[float32, ndim=2] peaks_a_np
cdef np.ndarray[float32, ndim=2] peaks_b_np
if clean_spectra:
Expand Down
2 changes: 1 addition & 1 deletion ms_entropy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.2'
__version__ = '1.3.3'

0 comments on commit c7fa950

Please sign in to comment.