diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 989d8c25..64a36fc0 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-11-23T00:22:04","documenter_version":"1.8.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-11-24T00:24:37","documenter_version":"1.8.0"}} \ No newline at end of file diff --git a/dev/examples/initializing-hmc/cf96fdb7.svg b/dev/examples/initializing-hmc/1713e8ec.svg similarity index 69% rename from dev/examples/initializing-hmc/cf96fdb7.svg rename to dev/examples/initializing-hmc/1713e8ec.svg index 371c64aa..c87cd1fe 100644 --- a/dev/examples/initializing-hmc/cf96fdb7.svg +++ b/dev/examples/initializing-hmc/1713e8ec.svg @@ -1,141 +1,141 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/examples/initializing-hmc/index.html b/dev/examples/initializing-hmc/index.html index 7e081e99..15bb18da 100644 --- a/dev/examples/initializing-hmc/index.html +++ b/dev/examples/initializing-hmc/index.html @@ -6,7 +6,7 @@ x = 0:0.01:1 y = @. sin(10x) + randn() * 0.2 + x -scatter(x, y; xlabel="x", ylabel="y", legend=false, msw=0, ms=2)Example block output

We'll fit this using a simple polynomial regression model:

\[\begin{aligned} +scatter(x, y; xlabel="x", ylabel="y", legend=false, msw=0, ms=2)Example block output

We'll fit this using a simple polynomial regression model:

\[\begin{aligned} \sigma &\sim \text{Half-Normal}(\mu=0, \sigma=1)\\ \alpha, \beta_j &\sim \mathrm{Normal}(\mu=0, \sigma=1)\\ \hat{y}_i &= \alpha + \sum_{j=1}^J x_i^j \beta_j\\ @@ -134,4 +134,4 @@ nadapts; drop_warmup=true, progress=false, -)

([[-0.2527388088852728, 0.17208012699750494, 0.2952584936465345, 0.022320068103348634, 0.15733575613528494], [-0.4291377134539547, 0.32920513736825285, 0.4393892488007558, -0.0013200027011879278, 0.12258003572248383], [-0.26001217742047933, 0.15318182286726076, 0.09201227904075221, 1.6526601688816887, -0.7518870811979403], [-0.3155436513687605, -0.07998549561625119, 0.6051193124268837, -0.5513730052747756, 0.6328849786592662], [-0.2661332913313262, -0.13712984516614357, 0.5149913494112253, -0.3012780402723181, 0.5497272872853781], [-0.22215648646250585, 0.14331381776470486, 0.3672360499575149, 0.09222757546176336, 0.17784971126504545], [-0.2915732506855215, 0.13630978100186972, 0.7166718756613559, -1.5679400391247573, 1.2013957899252157], [-0.37987489735390434, 0.09441089965302114, -0.005856445119694742, -1.7669976761242954, 1.5021189630490048], [-0.36848708101523586, 0.11024118611250996, 0.20064485677944982, 1.4980326696396744, -0.7893281756963201], [-0.493791079519271, 0.38354181140226445, 0.5781455885728157, -0.1908567677105213, 0.13789219645054585]  …  [-0.17490736182536634, 0.12978027511029805, 1.7563948998902064, -0.6258320715159139, 0.2545713096188753], [-0.22008437130092529, 0.06035052678847744, 2.3213092144480676, -0.9865270787613014, 0.33159670390632734], [-0.32531258068535274, 0.03470187710029662, 0.7424389257389611, 0.2005961339483665, -0.03076543093762596], [-0.3060455151009557, 0.35466336316635066, 0.456007030648103, 1.3776087300218438, -0.7938605613689966], [-0.3963760453216015, 0.14904832572424143, 0.881242775769902, -1.0458455740128305, 0.6677602549323026], [-0.26298562354650795, 0.2987678107909115, 0.1489465799270607, -0.49949266397200365, 0.5776019009846981], [-0.4364036232907639, 0.24159281172976876, -1.0758712438719928, 0.5684848433644487, 0.27242714627248477], [-0.3507538932954303, 0.1193680086172931, -1.033366394540409, 0.3184873648953528, 0.44861709632980806], [-0.5004509888714077, 0.44079917750099606, -0.9223444311776047, -0.3205539046575383, 0.7067786708158721], [-0.14769846606332743, 0.05859371997690402, -1.2941895126042766, 1.1066668181469903, 0.04985178354923539]], NamedTuple[(n_steps = 7, is_accept = true, acceptance_rate = 0.8760332522622697, log_density = -113.52733133342548, hamiltonian_energy = 115.85739868389065, hamiltonian_energy_error = -0.06182447511865519, max_hamiltonian_energy_error = 0.26543666254804066, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 27, is_accept = true, acceptance_rate = 0.9858019138894797, log_density = -113.48500877948257, hamiltonian_energy = 114.5703562976834, hamiltonian_energy_error = 0.017863263965594456, max_hamiltonian_energy_error = -0.16204274869353696, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 7, is_accept = true, acceptance_rate = 0.4724630505109441, log_density = -115.65995231186191, hamiltonian_energy = 119.46668216430464, hamiltonian_energy_error = 0.614371741812306, max_hamiltonian_energy_error = 1.2561289467941776, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 31, is_accept = true, acceptance_rate = 0.996561839426301, log_density = -115.60223605427826, hamiltonian_energy = 117.88016018368306, hamiltonian_energy_error = -0.03397291414280801, max_hamiltonian_energy_error = -0.3202962841468775, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.947636115057466, log_density = -117.17589956576387, hamiltonian_energy = 118.12572720710554, hamiltonian_energy_error = 0.17089705147913037, max_hamiltonian_energy_error = -0.8237253260316777, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.9723237920918238, log_density = -114.24688410273087, hamiltonian_energy = 117.88183561301392, hamiltonian_energy_error = -0.400823278166456, max_hamiltonian_energy_error = -0.5519515652853215, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.7182668669710662, log_density = -116.13402003886873, hamiltonian_energy = 117.73014161656154, hamiltonian_energy_error = 0.4150879491173072, max_hamiltonian_energy_error = 0.4150879491173072, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 27, is_accept = true, acceptance_rate = 0.9963872327824952, log_density = -115.6709924532715, hamiltonian_energy = 118.77036353271669, hamiltonian_energy_error = -0.2167908457387142, max_hamiltonian_energy_error = -0.4312459887147213, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 39, is_accept = true, acceptance_rate = 0.928918428585088, log_density = -115.32821256554415, hamiltonian_energy = 119.79091199125762, hamiltonian_energy_error = -0.065616000936501, max_hamiltonian_energy_error = 0.28057853294632196, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 31, is_accept = true, acceptance_rate = 0.9531250659445826, log_density = -115.1341003614533, hamiltonian_energy = 117.97502728480856, hamiltonian_energy_error = -0.09197827052622642, max_hamiltonian_energy_error = 0.13546838454789167, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false)  …  (n_steps = 3, is_accept = true, acceptance_rate = 0.7458022550322915, log_density = -118.72354235333272, hamiltonian_energy = 121.26500194465272, hamiltonian_energy_error = 0.33027560593130545, max_hamiltonian_energy_error = 0.6564659506890251, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 15, is_accept = true, acceptance_rate = 0.994363299329306, log_density = -119.19540623223247, hamiltonian_energy = 122.41313663497087, hamiltonian_energy_error = -0.043231690232758524, max_hamiltonian_energy_error = -0.5308886451997523, tree_depth = 3, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 43, is_accept = true, acceptance_rate = 0.9866384032472298, log_density = -113.73899223343896, hamiltonian_energy = 119.88450884422788, hamiltonian_energy_error = -0.6825097915696574, max_hamiltonian_energy_error = -0.7362172408297312, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.8552913971515622, log_density = -114.8533306625371, hamiltonian_energy = 115.85155095370388, hamiltonian_energy_error = 0.2533504997957863, max_hamiltonian_energy_error = 0.2533504997957863, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 7, is_accept = true, acceptance_rate = 0.9970629526698467, log_density = -114.75743755648226, hamiltonian_energy = 115.25064120563096, hamiltonian_energy_error = 0.020773616490942004, max_hamiltonian_energy_error = -0.429409959493654, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 43, is_accept = true, acceptance_rate = 0.8476040522972915, log_density = -113.75729018165242, hamiltonian_energy = 120.6941341365927, hamiltonian_energy_error = -0.20165815065332993, max_hamiltonian_energy_error = 0.5448746223740955, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 39, is_accept = true, acceptance_rate = 0.987812934971051, log_density = -113.70314936044402, hamiltonian_energy = 115.22660485421288, hamiltonian_energy_error = -0.14718026758713165, max_hamiltonian_energy_error = -0.1891450656758309, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.8994347705037488, log_density = -113.26163153307867, hamiltonian_energy = 114.67505222756724, hamiltonian_energy_error = -0.03603071070953945, max_hamiltonian_energy_error = 0.1741619501261482, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.5864229086241388, log_density = -116.61130583106993, hamiltonian_energy = 117.58384196707065, hamiltonian_energy_error = 0.7262788052466504, max_hamiltonian_energy_error = 0.7262788052466504, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.7920594933971575, log_density = -117.81654728806015, hamiltonian_energy = 119.7676456911751, hamiltonian_energy_error = 0.36010150070316627, max_hamiltonian_energy_error = -0.5722561419494951, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false)])
+)
([[-0.2527388088852728, 0.17208012699750494, 0.2952584936465345, 0.022320068103348634, 0.15733575613528494], [-0.4291377134539547, 0.32920513736825285, 0.4393892488007558, -0.0013200027011879278, 0.12258003572248383], [-0.26001217742047933, 0.15318182286726076, 0.09201227904075221, 1.6526601688816887, -0.7518870811979403], [-0.3155436513687605, -0.07998549561625119, 0.6051193124268837, -0.5513730052747756, 0.6328849786592662], [-0.2661332913313262, -0.13712984516614357, 0.5149913494112253, -0.3012780402723181, 0.5497272872853781], [-0.22215648646250585, 0.14331381776470486, 0.3672360499575149, 0.09222757546176336, 0.17784971126504545], [-0.2915732506855215, 0.13630978100186972, 0.7166718756613559, -1.5679400391247573, 1.2013957899252157], [-0.37987489735390434, 0.09441089965302114, -0.005856445119694742, -1.7669976761242954, 1.5021189630490048], [-0.36848708101523586, 0.11024118611250996, 0.20064485677944982, 1.4980326696396744, -0.7893281756963201], [-0.493791079519271, 0.38354181140226445, 0.5781455885728157, -0.1908567677105213, 0.13789219645054585]  …  [-0.17490736182536634, 0.12978027511029805, 1.7563948998902064, -0.6258320715159139, 0.2545713096188753], [-0.22008437130092529, 0.06035052678847744, 2.3213092144480676, -0.9865270787613014, 0.33159670390632734], [-0.32531258068535274, 0.03470187710029662, 0.7424389257389611, 0.2005961339483665, -0.03076543093762596], [-0.3060455151009557, 0.35466336316635066, 0.456007030648103, 1.3776087300218438, -0.7938605613689966], [-0.3963760453216015, 0.14904832572424143, 0.881242775769902, -1.0458455740128305, 0.6677602549323026], [-0.26298562354650795, 0.2987678107909115, 0.1489465799270607, -0.49949266397200365, 0.5776019009846981], [-0.4364036232907639, 0.24159281172976876, -1.0758712438719928, 0.5684848433644487, 0.27242714627248477], [-0.3507538932954303, 0.1193680086172931, -1.033366394540409, 0.3184873648953528, 0.44861709632980806], [-0.5004509888714077, 0.44079917750099606, -0.9223444311776047, -0.3205539046575383, 0.7067786708158721], [-0.14769846606332743, 0.05859371997690402, -1.2941895126042766, 1.1066668181469903, 0.04985178354923539]], NamedTuple[(n_steps = 7, is_accept = true, acceptance_rate = 0.8760332522622697, log_density = -113.52733133342548, hamiltonian_energy = 115.85739868389065, hamiltonian_energy_error = -0.06182447511865519, max_hamiltonian_energy_error = 0.26543666254804066, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 27, is_accept = true, acceptance_rate = 0.9858019138894797, log_density = -113.48500877948257, hamiltonian_energy = 114.5703562976834, hamiltonian_energy_error = 0.017863263965594456, max_hamiltonian_energy_error = -0.16204274869353696, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 7, is_accept = true, acceptance_rate = 0.4724630505109441, log_density = -115.65995231186191, hamiltonian_energy = 119.46668216430464, hamiltonian_energy_error = 0.614371741812306, max_hamiltonian_energy_error = 1.2561289467941776, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 31, is_accept = true, acceptance_rate = 0.996561839426301, log_density = -115.60223605427826, hamiltonian_energy = 117.88016018368306, hamiltonian_energy_error = -0.03397291414280801, max_hamiltonian_energy_error = -0.3202962841468775, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.947636115057466, log_density = -117.17589956576387, hamiltonian_energy = 118.12572720710554, hamiltonian_energy_error = 0.17089705147913037, max_hamiltonian_energy_error = -0.8237253260316777, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.9723237920918238, log_density = -114.24688410273087, hamiltonian_energy = 117.88183561301392, hamiltonian_energy_error = -0.400823278166456, max_hamiltonian_energy_error = -0.5519515652853215, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.7182668669710662, log_density = -116.13402003886873, hamiltonian_energy = 117.73014161656154, hamiltonian_energy_error = 0.4150879491173072, max_hamiltonian_energy_error = 0.4150879491173072, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 27, is_accept = true, acceptance_rate = 0.9963872327824952, log_density = -115.6709924532715, hamiltonian_energy = 118.77036353271669, hamiltonian_energy_error = -0.2167908457387142, max_hamiltonian_energy_error = -0.4312459887147213, tree_depth = 4, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 39, is_accept = true, acceptance_rate = 0.928918428585088, log_density = -115.32821256554415, hamiltonian_energy = 119.79091199125762, hamiltonian_energy_error = -0.065616000936501, max_hamiltonian_energy_error = 0.28057853294632196, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 31, is_accept = true, acceptance_rate = 0.9531250659445826, log_density = -115.1341003614533, hamiltonian_energy = 117.97502728480856, hamiltonian_energy_error = -0.09197827052622642, max_hamiltonian_energy_error = 0.13546838454789167, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false)  …  (n_steps = 3, is_accept = true, acceptance_rate = 0.7458022550322915, log_density = -118.72354235333272, hamiltonian_energy = 121.26500194465272, hamiltonian_energy_error = 0.33027560593130545, max_hamiltonian_energy_error = 0.6564659506890251, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 15, is_accept = true, acceptance_rate = 0.994363299329306, log_density = -119.19540623223247, hamiltonian_energy = 122.41313663497087, hamiltonian_energy_error = -0.043231690232758524, max_hamiltonian_energy_error = -0.5308886451997523, tree_depth = 3, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 43, is_accept = true, acceptance_rate = 0.9866384032472298, log_density = -113.73899223343896, hamiltonian_energy = 119.88450884422788, hamiltonian_energy_error = -0.6825097915696574, max_hamiltonian_energy_error = -0.7362172408297312, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.8552913971515622, log_density = -114.8533306625371, hamiltonian_energy = 115.85155095370388, hamiltonian_energy_error = 0.2533504997957863, max_hamiltonian_energy_error = 0.2533504997957863, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 7, is_accept = true, acceptance_rate = 0.9970629526698467, log_density = -114.75743755648226, hamiltonian_energy = 115.25064120563096, hamiltonian_energy_error = 0.020773616490942004, max_hamiltonian_energy_error = -0.429409959493654, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 43, is_accept = true, acceptance_rate = 0.8476040522972915, log_density = -113.75729018165242, hamiltonian_energy = 120.6941341365927, hamiltonian_energy_error = -0.20165815065332993, max_hamiltonian_energy_error = 0.5448746223740955, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 39, is_accept = true, acceptance_rate = 0.987812934971051, log_density = -113.70314936044402, hamiltonian_energy = 115.22660485421288, hamiltonian_energy_error = -0.14718026758713165, max_hamiltonian_energy_error = -0.1891450656758309, tree_depth = 5, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.8994347705037488, log_density = -113.26163153307867, hamiltonian_energy = 114.67505222756724, hamiltonian_energy_error = -0.03603071070953945, max_hamiltonian_energy_error = 0.1741619501261482, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.5864229086241388, log_density = -116.61130583106993, hamiltonian_energy = 117.58384196707065, hamiltonian_energy_error = 0.7262788052466504, max_hamiltonian_energy_error = 0.7262788052466504, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false), (n_steps = 3, is_accept = true, acceptance_rate = 0.7920594933971575, log_density = -117.81654728806015, hamiltonian_energy = 119.7676456911751, hamiltonian_energy_error = 0.36010150070316627, max_hamiltonian_energy_error = -0.5722561419494951, tree_depth = 2, numerical_error = false, step_size = 0.9357093479683786, nom_step_size = 0.9357093479683786, is_adapt = false)])
diff --git a/dev/examples/quickstart/127cb37c.svg b/dev/examples/quickstart/430db631.svg similarity index 92% rename from dev/examples/quickstart/127cb37c.svg rename to dev/examples/quickstart/430db631.svg index 789bd4be..03c1c0b0 100644 --- a/dev/examples/quickstart/127cb37c.svg +++ b/dev/examples/quickstart/430db631.svg @@ -1,92 +1,92 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/examples/quickstart/50ba1252.svg b/dev/examples/quickstart/7c351ee5.svg similarity index 69% rename from dev/examples/quickstart/50ba1252.svg rename to dev/examples/quickstart/7c351ee5.svg index c6967c1e..98742237 100644 --- a/dev/examples/quickstart/50ba1252.svg +++ b/dev/examples/quickstart/7c351ee5.svg @@ -1,1092 +1,1092 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/examples/quickstart/c64ceb58.svg b/dev/examples/quickstart/ae89033d.svg similarity index 87% rename from dev/examples/quickstart/c64ceb58.svg rename to dev/examples/quickstart/ae89033d.svg index baaded9d..9ed6959d 100644 --- a/dev/examples/quickstart/c64ceb58.svg +++ b/dev/examples/quickstart/ae89033d.svg @@ -1,1103 +1,1103 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/examples/quickstart/index.html b/dev/examples/quickstart/index.html index 68eb8027..f9a90e4d 100644 --- a/dev/examples/quickstart/index.html +++ b/dev/examples/quickstart/index.html @@ -104,7 +104,7 @@ prob_banana = BananaProblem()

