import%20marimo%0A%0A__generated_with%20%3D%20%220.19.11%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Load%20Hyperfit%20functions%20and%20interpolator%0A%0A%20%20%20%20(Please%20update%20to%20the%20latest%20version%20of%20%60jaxqualin%60%20to%20avoid%20errors!)%0A%0A%20%20%20%20In%20this%20example%20we%20will%20call%20the%20hyperfit%20functions%20(listed%20in%20the%20%60jaxqualin%60%20paper)%20and%20corresponding%20interpolators%20to%20estimate%20the%20amplitudes%20and%20phases%20of%20different%20modes%2C%20as%20a%20function%20of%20the%20binary%20black%20hole%20simulation%20parameters.%0A%20%20%20%20The%20hyperfit%20polynomial%20terms%20and%20interpolation%20data%20might%20be%20updated%20in%20future%20versions%20of%20the%20paper.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Import%20functions%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20jaxqualin.data%20import%20(download_hyperfit_data%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20download_interpolate_data%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20make_hyper_fit_functions%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20make_interpolators)%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20download_hyperfit_data%2C%0A%20%20%20%20%20%20%20%20download_interpolate_data%2C%0A%20%20%20%20%20%20%20%20make_hyper_fit_functions%2C%0A%20%20%20%20%20%20%20%20make_interpolators%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Download%20data%0A%0A%20%20%20%20By%20default%2C%20the%20download%20functions%20compares%20the%20local%20version%20of%20the%20data%20with%20the%20one%20hosted%20on%20this%20webpage.%0A%20%20%20%20If%20the%20online%20one%20is%20newer%2C%20it%20will%20be%20downloaded%20and%20the%20local%20version%20will%20be%20overriden.%0A%20%20%20%20Use%20%60overwrite%20%3D%20'force'%60%20to%20force%20overwrite%2C%20and%20%60never%60%20to%20avoid%20overwriting.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(download_hyperfit_data%2C%20download_interpolate_data)%3A%0A%20%20%20%20download_hyperfit_data()%0A%20%20%20%20download_interpolate_data()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Make%20hyperfit%20functions%20and%20interpolators%0A%0A%20%20%20%20Now%20we%20convert%20the%20downloaded%20data%20into%20functions%20and%20interpolators%20that%20we%20can%20easily%20call.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(make_hyper_fit_functions%2C%20make_interpolators)%3A%0A%20%20%20%20hyperfit_functions%20%3D%20make_hyper_fit_functions()%0A%20%20%20%20hyper_interpolators%20%3D%20make_interpolators()%0A%20%20%20%20return%20hyper_interpolators%2C%20hyperfit_functions%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Estimating%20the%20amplitude%20and%20phase%0A%0A%20%20%20%20We%20can%20estimate%20the%20amplitude%20and%20phase%20for%20a%20set%20of%20progenitor%20parameters%20%24(%5Ceta%2C%20%5Cchi_%2B%2C%20%5Cchi_-)%24.%0A%20%20%20%20All%20is%20well%20if%20the%20hyperfit%20and%20interpolation%20returns%20similar%20results.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(hyper_interpolators%2C%20hyperfit_functions)%3A%0A%20%20%20%20mode_name%20%3D%20'2.2.1'%0A%20%20%20%20eta%2C%20chi_p%2C%20chi_m%20%3D%20(0.2%2C%200.1%2C%200.4)%0A%20%20%20%20_A_fit%20%3D%20hyperfit_functions%5Bmode_name%5D%5B'A'%5D(eta%2C%20chi_p%2C%20chi_m)%0A%20%20%20%20_A_interp%20%3D%20hyper_interpolators%5Bmode_name%5D%5B'A'%5D(eta%2C%20chi_p%2C%20chi_m)%0A%20%20%20%20_phi_fit%20%3D%20hyperfit_functions%5Bmode_name%5D%5B'phi'%5D(eta%2C%20chi_p%2C%20chi_m)%0A%20%20%20%20_phi_interp%20%3D%20hyper_interpolators%5Bmode_name%5D%5B'phi'%5D(eta%2C%20chi_p%2C%20chi_m)%0A%20%20%20%20print(f'A_fit%3A%20%7B_A_fit%3A.5f%7D%2C%20A_interp%3A%20%7B_A_interp%3A.5f%7D')%0A%20%20%20%20print(f'phi_fit%3A%20%7B_phi_fit%3A.5f%7D%2C%20phi_interp%3A%20%7B_phi_interp%3A.5f%7D')%0A%20%20%20%20return%20(mode_name%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20interpolator%20returns%20%60nan%60%20if%20the%20requested%20point%20is%20outside%20of%20the%20convex%20hull%20of%20the%20interpolation%20data.%0A%20%20%20%20This%20can%20be%20used%20to%20check%20whether%20the%20hyperfit%20is%20extrapolating%20at%20the%20point%2C%20because%20the%20fit%20is%20trained%20with%20the%20same%20data%20used%20to%20construct%20the%20interpolator.%0A%20%20%20%20If%20the%20point%20is%20not%20covered%20by%20the%20convex%20hull%2C%20it%20could%20be%20because%20no%20simulations%20in%20the%20SXS%20catalog%20cover%20that%20region%20of%20the%20parameter%20space%2C%20or%20the%20mode%20amplitude%20is%20too%20weak%20(such%20that%20the%20mode%20extraction%20procedure%20missed%20the%20mode).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(hyper_interpolators%2C%20hyperfit_functions%2C%20mode_name)%3A%0A%20%20%20%20eta_1%2C%20chi_p_1%2C%20chi_m_1%20%3D%20(0.1%2C%200.9%2C%20-0.9)%0A%20%20%20%20_A_fit%20%3D%20hyperfit_functions%5Bmode_name%5D%5B'A'%5D(eta_1%2C%20chi_p_1%2C%20chi_m_1)%0A%20%20%20%20_A_interp%20%3D%20hyper_interpolators%5Bmode_name%5D%5B'A'%5D(eta_1%2C%20chi_p_1%2C%20chi_m_1)%0A%20%20%20%20_phi_fit%20%3D%20hyperfit_functions%5Bmode_name%5D%5B'phi'%5D(eta_1%2C%20chi_p_1%2C%20chi_m_1)%0A%20%20%20%20_phi_interp%20%3D%20hyper_interpolators%5Bmode_name%5D%5B'phi'%5D(eta_1%2C%20chi_p_1%2C%20chi_m_1)%0A%20%20%20%20print(f'A_fit%3A%20%7B_A_fit%3A.5f%7D%2C%20A_interp%3A%20%7B_A_interp%3A.5f%7D')%0A%20%20%20%20print(f'phi_fit%3A%20%7B_phi_fit%3A.5f%7D%2C%20phi_interp%3A%20%7B_phi_interp%3A.5f%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20When%20the%20hyperfit%20and%20interpolation%20returns%20significantly%20different%20results%2C%20care%20should%20be%20taken.%0A%20%20%20%20The%20mode%20amplitude%20might%20be%20too%20small%20for%20the%20hyperfit%20to%20work%20accurately%2C%20and%20the%20results%20in%20these%20regions%20of%20parameter%20space%20should%20at%20most%20be%20used%20as%20an%20order%20of%20magnitude%20estimation.%0A%20%20%20%20In%20fact%2C%20the%20hyperfit%20amplitude%20could%20even%20be%20negative%2C%20if%20the%20mode%20amplitude%20is%20too%20low.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(hyper_interpolators%2C%20hyperfit_functions)%3A%0A%20%20%20%20mode_name_1%20%3D%20'-2.2.0'%0A%20%20%20%20eta_2%2C%20chi_p_2%2C%20chi_m_2%20%3D%20(0.2%2C%20-0.1%2C%200.4)%0A%20%20%20%20_A_fit%20%3D%20hyperfit_functions%5Bmode_name_1%5D%5B'A'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20_A_interp%20%3D%20hyper_interpolators%5Bmode_name_1%5D%5B'A'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20_phi_fit%20%3D%20hyperfit_functions%5Bmode_name_1%5D%5B'phi'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20_phi_interp%20%3D%20hyper_interpolators%5Bmode_name_1%5D%5B'phi'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20print(f'A_fit%3A%20%7B_A_fit%3A.5e%7D%2C%20A_interp%3A%20%7B_A_interp%3A.5e%7D')%0A%20%20%20%20print(f'phi_fit%3A%20%7B_phi_fit%3A.5f%7D%2C%20phi_interp%3A%20%7B_phi_interp%3A.5f%7D')%0A%20%20%20%20return%20chi_m_2%2C%20chi_p_2%2C%20eta_2%2C%20mode_name_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20We%20can%20also%20interpolate%20the%20fluctuation%20of%20the%20mode%20amplitude%20and%20phase%20when%20they%20were%20extracted%20with%20our%20procedure%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(chi_m_2%2C%20chi_p_2%2C%20eta_2%2C%20hyper_interpolators%2C%20mode_name_1)%3A%0A%20%20%20%20dA_interp%20%3D%20hyper_interpolators%5Bmode_name_1%5D%5B'dA'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20dphi_interp%20%3D%20hyper_interpolators%5Bmode_name_1%5D%5B'dphi'%5D(eta_2%2C%20chi_p_2%2C%20chi_m_2)%0A%20%20%20%20print(f'dA_interp%3A%20%7BdA_interp%3A.5e%7D%2C%20dphi_interp%3A%20%7Bdphi_interp%3A.5f%7D')%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Changing%20parameterization%0A%0A%20%20%20%20By%20specifying%20%60PN%20%3D%20False%60%2C%20we%20can%20use%20the%20%24(q%2C%20%5Cchi_1%2C%20%5Cchi_2)%24%20parameterization%20instead%20of%20%24(%5Ceta%2C%20%5Cchi_%2B%2C%20%5Cchi_-)%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(make_hyper_fit_functions%2C%20make_interpolators)%3A%0A%20%20%20%20hyperfit_functions_1%20%3D%20make_hyper_fit_functions(PN%3DFalse)%0A%20%20%20%20hyper_interpolators_1%20%3D%20make_interpolators(PN%3DFalse)%0A%20%20%20%20return%20hyper_interpolators_1%2C%20hyperfit_functions_1%0A%0A%0A%40app.cell%0Adef%20_(hyper_interpolators_1%2C%20hyperfit_functions_1)%3A%0A%20%20%20%20mode_name_2%20%3D%20'2.2.1'%0A%20%20%20%20q%2C%20chi_1%2C%20chi_2%20%3D%20(2.3%2C%200.2%2C%20-0.2)%0A%20%20%20%20_A_fit%20%3D%20hyperfit_functions_1%5Bmode_name_2%5D%5B'A'%5D(q%2C%20chi_1%2C%20chi_2)%0A%20%20%20%20_A_interp%20%3D%20hyper_interpolators_1%5Bmode_name_2%5D%5B'A'%5D(q%2C%20chi_1%2C%20chi_2)%0A%20%20%20%20_phi_fit%20%3D%20hyperfit_functions_1%5Bmode_name_2%5D%5B'phi'%5D(q%2C%20chi_1%2C%20chi_2)%0A%20%20%20%20_phi_interp%20%3D%20hyper_interpolators_1%5Bmode_name_2%5D%5B'phi'%5D(q%2C%20chi_1%2C%20chi_2)%0A%20%20%20%20print(f'A_fit%3A%20%7B_A_fit%3A.5f%7D%2C%20A_interp%3A%20%7B_A_interp%3A.5f%7D')%0A%20%20%20%20print(f'phi_fit%3A%20%7B_phi_fit%3A.5f%7D%2C%20phi_interp%3A%20%7B_phi_interp%3A.5f%7D')%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
680cb66e51be413b943ccccf74c12b3f