bactoscoop.signalcorrelation¶
Classes and public operations¶
SignalCorrelation¶
- class bactoscoop.signalcorrelation.SignalCorrelation(df, channel1, channel2, feature, method_name, prepared_feature=None)¶
Select an implemented relationship between two channel-prefixed feature columns.
The feature must exist for both channels. calculate mutates the supplied DataFrame; prepared_feature can cache the numerical input arrays.
- Parameters:
df – DataFrame to inspect, transform, or augment. Correlation mutates it in place and returns it.
channel1 – First channel prefix for the matching feature.
channel2 – Second channel prefix for the matching feature.
feature – Unprefixed shared feature name; corresponding channel-prefixed columns must exist.
method_name – Implemented correlation selector, such as pearson, manders, or ratio.
prepared_feature – Optional cached signal arrays and validity mask for a channel/feature pair.
- Returns:
None (no explicit return statement).
Assigned state:
self.df,self.channel1,self.channel2,self.feature,self.method_name,self.prepared_feature,self.method.
SignalCorrelation.get_method¶
- SignalCorrelation.get_method()¶
Get method.
Return expressions in source:
methods[self.method_name]
Explicitly raised exceptions:
ValueError. Errors from called functions can also propagate or be recorded.
SignalCorrelation.validate_inputs¶
- SignalCorrelation.validate_inputs()¶
Validate inputs.
- Returns:
None (no explicit return statement).
Explicitly raised exceptions:
ValueError. Errors from called functions can also propagate or be recorded.
SignalCorrelation.calculate¶
- SignalCorrelation.calculate()¶
Calculate the selected signal relationship row by row.
Requires matching prefixed columns. Adds a function-name-suffixed column to df and returns that same DataFrame.
Return expressions in source:
self.df
Assigned state:
self.df.
SignalCorrelation.prepare_feature_pair¶
- SignalCorrelation.prepare_feature_pair(df, channel1, channel2, feature)¶
Prepare feature pair.
- Parameters:
df – DataFrame to inspect, transform, or augment. Correlation mutates it in place and returns it.
channel1 – First channel prefix for the matching feature.
channel2 – Second channel prefix for the matching feature.
feature – Unprefixed shared feature name; corresponding channel-prefixed columns must exist.
Return expressions in source:
{'signals1': signals1, 'signals2': signals2, 'valid_mask': valid_mask}
SignalCorrelation.is_valid_signal¶
- SignalCorrelation.is_valid_signal(signal)¶
Is valid signal.
- Parameters:
signal – Input
signalconsumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
bool(signal_array.size and np.isfinite(signal_array).all()) False
SignalCorrelation.ratio¶
- SignalCorrelation.ratio(signal1, signal2)¶
Ratio.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan signal1 / signal2
SignalCorrelation.manders_overlap_coefficient¶
- SignalCorrelation.manders_overlap_coefficient(signal1, signal2)¶
Manders overlap coefficient.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.sum(signal1 * signal2) / np.sqrt(np.sum(signal1 ** 2) * np.sum(signal2 ** 2))
SignalCorrelation.pearson_correlation_coefficient¶
- SignalCorrelation.pearson_correlation_coefficient(signal1, signal2)¶
Pearson correlation coefficient.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan stats.pearsonr(signal1, signal2)[0]
SignalCorrelation.li_icq¶
- SignalCorrelation.li_icq(signal1, signal2)¶
Li icq.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan (np.sum(product) / len(signal1) - 0.5) * 2
SignalCorrelation.spearman_rank_correlation¶
- SignalCorrelation.spearman_rank_correlation(signal1, signal2)¶
Spearman rank correlation.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan stats.spearmanr(signal1, signal2)[0]
SignalCorrelation.kendall_tau¶
- SignalCorrelation.kendall_tau(signal1, signal2)¶
Kendall tau.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan corr
SignalCorrelation.distance_correlation¶
- SignalCorrelation.distance_correlation(signal1, signal2)¶
Biased sample distance correlation; undefined profiles return NaN.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan float(np.sqrt(np.clip(correlation_squared, 0, 1)))
View current source, line 191.
Original docstring (legacy wording may differ from the current signature)
Biased sample distance correlation; undefined profiles return NaN.
SignalCorrelation.covariance¶
- SignalCorrelation.covariance(signal1, signal2)¶
Covariance.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.cov(signal1, signal2)[0, 1]
SignalCorrelation.normalized_cross_correlation¶
- SignalCorrelation.normalized_cross_correlation(signal1, signal2)¶
Normalized cross correlation.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.correlate(signal1 - np.mean(signal1), signal2 - np.mean(signal2))[0] / (len(signal1) * np.std(signal1) * np.std(signal2))
SignalCorrelation.entropy_difference¶
- SignalCorrelation.entropy_difference(signal1, signal2)¶
Entropy difference.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.abs(entropy1 - entropy2)
SignalCorrelation.kurtosis_ratio¶
- SignalCorrelation.kurtosis_ratio(signal1, signal2)¶
Kurtosis ratio.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.abs(kurtosis1 / kurtosis2) if kurtosis2 != 0 else np.nan
SignalCorrelation.skewness_product¶
- SignalCorrelation.skewness_product(signal1, signal2)¶
Skewness product.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan skew1 * skew2
SignalCorrelation.zero_crossings_difference¶
- SignalCorrelation.zero_crossings_difference(signal1, signal2)¶
Zero crossings difference.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.abs(zero_crossings1 - zero_crossings2)
SignalCorrelation.fft_peak_ratio¶
- SignalCorrelation.fft_peak_ratio(signal1, signal2)¶
Fft peak ratio.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan peak1 / peak2 if peak2 != 0 else np.nan
SignalCorrelation.fft_energy_ratio¶
- SignalCorrelation.fft_energy_ratio(signal1, signal2)¶
Fft energy ratio.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan energy1 / energy2 if energy2 != 0 else np.nan
SignalCorrelation.histogram_intersection¶
- SignalCorrelation.histogram_intersection(signal1, signal2, bins=10)¶
Intersect probability histograms using shared bins for both profiles.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.bins – Input
binsconsumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan float(np.minimum(hist1 / count1, hist2 / count2).sum())
View current source, line 330.
Original docstring (legacy wording may differ from the current signature)
Intersect probability histograms using shared bins for both profiles.
SignalCorrelation.cosine_similarity¶
- SignalCorrelation.cosine_similarity(signal1, signal2)¶
Cosine similarity.
- Parameters:
signal1 – Input
signal1consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.signal2 – Input
signal2consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring.
Return expressions in source:
np.nan np.dot(signal1, signal2) / (np.linalg.norm(signal1) * np.linalg.norm(signal2))