Commit 5015902e authored by Malthe Kjær Bisbo's avatar Malthe Kjær Bisbo
Browse files

slight changes to descriptors and prior

parent dd3edadb
import numpy as np
import unittest
from gpr import gpr
class test_kernel(unittest.TestCase):
@classmethod
def setUpClass(cls):
print('setupClass')
@classmethod
def tearDownClass(cls):
print('teardownClass')
def setUp(self):
print('setUp')
#self.kernel = gauss_kernel()
self.gpr = gpr()
def tearDown(self):
print('tearDown\n')
def test_jac(self):
x1 = np.array([1.,2.,3.])
x2 = np.array([1.5,2.,1.])
x3 = np.array([3.,1.,1.])
y = np.c_[x1,x2,x3].T
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x1,x2),
self.kernel.numerical_jacobian(x1,x2))
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x1,y),
self.kernel.numerical_jacobian(x1,y))
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x2,y),
self.kernel.numerical_jacobian(x2,y))
def test_hyper_jac(self):
x1 = np.array([1.,2.,3.])
x2 = np.array([1.5,2.,1.])
x3 = np.array([3.,1.,1.])
X = np.c_[x1,x2,x3].T
np.testing.assert_almost_equal(self.kernel.kernel_hyperparameter_gradient(X),
self.kernel.numerical_hyperparameter_gradient(X))
if __name__ == '__main__':
unittest.main()
import numpy as np
import unittest
from kernel import gauss_kernel, double_gauss_kernel
class test_kernel(unittest.TestCase):
@classmethod
def setUpClass(cls):
print('setupClass')
@classmethod
def tearDownClass(cls):
print('teardownClass')
def setUp(self):
print('setUp')
#self.kernel = gauss_kernel()
self.kernel = double_gauss_kernel()
def tearDown(self):
print('tearDown\n')
def test_jac(self):
x1 = np.array([1.,2.,3.])
x2 = np.array([1.5,2.,1.])
x3 = np.array([3.,1.,1.])
y = np.c_[x1,x2,x3].T
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x1,x2),
self.kernel.numerical_jacobian(x1,x2))
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x1,y),
self.kernel.numerical_jacobian(x1,y))
np.testing.assert_almost_equal(self.kernel.kernel_jacobian(x2,y),
self.kernel.numerical_jacobian(x2,y))
def test_hyper_jac(self):
x1 = np.array([1.,2.,3.])
x2 = np.array([1.5,2.,1.])
x3 = np.array([3.,1.,1.])
X = np.c_[x1,x2,x3].T
np.testing.assert_almost_equal(self.kernel.kernel_hyperparameter_gradient(X),
self.kernel.numerical_hyperparameter_gradient(X))
if __name__ == '__main__':
unittest.main()
mkb@s81n11.grendel.cscaa.dk.9244:1576483191
\ No newline at end of file
mkb@s81n11.grendel.cscaa.dk.9244:1576483191
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -91,10 +91,10 @@ def convert_atom_types(num): ...@@ -91,10 +91,10 @@ def convert_atom_types(num):
num_converted[i] = j num_converted[i] = j
return num_converted return num_converted
class Angular_Fingerprint(object): class Fingerprint(object):
""" comparator for construction of angular fingerprints """ comparator for construction of angular fingerprints
""" """
def __init__(self, atoms, Rc1=4.0, Rc2=4.0, binwidth1=0.1, Nbins2=30, sigma1=0.2, sigma2=0.10, nsigma=4, eta=1, gamma=3, use_angular=True): def __init__(self, Rc1=6.0, Rc2=4.0, binwidth1=0.2, Nbins2=30, sigma1=0.2, sigma2=0.2, eta=20, gamma=2, use_angular=True):
""" Set a common cut of radius """ Set a common cut of radius
""" """
...@@ -105,11 +105,14 @@ class Angular_Fingerprint(object): ...@@ -105,11 +105,14 @@ class Angular_Fingerprint(object):
self.binwidth2 = np.pi / Nbins2 self.binwidth2 = np.pi / Nbins2
self.sigma1 = sigma1 self.sigma1 = sigma1
self.sigma2 = sigma2 self.sigma2 = sigma2
self.nsigma = nsigma
self.eta = eta self.eta = eta
self.gamma = gamma self.gamma = gamma
self.use_angular = use_angular self.use_angular = use_angular
self.initialized = False
def initialize_from_atoms(self, atoms):
self.nsigma = 4
self.volume = atoms.get_volume() self.volume = atoms.get_volume()
self.pbc = atoms.get_pbc() self.pbc = atoms.get_pbc()
...@@ -123,7 +126,7 @@ class Angular_Fingerprint(object): ...@@ -123,7 +126,7 @@ class Angular_Fingerprint(object):
self.m2 = self.nsigma*self.sigma2/self.binwidth2 # number of neighbour bins included. self.m2 = self.nsigma*self.sigma2/self.binwidth2 # number of neighbour bins included.
self.smearing_norm2 = erf(1/np.sqrt(2) * self.m2 * self.binwidth2/self.sigma2) # Integral of the included part of the gauss self.smearing_norm2 = erf(1/np.sqrt(2) * self.m2 * self.binwidth2/self.sigma2) # Integral of the included part of the gauss
self.binwidth2 = np.pi/Nbins2 self.binwidth2 = np.pi/self.Nbins2
# Prepare stuff to handle multiple species # Prepare stuff to handle multiple species
self.num = atoms.get_atomic_numbers() self.num = atoms.get_atomic_numbers()
...@@ -184,7 +187,7 @@ class Angular_Fingerprint(object): ...@@ -184,7 +187,7 @@ class Angular_Fingerprint(object):
self.Nelements_2body = self.Nbondtypes_2body * self.Nbins1 self.Nelements_2body = self.Nbondtypes_2body * self.Nbins1
self.Nelements_3body = self.Nbondtypes_3body * self.Nbins2 self.Nelements_3body = self.Nbondtypes_3body * self.Nbins2
if use_angular: if self.use_angular:
self.Nelements = self.Nelements_2body + self.Nelements_3body self.Nelements = self.Nelements_2body + self.Nelements_3body
else: else:
self.Nelements = self.Nelements_2body self.Nelements = self.Nelements_2body
...@@ -194,9 +197,15 @@ class Angular_Fingerprint(object): ...@@ -194,9 +197,15 @@ class Angular_Fingerprint(object):
self.cell = atoms.get_cell() self.cell = atoms.get_cell()
self.neighbourcells_disp = self.__get_neighbour_cells_displacement(self.pbc, self.cell) self.neighbourcells_disp = self.__get_neighbour_cells_displacement(self.pbc, self.cell)
self.initialized = True
def get_feature(self, atoms): def get_feature(self, atoms):
""" """
""" """
if not self.initialized:
self.initialize_from_atoms(atoms)
cdef double Rc1 = self.Rc1 cdef double Rc1 = self.Rc1
cdef double Rc2 = self.Rc2 cdef double Rc2 = self.Rc2
cdef double binwidth1 = self.binwidth1 cdef double binwidth1 = self.binwidth1
...@@ -437,6 +446,9 @@ class Angular_Fingerprint(object): ...@@ -437,6 +446,9 @@ class Angular_Fingerprint(object):
def get_featureGradient(self, atoms): def get_featureGradient(self, atoms):
if not self.initialized:
self.initialize_from_atoms(atoms)
cdef double Rc1 = self.Rc1 cdef double Rc1 = self.Rc1
cdef double Rc2 = self.Rc2 cdef double Rc2 = self.Rc2
cdef double binwidth1 = self.binwidth1 cdef double binwidth1 = self.binwidth1
......
...@@ -2,4 +2,4 @@ from distutils.core import setup ...@@ -2,4 +2,4 @@ from distutils.core import setup
from Cython.Build import cythonize from Cython.Build import cythonize
import numpy import numpy
setup(ext_modules=cythonize('angular_fingerprintFeature_cy.pyx'), include_dirs=[numpy.get_include()]) setup(ext_modules=cythonize('fingerprint.pyx'), include_dirs=[numpy.get_include()])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment