-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced Features
This page covers advanced entropy measurement techniques and features available in the entropic_measurement library.
Conditional entropy measures the uncertainty of one variable given knowledge of another variable. It's particularly useful for understanding information dependencies.
from entropic_measurement import conditional_entropy
# Calculate H(Y|X)
entropy_y_given_x = conditional_entropy(y_data, x_data)
print(f"Conditional entropy H(Y|X): {entropy_y_given_x:.4f}")Mutual information quantifies the amount of information shared between two variables.
from entropic_measurement import mutual_information
# Calculate mutual information between X and Y
mi = mutual_information(x_data, y_data)
print(f"Mutual information I(X;Y): {mi:.4f}")Cross entropy measures the difference between two probability distributions.
from entropic_measurement import cross_entropy
# Calculate cross entropy between predicted and actual distributions
ce = cross_entropy(predicted_dist, actual_dist)
print(f"Cross entropy: {ce:.4f}")Kullback-Leibler divergence measures how one probability distribution differs from another.
from entropic_measurement import kl_divergence
# Calculate KL divergence D(P||Q)
kl_div = kl_divergence(p_distribution, q_distribution)
print(f"KL divergence D(P||Q): {kl_div:.4f}")The library provides several bias correction methods for entropy estimation:
from entropic_measurement import shannon_entropy
# Apply Miller-Madow bias correction
entropy_corrected = shannon_entropy(data, correction='miller_madow')# Apply Grassberger correction for small samples
entropy_corrected = shannon_entropy(data, correction='grassberger')def custom_correction(entropy, sample_size, alphabet_size):
"""Custom bias correction function"""
return entropy + (alphabet_size - 1) / (2 * sample_size)
# Use custom correction
entropy_corrected = shannon_entropy(data, correction=custom_correction)Smoothing helps handle zero probabilities in sparse data:
# Laplace smoothing (add-one smoothing)
entropy_smooth = shannon_entropy(data, smoothing='laplace', alpha=1.0)
# Lidstone smoothing with custom alpha
entropy_smooth = shannon_entropy(data, smoothing='lidstone', alpha=0.5)Create comprehensive entropy profiles for complex data analysis:
from entropic_measurement import EntropyProfile
# Create entropy profile with multiple measures
profile = EntropyProfile(data)
results = profile.compute_all()
print(f"Shannon entropy: {results['shannon']:.4f}")
print(f"Rényi entropy (α=2): {results['renyi_2']:.4f}")
print(f"Tsallis entropy (q=2): {results['tsallis_2']:.4f}")
print(f"Hartley entropy: {results['hartley']:.4f}")Combine multiple entropy measures with custom weights:
from entropic_measurement import weighted_entropy_combination
entropies = {
'shannon': shannon_entropy(data),
'renyi': renyi_entropy(data, alpha=2),
'tsallis': tsallis_entropy(data, q=2)
}
weights = {'shannon': 0.5, 'renyi': 0.3, 'tsallis': 0.2}
combined_entropy = weighted_entropy_combination(entropies, weights)Analyze entropy across multiple dimensions or variables:
from entropic_measurement import multidimensional_entropy
# For multivariate data
entropy_2d = multidimensional_entropy(data_2d, method='joint')
entropy_marginal = multidimensional_entropy(data_2d, method='marginal')Leverage parallel processing for large datasets:
from entropic_measurement import shannon_entropy
# Enable parallel processing
entropy_parallel = shannon_entropy(large_data, parallel=True, n_jobs=4)For very large datasets, use streaming computation:
from entropic_measurement import StreamingEntropy
# Initialize streaming entropy calculator
streaming_calc = StreamingEntropy()
# Process data in chunks
for chunk in data_chunks:
streaming_calc.update(chunk)
final_entropy = streaming_calc.finalize()# Use different logarithm bases
entropy_log2 = shannon_entropy(data, base=2) # bits
entropy_ln = shannon_entropy(data, base='e') # nats
entropy_log10 = shannon_entropy(data, base=10) # dits# High precision computation
from decimal import Decimal
entropy_precise = shannon_entropy(data, precision=Decimal)- API Reference - Complete function and class documentation
- Examples - Practical usage examples
- Theory - Mathematical foundations of entropy measures
- Information Theory Textbook - Cover & Thomas (PDF)
- Entropy in Data Science - Practical applications
- Python Information Theory - Alternative library
- Paninski, L. (2003). "Estimation of entropy and mutual information" - Bias correction methods
- Grassberger, P. (1988). "Finite sample corrections to entropy and dimension estimates" - Advanced corrections
- Schürmann, T. (2004). "Bias analysis in entropy estimation" - Comprehensive bias analysis
- GitHub Issues - Report bugs and request features
- Discussions - Community Q&A
- Contributing Guide - How to contribute to the project
Last updated: July 23, 2025