BitVecCorrelation

Table of Contents

BitVecCorrelation

Description

Calculate Pearson correlation coefficient between two bitvectors. Treats bits as 0/1 values and computes linear correlation.

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  double correlation = BitVecCorrelation(&bv1, &bv2);

Usage example (Cross-references)

    }
    
    double BitVecCorrelation(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecCorrelation basic functionality
    bool test_bitvec_correlation_basic(void) {
    printf("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) {
    printf("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) {
    printf("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) {
    printf("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;

Share :

Related Posts

BitVecCosineSimilarity

BitVecCosineSimilarity Description Calculate cosine similarity between two bitvectors. Treats bitvectors as binary vectors and computes cosine of angle between them.

Read More

BitVecDotProduct

BitVecDotProduct Description Calculate dot product of two bitvectors. Dot product is the count of positions where both bits are 1.

Read More

BitVecJaccardSimilarity

BitVecJaccardSimilarity Description Calculate Jaccard similarity between two bitvectors. Jaccard similarity = |intersection| / |union|

Read More