Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Linear kernel #29

Merged
merged 3 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions qml/arad.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

import numpy as np

from .farad_kernels import fget_global_kernels_arad
from .farad_kernels import fget_global_symmetric_kernels_arad

from .farad_kernels import fget_local_kernels_arad
from .farad_kernels import fget_local_symmetric_kernels_arad

Expand Down Expand Up @@ -131,6 +134,85 @@ def generate_arad_representation(coordinates, nuclear_charges, size=23, cut_dist

return M

def get_global_kernels_arad(X1, X2, sigmas,
width=0.2, cut_distance=5.0, r_width=1.0, c_width=0.5):
""" Calculates the global Gaussian kernel matrix K for atomic ARAD
descriptors for a list of different sigmas. Each kernel element
is the sum of all kernel elements between pairs of atoms in two molecules.

K is calculated using an OpenMP parallel Fortran routine.

:param X1: ARAD descriptors for molecules in set 1.
:type X1: numpy array
:param X2: Array of ARAD descriptors for molecules in set 2.
:type X2: numpy array
:param sigmas: List of sigmas for which to calculate the Kernel matrices.
:type sigmas: list

:return: The kernel matrices for each sigma - shape (number_sigmas, number_molecules1, number_molecules2)
:rtype: numpy array
"""

amax = X1.shape[1]

assert X1.shape[3] == amax, "ERROR: Check ARAD decriptor sizes! code = 1"
assert X2.shape[1] == amax, "ERROR: Check ARAD decriptor sizes! code = 2"
assert X2.shape[3] == amax, "ERROR: Check ARAD decriptor sizes! code = 3"

nm1 = X1.shape[0]
nm2 = X2.shape[0]

N1 = np.empty(nm1, dtype = np.int32)
Z1_arad = np.zeros((nm1, amax, 2))
for i in range(nm1):
N1[i] = len(np.where(X1[i,:,2,0] > 0)[0])
Z1_arad[i] = X1[i,:,1:3,0]

N2 = np.empty(nm2, dtype = np.int32)
Z2_arad = np.zeros((nm2, amax, 2))
for i in range(nm2):
N2[i] = len(np.where(X2[i,:,2,0] > 0)[0])
Z2_arad[i] = X2[i,:,1:3,0]

sigmas = np.array(sigmas)
nsigmas = sigmas.size

return fget_global_kernels_arad(X1, X2, Z1_arad, Z2_arad, N1, N2, sigmas,
nm1, nm2, nsigmas, width, cut_distance, r_width, c_width)


def get_global_symmetric_kernels_arad(X1, sigmas,
width=0.2, cut_distance=5.0, r_width=1.0, c_width=0.5):
""" Calculates the global Gaussian kernel matrix K for atomic ARAD
descriptors for a list of different sigmas. Each kernel element
is the sum of all kernel elements between pairs of atoms in two molecules.

K is calculated using an OpenMP parallel Fortran routine.

:param X1: ARAD descriptors for molecules in set 1.
:type X1: numpy array
:param sigmas: List of sigmas for which to calculate the Kernel matrices.
:type sigmas: list

:return: The kernel matrices for each sigma - shape (number_sigmas, number_molecules1, number_molecules1)
:rtype: numpy array
"""

nm1 = X1.shape[0]
amax = X1.shape[1]

N1 = np.empty(nm1, dtype = np.int32)
Z1_arad = np.zeros((nm1, amax, 2))
for i in range(nm1):
N1[i] = len(np.where(X1[i,:,2,0] > 0)[0])
Z1_arad[i] = X1[i,:,1:3,0]

sigmas = np.array(sigmas)
nsigmas = sigmas.size

return fget_global_symmetric_kernels_arad(X1, Z1_arad, N1, sigmas,
nm1, nsigmas, width, cut_distance, r_width, c_width)


def get_local_kernels_arad(X1, X2, sigmas,
width=0.2, cut_distance=5.0, r_width=1.0, c_width=0.5):
Expand Down
Loading