digital-art-api / tests /test_phash.py

Commit History

  1. fallback legacy

    Ruzzel Mendoza
    18f4339
  2. asd

    Ruzzel Mendoza
    5d0b1a5

  1. Fix transform_consistency default + expose agreement counts⁠

    Ruzzel Mendoza
    6f114bb

  1. Phase 5: rotation-aware global pre-filter + scoring refinements - global_prefilter_distance: query phash('0') vs ALL SIX stored transform-variant phashes (6 Hamming ops, no re-hashing); scan_database skips a row only when every variant exceeds GLOBAL_PREFILTER_MAX_DISTANCE (default 28, env-overridable) - pre-filter is performance-only: never sets or influences scores of rows that pass; skip count logged - scan_database/check_distance_between_serp now return true top-5 sorted by calibrated_confidence (primary score) with the full new field set per match (was: history of interim bests) - scoring refinement for rotate-and-repost: final = 0.3*T*transform_cap + 0.7*B*block_multiplier so block geometry can no longer zero out transform evidence (pure rotations: T~65, blocks 0 -> final ~20, flagged) - background-coincidence guard: transform resemblance without ANY block corroboration is voided unless the alignment is tight (avg dist <= STRICT/2) - fixes the matching-background false positive at the global level while preserving rotation/mirror/flip detection - regression fixture verified: legacy 96.48% (old bug) vs new 0.0; sparse-art exact copy stays 100.0 (no over-suppression); real-data baseline re-verified: 78/78 unrelated pairs score 0.0, prefilter dists 18-32 vs cutoff 28 (kept: conservative, true copies at <=10) - tests 5/6/7 added: sparse-art multiplier, original-bug regression, prefilter + scan_database

    Ruzzel Mendoza
    f83b9ab
  2. Phase 4: baseline calibration + calibrated_confidence - scripts/calibrate_baseline.py: offline script (not wired to API) that cross-pairs registered artworks from Supabase (or a --from-json dump) through the consensus pipeline and persists config/calibration.json - lib/phash: load_calibration()/calibrated_confidence()/plagiarism_threshold(); percentile-table interpolation with normal-CDF tails, identity fallback until calibrated; compare_hash_sets now returns calibrated_confidence + calibration_loaded - ran against live DB: 13 artworks / 78 unrelated pairs. Result: legacy scores unrelated pairs 56.7-72.3% (reproduces reported false positives); new consensus scores all 78 pairs 0.0 (0/78 block agreements; best unrelated block distance min 17.7 vs STRICT_MATCH_DISTANCE 12) - threshold: degenerate baseline (stddev 0) -> documented rule threshold = best unrelated score + 5 = 5.0; switches to p99 once the catalog yields a spread - constants revisited vs data (follow-up brief item 4): STRICT_MATCH_DISTANCE=12 supported by 17.7+ gap; MIN_BLOCK_STDDEV=5 unverifiable until DB rows carry entropy (kept); prefilter cutoff validated in Phase 5 - tests: percentile interpolation, tail extrapolation/clamping, identity fallback, threshold lookup, compare_hash_sets field presence

    Ruzzel Mendoza
    61d2c38
  3. Phase 3: transform/geometric consistency confidence multiplier - TRANSFORM_BLOCK_MAP: where each block position lands under 0/90/180/270/mirror/flip - compute_transform_consistency: agreeing block pairs vote for the transform implied by their position mapping (center matches excluded as uninformative, ambiguous pairs split votes); returns fraction of votes held by dominant transform - confidence_multiplier = consistency * evidence cap; cap ramps to 1 at MIN_CONSENSUS_BLOCKS (default 2) but never demands more agreeing blocks than the image has content blocks (sparse-art fairness) - final score = (0.3*transform + 0.7*block consensus) * multiplier; expose transform_consistency and dominant_transform in compare_hash_sets - tests: unit votes, identical=1.0 dominant '0', scrambled quadrants -> 0.5 + suppressed score, single lucky match capped at 0.5

    Ruzzel Mendoza
    f98281a
  4. Phase 2: consensus-based scoring - replace single-minimum-distance logic in compare_blocks/compare_transforms with per-component best-match consensus: count pairs below tunable STRICT_MATCH_DISTANCE (default 12.0), derive similarity from (agreement ratio, avg distance of agreeing pairs) - expose agreements/agreement_ratio/content_blocks_used in results - retain old algorithm as compare_blocks_legacy/compare_transforms_legacy; compare_hash_sets now returns raw_similarity (new method) and raw_similarity_legacy (old method) side by side for transition-period validation - tests: identical -> ~100, one shared block -> legacy ~90 but consensus capped ~20, unrelated -> low

    Ruzzel Mendoza
    f731132
  5. Phase 1: entropy filtering for block matching - add block_entropy() (stddev of preprocessed grayscale block) and tunable MIN_BLOCK_STDDEV (env-overridable, default 5.0) - tag each block hash dict with its entropy score in generate_block_hashes - compare_blocks excludes pairs where either block is flat/low-detail; falls back to all blocks with low_content_warning when an image has no content - propagate content_blocks_used/low_content_warning through compare_hash_sets - legacy DB rows without entropy stay eligible (backward compat) - add pytest scaffolding and entropy-filtering tests

    Ruzzel Mendoza
    4b85872