def test_min_sorted(jla_full_paths, ref_ev): binned_sn_sorted = libsncompress.BinnedSN(*jla_full_paths, sort_by_z=True) ev = libsncompress.CovEvaluator(binned_sn_sorted) ev.minimize() assert ev.res.success assert numpy.allclose(ref_ev.res.x, ev.res.x) assert numpy.allclose(ref_ev.compressed_cov, ev.compressed_cov)
def test_min_alter_x0(ref_binned_sn, ref_ev): ev = libsncompress.CovEvaluator(ref_binned_sn) x0 = numpy.zeros(3 + ref_binned_sn.bins.ncontrolpoints) x0[3:] = 10.0 ev.minimize(x0=x0) assert ev.res.success assert veryclose_p(ref_ev, ev)
def test_min_method_powell(ref_binned_sn, ref_ev): ev = libsncompress.CovEvaluator(ref_binned_sn) ev.minimize(method="Powell", jac=lambda x: None, hess=lambda x: None, options=dict(xtol=5e-3, ftol=5e-3)) assert ev.res.success
def test_min_onebigbin(jla_full_paths): binned_sn_1b = libsncompress.BinnedSN(*jla_full_paths, logbins=[[-2.0, numpy.log10(1.3)]]) ev = libsncompress.CovEvaluator(binned_sn_1b) ev.minimize() # This is a garbage-in case, but we should at least converge to the # outgarbage. assert ev.res.success # The output should at least have some basic properties, bad as it is. assert ev.res.x[-1] >= ev.res.x[-2]
def test_min_alter_scalings(ref_binned_sn, ref_ev): ev = libsncompress.CovEvaluator(ref_binned_sn) xs = numpy.ones(3 + ref_binned_sn.bins.ncontrolpoints) ev.minimize(xscalings=xs) assert ev.res.success assert veryclose_p(ref_ev, ev)
def test_min_method_trust_regions(ref_binned_sn, ref_ev, method): ev = libsncompress.CovEvaluator(ref_binned_sn) ev.minimize(method=method) assert ev.res.success assert veryclose_p(ref_ev, ev)
def test_min_method_bfgs(ref_binned_sn, ref_ev): ev = libsncompress.CovEvaluator(ref_binned_sn) # BFGS does not use Hessian at all, we can even pass in garbage ev.minimize(method="bfgs", hess=lambda x: None, options=dict(gtol=1e-6)) assert ev.res.success assert veryclose_p(ref_ev, ev)
def test_min_method_newton_cg(ref_binned_sn, ref_ev): ev = libsncompress.CovEvaluator(ref_binned_sn) ev.minimize(method="Newton-CG", options=dict(xtol=1e-7)) assert ev.res.success assert veryclose_p(ref_ev, ev)
def test_unready_evaluator(ref_binned_sn): ev = libsncompress.CovEvaluator(ref_binned_sn) assert ev.res is None with pytest.raises(ValueError): _ = ev.compressed_cov
def ref_ev_nologdet(ref_binned_sn): ev = libsncompress.CovEvaluator(ref_binned_sn, withlogdet=False) ev.minimize() assert ev.res.success return ev
def ref_ev(ref_binned_sn): ev = libsncompress.CovEvaluator(ref_binned_sn) ev.minimize() assert ev.res.success return ev