本文整理汇总了Python中sg.sg函数的典型用法代码示例。如果您正苦于以下问题:Python sg函数的具体用法?Python sg怎么用?Python sg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multiplicity
def multiplicity(hkls, sgname=None, sgno=None, cell_choice="standard"):
"""
Calculate the powder diffraction multiplicity of a set of reflections
INPUT: hkls : HKLs for the reflections
sgno/sgname : provide either the space group number or its name
e.g. sgno=225 or equivalently
sgname='Fm-3m'
OUTPUT: array of multiplicities
"""
if sgname != None:
spg = sg.sg(sgname=sgname, cell_choice=cell_choice)
elif sgno != None:
spg = sg.sg(sgno=sgno, cell_choice=cell_choice)
else:
raise ValueError, "No space group information given"
# Making sure that the inversion element also for non-centrosymmetric space groups
Rots = np.concatenate((spg.rot[: spg.nuniq], -spg.rot[: spg.nuniq]))
(dummy, rows) = np.unique((Rots * np.random.rand(3, 3)).sum(axis=2).sum(axis=1), return_index=True)
Rots = Rots[np.sort(rows)]
M = []
for refl in hkls:
a = np.array([np.dot(refl[:3], R) for R in Rots])
(dummy, rows) = np.unique((a * np.random.rand(3)).sum(axis=1), return_index=True)
M.append(a[rows].shape[0])
return np.array(M)
示例2: _get_alpha_and_sv
def _get_alpha_and_sv(indata, prefix):
if not indata.has_key(prefix+'alpha_sum') and \
not indata.has_key(prefix+'sv_sum'):
return None, None
a=0
sv=0
if indata.has_key(prefix+'label_type') and \
indata[prefix+'label_type']=='series':
for i in xrange(sg('get_num_svms')):
[dump, weights]=sg('get_svm', i)
weights=weights.T
for item in weights[0].tolist():
a+=item
for item in weights[1].tolist():
sv+=item
a=abs(a-indata[prefix+'alpha_sum'])
sv=abs(sv-indata[prefix+'sv_sum'])
else:
[dump, weights]=sg('get_svm')
weights=weights.T
for item in weights[0].tolist():
a+=item
a=abs(a-indata[prefix+'alpha_sum'])
for item in weights[1].tolist():
sv+=item
sv=abs(sv-indata[prefix+'sv_sum'])
return a, sv
示例3: multiplicity
def multiplicity(position, sgname=None, sgno=None, cell_choice='standard'):
"""
Calculates the multiplicity of a fractional position in the unit cell.
If called by sgno, cell_choice is necessary for eg rhombohedral space groups.
"""
if sgname != None:
mysg = sg.sg(sgname=sgname, cell_choice=cell_choice)
elif sgno !=None:
mysg = sg.sg(sgno=sgno, cell_choice=cell_choice)
else:
raise ValueError, 'No space group information provided'
lp = n.zeros((mysg.nsymop, 3))
for i in range(mysg.nsymop):
lp[i, :] = n.dot(position, mysg.rot[i]) + mysg.trans[i]
lpu = n.array([lp[0, :]])
multi = 1
for i in range(1, mysg.nsymop):
for j in range(multi):
t = lp[i]-lpu[j]
if n.sum(n.mod(t, 1)) < 0.00001:
break
else:
if j == multi-1:
lpu = n.concatenate((lpu, [lp[i, :]]))
multi += 1
return multi
示例4: _set_distribution
def _set_distribution (indata):
prefix='distribution_'
if indata[prefix+'name']=='HMM':
sg('new_hmm', indata[prefix+'N'], indata[prefix+'M'])
sg('bw')
else:
raise NotImplementedError, 'Can\'t yet train other distributions than HMM in static interface.'
示例5: _evaluate
def _evaluate (indata, prefix):
dmatrix=sg('get_distance_matrix', 'TRAIN')
dm_train=max(abs(indata['distance_matrix_train']-dmatrix).flat)
dmatrix=sg('get_distance_matrix', 'TEST')
dm_test=max(abs(indata['distance_matrix_test']-dmatrix).flat)
return util.check_accuracy(
indata[prefix+'accuracy'], dm_train=dm_train, dm_test=dm_test)
示例6: _train
def _train (indata):
if indata['regression_type']=='svm':
sg('c', double(indata['regression_C']))
sg('svm_epsilon', indata['regression_epsilon'])
sg('svr_tube_epsilon', indata['regression_tube_epsilon'])
elif indata['regression_type']=='kernelmachine':
sg('krr_tau', indata['regression_tau'])
else:
raise StandardError, 'Incomplete regression data.'
sg('train_regression')
示例7: predict
def predict(self, testPoints):
"""Predicts performance using previously learned model.
self.train() must be called before this!"""
if len(testPoints.shape) < 2:
testPoints = array([testPoints])
sg("set_features", "TEST", phys2unif(testPoints, self.ranges).T)
predictions = sg("classify")
return predictions
示例8: predict
def predict(self, testPoints):
'''Predicts performance using previously learned model.
self.train() must be called before this!'''
if len(testPoints.shape) < 2:
testPoints = array([testPoints])
sg('set_features', 'TEST', phys2unif(testPoints,self.ranges).T)
predictions = sg('classify')
return predictions
示例9: _evaluate
def _evaluate (indata, prefix):
util.set_and_train_kernel(indata)
kmatrix=sg('get_kernel_matrix', 'TRAIN')
km_train=max(abs(indata['kernel_matrix_train']-kmatrix).flat)
kmatrix=sg('get_kernel_matrix', 'TEST')
km_test=max(abs(indata['kernel_matrix_test']-kmatrix).flat)
return util.check_accuracy(
indata[prefix+'accuracy'], km_train=km_train, km_test=km_test)
示例10: clustering_kmeans
def clustering_kmeans (fm_train=traindat, size_cache=10,k=3,iter=1000):
sg('set_features', 'TRAIN', fm_train)
sg('set_distance', 'EUCLIDIAN', 'REAL')
sg('new_clustering', 'KMEANS')
sg('train_clustering', k, iter)
[radi, centers]=sg('get_clustering')
return [radi, centers]
示例11: clustering_hierarchical
def clustering_hierarchical (fm_train=traindat, size_cache=10,merges=3):
sg('set_features', 'TRAIN', fm_train)
sg('set_distance', 'EUCLIDIAN', 'REAL')
sg('new_clustering', 'HIERARCHICAL')
sg('train_clustering', merges)
[merge_distance, pairs]=sg('get_clustering')
return [merge_distance, pairs]
示例12: kernel_const
def kernel_const(fm_train_real=traindat, fm_test_real=testdat, c=23.0, size_cache=10):
sg("set_features", "TRAIN", fm_train_real)
sg("set_features", "TEST", fm_test_real)
sg("set_kernel", "CONST", "REAL", size_cache, c)
km = sg("get_kernel_matrix", "TRAIN")
km = sg("get_kernel_matrix", "TEST")
return km
示例13: distance_chisquare
def distance_chisquare (fm_train_real=traindat,fm_test_real=testdat):
sg('set_distance', 'CHISQUARE', 'REAL')
sg('set_features', 'TRAIN', fm_train_real)
dm=sg('get_distance_matrix', 'TRAIN')
sg('set_features', 'TEST', fm_test_real)
dm=sg('get_distance_matrix', 'TEST')
return dm
示例14: distance_braycurtis
def distance_braycurtis (fm_train_real=traindat,fm_test_real=testdat):
sg('set_distance', 'BRAYCURTIS', 'REAL')
sg('set_features', 'TRAIN', fm_train_real)
dm=sg('get_distance_matrix', 'TRAIN')
sg('set_features', 'TEST', fm_test_real)
dm=sg('get_distance_matrix', 'TEST')
return dm
示例15: distance_cosine
def distance_cosine (fm_train_real=traindat,fm_test_real=testdat):
sg('set_distance', 'COSINE', 'REAL')
sg('set_features', 'TRAIN', fm_train_real)
dm=sg('get_distance_matrix', 'TRAIN')
sg('set_features', 'TEST', fm_test_real)
dm=sg('get_distance_matrix', 'TEST')
return dm