本文整理汇总了Python中shogun.Features.StringCharFeatures.get_max_vector_length方法的典型用法代码示例。如果您正苦于以下问题:Python StringCharFeatures.get_max_vector_length方法的具体用法?Python StringCharFeatures.get_max_vector_length怎么用?Python StringCharFeatures.get_max_vector_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogun.Features.StringCharFeatures
的用法示例。
在下文中一共展示了StringCharFeatures.get_max_vector_length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_sensor
# 需要导入模块: from shogun.Features import StringCharFeatures [as 别名]
# 或者: from shogun.Features.StringCharFeatures import get_max_vector_length [as 别名]
def init_sensor(self, kernel, svs):
f = StringCharFeatures(svs, DNA)
kname = kernel['name']
if kname == 'spectrum':
wf = StringWordFeatures(f.get_alphabet())
wf.obtain_from_char(f, kernel['order'] - 1, kernel['order'], 0, False)
pre = SortWordString()
pre.init(wf)
wf.add_preprocessor(pre)
wf.apply_preprocessor()
f = wf
k = CommWordStringKernel(0, False)
k.set_use_dict_diagonal_optimization(kernel['order'] < 8)
self.preproc = pre
elif kname == 'wdshift':
k = WeightedDegreePositionStringKernel(0, kernel['order'])
k.set_normalizer(IdentityKernelNormalizer())
k.set_shifts(kernel['shift'] *
numpy.ones(f.get_max_vector_length(), dtype=numpy.int32))
k.set_position_weights(1.0 / f.get_max_vector_length() *
numpy.ones(f.get_max_vector_length(), dtype=numpy.float64))
else:
raise "Currently, only wdshift and spectrum kernels supported"
self.kernel = k
self.train_features = f
return (self.kernel, self.train_features)
示例2:
# 需要导入模块: from shogun.Features import StringCharFeatures [as 别名]
# 或者: from shogun.Features.StringCharFeatures import get_max_vector_length [as 别名]
from shogun.Features import StringCharFeatures, RAWBYTE
from numpy import array
#create string features
f=StringCharFeatures(['hey','guys','i','am','a','string'], RAWBYTE)
#and output several stats
print "max string length", f.get_max_vector_length()
print "number of strings", f.get_num_vectors()
print "length of first string", f.get_vector_length(0)
print "string[5]", ''.join(f.get_feature_vector(5))
print "strings", f.get_features()
#replace string 0
f.set_feature_vector(array(['t','e','s','t']), 0)
print "strings", f.get_features()