and then visualise it:

xrange = -3.5:0.05:3.5
 yrange = -3:0.05:7
 logp_banana(x) = LogDensityProblems.logdensity(prob_banana, x)
-contour(xrange, yrange, exp ∘ logp_banana ∘ Base.vect; xlabel="x₁", ylabel="x₂")
Example block output

Now we run pathfinder.

result = pathfinder(prob_banana; init_scale=10)
Single-path Pathfinder result
+contour(xrange, yrange, exp ∘ logp_banana ∘ Base.vect; xlabel="x₁", ylabel="x₂")
Example block output

Now we run pathfinder.

result = pathfinder(prob_banana; init_scale=10)
Single-path Pathfinder result
   tries: 1
   draws: 5
   fit iteration: 10 (total: 17)
@@ -127,7 +127,7 @@
 
 contour(xrange, yrange, exp ∘ logp_banana ∘ Base.vect)
 scatter!(x₁_approx, x₂_approx; msw=0, ms=2, alpha=0.5, color=1)
-plot!(xlims=extrema(xrange), ylims=extrema(yrange), xlabel="x₁", ylabel="x₂", legend=false)
Example block output

While the draws do a poor job of covering the tails of the distribution, they are still useful for identifying the nonlinear correlation between these two parameters.

A 100-dimensional funnel

As we have seen above, running multi-path Pathfinder is much more useful for target distributions that are far from normal. One particularly difficult distribution to sample is Neal's funnel:

\[\begin{aligned} +plot!(xlims=extrema(xrange), ylims=extrema(yrange), xlabel="x₁", ylabel="x₂", legend=false)Example block output

While the draws do a poor job of covering the tails of the distribution, they are still useful for identifying the nonlinear correlation between these two parameters.

A 100-dimensional funnel

As we have seen above, running multi-path Pathfinder is much more useful for target distributions that are far from normal. One particularly difficult distribution to sample is Neal's funnel:

\[\begin{aligned} \tau &\sim \mathrm{Normal}(\mu=0, \sigma=3)\\ \beta_i &\sim \mathrm{Normal}(\mu=0, \sigma=e^{\tau/2}) \end{aligned}\]

Such funnel geometries appear in other models (e.g. many hierarchical models) and typically frustrate MCMC sampling. Multi-path Pathfinder can't sample the funnel well, but it can quickly give us draws that can help us diagnose that we have a funnel.

In this example, we draw from a 100-dimensional funnel and visualize 2 dimensions.

using ReverseDiff, ADTypes
@@ -165,4 +165,4 @@
 
 contour(τ_range, β₁_range, exp ∘ logp_funnel ∘ Base.vect)
 scatter!(τ_approx, β₁_approx; msw=0, ms=2, alpha=0.5, color=1)
-plot!(; xlims=extrema(τ_range), ylims=extrema(β₁_range), xlabel="τ", ylabel="β₁", legend=false)
Example block output +plot!(; xlims=extrema(τ_range), ylims=extrema(β₁_range), xlabel="τ", ylabel="β₁", legend=false)Example block output diff --git a/dev/examples/turing/index.html b/dev/examples/turing/index.html index 16a39cf3..26e660b4 100644 --- a/dev/examples/turing/index.html +++ b/dev/examples/turing/index.html @@ -59,8 +59,8 @@ Iterations = 501:1:1500 Number of chains = 8 Samples per chain = 1000 -Wall duration = 6.55 seconds -Compute duration = 4.77 seconds +Wall duration = 6.8 seconds +Compute duration = 5.09 seconds parameters = α, β, σ internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size @@ -102,8 +102,8 @@ Iterations = 51:1:1050 Number of chains = 8 Samples per chain = 1000 -Wall duration = 2.8 seconds -Compute duration = 2.39 seconds +Wall duration = 2.72 seconds +Compute duration = 2.32 seconds parameters = α, β, σ internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size, is_adapt @@ -123,4 +123,4 @@ α 1.3916 1.4468 1.4750 1.5028 1.5585 β 1.9914 2.0011 2.0061 2.0110 2.0205 σ 0.1890 0.2057 0.2160 0.2267 0.2501 -

See Initializing HMC with Pathfinder for further examples.

+

See Initializing HMC with Pathfinder for further examples.

diff --git a/dev/index.html b/dev/index.html index a2970bb1..4d5dd09c 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · Pathfinder.jl

Pathfinder.jl: Parallel quasi-Newton variational inference

This package implements Pathfinder, [Zhang2021] a variational method for initializing Markov chain Monte Carlo (MCMC) methods.

Single-path Pathfinder

Single-path Pathfinder (pathfinder) attempts to return draws in or near the typical set, usually with many fewer gradient evaluations. Pathfinder uses the limited-memory BFGS(L-BFGS) optimizer to construct a maximum a posteriori (MAP) estimate of a target posterior distribution $p$. It then uses the trace of the optimization to construct a sequence of multivariate normal approximations to the target distribution, returning the approximation that maximizes the evidence lower bound (ELBO) – equivalently, minimizes the Kullback-Leibler divergence from the target distribution – as well as draws from the distribution.

Multi-path Pathfinder

Multi-path Pathfinder (multipathfinder) consists of running Pathfinder multiple times. It returns a uniformly-weighted mixture model of the multivariate normal approximations of the individual runs. It also uses importance resampling to return samples that better approximate the target distribution and assess the quality of the approximation.

Uses

Using the Pathfinder draws

Folk theorem of statistical computing

When you have computational problems, often there’s a problem with your model.

Visualizing posterior draws is a common way to diagnose problems with a model. However, problematic models often tend to be slow to warm-up. Even if the draws returned by Pathfinder are only approximations to the posterior, they can sometimes still be used to diagnose basic issues such as highly correlated parameters, parameters with very different posterior variances, and multimodality.

Initializing MCMC

Pathfinder can be used to initialize MCMC. This especially useful when sampling with Hamiltonian Monte Carlo. See Initializing HMC with Pathfinder for details.

Integration with the Julia ecosystem

Pathfinder uses several packages for extended functionality:

  • Optimization.jl: This allows the L-BFGS optimizer to be replaced with any of the many Optimization-compatible optimizers and supports use of callbacks. Note that any changes made to Pathfinder using these features would be experimental.
  • ADTypes.jl: Supports specifying the automatic differentiation engine to be used for computing gradient and Hessian, if needed.
  • Transducers.jl: parallelization support
  • Distributions.jl/PDMats.jl: fits can be used anywhere a Distribution can be used
  • LogDensityProblems.jl: defining the log-density function, gradient, and Hessian
  • ProgressLogging.jl: In Pluto, Juno, and VSCode, nested progress bars are shown. In the REPL, use TerminalLoggers.jl to get progress bars.
  • Zhang2021Lu Zhang, Bob Carpenter, Andrew Gelman, Aki Vehtari (2021). Pathfinder: Parallel quasi-Newton variational inference. arXiv: 2108.03782 [stat.ML]. Code
+Home · Pathfinder.jl

Pathfinder.jl: Parallel quasi-Newton variational inference

This package implements Pathfinder, [Zhang2021] a variational method for initializing Markov chain Monte Carlo (MCMC) methods.

Single-path Pathfinder

Single-path Pathfinder (pathfinder) attempts to return draws in or near the typical set, usually with many fewer gradient evaluations. Pathfinder uses the limited-memory BFGS(L-BFGS) optimizer to construct a maximum a posteriori (MAP) estimate of a target posterior distribution $p$. It then uses the trace of the optimization to construct a sequence of multivariate normal approximations to the target distribution, returning the approximation that maximizes the evidence lower bound (ELBO) – equivalently, minimizes the Kullback-Leibler divergence from the target distribution – as well as draws from the distribution.

Multi-path Pathfinder

Multi-path Pathfinder (multipathfinder) consists of running Pathfinder multiple times. It returns a uniformly-weighted mixture model of the multivariate normal approximations of the individual runs. It also uses importance resampling to return samples that better approximate the target distribution and assess the quality of the approximation.

Uses

Using the Pathfinder draws

Folk theorem of statistical computing

When you have computational problems, often there’s a problem with your model.

Visualizing posterior draws is a common way to diagnose problems with a model. However, problematic models often tend to be slow to warm-up. Even if the draws returned by Pathfinder are only approximations to the posterior, they can sometimes still be used to diagnose basic issues such as highly correlated parameters, parameters with very different posterior variances, and multimodality.

Initializing MCMC

Pathfinder can be used to initialize MCMC. This especially useful when sampling with Hamiltonian Monte Carlo. See Initializing HMC with Pathfinder for details.

Integration with the Julia ecosystem

Pathfinder uses several packages for extended functionality:

  • Optimization.jl: This allows the L-BFGS optimizer to be replaced with any of the many Optimization-compatible optimizers and supports use of callbacks. Note that any changes made to Pathfinder using these features would be experimental.
  • ADTypes.jl: Supports specifying the automatic differentiation engine to be used for computing gradient and Hessian, if needed.
  • Transducers.jl: parallelization support
  • Distributions.jl/PDMats.jl: fits can be used anywhere a Distribution can be used
  • LogDensityProblems.jl: defining the log-density function, gradient, and Hessian
  • ProgressLogging.jl: In Pluto, Juno, and VSCode, nested progress bars are shown. In the REPL, use TerminalLoggers.jl to get progress bars.
  • Zhang2021Lu Zhang, Bob Carpenter, Andrew Gelman, Aki Vehtari (2021). Pathfinder: Parallel quasi-Newton variational inference. arXiv: 2108.03782 [stat.ML]. Code
diff --git a/dev/lib/internals/index.html b/dev/lib/internals/index.html index 1b14ed30..69e63b03 100644 --- a/dev/lib/internals/index.html +++ b/dev/lib/internals/index.html @@ -23,4 +23,4 @@ \end{align}\]

