JWS C Library
C language utility library
dynamics.h File Reference

Collection of functions for stochastic dynamics on an energy function to generate random samples. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <inttypes.h>
#include "jwsc/base/error.h"
#include "jwsc/vector/vector.h"
#include "jwsc/matrix/matrix.h"
Include dependency graph for dynamics.h:

Go to the source code of this file.

Functions

stochastic_dynamics

Leapfrog discretization of stochastic dynamics to sample from an energy function.

Errorstochastic_dynamics_1_d (uint32_t iterations, double delta_t, double alpha, uint32_t kick, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, const Vector_d *momenta, void *params))
 Double precision leapfrog stochastic dynamics.
Errorstochastic_dynamics_2_d (uint32_t iterations, const Vector_d *delta_t, double alpha, uint32_t kick, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, const Vector_d *momenta, void *params))
 Double precision leapfrog stochastic dynamics.
hybrid_monte_carlo

Stochastic dynamics combined with Metropolis-Hastings for quickly converging and unbiased sampling.

Errorhybrid_monte_carlo_1_d (uint32_t iterations, uint32_t leap_itera, double delta_t, double alpha, uint32_t kick, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_d *p, void *params), Error *(*energy_func)(double *energy_out, void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, const Vector_d *momenta, void *params), Error *(*reject_sample)(const Vector_d *sample, const Vector_d *momenta, void *params))
 Double precision hybrid monte carlo.
Errorhybrid_monte_carlo_2_d (uint32_t iterations, uint32_t leap_itera, const Vector_d *delta_t, double alpha, uint32_t kick, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_d *p, void *params), Error *(*energy_func)(double *energy_out, void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, const Vector_d *momenta, void *params), Error *(*reject_sample)(const Vector_d *sample, const Vector_d *momenta, void *params))
 Double precision hybrid monte carlo.
langevin

Langevin dynamics for generating samples from a energy function.

Errorlangevin_1_f (uint32_t iterations, float delta_t, void *params, void(*get_pt_from_params)(Vector_f **p_out, const void *params), Error *(*grad_energy_func)(Vector_f **grad_out, void *params), Error *(*accept_sample)(const Vector_f *sample, void *params))
 Single precision Langevin dynamics.
Errorlangevin_2_f (uint32_t iterations, const Vector_f *delta_t, void *params, void(*get_pt_from_params)(Vector_f **p_out, const void *params), Error *(*grad_energy_func)(Vector_f **grad_out, void *params), Error *(*accept_sample)(const Vector_f *sample, void *params))
 Single precision Langevin dynamics.
Errorlangevin_1_d (uint32_t iterations, double delta_t, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, void *params))
 Double precision Langevin dynamics.
Errorlangevin_2_d (uint32_t iterations, const Vector_d *delta_t, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, void *params))
 Double precision Langevin dynamics.
langevin_hyperdynamics

Voter's hyperdynamics biasing for generating samples from an energy function using Langevin dynamics.

Errorlangevin_hyperdynamics_1_f (uint32_t iterations, float delta_t, float gamma, float eta, float h, float d, void *params, void(*get_pt_from_params)(Vector_f **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_f *p, void *params), Error *(*energy_func)(float *energy_out, void *params), Error *(*grad_energy_func)(Vector_f **grad_out, void *params), Error *(*accept_sample)(const Vector_f *sample, void *params, float energy_bias))
 Single precision Voter hyperdynamics.
Errorlangevin_hyperdynamics_2_f (uint32_t iterations, const Vector_f *init_delta_t, float gamma, float eta, float h, float d, void *params, void(*get_pt_from_params)(Vector_f **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_f *p, void *params), Error *(*energy_func)(float *energy_out, void *params), Error *(*grad_energy_func)(Vector_f **grad_out, void *params), Error *(*accept_sample)(const Vector_f *sample, void *params, float energy_bias))
 Single precision Voter hyperdynamics.
Errorlangevin_hyperdynamics_1_d (uint32_t iterations, double delta_t, double gamma, double eta, double h, double d, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_d *p, void *params), Error *(*energy_func)(double *energy_out, void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, void *params, double energy_bias))
 Double precision Voter hyperdynamics.
Errorlangevin_hyperdynamics_2_d (uint32_t iterations, const Vector_d *init_delta_t, double gamma, double eta, double h, double d, void *params, void(*get_pt_from_params)(Vector_d **p_out, const void *params), Error *(*set_params_from_pt)(const Vector_d *p, void *params), Error *(*energy_func)(double *energy_out, void *params), Error *(*grad_energy_func)(Vector_d **grad_out, void *params), Error *(*accept_sample)(const Vector_d *sample, void *params, double energy_bias))
 Double precision Voter hyperdynamics.

Detailed Description

Collection of functions for stochastic dynamics on an energy function to generate random samples.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Definition in file dynamics.h.


Function Documentation

Error* stochastic_dynamics_1_d ( uint32_t  iterations,
double  delta_t,
double  alpha,
uint32_t  kick,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  accept_sample 
)

Double precision leapfrog stochastic dynamics.

See Neal '93 for details.

Preserves phase space volume.

Parameters:
iterationsNumber of leapfrog steps to take; number of samples to generate.
delta_tTime discretization step size.
alphaParameter for stochastic dynamics. Should be in in the interval [0,1].
kickFrequency (in iterations) to kick the particle and reset the momenta. Set to zero if no kicking is needed.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 97 of file dynamics.c.

Error* stochastic_dynamics_2_d ( uint32_t  iterations,
const Vector_d delta_t,
double  alpha,
uint32_t  kick,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  accept_sample 
)

Double precision leapfrog stochastic dynamics.

See Neal '93 for details.

Preserves phase space volume.

Parameters:
iterationsNumber of leapfrog steps to take; number of samples to generate.
delta_tTime discretization step size.
alphaParameter for stochastic dynamics. Should be in in the interval [0,1].
kickFrequency (in iterations) to kick the particle and reset the momenta. Set to zero if no kicking is needed.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 152 of file dynamics.c.

Error* hybrid_monte_carlo_1_d ( uint32_t  iterations,
uint32_t  leap_iter,
double  delta_t,
double  alpha,
uint32_t  kick,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_d *p, void *params)  set_params_from_pt,
Error *(*)(double *energy_out, void *params)  energy_func,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  accept_sample,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  reject_sample 
)

Double precision hybrid monte carlo.

See Neal '93 for details.

Preserves phase space volume and generates unbiased samples.

Parameters:
iterationsNumber of Metropolis-Hastings iterations. Proportional to the number of samples generated, depending on the rejection rate.
leap_iterNumber of leapfrog iterations between each Metropolis-Hastings iterations.
delta_tTime discretization step size.
alphaParameter for stochastic dynamics. Should be in in the interval [0,1].
kickFrequency (in iterations) to kick the particle and reset the momenta. Set to zero if no kicking is needed.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the parameters in params from a point.
energy_funcComputes the energy function at a point specified in params
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
reject_sampleRejects a generated sample. This is optional and can be set to NULL.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 301 of file dynamics.c.

Error* hybrid_monte_carlo_2_d ( uint32_t  iterations,
uint32_t  leap_iter,
const Vector_d delta_t,
double  alpha,
uint32_t  kick,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_d *p, void *params)  set_params_from_pt,
Error *(*)(double *energy_out, void *params)  energy_func,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  accept_sample,
Error *(*)(const Vector_d *sample, const Vector_d *momenta, void *params)  reject_sample 
)

Double precision hybrid monte carlo.

See Neal '93 for details.

Preserves phase space volume and generates unbiased samples.

Parameters:
iterationsNumber of Metropolis-Hastings iterations. Proportional to the number of samples generated, depending on the rejection rate.
leap_iterNumber of leapfrog iterations between each Metropolis-Hastings iterations.
delta_tTime discretization step size.
alphaParameter for stochastic dynamics. Should be in in the interval [0,1].
kickFrequency (in iterations) to kick the particle and reset the momenta. Set to zero if no kicking is needed.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the parameters in params from a point.
energy_funcComputes the energy function at a point specified in params
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample. Updates the params with the sample.
reject_sampleRejects a generated sample. This is optional and can be set to NULL.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 368 of file dynamics.c.

Error* langevin_1_f ( uint32_t  iterations,
float  delta_t,
void *  params,
void(*)(Vector_f **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_f **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_f *sample, void *params)  accept_sample 
)

Single precision Langevin dynamics.

Follows the negative gradient of an energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 598 of file dynamics.c.

Error* langevin_2_f ( uint32_t  iterations,
const Vector_f delta_t,
void *  params,
void(*)(Vector_f **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_f **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_f *sample, void *params)  accept_sample 
)

Single precision Langevin dynamics.

Follows the negative gradient of an energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 645 of file dynamics.c.

Error* langevin_1_d ( uint32_t  iterations,
double  delta_t,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, void *params)  accept_sample 
)

Double precision Langevin dynamics.

