BitVecEntropy
Description
Calculate information entropy of a bitvector. Entropy measures the randomness/information content of the bit pattern.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to analyze |
Usage example (from documentation)
double entropy = BitVecEntropy(&flags);Success
Returns the Shannon entropy of the bit pattern, in bits, in [0.0, 1.0]. The bitvector is not modified.
Failure
Returns 0.0 for an empty bitvector or one whose bits are all equal; the caller cannot distinguish that from a true zero entropy.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1646:
}
double BitVecEntropy(BitVec *bv) {
ValidateBitVec(bv);- In
Math.c:527:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecEntropy basic functionality\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:538:
BitVecPush(&bv, false);
double entropy = BitVecEntropy(&bv);
result = result && (F64Abs(entropy - 1.0) < 0.001);- In
Math.c:547:
BitVecPush(&bv, true);
entropy = BitVecEntropy(&bv);
result = result && (entropy == 0.0);- In
Math.c:559:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecEntropy edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:565:
// Test empty bitvector
double entropy = BitVecEntropy(&bv);
result = result && (entropy == 0.0);- In
Math.c:570:
// Test single bit
BitVecPush(&bv, true);
entropy = BitVecEntropy(&bv);
result = result && (entropy == 0.0);- In
Math.c:727:
u64 dot_prod = BitVecDotProduct(&bv1, &bv2);
double correlation = BitVecCorrelation(&bv1, &bv2);
double entropy1 = BitVecEntropy(&bv1);
int align_score = BitVecAlignmentScore(&bv1, &bv2, 1, -1);
u64 best_align = BitVecBestAlignment(&bv1, &bv2);- In
Math.c:909:
bool test_bitvec_entropy_null(void) {
WriteFmt("Testing BitVecEntropy(NULL) - should fatal\n");
BitVecEntropy(NULL);
return true;- In
Math.c:910:
bool test_bitvec_entropy_null(void) {
WriteFmt("Testing BitVecEntropy(NULL) - should fatal\n");
BitVecEntropy(NULL);
return true;
}- In
Math.c:1321:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecEntropy on an unbalanced (3 ones, 1 zero) vector\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:1331:
BitVecPush(&bv, false);
double entropy = BitVecEntropy(&bv);
// True value 0.811278; mutant value 0.436278 is well outside this band.
result = result && (F64Abs(entropy - 0.811278) < 0.01);- In
Math.c:1415:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecEntropy of a 3:1 distribution\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:1427:
BitVecPush(&bv, false);
double entropy = BitVecEntropy(&bv);
result = result && (F64Abs(entropy - 0.8112782517394319) < 0.001);- In
Math.c:1453:
BitVecPush(&bv, false);
double entropy = BitVecEntropy(&bv);
result = result && (F64Abs(entropy - 0.8112781245) < 0.001);
Last updated on