source
Pathfinder.lbfgs_inverse_hessiansMethod
lbfgs_inverse_hessians(
     θs, ∇logpθs; Hinit=gilbert_init, history_length=5, ϵ=1e-12
 ) -> Tuple{Vector{WoodburyPDMat},Int}

From an L-BFGS trajectory and gradients, compute the inverse Hessian approximations at each point.

Given positions θs with gradients ∇logpθs, construct LBFGS inverse Hessian approximations with the provided history_length.

The 2nd returned value is the number of BFGS updates to the inverse Hessian matrices that were rejected due to keeping the inverse Hessian positive definite.

source
Pathfinder.pdfactorizeMethod
pdfactorize(A, B, D) -> WoodburyPDFactorization

Factorize the positive definite matrix $W = A + B D B^\mathrm{T}$.

The result is the "square root" factorization (L, R), where $W = L R$ and $L = R^\mathrm{T}$.

Let $U^\mathrm{T} U = A$ be the Cholesky decomposition of $A$, and let $Q X = U^{-\mathrm{T}} B$ be a thin QR decomposition. Define $C = I + XDX^\mathrm{T}$, with the Cholesky decomposition $V^\mathrm{T} V = C$. Then, $W = R^\mathrm{T} R$, where

\[R = \begin{pmatrix} U & 0 \\ 0 & I \end{pmatrix} Q^\mathrm{T} V.\]

