Commit d6724683 authored by Carl Poelking's avatar Carl Poelking
Browse files

Kernel adaptor, 'specific' mode.

parent 9d3c59fe
......@@ -29,6 +29,93 @@ class TrajectoryLogger(object):
self.ofs.close()
return
class Xnklab(object):
def __init__(self, atomic, types_global):
self.types_global = types_global
self.S = len(types_global)
self.N = atomic.basis.N
self.L = atomic.basis.L
# Descriptor dimension
self.dim_linear_xnklab = (self.S*self.S+self.S)/2*(self.N*self.N*(self.L+1))
self.dim_linear_xnkl = self.N*self.N*(self.L+1)
S = self.S
N = self.N
L = self.L
# Setup
self.X = np.zeros((S*N*N,S*(L+1)))
types_atomic = atomic.getTypes()
S_atomic = len(types_atomic)
for i in range(S_atomic):
a = types_atomic[i]
sa = types_global.index(a)
for j in range(S_atomic):
b = types_atomic[j]
sb = types_global.index(b)
xnklab = atomic.getPower(a,b).array
r1 = sa*N*N
r2 = r1+N*N
c1 = sb*(L+1)
c2 = c1+(L+1)
self.X[r1:r2,c1:c2] = xnklab.real
#print a, b, sa, sb
#print self.X
#raw_input('...')
#print "DONE"
return
def reduce(self):
dim_linear_xnklab = self.dim_linear_xnklab
dim_linear_xnkl = self.dim_linear_xnkl
self.X_linear = np.zeros((dim_linear_xnklab))
for sa in range(self.S):
for sb in range(sa,self.S):
# Find slice in matrix X
r1 = sa*self.N*self.N
r2 = r1+self.N*self.N
c1 = sb*(self.L+1)
c2 = c1+(self.L+1)
xnkl_linear = self.X[r1:r2,c1:c2].reshape((dim_linear_xnkl))
# Map to vector
sab = self.S*sa - (sa*sa-sa)/2 + (sb-sa) # Linear summation over upper triagonal section
idx0 = sab*dim_linear_xnkl
idx1 = (sab+1)*dim_linear_xnkl
self.X_linear[idx0:idx1] = xnkl_linear
#print sa, sb, sab, idx0, idx1
#print self.X_linear
#raw_input('...')
return self.X_linear
class KernelAdaptorSpecific(object):
def __init__(self, options, types_global):
self.types = types_global
self.S = len(types_global)
return
def adapt(self, spectrum):
IX = np.zeros((0.,0.), dtype='float64')
dimX = -1
for atomic_i in spectrum:
Xi_unnorm, Xi_norm = self.adaptScalar(atomic_i)
dimX = Xi_norm.shape[0]
if not IX.any():
IX = np.copy(Xi_norm) # TODO Is this necessary?
IX.resize((1, dimX))
else:
i = IX.shape[0]
IX.resize((i+1, dimX))
IX[-1,:] = Xi_norm
#print IX
return IX
def adaptScalar(self, atomic):
xnklab_atomic = Xnklab(atomic, self.types)
X = xnklab_atomic.reduce()
X_norm = X/np.dot(X,X)**0.5
return X, X_norm
class KernelAdaptorGlobalSpecific(object):
def __init__(self, options, *args, **kwargs):
if kwargs != {}: raise ValueError
if args != (): raise ValueError
return
class KernelAdaptorGeneric(object):
def __init__(self, options):
return
......@@ -272,7 +359,8 @@ class KernelFunctionDot3HarmonicDist(object):
KernelAdaptorFactory = {
'generic': KernelAdaptorGeneric,
'global-generic': KernelAdaptorGlobalGeneric
'specific': KernelAdaptorSpecific,
'global-generic': KernelAdaptorGlobalGeneric
}
KernelFunctionFactory = {
......
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