| |
| """ |
| African Anti-Corruption Enforcement Dataset Generator |
| |
| Generates synthetic records for 12 Sub-Saharan African countries across |
| three enforcement scenarios. Parameters are informed by: |
| - Transparency International CPI 2025 (SSA avg=32, range 9-68) |
| - EFCC Nigeria 2024 statistics (12,928 investigated, 5,083 prosecuted, |
| 4,111 convictions, ~$214M recovered) |
| - South Africa SIU 2023/24 (1,919 investigations, 583 referrals, |
| R8B saved, ~80% conviction rate in commercial cases) |
| - Kenya EACC 2023/24 (5,171 reports, 534 under probe, 26.7% conviction |
| rate, Ksh2.9B recovered) |
| - AU Common African Position on Asset Recovery (asset recovery <10%) |
| - G20 2025 Accountability Report on Whistleblower Protection |
| """ |
|
|
| import os |
| import argparse |
| import numpy as np |
| import pandas as pd |
| from scipy import stats |
|
|
| RNG_SEED = 42 |
|
|
| |
| |
| |
| COUNTRIES = { |
| "Nigeria": { |
| "cpi_mean": 32, "cpi_std": 2.0, |
| "pop_millions": 220, |
| "agency_independence_mean": 42, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 33, "whistleblower_protection_std": 7, |
| "cases_investigated_range": (10000, 18000), |
| "prosecution_rate_base": 0.35, |
| "conviction_rate_base": 0.72, |
| "asset_recovery_rate_base": 0.08, |
| "assets_usd_millions_range": (80, 250), |
| }, |
| "South Africa": { |
| "cpi_mean": 43, "cpi_std": 2.5, |
| "pop_millions": 60, |
| "agency_independence_mean": 55, "agency_independence_std": 10, |
| "whistleblower_protection_mean": 48, "whistleblower_protection_std": 9, |
| "cases_investigated_range": (1800, 2800), |
| "prosecution_rate_base": 0.28, |
| "conviction_rate_base": 0.75, |
| "asset_recovery_rate_base": 0.12, |
| "assets_usd_millions_range": (100, 350), |
| }, |
| "Kenya": { |
| "cpi_mean": 30, "cpi_std": 2.0, |
| "pop_millions": 55, |
| "agency_independence_mean": 38, "agency_independence_std": 7, |
| "whistleblower_protection_mean": 30, "whistleblower_protection_std": 6, |
| "cases_investigated_range": (4000, 6000), |
| "prosecution_rate_base": 0.22, |
| "conviction_rate_base": 0.45, |
| "asset_recovery_rate_base": 0.06, |
| "assets_usd_millions_range": (15, 40), |
| }, |
| "Ghana": { |
| "cpi_mean": 43, "cpi_std": 2.5, |
| "pop_millions": 34, |
| "agency_independence_mean": 50, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 40, "whistleblower_protection_std": 7, |
| "cases_investigated_range": (800, 1500), |
| "prosecution_rate_base": 0.30, |
| "conviction_rate_base": 0.55, |
| "asset_recovery_rate_base": 0.07, |
| "assets_usd_millions_range": (8, 30), |
| }, |
| "Tanzania": { |
| "cpi_mean": 38, "cpi_std": 2.0, |
| "pop_millions": 65, |
| "agency_independence_mean": 35, "agency_independence_std": 7, |
| "whistleblower_protection_mean": 25, "whistleblower_protection_std": 6, |
| "cases_investigated_range": (2000, 4000), |
| "prosecution_rate_base": 0.25, |
| "conviction_rate_base": 0.60, |
| "asset_recovery_rate_base": 0.05, |
| "assets_usd_millions_range": (10, 35), |
| }, |
| "Uganda": { |
| "cpi_mean": 26, "cpi_std": 2.0, |
| "pop_millions": 48, |
| "agency_independence_mean": 30, "agency_independence_std": 7, |
| "whistleblower_protection_mean": 22, "whistleblower_protection_std": 5, |
| "cases_investigated_range": (1500, 3000), |
| "prosecution_rate_base": 0.18, |
| "conviction_rate_base": 0.40, |
| "asset_recovery_rate_base": 0.04, |
| "assets_usd_millions_range": (5, 20), |
| }, |
| "Ethiopia": { |
| "cpi_mean": 30, "cpi_std": 2.5, |
| "pop_millions": 120, |
| "agency_independence_mean": 28, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 18, "whistleblower_protection_std": 5, |
| "cases_investigated_range": (1000, 2500), |
| "prosecution_rate_base": 0.15, |
| "conviction_rate_base": 0.50, |
| "asset_recovery_rate_base": 0.04, |
| "assets_usd_millions_range": (5, 25), |
| }, |
| "Senegal": { |
| "cpi_mean": 46, "cpi_std": 2.0, |
| "pop_millions": 18, |
| "agency_independence_mean": 55, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 42, "whistleblower_protection_std": 7, |
| "cases_investigated_range": (600, 1200), |
| "prosecution_rate_base": 0.32, |
| "conviction_rate_base": 0.55, |
| "asset_recovery_rate_base": 0.08, |
| "assets_usd_millions_range": (5, 20), |
| }, |
| "Mozambique": { |
| "cpi_mean": 21, "cpi_std": 2.0, |
| "pop_millions": 33, |
| "agency_independence_mean": 22, "agency_independence_std": 6, |
| "whistleblower_protection_mean": 15, "whistleblower_protection_std": 4, |
| "cases_investigated_range": (300, 800), |
| "prosecution_rate_base": 0.12, |
| "conviction_rate_base": 0.35, |
| "asset_recovery_rate_base": 0.03, |
| "assets_usd_millions_range": (2, 10), |
| }, |
| "Zambia": { |
| "cpi_mean": 33, "cpi_std": 2.0, |
| "pop_millions": 20, |
| "agency_independence_mean": 40, "agency_independence_std": 7, |
| "whistleblower_protection_mean": 28, "whistleblower_protection_std": 6, |
| "cases_investigated_range": (500, 1200), |
| "prosecution_rate_base": 0.20, |
| "conviction_rate_base": 0.45, |
| "asset_recovery_rate_base": 0.05, |
| "assets_usd_millions_range": (3, 15), |
| }, |
| "Rwanda": { |
| "cpi_mean": 58, "cpi_std": 2.5, |
| "pop_millions": 14, |
| "agency_independence_mean": 65, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 55, "whistleblower_protection_std": 8, |
| "cases_investigated_range": (400, 900), |
| "prosecution_rate_base": 0.45, |
| "conviction_rate_base": 0.70, |
| "asset_recovery_rate_base": 0.15, |
| "assets_usd_millions_range": (3, 12), |
| }, |
| "Botswana": { |
| "cpi_mean": 58, "cpi_std": 2.5, |
| "pop_millions": 2.6, |
| "agency_independence_mean": 62, "agency_independence_std": 8, |
| "whistleblower_protection_mean": 50, "whistleblower_protection_std": 8, |
| "cases_investigated_range": (200, 500), |
| "prosecution_rate_base": 0.40, |
| "conviction_rate_base": 0.65, |
| "asset_recovery_rate_base": 0.12, |
| "assets_usd_millions_range": (2, 8), |
| }, |
| } |
|
|
| SCENARIOS = { |
| "baseline": { |
| "cpi_shift": 0, |
| "agency_shift": 0, |
| "whistleblower_shift": 0, |
| "prosecution_multiplier": 1.0, |
| "conviction_multiplier": 1.0, |
| "asset_recovery_multiplier": 1.0, |
| "investigated_multiplier": 1.0, |
| }, |
| "strengthened_enforcement": { |
| "cpi_shift": 8, |
| "agency_shift": 18, |
| "whistleblower_shift": 20, |
| "prosecution_multiplier": 1.45, |
| "conviction_multiplier": 1.15, |
| "asset_recovery_multiplier": 2.0, |
| "investigated_multiplier": 1.25, |
| }, |
| "weakened_accountability": { |
| "cpi_shift": -10, |
| "agency_shift": -15, |
| "whistleblower_shift": -15, |
| "prosecution_multiplier": 0.60, |
| "conviction_multiplier": 0.80, |
| "asset_recovery_multiplier": 0.40, |
| "investigated_multiplier": 0.70, |
| }, |
| } |
|
|
|
|
| def clamp(x, lo, hi): |
| return np.clip(x, lo, hi) |
|
|
|
|
| def generate_country_scenario(country_name, params, scenario_name, scenario_params, n_records, rng): |
| """Generate n_records for one country under one scenario.""" |
|
|
| |
| cpi = rng.normal( |
| params["cpi_mean"] + scenario_params["cpi_shift"], |
| params["cpi_std"], n_records |
| ) |
| cpi = clamp(cpi, 0, 100) |
|
|
| agency_independence = rng.normal( |
| params["agency_independence_mean"] + scenario_params["agency_shift"], |
| params["agency_independence_std"], n_records |
| ) |
| agency_independence = clamp(agency_independence, 0, 100) |
|
|
| whistleblower_protection = rng.normal( |
| params["whistleblower_protection_mean"] + scenario_params["whistleblower_shift"], |
| params["whistleblower_protection_std"], n_records |
| ) |
| whistleblower_protection = clamp(whistleblower_protection, 0, 100) |
|
|
| |
| pop_scale = params["pop_millions"] / 60 |
| inv_lo, inv_hi = params["cases_investigated_range"] |
| inv_base = rng.uniform(inv_lo * pop_scale, inv_hi * pop_scale, n_records) |
| cases_investigated = np.round( |
| inv_base * scenario_params["investigated_multiplier"] |
| ).astype(int) |
| cases_investigated = np.maximum(cases_investigated, 10) |
|
|
| |
| prot_base = params["prosecution_rate_base"] * scenario_params["prosecution_multiplier"] |
| |
| agency_effect = (agency_independence - 50) / 500 |
| prosecution_rate = prot_base + agency_effect + rng.normal(0, 0.04, n_records) |
| prosecution_rate = clamp(prosecution_rate, 0.02, 0.85) |
|
|
| cases_prosecuted = np.round(cases_investigated * prosecution_rate).astype(int) |
| cases_prosecuted = np.minimum(cases_prosecuted, cases_investigated) |
| cases_prosecuted = np.maximum(cases_prosecuted, 0) |
|
|
| |
| conv_base = params["conviction_rate_base"] * scenario_params["conviction_multiplier"] |
| conv_rate = conv_base + rng.normal(0, 0.06, n_records) |
| conv_rate = clamp(conv_rate, 0.05, 0.95) |
|
|
| convictions = np.round(cases_prosecuted * conv_rate).astype(int) |
| convictions = np.minimum(convictions, cases_prosecuted) |
| convictions = np.maximum(convictions, 0) |
|
|
| |
| asset_lo, asset_hi = params["assets_usd_millions_range"] |
| assets_confiscated = rng.uniform(asset_lo, asset_hi, n_records) * scenario_params["asset_recovery_multiplier"] |
| assets_confiscated = np.maximum(assets_confiscated, 0.1) |
|
|
| asset_recovery_rate = params["asset_recovery_rate_base"] * scenario_params["asset_recovery_multiplier"] |
| asset_recovery_rate = clamp( |
| asset_recovery_rate + rng.normal(0, 0.02, n_records), 0.01, 0.50 |
| ) |
|
|
| |
| wb_base = cases_investigated * rng.uniform(0.3, 0.8, n_records) |
| wb_effect = 1 + (whistleblower_protection - 30) / 100 |
| whistleblower_reports = np.round(wb_base * wb_effect).astype(int) |
| whistleblower_reports = np.maximum(whistleblower_reports, 0) |
|
|
| |
| enforcement_effectiveness = ( |
| 0.25 * (prosecution_rate / 0.5) + |
| 0.25 * (conv_rate / 0.8) + |
| 0.20 * (asset_recovery_rate / 0.15) + |
| 0.15 * (agency_independence / 100) + |
| 0.15 * (whistleblower_protection / 100) |
| ) * 100 |
| enforcement_effectiveness = clamp(enforcement_effectiveness, 0, 100) |
|
|
| |
| enforcement_class = np.where( |
| enforcement_effectiveness >= 60, "strong", |
| np.where(enforcement_effectiveness >= 35, "moderate", "weak") |
| ) |
|
|
| |
| df = pd.DataFrame({ |
| "country": country_name, |
| "scenario": scenario_name, |
| "corruption_perception_index": np.round(cpi, 1), |
| "cases_investigated": cases_investigated, |
| "cases_prosecuted": cases_prosecuted, |
| "prosecution_rate": np.round(prosecution_rate, 4), |
| "convictions": convictions, |
| "conviction_rate": np.round(conv_rate, 4), |
| "assets_confiscated_usd_millions": np.round(assets_confiscated, 2), |
| "asset_recovery_rate": np.round(asset_recovery_rate, 4), |
| "whistleblower_reports": whistleblower_reports, |
| "whistleblower_protection_score": np.round(whistleblower_protection, 1), |
| "agency_independence_score": np.round(agency_independence, 1), |
| "enforcement_effectiveness_score": np.round(enforcement_effectiveness, 1), |
| "enforcement_class": enforcement_class, |
| }) |
| return df |
|
|
|
|
| def generate_dataset(scenario, n_per_country=834, seed=RNG_SEED): |
| """Generate full dataset for one scenario across all 12 countries.""" |
| rng = np.random.default_rng(seed) |
| scenario_params = SCENARIOS[scenario] |
| frames = [] |
| for country_name, params in COUNTRIES.items(): |
| df = generate_country_scenario( |
| country_name, params, scenario, scenario_params, n_per_country, rng |
| ) |
| frames.append(df) |
| full = pd.concat(frames, ignore_index=True) |
| |
| full = full.sample(frac=1, random_state=seed).reset_index(drop=True) |
| return full |
|
|
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Generate anti-corruption enforcement dataset") |
| parser.add_argument("--scenario", type=str, default="all", |
| choices=list(SCENARIOS.keys()) + ["all"]) |
| parser.add_argument("--n-records", type=int, default=10000, |
| help="Total records per scenario (split across 12 countries)") |
| parser.add_argument("--output-dir", type=str, default="data") |
| args = parser.parse_args() |
|
|
| os.makedirs(args.output_dir, exist_ok=True) |
| scenarios = list(SCENARIOS.keys()) if args.scenario == "all" else [args.scenario] |
|
|
| for scen in scenarios: |
| n_per_country = args.n_records // len(COUNTRIES) |
| remainder = args.n_records - n_per_country * len(COUNTRIES) |
| df = generate_dataset(scen, n_per_country=n_per_country) |
| |
| if remainder > 0: |
| rng = np.random.default_rng(RNG_SEED + 99) |
| extra = generate_country_scenario( |
| list(COUNTRIES.keys())[0], |
| COUNTRIES[list(COUNTRIES.keys())[0]], |
| scen, SCENARIOS[scen], remainder, rng |
| ) |
| df = pd.concat([df, extra], ignore_index=True) |
| df = df.sample(frac=1, random_state=RNG_SEED).reset_index(drop=True) |
|
|
| out_path = os.path.join(args.output_dir, f"{scen}.csv") |
| df.to_csv(out_path, index=False) |
| print(f"Generated {len(df)} records → {out_path}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|