The positive definite requirement is equivalent to the requirement that both $A$ and $C$ are positive definite.

For a derivation of this decomposition for the special case of diagonal $A$, see appendix A of [Zhang2021].

See pdunfactorize, WoodburyPDFactorization, WoodburyPDMat

source
Pathfinder.pdunfactorizeMethod
pdunfactorize(F::WoodburyPDFactorization) -> (A, B, D)

Perform a reverse operation to pdfactorize.

Note that this function does not compute the inverse of pdfactorize. It only computes matrices that produce the same matrix $W = A + B D B^\mathrm{T}$ as for the inputs to pdfactorize.

source
Pathfinder.resampleMethod
resample(rng, x, log_weights, ndraws) -> (draws, psis_result)
-resample(rng, x, ndraws) -> draws

Draw ndraws samples from x, with replacement.

If log_weights is provided, perform Pareto smoothed importance resampling.

source
+resample(rng, x, ndraws) -> draws

Draw ndraws samples from x, with replacement.

If log_weights is provided, perform Pareto smoothed importance resampling.

source
diff --git a/dev/lib/public/index.html b/dev/lib/public/index.html index e7ff5a77..43dce789 100644 --- a/dev/lib/public/index.html +++ b/dev/lib/public/index.html @@ -1,2 +1,2 @@ -Public · Pathfinder.jl

Public Documentation

Documentation for Pathfinder.jl's public interface.

See the Internals section for documentation of internal functions.

Index

Public Interface