Follows the negative gradient of an energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 718 of file dynamics.c.

Error* langevin_2_d ( uint32_t  iterations,
const Vector_d delta_t,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, void *params)  accept_sample 
)

Double precision Langevin dynamics.

Follows the negative gradient of an energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 765 of file dynamics.c.

Error* langevin_hyperdynamics_1_f ( uint32_t  iterations,
float  delta_t,
float  gamma,
float  eta,
float  h,
float  d,
void *  params,
void(*)(Vector_f **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_f *p, void *params)  set_params_from_pt,
Error *(*)(float *energy_out, void *params)  energy_func,
Error *(*)(Vector_f **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_f *sample, void *params, float energy_bias)  accept_sample 
)

Single precision Voter hyperdynamics.

Follows the negative gradient of a (biased) energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your energy_func and grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
gammaStep size for gradient descent for each parameter. Very small positive value.
etaDifference parameter for derivative numerical approximations. Small positive value.
hBias scaling of the Voter's function (h). Height of the smallest transition area is good starting value.
dDistance scale from one minima to another in terms of 2*pi*d.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the params from a point.
energy_funcComputes the energy function at a point specified in params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 2711 of file dynamics.c.

Error* langevin_hyperdynamics_2_f ( uint32_t  iterations,
const Vector_f delta_t,
float  gamma,
float  eta,
float  h,
float  d,
void *  params,
void(*)(Vector_f **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_f *p, void *params)  set_params_from_pt,
Error *(*)(float *energy_out, void *params)  energy_func,
Error *(*)(Vector_f **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_f *sample, void *params, float energy_bias)  accept_sample 
)

Single precision Voter hyperdynamics.

Follows the negative gradient of a (biased) energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your energy_func and grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
gammaStep size for gradient descent for each parameter. Very small positive value.
etaDifference parameter for derivative numerical approximations. Small positive value.
hBias scaling of the Voter's function (h). Height of the smallest transition area is good starting value.
dDistance scale from one minima to another in terms of 2*pi*d.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the params from a point.
energy_funcComputes the energy function at a point specified in params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample by. Updates the params with the sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 2777 of file dynamics.c.

Error* langevin_hyperdynamics_1_d ( uint32_t  iterations,
double  delta_t,
double  gamma,
double  eta,
double  h,
double  d,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_d *p, void *params)  set_params_from_pt,
Error *(*)(double *energy_out, void *params)  energy_func,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, void *params, double energy_bias)  accept_sample 
)

Double precision Voter hyperdynamics.

Follows the negative gradient of a (biased) energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your energy_func and grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
gammaStep size for gradient descent for each parameter. Very small positive value.
etaDifference parameter for derivative numerical approximations. Small positive value.
hBias scaling of the Voter's function (h). Height of the smallest transition area is good starting value.
dDistance scale from one minima to another in terms of 2*pi*d.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the params from a point.
energy_funcComputes the energy function at a point specified in params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 2970 of file dynamics.c.

Error* langevin_hyperdynamics_2_d ( uint32_t  iterations,
const Vector_d delta_t,
double  gamma,
double  eta,
double  h,
double  d,
void *  params,
void(*)(Vector_d **p_out, const void *params)  get_pt_from_params,
Error *(*)(const Vector_d *p, void *params)  set_params_from_pt,
Error *(*)(double *energy_out, void *params)  energy_func,
Error *(*)(Vector_d **grad_out, void *params)  grad_energy_func,
Error *(*)(const Vector_d *sample, void *params, double energy_bias)  accept_sample 
)

Double precision Voter hyperdynamics.

Follows the negative gradient of a (biased) energy function. Note that this will focus samples in areas of low energy. If you are interested in maxima, have your energy_func and grad_energy_func negate things.

Parameters:
iterationsNumber of Langevin dynamcs steps to take; number of samples to generate.
delta_tStochastics dynamics integration step size.
gammaStep size for gradient descent for each parameter. Very small positive value.
etaDifference parameter for derivative numerical approximations. Small positive value.
hBias scaling of the Voter's function (h). Height of the smallest transition area is good starting value.
dDistance scale from one minima to another in terms of 2*pi*d.
paramsParameter(s) for the callback functions.
get_pt_from_paramsGets the parameters as a point from params.
set_params_from_ptSets the params from a point.
energy_funcComputes the energy function at a point specified in params.
grad_energy_funcComputes the gradient of the energy function at a point specified in params
accept_sampleAccepts a generated sample.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 3035 of file dynamics.c.