35 INTEGER :: i, ikind, info, j, npoints
36 REAL(
dp),
DIMENSION(:),
POINTER :: idescr, jdescr
40 DO ikind = 1,
SIZE(pao%ml_training_matrices)
41 training_matrix => pao%ml_training_matrices(ikind)
42 npoints =
SIZE(training_matrix%inputs, 2)
43 cpassert(
SIZE(training_matrix%outputs, 2) == npoints)
44 IF (npoints == 0) cycle
46 IF (pao%iw > 0)
WRITE (pao%iw, *)
"PAO|ML| Building covariance matrix for kind: ", &
47 trim(training_matrix%kindname),
" from ", npoints,
"training points."
50 ALLOCATE (training_matrix%GP(npoints, npoints))
53 idescr => training_matrix%inputs(:, i)
54 jdescr => training_matrix%inputs(:, j)
55 training_matrix%GP(i, j) = kernel(pao%gp_scale, idescr, jdescr)
56 training_matrix%GP(j, i) = training_matrix%GP(i, j)
62 training_matrix%GP(i, i) = training_matrix%GP(i, i) + pao%gp_noise_var**2
66 CALL dpotrf(
"U", npoints, training_matrix%GP, npoints, info)
82 INTEGER,
INTENT(IN) :: ikind
83 REAL(
dp),
DIMENSION(:),
INTENT(IN) :: descriptor
84 REAL(
dp),
DIMENSION(:),
INTENT(OUT) :: output
85 REAL(
dp),
INTENT(OUT) :: variance
87 INTEGER :: i, info, npoints
88 REAL(
dp),
ALLOCATABLE,
DIMENSION(:) :: cov, weights
91 training_matrix => pao%ml_training_matrices(ikind)
92 npoints =
SIZE(training_matrix%outputs, 2)
95 ALLOCATE (cov(npoints))
97 cov(i) = kernel(pao%gp_scale, descriptor, training_matrix%inputs(:, i))
101 ALLOCATE (weights(npoints))
103 CALL dpotrs(
"U", npoints, 1, training_matrix%GP, npoints, weights, npoints, info)
109 output(:) = output + weights(i)*training_matrix%outputs(:, i)
113 variance = kernel(pao%gp_scale, descriptor, descriptor) - dot_product(weights, cov)
115 IF (variance < 0.0_dp) &
116 cpabort(
"PAO gaussian process found negative variance")
118 DEALLOCATE (cov, weights)
131 INTEGER,
INTENT(IN) :: ikind
132 REAL(
dp),
DIMENSION(:),
INTENT(IN),
TARGET :: descriptor
133 REAL(
dp),
DIMENSION(:),
INTENT(IN) :: outer_deriv
134 REAL(
dp),
DIMENSION(:),
INTENT(OUT) :: gradient
136 INTEGER :: i, info, npoints
137 REAL(
dp),
ALLOCATABLE,
DIMENSION(:) :: cov_deriv, weights_deriv
138 REAL(
dp),
DIMENSION(SIZE(descriptor)) :: kg
141 training_matrix => pao%ml_training_matrices(ikind)
142 npoints =
SIZE(training_matrix%outputs, 2)
145 ALLOCATE (weights_deriv(npoints))
147 weights_deriv(i) = sum(outer_deriv*training_matrix%outputs(:, i))
151 ALLOCATE (cov_deriv(npoints))
152 cov_deriv(:) = weights_deriv(:)
153 CALL dpotrs(
"U", npoints, 1, training_matrix%GP, npoints, cov_deriv, npoints, info)
159 kg = kernel_grad(pao%gp_scale, descriptor, training_matrix%inputs(:, i))
160 gradient(:) = gradient(:) + kg(:)*cov_deriv(i)
163 DEALLOCATE (cov_deriv, weights_deriv)
subroutine, public pao_ml_gp_gradient(pao, ikind, descriptor, outer_deriv, gradient)
Calculate gradient of Gaussian process.
subroutine, public pao_ml_gp_predict(pao, ikind, descriptor, output, variance)
Uses covariance matrix to make prediction.