Pathfinder.pathfinderFunction
pathfinder(fun; kwargs...)

Find the best multivariate normal approximation encountered while maximizing a log density.

From an optimization trajectory, Pathfinder constructs a sequence of (multivariate normal) approximations to the distribution specified by a log density function. The approximation that maximizes the evidence lower bound (ELBO), or equivalently, minimizes the KL divergence between the approximation and the true distribution, is returned.

The covariance of the multivariate normal distribution is an inverse Hessian approximation constructed using at most the previous history_length steps.

Arguments

  • fun: An object representing the log-density of the target distribution. Supported types include:
    • a callable with the signature f(params::AbstractVector{<:Real}) -> log_density::Real.
    • an object implementing the LogDensityProblems interface.
    • SciMLBase.OptimizationFunction: wraps the negative log density. It must have the necessary features (e.g. a gradient or Hessian function) for the chosen optimizer. For details, see Optimization.jl: OptimizationFunction.
    • SciMLBase.OptimizationProblem: an optimization problem containing a function with the same properties as the above OptimizationFunction, as well as an initial point. If provided, init and dim are ignored.
    • DynamicPPL.Model: a Turing model. If provided, init and dim are ignored.

Keywords

  • dim::Int: dimension of the target distribution. Ignored if init provided.
  • init::AbstractVector{<:Real}: initial point of length dim from which to begin optimization. If not provided and fun does not contain an initial point, an initial point of type Vector{Float64} and length dim is created and filled using init_sampler.
  • init_scale::Real: scale factor $s$ such that the default init_sampler samples entries uniformly in the range $[-s, s]$
  • init_sampler: function with the signature (rng, x) -> x that modifies a vector of length dims in-place to generate an initial point
  • ndraws_elbo::Int=5: Number of draws used to estimate the ELBO
  • ndraws::Int=ndraws_elbo: number of approximate draws to return
  • rng::Random.AbstractRNG: The random number generator to be used for drawing samples
  • executor::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor that determines if and how to perform ELBO computation in parallel. The default (SequentialEx()) performs no parallelization. If rng is known to be thread-safe, and the log-density function is known to have no internal state, then Transducers.PreferParallel() may be used to parallelize log-density evaluation. This is generally only faster for expensive log density functions.
  • history_length::Int=6: Size of the history used to approximate the inverse Hessian.
  • optimizer: Optimizer to be used for constructing trajectory. Can be any optimizer compatible with Optimization.jl, so long as it supports callbacks. Defaults to Optim.LBFGS(; m=history_length, linesearch=LineSearches.HagerZhang(), alphaguess=LineSearches.InitialHagerZhang()). See the Optimization.jl documentation for details.
  • adtype::ADTypes.AbstractADType=AutoForwardDiff(): Specifies which automatic differentiation backend should be used to compute the gradient, if fun does not already specify the gradient. See SciML's Automatic Differentiation Recommendations.
  • ntries::Int=1_000: Number of times to try the optimization, restarting if it fails. Before every restart, a new initial point is drawn using init_sampler.
  • fail_on_nonfinite::Bool=true: If true, optimization fails if the log-density is a NaN or Inf or if the gradient is ever non-finite. If nretries > 0, then optimization will be retried after reinitialization.
  • kwargs... : Remaining keywords are forwarded to Optimization.solve.

Returns

source
Pathfinder.PathfinderResultType
PathfinderResult

Container for results of single-path Pathfinder.

Fields

  • input: User-provided input object, e.g. a LogDensityProblem, optim_fun, optim_prob, or another object.
  • optimizer: Optimizer used for maximizing the log-density
  • rng: Pseudorandom number generator that was used for sampling
  • optim_prob::SciMLBase.OptimizationProblem: Otimization problem used for optimization
  • logp: Log-density function
  • fit_distribution::Distributions.MvNormal: ELBO-maximizing multivariate normal distribution
  • draws::AbstractMatrix{<:Real}: draws from multivariate normal with size (dim, ndraws)
  • fit_distribution_transformed: fit_distribution transformed to the same space as the user-supplied target distribution. This is only different from fit_distribution when integrating with other packages, and its type depends on the type of input.
  • draws_transformed: draws transformed to be draws from fit_distribution_transformed.
  • fit_iteration::Int: Iteration at which ELBO estimate was maximized
  • num_tries::Int: Number of tries until Pathfinder succeeded
  • optim_solution::SciMLBase.OptimizationSolution: Solution object of optimization.
  • optim_trace::Pathfinder.OptimizationTrace: container for optimization trace of points, log-density, and gradient. The first point is the initial point.
  • fit_distributions::AbstractVector{Distributions.MvNormal}: Multivariate normal distributions for each point in optim_trace, where fit_distributions[fit_iteration + 1] == fit_distribution
  • elbo_estimates::AbstractVector{<:Pathfinder.ELBOEstimate}: ELBO estimates for all but the first distribution in fit_distributions.
  • num_bfgs_updates_rejected::Int: Number of times a BFGS update to the reconstructed inverse Hessian was rejected to keep the inverse Hessian positive definite.

Returns

source
Pathfinder.multipathfinderFunction
multipathfinder(fun, ndraws; kwargs...)

Run pathfinder multiple times to fit a multivariate normal mixture model.

For nruns=length(init), nruns parallel runs of pathfinder produce nruns multivariate normal approximations $q_k = q(\phi | \mu_k, \Sigma_k)$ of the posterior. These are combined to a mixture model $q$ with uniform weights.

$q$ is augmented with the component index to generate random samples, that is, elements $(k, \phi)$ are drawn from the augmented mixture model

\[\tilde{q}(\phi, k | \mu, \Sigma) = K^{-1} q(\phi | \mu_k, \Sigma_k),\]

where $k$ is a component index, and $K=$ nruns. These draws are then resampled with replacement. Discarding $k$ from the samples would reproduce draws from $q$.

If importance=true, then Pareto smoothed importance resampling is used, so that the resulting draws better approximate draws from the target distribution $p$ instead of $q$. This also prints a warning message if the importance weighted draws are unsuitable for approximating expectations with respect to $p$.

