Skip to content

simulate_media produces inf clicks when noisy CPC goes non-positive #43

@takechanman1228

Description

@takechanman1228

Describe the bug

  • Additive noise in simulate_media() can push CPC below zero; _negative_replace() then sets it to 0, and the subsequent spend / noisy_cpc division produces inf in lifetime_clicks (and similarly for CPM/impressions).
  • The logger warns about negative CPC, but the data frame still contains inf, which contaminates downstream ROI calculations.

To Reproduce

sim.simulate_media(
    true_cpm={'Display': 5.0},
    true_cpc={'Search': 0.5},  # Low CPC
    noisy_cpm_cpc={
        'Display': {'loc': 0, 'scale': 1.0},
        'Search': {'loc': 0, 'scale': 0.2},  # scale/CPC = 40%
    },
)
# Warning: "negative values... will be set to 0"
# Result: inf in lifetime_clicks

With true_cpc=0.5 and scale=0.2, approximately 48% of random seeds produce inf values.

Expected behavior
No inf values in lifetime_clicks/lifetime_impressions

Root Cause
In src/pysimmmulator/simulate.py the helper _negative_replace() replaces negative CPC/CPM with 0 (see ~L171–L183), and simulate_media() divides by that column (see ~L212–L228), yielding divide-by-zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions