API
API#
- pccg.spline.bs(x, knots, boundary_knots, degree=3, intercept=False)#
Generate the B-spline basis matrix for a polynomial spline.
This function mimics the function bs in the R package splines.
- Parameters
x (Tensor) – Values at which basis functions are evaluated.
knots (Tensor) – Internal breakpoints that define the spline.
boundary_knots (Tensor) – Boundary points
degree (int, default = 3) – The degree of the piecewise polynomial. The default is 3, which corresponds to cubic splines.
intercept (bool, default =
False) – If set toTrue, an intercept is included in the basis. Default isFalse.
- Returns
The design matrix, which is a tensor of dimension (len(x), df), where df = len(knots) + 2 + degree if intercept is
False, df = len(knots) + 2 + degree + 1 if intercept isTrue.
- pccg.spline.pbs(x, knots, boundary_knots=tensor([- 3.1416, 3.1416]), degree=3, intercept=False)#
Compute the design matrix of a periodic B-spline.
This function mimics the pbs function in R package pbs.
- Parameters
x (Tensor) – Values at which basis functions are evaludated.
knots (Tensor) – Internal breakpoints that define the spline.
boundary_knots (Tensor) – Boundary points
degree (int, optional) – The degree of the piecewise polynomial. The default is 3 for cubic splines.
intercept (bool, optional) – If set to
True, an intercept is included in the basis. Default isFalse.
- Returns
The design matrix, which is a tensor of dimension (len(x), df), where df = len(knots) if intercept is
False, df = len(knots) + 1 if intercept isTrue.
- pccg.spline.bs_lj(r, r_min, r_max, num_of_basis, omega=False)#
Compute the design matrix of a custimized B-spline for interactions of Lennard-Jones type.
- Parameters
r (Tensor) – Distances at which basis functions are evaluated.
r_min (float) – A cutoff distance. When r < r_min, the interaction becomes repulsive and the basis function will provide a postive value.
r_max (float) – A cutoff distance. When r > r_max, all basis functions are zeros.
num_of_basis (int) – The number of basis.
omega (bool) – Integral of secondary derivatives. If set to
True, the function will also return a matrix \(\Omega\), where \(\Omega(i,j) = \int_{r_\mathrm{min}}^{r_\mathrm{max}} N_i''(r)*N_j''(r) \mathrm{d}r\). This matrix is useful when fitting a smoothing splines by addding a penaly term controling the secondary derivative of splines.
- Returns
The design matrix, which is a matrix of dimension (len(r), num_of_basis). If omega is set to
True, the function returns a tuple (mat_a, mat_b), where mat_a is the design matrix and mat_b is the the \(\Omega\) matrix containing the integral of spline basis functions’ second derivatives.
- pccg.spline.bs_rmsd(r, r_max, num_of_basis)#
Compute the design matrix of a custimized B-spline for a biasing potential on RMSD.
- Parameters
r (Tensor) – Distances at which basis functions are evaluated.
r_max (float) – A cutoff distance. When r > r_max, all basis functions are zeros.
num_of_basis (int) – The number of basis.
- Returns
The design matrix of dimension (len(r), num_of_basis).
- pccg.NCE(log_q_noise, log_q_data, basis_noise, basis_data, verbose=True, options={'maxiter': 1000})[source]#
Noise contrastive estimation
- Parameters
log_q_noise (Tensor) – 1-D vector, the logrithm of probability density for noise data under the noise distribution
log_q_data (Tensor) – 1-D vector, the logrithm of probability density for target data under the noise distribution
basis_noise (Tensor) – 2-D vector, the design matrix contraining basis values of noise data for compute the logrithm of probablity density for the target distribution
basis_data (Tensor) – 2-D vector, the design matrix contraining basis values of target data for compute the logrithm of probablity density for the target distribution
verbose (bool, default =
True) – whether to print the optimization information
- Returns
A namedtuple (
theta,dF) wherethetais a vector of learned basis coefficients anddFis the free energy difference between the ensemble defined by the target energy function and that defined by the noise energy function.