Arguments

  • fun: An object representing the log-density of the target distribution. Supported types include:

    • a callable with the signature f(params::AbstractVector{<:Real}) -> log_density::Real.
    • an object implementing the LogDensityProblems interface.
    • SciMLBase.OptimizationFunction: wraps the negative log density. It must have the necessary features (e.g. a gradient or Hessian function) for the chosen optimizer. For details, see Optimization.jl: OptimizationFunction.
    • SciMLBase.OptimizationProblem: an optimization problem containing a function with the same properties as the above OptimizationFunction, as well as an initial point. If provided, init and dim are ignored.
    • DynamicPPL.Model: a Turing model. If provided, init and dim are ignored.
  • ndraws::Int: number of approximate draws to return

Keywords

  • init: iterator of length nruns of initial points of length dim from which each single-path Pathfinder run will begin. length(init) must be implemented. If init is not provided, nruns must be, and dim must be if fun provided.
  • nruns::Int: number of runs of Pathfinder to perform. Ignored if init is provided.
  • ndraws_per_run::Int: The number of draws to take for each component before resampling. Defaults to a number such that ndraws_per_run * nruns > ndraws.
  • importance::Bool=true: Perform Pareto smoothed importance resampling of draws.
  • rng::AbstractRNG=Random.GLOBAL_RNG: Pseudorandom number generator. It is recommended to use a parallelization-friendly PRNG like the default PRNG on Julia 1.7 and up.
  • executor::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor that determines if and how to run the single-path runs in parallel. If a transducer for multi-threaded computation is selected, you must first verify that rng and the log density function are thread-safe.
  • executor_per_run::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor used within each run to parallelize PRNG calls. Defaults to no parallelization. See pathfinder for a description.
  • kwargs... : Remaining keywords are forwarded to pathfinder.

Returns

source
Pathfinder.MultiPathfinderResultType
MultiPathfinderResult

Container for results of multi-path Pathfinder.

Fields

  • input: User-provided input object, e.g. either logp, (logp, ∇logp), optim_fun, optim_prob, or another object.
  • optimizer: Optimizer used for maximizing the log-density
  • rng: Pseudorandom number generator that was used for sampling
  • optim_prob::SciMLBase.OptimizationProblem: Otimization problem used for optimization
  • logp: Log-density function
  • fit_distribution::Distributions.MixtureModel: uniformly-weighted mixture of ELBO- maximizing multivariate normal distributions from each run.
  • draws::AbstractMatrix{<:Real}: draws from fit_distribution with size (dim, ndraws), potentially resampled using importance resampling to be closer to the target distribution.
  • draw_component_ids::Vector{Int}: component id of each draw in draws.
  • fit_distribution_transformed: fit_distribution transformed to the same space as the user-supplied target distribution. This is only different from fit_distribution when integrating with other packages, and its type depends on the type of input.
  • draws_transformed: draws transformed to be draws from fit_distribution_transformed.
  • pathfinder_results::Vector{<:PathfinderResult}: results of each single-path Pathfinder run.
  • psis_result::Union{Nothing,<:PSIS.PSISResult}: If importance resampling was used, the result of Pareto-smoothed importance resampling. psis_result.pareto_shape also diagnoses whether draws can be used to compute estimates from the target distribution. See PSIS.PSISResult for details
source
+Public · Pathfinder.jl

Public Documentation

Documentation for Pathfinder.jl's public interface.

See the Internals section for documentation of internal functions.

Index

Public Interface

Pathfinder.pathfinderFunction
pathfinder(fun; kwargs...)

Find the best multivariate normal approximation encountered while maximizing a log density.

From an optimization trajectory, Pathfinder constructs a sequence of (multivariate normal) approximations to the distribution specified by a log density function. The approximation that maximizes the evidence lower bound (ELBO), or equivalently, minimizes the KL divergence between the approximation and the true distribution, is returned.

The covariance of the multivariate normal distribution is an inverse Hessian approximation constructed using at most the previous history_length steps.

Arguments

  • fun: An object representing the log-density of the target distribution. Supported types include:
    • a callable with the signature f(params::AbstractVector{<:Real}) -> log_density::Real.
    • an object implementing the LogDensityProblems interface.
    • SciMLBase.OptimizationFunction: wraps the negative log density. It must have the necessary features (e.g. a gradient or Hessian function) for the chosen optimizer. For details, see Optimization.jl: OptimizationFunction.
    • SciMLBase.OptimizationProblem: an optimization problem containing a function with the same properties as the above OptimizationFunction, as well as an initial point. If provided, init and dim are ignored.
    • DynamicPPL.Model: a Turing model. If provided, init and dim are ignored.

Keywords

  • dim::Int: dimension of the target distribution. Ignored if init provided.
  • init::AbstractVector{<:Real}: initial point of length dim from which to begin optimization. If not provided and fun does not contain an initial point, an initial point of type Vector{Float64} and length dim is created and filled using init_sampler.
  • init_scale::Real: scale factor $s$ such that the default init_sampler samples entries uniformly in the range $[-s, s]$
  • init_sampler: function with the signature (rng, x) -> x that modifies a vector of length dims in-place to generate an initial point
  • ndraws_elbo::Int=5: Number of draws used to estimate the ELBO
  • ndraws::Int=ndraws_elbo: number of approximate draws to return
  • rng::Random.AbstractRNG: The random number generator to be used for drawing samples
  • executor::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor that determines if and how to perform ELBO computation in parallel. The default (SequentialEx()) performs no parallelization. If rng is known to be thread-safe, and the log-density function is known to have no internal state, then Transducers.PreferParallel() may be used to parallelize log-density evaluation. This is generally only faster for expensive log density functions.
  • history_length::Int=6: Size of the history used to approximate the inverse Hessian.
  • optimizer: Optimizer to be used for constructing trajectory. Can be any optimizer compatible with Optimization.jl, so long as it supports callbacks. Defaults to Optim.LBFGS(; m=history_length, linesearch=LineSearches.HagerZhang(), alphaguess=LineSearches.InitialHagerZhang()). See the Optimization.jl documentation for details.
  • adtype::ADTypes.AbstractADType=AutoForwardDiff(): Specifies which automatic differentiation backend should be used to compute the gradient, if fun does not already specify the gradient. See SciML's Automatic Differentiation Recommendations.
  • ntries::Int=1_000: Number of times to try the optimization, restarting if it fails. Before every restart, a new initial point is drawn using init_sampler.
  • fail_on_nonfinite::Bool=true: If true, optimization fails if the log-density is a NaN or Inf or if the gradient is ever non-finite. If nretries > 0, then optimization will be retried after reinitialization.
  • kwargs... : Remaining keywords are forwarded to Optimization.solve.

