Skip to content
BitVecCorrelation

BitVecCorrelation

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);

Returns

Correlation coefficient (-1.0 to 1.0)

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    double BitVecCorrelation(BitVec *bv1, BitVec *bv2) {
        ValidateBitVec(bv1);
        ValidateBitVec(bv2);
    // Test BitVecCorrelation basic functionality
    bool test_bitvec_correlation_basic(void) {
        WriteFmt("Testing BitVecCorrelation basic functionality\n");
    
        BitVec bv1    = BitVecInit();
        BitVecPush(&bv2, false);
    
        double correlation = BitVecCorrelation(&bv1, &bv2);
        result             = result && (fabs(correlation - 1.0) < 0.001);
        BitVecPush(&bv2, true);
    
        correlation = BitVecCorrelation(&bv1, &bv2);
        result      = result && (fabs(correlation + 1.0) < 0.001);
    // Test BitVecCorrelation edge cases
    bool test_bitvec_correlation_edge_cases(void) {
        WriteFmt("Testing BitVecCorrelation edge cases\n");
    
        BitVec bv1    = BitVecInit();
    
        // Test empty bitvectors
        double correlation = BitVecCorrelation(&bv1, &bv2);
        result             = result && (correlation == 1.0);
        BitVecPush(&bv2, true);
    
        correlation = BitVecCorrelation(&bv1, &bv2);
        result      = result && (correlation == 0.0); // No variance
        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);
    
    bool test_bitvec_correlation_null_bv1(void) {
        WriteFmt("Testing BitVecCorrelation(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit();
        BitVecPush(&bv2, true);
        BitVec bv2 = BitVecInit();
        BitVecPush(&bv2, true);
        BitVecCorrelation(NULL, &bv2);
        BitVecDeinit(&bv2);
        return true;
    
    bool test_bitvec_correlation_null_bv2(void) {
        WriteFmt("Testing BitVecCorrelation(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit();
        BitVecPush(&bv1, true);
        BitVec bv1 = BitVecInit();
        BitVecPush(&bv1, true);
        BitVecCorrelation(&bv1, NULL);
        BitVecDeinit(&bv1);
        return true;
Last updated on