BitVecCorrelation
Description
Calculate Pearson correlation coefficient between two bitvectors. Treats bits as 0/1 values and computes linear correlation.
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector |
bv2 |
in | Second bitvector |
Usage example (from documentation)
double correlation = BitVecCorrelation(&bv1, &bv2);Success
Returns the Pearson correlation coefficient in [-1.0, 1.0]. Neither operand is modified.
Failure
Returns 0.0 when either operand has zero variance (all bits equal); the caller cannot distinguish that from a true zero coefficient.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1618:
}
double BitVecCorrelation(BitVec *bv1, BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
Math.c:457:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation basic functionality\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:473:
BitVecPush(&bv2, false);
double correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (F64Abs(correlation - 1.0) < 0.001);- In
Math.c:483:
BitVecPush(&bv2, true);
correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (F64Abs(correlation + 1.0) < 0.001);- In
Math.c:496:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation edge cases\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:503:
// Test empty bitvectors
double correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (correlation == 1.0);- In
Math.c:514:
BitVecPush(&bv2, true);
correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (correlation == 0.0); // No variance
- In
Math.c:726:
double cosine = BitVecCosineSimilarity(&bv1, &bv2);
u64 dot_prod = BitVecDotProduct(&bv1, &bv2);
double correlation = BitVecCorrelation(&bv1, &bv2);
double entropy1 = BitVecEntropy(&bv1);
int align_score = BitVecAlignmentScore(&bv1, &bv2, 1, -1);- In
Math.c:887:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation(NULL, bv2) - should fatal\n");
BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv2, true);- In
Math.c:890:
BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv2, true);
BitVecCorrelation(NULL, &bv2);
BitVecDeinit(&bv2);
DefaultAllocatorDeinit(&alloc);- In
Math.c:899:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation(bv1, NULL) - should fatal\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv1, true);- In
Math.c:902:
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv1, true);
BitVecCorrelation(&bv1, NULL);
BitVecDeinit(&bv1);
DefaultAllocatorDeinit(&alloc);- In
Math.c:1259:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation with bv1 shorter than bv2 (no OOB)\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:1274:
BitVecPush(&bv2, false);
double correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (correlation >= -1.0 && correlation <= 1.0);- In
Math.c:1289:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCorrelation with bv2 shorter than bv1 (no OOB)\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Math.c:1304:
BitVecPush(&bv2, false);
double correlation = BitVecCorrelation(&bv1, &bv2);
result = result && (correlation >= -1.0 && correlation <= 1.0);
Last updated on