Returns

source
Pathfinder.PathfinderResultType
PathfinderResult

Container for results of single-path Pathfinder.

Fields

  • input: User-provided input object, e.g. a LogDensityProblem, optim_fun, optim_prob, or another object.
  • optimizer: Optimizer used for maximizing the log-density
  • rng: Pseudorandom number generator that was used for sampling
  • optim_prob::SciMLBase.OptimizationProblem: Otimization problem used for optimization
  • logp: Log-density function
  • fit_distribution::Distributions.MvNormal: ELBO-maximizing multivariate normal distribution
  • draws::AbstractMatrix{<:Real}: draws from multivariate normal with size (dim, ndraws)
  • fit_distribution_transformed: fit_distribution transformed to the same space as the user-supplied target distribution. This is only different from fit_distribution when integrating with other packages, and its type depends on the type of input.
  • draws_transformed: draws transformed to be draws from fit_distribution_transformed.
  • fit_iteration::Int: Iteration at which ELBO estimate was maximized
  • num_tries::Int: Number of tries until Pathfinder succeeded
  • optim_solution::SciMLBase.OptimizationSolution: Solution object of optimization.
  • optim_trace::Pathfinder.OptimizationTrace: container for optimization trace of points, log-density, and gradient. The first point is the initial point.
  • fit_distributions::AbstractVector{Distributions.MvNormal}: Multivariate normal distributions for each point in optim_trace, where fit_distributions[fit_iteration + 1] == fit_distribution
  • elbo_estimates::AbstractVector{<:Pathfinder.ELBOEstimate}: ELBO estimates for all but the first distribution in fit_distributions.
  • num_bfgs_updates_rejected::Int: Number of times a BFGS update to the reconstructed inverse Hessian was rejected to keep the inverse Hessian positive definite.

Returns

source
Pathfinder.multipathfinderFunction
multipathfinder(fun, ndraws; kwargs...)

Run pathfinder multiple times to fit a multivariate normal mixture model.

For nruns=length(init), nruns parallel runs of pathfinder produce nruns multivariate normal approximations $q_k = q(\phi | \mu_k, \Sigma_k)$ of the posterior. These are combined to a mixture model $q$ with uniform weights.

$q$ is augmented with the component index to generate random samples, that is, elements $(k, \phi)$ are drawn from the augmented mixture model

\[\tilde{q}(\phi, k | \mu, \Sigma) = K^{-1} q(\phi | \mu_k, \Sigma_k),\]

where $k$ is a component index, and $K=$ nruns. These draws are then resampled with replacement. Discarding $k$ from the samples would reproduce draws from $q$.

If importance=true, then Pareto smoothed importance resampling is used, so that the resulting draws better approximate draws from the target distribution $p$ instead of $q$. This also prints a warning message if the importance weighted draws are unsuitable for approximating expectations with respect to $p$.

Arguments

  • fun: An object representing the log-density of the target distribution. Supported types include:

    • a callable with the signature f(params::AbstractVector{<:Real}) -> log_density::Real.
    • an object implementing the LogDensityProblems interface.
    • SciMLBase.OptimizationFunction: wraps the negative log density. It must have the necessary features (e.g. a gradient or Hessian function) for the chosen optimizer. For details, see Optimization.jl: OptimizationFunction.
    • SciMLBase.OptimizationProblem: an optimization problem containing a function with the same properties as the above OptimizationFunction, as well as an initial point. If provided, init and dim are ignored.
    • DynamicPPL.Model: a Turing model. If provided, init and dim are ignored.
  • ndraws::Int: number of approximate draws to return

Keywords

  • init: iterator of length nruns of initial points of length dim from which each single-path Pathfinder run will begin. length(init) must be implemented. If init is not provided, nruns must be, and dim must be if fun provided.
  • nruns::Int: number of runs of Pathfinder to perform. Ignored if init is provided.
  • ndraws_per_run::Int: The number of draws to take for each component before resampling. Defaults to a number such that ndraws_per_run * nruns > ndraws.
  • importance::Bool=true: Perform Pareto smoothed importance resampling of draws.
  • rng::AbstractRNG=Random.GLOBAL_RNG: Pseudorandom number generator. It is recommended to use a parallelization-friendly PRNG like the default PRNG on Julia 1.7 and up.
  • executor::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor that determines if and how to run the single-path runs in parallel. If a transducer for multi-threaded computation is selected, you must first verify that rng and the log density function are thread-safe.
  • executor_per_run::Transducers.Executor=Transducers.SequentialEx(): Transducers.jl executor used within each run to parallelize PRNG calls. Defaults to no parallelization. See pathfinder for a description.
  • kwargs... : Remaining keywords are forwarded to pathfinder.

Returns

source
Pathfinder.MultiPathfinderResultType
MultiPathfinderResult

Container for results of multi-path Pathfinder.

Fields

  • input: User-provided input object, e.g. either logp, (logp, ∇logp), optim_fun, optim_prob, or another object.
  • optimizer: Optimizer used for maximizing the log-density
  • rng: Pseudorandom number generator that was used for sampling
  • optim_prob::SciMLBase.OptimizationProblem: Otimization problem used for optimization
  • logp: Log-density function
  • fit_distribution::Distributions.MixtureModel: uniformly-weighted mixture of ELBO- maximizing multivariate normal distributions from each run.
  • draws::AbstractMatrix{<:Real}: draws from fit_distribution with size (dim, ndraws), potentially resampled using importance resampling to be closer to the target distribution.
  • draw_component_ids::Vector{Int}: component id of each draw in draws.
  • fit_distribution_transformed: fit_distribution transformed to the same space as the user-supplied target distribution. This is only different from fit_distribution when integrating with other packages, and its type depends on the type of input.
  • draws_transformed: draws transformed to be draws from fit_distribution_transformed.
  • pathfinder_results::Vector{<:PathfinderResult}: results of each single-path Pathfinder run.
  • psis_result::Union{Nothing,<:PSIS.PSISResult}: If importance resampling was used, the result of Pareto-smoothed importance resampling. psis_result.pareto_shape also diagnoses whether draws can be used to compute estimates from the target distribution. See PSIS.PSISResult for details
source