jiwoncpark / h0rton

Deep Modeling of Strong Gravitational Time Delay Lenses for Bayesian Inference of the Hubble Constant
MIT License
10 stars 1 forks source link

Use MCMC for the default BNN #29

Closed jiwoncpark closed 4 years ago

jiwoncpark commented 4 years ago

Simple MC sampling may be inefficient for the default BNN method.

jiwoncpark commented 4 years ago

Profiling infer_h0_default_mcmc.py shows that evaluation of logL is still the problem:

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001   96.802   96.802 infer_h0_mcmc.py:26(main)
        1    0.000    0.000   85.773   85.773 fitting_sequence.py:49(fit_sequence)
        1    0.000    0.000   85.773   85.773 fitting_sequence.py:188(mcmc)
        1    0.000    0.000   85.767   85.767 sampler.py:114(mcmc_emcee)
        1    0.000    0.000   85.765   85.765 ensemble.py:360(run_mcmc)
        4    0.000    0.000   85.765   21.441 ensemble.py:199(sample)
        7    0.001    0.000   85.761   12.252 ensemble.py:392(compute_log_prob)
      440    0.002    0.000   85.759    0.195 ensemble.py:543(__call__)
      440    0.002    0.000   85.757    0.195 likelihood.py:140(logL)
      440    0.007    0.000   85.696    0.195 likelihood.py:153(log_likelihood)
      440    0.004    0.000   85.486    0.194 time_delay_likelihood.py:29(logL)
      440    0.002    0.000   85.360    0.194 point_source.py:135(image_position)
      440    0.002    0.000   85.358    0.194 point_source_types.py:211(image_position)
      440    0.002    0.000   85.357    0.194 point_source_types.py:130(image_position)
      440    0.165    0.000   85.353    0.194 lens_equation_solver.py:72(image_position_from_source)
        3    0.001    0.000   66.204   22.068 red_blue.py:52(propose)
      440   42.329    0.096   42.336    0.096 util.py:395(neighborSelect)
    12784    0.320    0.000   40.293    0.003 single_plane.py:12(ray_shooting)
    11904    0.013    0.000   40.227    0.003 lens_model.py:61(ray_shooting)
    12784    0.597    0.000   39.973    0.003 single_plane.py:66(alpha)
    12784    0.020    0.000   37.980    0.003 spemd.py:43(derivatives)
    12784    0.723    0.000   37.960    0.003 spemd_smooth.py:72(derivatives)
    12784   35.901    0.003   35.920    0.003 fastell4py.py:39(fastelldefl)

(compute_log_prob being the culprit)

sibirrer commented 4 years ago

Hi Ji Won, it looks like neighborSelect is accounting for almost 50% of the run time. This is effectively a grid based search for minima in the first step of the lens equation solver. This part 'could' be improved or the numerical precision of the solver could be reduced. fastell4py is not really improvable at the moment but maybe the number of calls thereof.

jiwoncpark commented 4 years ago

Increasing min_distance and decreasing search_window sped up sampling to ~2s/iter from 20s/iter!