From 15ea445210bd4f0f7109ba67baa28e9f7a5494d9 Mon Sep 17 00:00:00 2001 From: pltaylor16 Date: Thu, 13 Nov 2025 15:55:32 -0500 Subject: [PATCH 1/3] minimally working BNT. --- .../likelihood/photometric_likelihoods.ipynb | 342 +++++++++++++++--- 1 file changed, 299 insertions(+), 43 deletions(-) diff --git a/tutorials/likelihood/photometric_likelihoods.ipynb b/tutorials/likelihood/photometric_likelihoods.ipynb index 7099cc1..1918221 100644 --- a/tutorials/likelihood/photometric_likelihoods.ipynb +++ b/tutorials/likelihood/photometric_likelihoods.ipynb @@ -12,10 +12,47 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "638d6c84-ae61-4d28-ab2a-15fbf745152c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-11-13 15:27:40.890901: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/srv/scratch1/taylor.4264/anaconda3/envs/cloe/lib/python3.10/site-packages/HMcode2020Emu\n", + "Loading linear emulator...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-11-13 15:27:41.919702: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1960] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.\n", + "Skipping registering GPU devices...\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Linear emulator loaded in memory.\n", + "Loading nonlinear emulator...\n", + "Non-linear emulator loaded in memory.\n", + "Loading linear emulator...\n", + "Baryonic boost emulator loaded in memory.\n", + "Loading sigma8 emulator...\n", + "Linear emulator loaded in memory.\n" + ] + } + ], "source": [ "# General imports\n", "import numpy as np\n", @@ -50,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "id": "b76eff88", "metadata": {}, "outputs": [ @@ -117,7 +154,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "id": "210466a1-5c00-4288-833e-eb9e52e532ce", "metadata": {}, "outputs": [], @@ -137,23 +174,10 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 4, "id": "c9d10658-f771-4bcc-a5b2-dfa2409938e4", "metadata": {}, - "outputs": [ - { - "ename": "FileNotFoundError", - "evalue": "[Errno 2] No such file or directory: 'cov_2x2pt.npz'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[16], line 8\u001b[0m\n\u001b[1;32m 6\u001b[0m covmat_WL \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mload(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcov_WL.npz\u001b[39m\u001b[38;5;124m\"\u001b[39m)[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124marr_0\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 7\u001b[0m covmat_GC \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mload(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcov_GCph.npz\u001b[39m\u001b[38;5;124m\"\u001b[39m)[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124marr_0\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m----> 8\u001b[0m covmat_2x2pt \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcov_2x2pt.npz\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124marr_0\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 9\u001b[0m covmat_3x2pt \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mload(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcov_3x2pt.npz\u001b[39m\u001b[38;5;124m\"\u001b[39m)[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124marr_0\u001b[39m\u001b[38;5;124m'\u001b[39m]\n", - "File \u001b[0;32m~/miniforge3/envs/cloe-org-cloelike/lib/python3.10/site-packages/numpy/lib/npyio.py:427\u001b[0m, in \u001b[0;36mload\u001b[0;34m(file, mmap_mode, allow_pickle, fix_imports, encoding, max_header_size)\u001b[0m\n\u001b[1;32m 425\u001b[0m own_fid \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 426\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 427\u001b[0m fid \u001b[38;5;241m=\u001b[39m stack\u001b[38;5;241m.\u001b[39menter_context(\u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mos_fspath\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 428\u001b[0m own_fid \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 430\u001b[0m \u001b[38;5;66;03m# Code to distinguish from NumPy binary files and pickles.\u001b[39;00m\n", - "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'cov_2x2pt.npz'" - ] - } - ], + "outputs": [], "source": [ "# We read with euclidlib v2025.2 (v2025.1 is also compatible)\n", "cls_data = el.photo.angular_power_spectra('cls_example.fits')\n", @@ -162,7 +186,7 @@ "# This matrix copies the format of seaborne, that produces a full 3x2pt matrix\n", "covmat_WL = np.load(\"cov_WL.npz\")['arr_0']\n", "covmat_GC = np.load(\"cov_GCph.npz\")['arr_0']\n", - "covmat_2x2pt = np.load(\"cov_2x2pt.npz\")['arr_0']\n", + "#covmat_2x2pt = np.load(\"cov_2x2pt.npz\")['arr_0']\n", "covmat_3x2pt = np.load(\"cov_3x2pt.npz\")['arr_0']" ] }, @@ -178,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 5, "id": "be0b200e-6432-4024-bcf4-0bd6f6f293fd", "metadata": {}, "outputs": [], @@ -235,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 6, "id": "082a6d05-ef09-473c-9f67-5d30faf9df41", "metadata": {}, "outputs": [ @@ -246,13 +270,13 @@ "πŸ” Timing log-likelihood initialisation (this only happens once) and displaying results:\n", "\n", "πŸ“Š WL loglike:\n", - "⏱️ Time elapsed (WL): 0.016 seconds\n", + "⏱️ Time elapsed (WL): 0.067 seconds\n", "\n", "πŸ“Š GC loglike:\n", - "⏱️ Time elapsed (GC): 0.008 seconds\n", + "⏱️ Time elapsed (GC): 0.053 seconds\n", "\n", "πŸ“Š 3x2pt loglike:\n", - "⏱️ Time elapsed (3x2pt): 0.008 seconds\n" + "⏱️ Time elapsed (3x2pt): 0.051 seconds\n" ] } ], @@ -310,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 7, "id": "4573baac", "metadata": {}, "outputs": [], @@ -338,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 8, "id": "9df11cc9-0870-4af1-9835-a557861f4f1b", "metadata": {}, "outputs": [ @@ -348,17 +372,36 @@ "text": [ "⏱️ Timing log-likelihood evaluations and displaying results:\n", "\n", - "πŸ“Š Weak Lensing (WL) loglike:\n", - "βœ… Returned value (WL): -27.651626565250503\n", - "⏱️ Time elapsed (WL): 0.161 seconds\n", + "πŸ“Š Weak Lensing (WL) loglike:\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:2025-11-13 15:29:06,631:jax._src.xla_bridge:969: An NVIDIA GPU may be present on this machine, but a CUDA-enabled jaxlib is not installed. Falling back to cpu.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "βœ… Returned value (WL): -27.651629352987\n", + "⏱️ Time elapsed (WL): 4.932 seconds\n", "\n", "πŸ“Š Photometric Angular Galaxy Clustering (GC) loglike:\n", - "βœ… Returned value (GC): -570.5360648741748\n", - "⏱️ Time elapsed (GC): 0.107 seconds\n", + "βœ… Returned value (GC): -570.5364830400092\n", + "⏱️ Time elapsed (GC): 1.313 seconds\n", "\n", - "πŸ“Š 3x2pt loglike:\n", - "βœ… Returned value (3x2pt): -262676.99760000233\n", - "⏱️ Time elapsed (3x2pt): 0.580 seconds\n" + "πŸ“Š 3x2pt loglike:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "βœ… Returned value (3x2pt): -84529.13245818252\n", + "⏱️ Time elapsed (3x2pt): 1.704 seconds\n" ] } ], @@ -394,7 +437,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 9, "id": "1c910f1f", "metadata": {}, "outputs": [ @@ -403,7 +446,7 @@ "output_type": "stream", "text": [ "{('SHE', 'SHE', 1, 1): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 1, 2): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 1, 3): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 1, 4): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 1, 5): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 1, 6): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 2, 2): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 2, 3): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 2, 4): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 2, 5): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 2, 6): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 3, 3): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 3, 4): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 3, 5): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 3, 6): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 4, 4): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 4, 5): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 4, 6): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 5, 5): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 5, 6): AngularPowerSpectrum(axis=(2,)), ('SHE', 'SHE', 6, 6): AngularPowerSpectrum(axis=(2,))}\n", - "{'sigma8_0': 0.8135475902671722}\n" + "{'sigma8_0': 0.8135475902671724}\n" ] } ], @@ -428,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 10, "id": "de2f80fa", "metadata": {}, "outputs": [ @@ -444,12 +487,19 @@ "name": "stderr", "output_type": "stream", "text": [ - "GC: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 50/50 [00:05<00:00, 8.89it/s]\n" + "GC: 0%| | 0/50 [00:00" ] @@ -495,10 +545,216 @@ "plt.show()\n" ] }, + { + "cell_type": "markdown", + "id": "240e4449", + "metadata": {}, + "source": [ + "## Compute the BNT likelihoods" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "2e56ebb8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "πŸ“Œ Evaluating log-likelihoods (BNT versions):\n", + "\n", + "πŸ“Š BNT Weak Lensing (WL) loglike:\n", + "βœ… Returned value (WL_BNT): -35.694437628572864\n", + "⏱️ Time elapsed (WL_BNT): 0.530 seconds\n", + "\n", + "πŸ“Š Photometric Angular Galaxy Clustering (GC) loglike:\n", + "βœ… Returned value (GC): -574.9552613510673\n", + "⏱️ Time elapsed (GC): 0.434 seconds\n", + "\n", + "πŸ“Š BNT 3x2pt loglike:\n", + "βœ… Returned value (3x2pt_BNT): -86798.28955116557\n", + "⏱️ Time elapsed (3x2pt_BNT): 1.592 seconds\n", + "\n", + "πŸ” Consistency checks: base vs BNT (same parameters)\n", + "\n", + "β–Ά WL:\n", + " base loglike = -35.694437628593874\n", + " BNT loglike = -35.694437628572864\n", + " Ξ”loglike = 2.1010748696426162e-11\n", + "\n", + "β–Ά GC:\n", + " base loglike = -574.9552613510673\n", + " BNT loglike = -574.9552613510673\n", + " Ξ”loglike = 0.0\n", + "\n", + "β–Ά 3x2pt:\n", + " base loglike = -86798.28955105296\n", + " BNT loglike = -86798.28955116557\n", + " Ξ”loglike = -1.126027200371027e-07\n" + ] + } + ], + "source": [ + "from cloelib.auxiliary.bnt import BNT\n", + "from cloelike.EuclidLikelihood_photo_Cls import (\n", + " EuclidLikelihood_WL_BNT,\n", + " EuclidLikelihood_GCph,\n", + " EuclidLikelihood_3x2pt_BNT,\n", + ")\n", + "\n", + "# ----------------------------------------------------------\n", + "# 1. Build a fiducial background for BNT computation\n", + "# ----------------------------------------------------------\n", + "fid_bg_params = {\n", + " k: default_pars[k]\n", + " for k in [\n", + " \"H0\",\n", + " \"Omega_cdm0\",\n", + " \"Omega_b0\",\n", + " \"Omega_k0\",\n", + " \"w0\",\n", + " \"wa\",\n", + " \"ns\",\n", + " \"As\",\n", + " \"mnu\",\n", + " \"gamma_MG\",\n", + " \"N_mnu\",\n", + " ]\n", + "}\n", + "\n", + "background_bnt = CAMBBackground(**fid_bg_params)\n", + "\n", + "# ----------------------------------------------------------\n", + "# 2. Compute the BNT matrix using cloelib BNT\n", + "# ----------------------------------------------------------\n", + "bnt_obj = BNT(\n", + " dndz_list=my_dndz_she_norm, # (n_she_bins, n_z)\n", + " z=myz, # same z-grid as used by likelihood\n", + " fid_parameters=fid_bg_params,\n", + " background=background_bnt,\n", + ")\n", + "\n", + "BNT_matrix = bnt_obj.get_matrix()\n", + "# (for identity test, you could do: BNT_matrix = np.eye(my_dndz_she_norm.shape[0]))\n", + "\n", + "# ----------------------------------------------------------\n", + "# 3. Build BNT-enabled data dictionaries\n", + "# ----------------------------------------------------------\n", + "data_WL_BNT = deepcopy(data_WL)\n", + "data_3x2pt_BNT = deepcopy(data_3x2pt)\n", + "\n", + "data_WL_BNT[\"BNT_matrix\"] = BNT_matrix\n", + "data_3x2pt_BNT[\"BNT_matrix\"] = BNT_matrix\n", + "\n", + "# ----------------------------------------------------------\n", + "# 4. Likelihood classes for BNT runs\n", + "# ----------------------------------------------------------\n", + "likelihood_classes_BNT = {\n", + " \"WL_BNT\": EuclidLikelihood_WL_BNT,\n", + " \"GC\": EuclidLikelihood_GCph,\n", + " \"3x2pt_BNT\": EuclidLikelihood_3x2pt_BNT,\n", + "}\n", + "\n", + "data_dicts_BNT = {\n", + " \"WL_BNT\": (data_WL_BNT, settings_WL),\n", + " \"GC\": (data_GC, settings_GC),\n", + " \"3x2pt_BNT\": (data_3x2pt_BNT, settings_3x2pt),\n", + "}\n", + "\n", + "# ----------------------------------------------------------\n", + "# 5. Initialize BNT likelihoods\n", + "# ----------------------------------------------------------\n", + "like_tests_BNT = {}\n", + "\n", + "for key in [\"WL_BNT\", \"GC\", \"3x2pt_BNT\"]:\n", + " data, settings = data_dicts_BNT[key]\n", + " cls = likelihood_classes_BNT[key]\n", + " like_tests_BNT[key] = cls(\n", + " data=data,\n", + " settings=settings,\n", + " Background=CAMBBackground,\n", + " LinPerturbations=HMemuLinearPerturbations,\n", + " NonLinPerturbations=HMemuNonLinearPerturbations,\n", + " )\n", + "\n", + "# ----------------------------------------------------------\n", + "# 6. Evaluate BNT likelihoods (just to see numbers)\n", + "# ----------------------------------------------------------\n", + "labels_pretty_BNT = {\n", + " \"WL_BNT\": \"BNT Weak Lensing (WL)\",\n", + " \"GC\": \"Photometric Angular Galaxy Clustering (GC)\",\n", + " \"3x2pt_BNT\": \"BNT 3x2pt\",\n", + "}\n", + "\n", + "loglike_results_BNT = {}\n", + "\n", + "print(\"πŸ“Œ Evaluating log-likelihoods (BNT versions):\")\n", + "\n", + "for key in [\"WL_BNT\", \"GC\", \"3x2pt_BNT\"]:\n", + " label = labels_pretty_BNT[key]\n", + " print(f\"\\nπŸ“Š {label} loglike:\")\n", + "\n", + " pars = default_pars.copy() # freeze parameters\n", + " start = time.time()\n", + " result = like_tests_BNT[key].loglike(pars)\n", + " elapsed = time.time() - start\n", + "\n", + " loglike_results_BNT[key] = result\n", + "\n", + " print(f\"βœ… Returned value ({key}): {result}\")\n", + " print(f\"⏱️ Time elapsed ({key}): {elapsed:.3f} seconds\")\n", + "\n", + "# ----------------------------------------------------------\n", + "# 7. Cross-check: base vs BNT likelihoods\n", + "# ----------------------------------------------------------\n", + "print(\"\\nπŸ” Consistency checks: base vs BNT (same parameters)\")\n", + "\n", + "# mapping: pretty label -> (base key in like_tests, BNT key in like_tests_BNT)\n", + "pairs = {\n", + " \"WL\": (\"WL\", \"WL_BNT\"),\n", + " \"GC\": (\"GC\", \"GC\"), # same class, but we can still compare\n", + " \"3x2pt\": (\"3x2pt\", \"3x2pt_BNT\"),\n", + "}\n", + "\n", + "for label, (base_key, bnt_key) in pairs.items():\n", + " pars = default_pars.copy()\n", + "\n", + " ll_base = like_tests[base_key].loglike(pars)\n", + " ll_bnt = like_tests_BNT[bnt_key].loglike(pars)\n", + "\n", + " print(f\"\\nβ–Ά {label}:\")\n", + " print(f\" base loglike = {ll_base}\")\n", + " print(f\" BNT loglike = {ll_bnt}\")\n", + " print(f\" Ξ”loglike = {ll_bnt - ll_base}\")\n", + "\n", + " # Optional strict check (comment out if you just want to look)\n", + " assert np.allclose(ll_base, ll_bnt, rtol=0, atol=1e-5), (\n", + " f\"{label} base and BNT loglikes differ!\"\n", + " )" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "240e4449", + "id": "e2f80e72", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f04ce064", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "714bd298", "metadata": {}, "outputs": [], "source": [] @@ -506,7 +762,7 @@ ], "metadata": { "kernelspec": { - "display_name": "cloe-org-cloelike", + "display_name": "cloe", "language": "python", "name": "python3" }, @@ -520,7 +776,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.18" + "version": "3.10.19" } }, "nbformat": 4, From cbb5c94dd317f4d4029a278a3d8a595419d2a569 Mon Sep 17 00:00:00 2001 From: pltaylor16 Date: Fri, 14 Nov 2025 09:00:37 -0500 Subject: [PATCH 2/3] New BNTMatrixCalculator naming convention --- tutorials/likelihood/photometric_likelihoods.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorials/likelihood/photometric_likelihoods.ipynb b/tutorials/likelihood/photometric_likelihoods.ipynb index 1918221..bb340a9 100644 --- a/tutorials/likelihood/photometric_likelihoods.ipynb +++ b/tutorials/likelihood/photometric_likelihoods.ipynb @@ -555,7 +555,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "2e56ebb8", "metadata": {}, "outputs": [ @@ -597,7 +597,7 @@ } ], "source": [ - "from cloelib.auxiliary.bnt import BNT\n", + "from cloelib.auxiliary.bnt import BNTMatrixCalculator\n", "from cloelike.EuclidLikelihood_photo_Cls import (\n", " EuclidLikelihood_WL_BNT,\n", " EuclidLikelihood_GCph,\n", @@ -629,14 +629,14 @@ "# ----------------------------------------------------------\n", "# 2. Compute the BNT matrix using cloelib BNT\n", "# ----------------------------------------------------------\n", - "bnt_obj = BNT(\n", + "bnt_obj = BNTMatrixCalculator(\n", " dndz_list=my_dndz_she_norm, # (n_she_bins, n_z)\n", " z=myz, # same z-grid as used by likelihood\n", " fid_parameters=fid_bg_params,\n", " background=background_bnt,\n", ")\n", "\n", - "BNT_matrix = bnt_obj.get_matrix()\n", + "BNT_matrix = bnt_obj.get_bnt_matrix()\n", "# (for identity test, you could do: BNT_matrix = np.eye(my_dndz_she_norm.shape[0]))\n", "\n", "# ----------------------------------------------------------\n", From c46f9f908782f0ef679ca340aceff341bf7669df Mon Sep 17 00:00:00 2001 From: pltaylor16 Date: Tue, 18 Nov 2025 10:16:51 -0500 Subject: [PATCH 3/3] Updated BNT code to match cloelib --- tutorials/likelihood/photometric_likelihoods.ipynb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tutorials/likelihood/photometric_likelihoods.ipynb b/tutorials/likelihood/photometric_likelihoods.ipynb index bb340a9..d4223a1 100644 --- a/tutorials/likelihood/photometric_likelihoods.ipynb +++ b/tutorials/likelihood/photometric_likelihoods.ipynb @@ -630,14 +630,13 @@ "# 2. Compute the BNT matrix using cloelib BNT\n", "# ----------------------------------------------------------\n", "bnt_obj = BNTMatrixCalculator(\n", - " dndz_list=my_dndz_she_norm, # (n_she_bins, n_z)\n", - " z=myz, # same z-grid as used by likelihood\n", - " fid_parameters=fid_bg_params,\n", + " dndz_list=my_dndz_she_norm, \n", + " z=myz, \n", " background=background_bnt,\n", ")\n", "\n", "BNT_matrix = bnt_obj.get_bnt_matrix()\n", - "# (for identity test, you could do: BNT_matrix = np.eye(my_dndz_she_norm.shape[0]))\n", + "\n", "\n", "# ----------------------------------------------------------\n", "# 3. Build BNT-enabled data dictionaries\n", @@ -696,7 +695,7 @@ " label = labels_pretty_BNT[key]\n", " print(f\"\\nπŸ“Š {label} loglike:\")\n", "\n", - " pars = default_pars.copy() # freeze parameters\n", + " pars = default_pars.copy() \n", " start = time.time()\n", " result = like_tests_BNT[key].loglike(pars)\n", " elapsed = time.time() - start\n", @@ -711,10 +710,10 @@ "# ----------------------------------------------------------\n", "print(\"\\nπŸ” Consistency checks: base vs BNT (same parameters)\")\n", "\n", - "# mapping: pretty label -> (base key in like_tests, BNT key in like_tests_BNT)\n", + "\n", "pairs = {\n", " \"WL\": (\"WL\", \"WL_BNT\"),\n", - " \"GC\": (\"GC\", \"GC\"), # same class, but we can still compare\n", + " \"GC\": (\"GC\", \"GC\"), \n", " \"3x2pt\": (\"3x2pt\", \"3x2pt_BNT\"),\n", "}\n", "\n", @@ -729,7 +728,6 @@ " print(f\" BNT loglike = {ll_bnt}\")\n", " print(f\" Ξ”loglike = {ll_bnt - ll_base}\")\n", "\n", - " # Optional strict check (comment out if you just want to look)\n", " assert np.allclose(ll_base, ll_bnt, rtol=0, atol=1e-5), (\n", " f\"{label} base and BNT loglikes differ!\"\n", " )"