@@ -15,6 +15,7 @@ public SpectralSimilarity(MzSpectrum experimentalSpectrum, MzSpectrum theoretica
1515 TheoreticalYArray = Normalize ( FilterOutIonsBelowThisMz ( theoreticalSpectrum . XArray , theoreticalSpectrum . YArray , filterOutBelowThisMz ) . Select ( p => p . Item2 ) . ToArray ( ) , scheme ) ;
1616 TheoreticalXArray = FilterOutIonsBelowThisMz ( theoreticalSpectrum . XArray , theoreticalSpectrum . YArray , filterOutBelowThisMz ) . Select ( p => p . Item1 ) . ToArray ( ) ;
1717 LocalPpmTolerance = toleranceInPpm ;
18+ normalizationScheme = scheme ;
1819 _intensityPairs = IntensityPairs ( allPeaks ) ;
1920 }
2021
@@ -25,6 +26,7 @@ public SpectralSimilarity(MzSpectrum experimentalSpectrum, double[] theoreticalX
2526 TheoreticalYArray = Normalize ( FilterOutIonsBelowThisMz ( theoreticalX , theoreticalY , filterOutBelowThisMz ) . Select ( p => p . Item2 ) . ToArray ( ) , scheme ) ;
2627 TheoreticalXArray = FilterOutIonsBelowThisMz ( theoreticalX , theoreticalY , filterOutBelowThisMz ) . Select ( p => p . Item1 ) . ToArray ( ) ;
2728 LocalPpmTolerance = toleranceInPpm ;
29+ normalizationScheme = scheme ;
2830 _intensityPairs = IntensityPairs ( allPeaks ) ;
2931 }
3032
@@ -42,6 +44,8 @@ public SpectralSimilarity(double[] P_XArray, double[] P_YArray, double[] Q_XArra
4244 public double [ ] TheoreticalYArray { get ; private set ; }
4345 public double [ ] TheoreticalXArray { get ; private set ; }
4446
47+ private SpectrumNormalizationScheme normalizationScheme ;
48+
4549 private double LocalPpmTolerance ;
4650
4751 private readonly List < ( double , double ) > _intensityPairs = new ( ) ;
@@ -315,6 +319,33 @@ private double[] NormalizeSpectrumSum(double[] spectrum)
315319 return sum ;
316320 }
317321
322+ // This method should only be used with the SpectrumSum normalization method
323+ // This method should only be used when allPeaks is set to true
324+ public double ? SpectralEntropy ( )
325+ {
326+ double theoreticalEntropy = 0 ;
327+ foreach ( double intensity in TheoreticalYArray )
328+ {
329+ theoreticalEntropy += - 1 * intensity * Math . Log ( intensity ) ;
330+ }
331+ double experimentalEntropy = 0 ;
332+ foreach ( double intensity in ExperimentalYArray )
333+ {
334+ experimentalEntropy += - 1 * intensity * Math . Log ( intensity ) ;
335+ }
336+
337+ double combinedEntropy = 0 ;
338+ foreach ( ( double , double ) intensityPair in _intensityPairs )
339+ {
340+ double combinedIntensity = intensityPair . Item1 / 2 + intensityPair . Item2 / 2 ;
341+ combinedEntropy += - 1 * combinedIntensity * Math . Log ( combinedIntensity ) ;
342+ }
343+
344+ double similarityScore = 1 - ( 2 * combinedEntropy - theoreticalEntropy - experimentalEntropy ) / Math . Log ( 4 ) ;
345+ return similarityScore ;
346+ }
347+
348+
318349 public double ? KullbackLeiblerDivergence_P_Q ( )
319350 {
320351 double divergence = 0 ;
0 commit comments