本文整理汇总了Python中record.Record.initialize_from_annotation方法的典型用法代码示例。如果您正苦于以下问题:Python Record.initialize_from_annotation方法的具体用法?Python Record.initialize_from_annotation怎么用?Python Record.initialize_from_annotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类record.Record
的用法示例。
在下文中一共展示了Record.initialize_from_annotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from record import Record [as 别名]
# 或者: from record.Record import initialize_from_annotation [as 别名]
def add(self, number_entities, records_per_entity):
"""
Adds additional entities to the database
:param number_entities:
:param records_per_entity:
"""
if len(self.labels) != len(self.database.records):
raise Exception('Number of records and labels do not match')
current_max_record_id = 0
current_max_entity_id = 0
for (record_id, _), (__, entity_id) in izip(self.database.records.iteritems(), self.labels.iteritems()):
if record_id > current_max_record_id:
current_max_record_id = record_id
if entity_id > current_max_entity_id:
current_max_entity_id = entity_id
record_index = current_max_record_id+1
for entity_index in range(current_max_entity_id+1, current_max_entity_id+1+number_entities):
features = np.random.rand(self.database.feature_descriptor.number)
features = features.astype(str)
number_records = records_per_entity
for _ in range(number_records):
r = Record(record_index, self.database.feature_descriptor)
r.initialize_from_annotation(features)
self.database.records[record_index] = r
self.labels[record_index] = entity_index
record_index += 1
示例2: __init__
# 需要导入模块: from record import Record [as 别名]
# 或者: from record.Record import initialize_from_annotation [as 别名]
def __init__(self, number_entities, records_per_entity, number_features=2):
"""
Initializes synthetic database
No initial corruption, so records from the same cluster have exact same features
:param number_entities:
:param records_per_entity: Number of records per entity
:param number_features:
"""
indices = range(0, number_features)
names = ['Name_{0}'.format(s) for s in indices]
types = ['float' for _ in indices]
strengths = ['weak' for _ in indices]
blocking = ['' for _ in indices]
pairwise_uses = ['numerical_difference' for _ in indices]
self.labels = dict() # [record identifier, cluster label]
self.database = Database()
feature_descriptor = FeatureDescriptor(names, types, strengths, blocking, pairwise_uses)
self.database.feature_descriptor = feature_descriptor
record_index = 0
for entity_index in range(0, number_entities):
features = np.random.rand(feature_descriptor.number)
features = features.astype(str)
number_records = records_per_entity
for _ in range(number_records):
r = Record(record_index, feature_descriptor)
r.initialize_from_annotation(features)
self.database.records[record_index] = r
self.labels[record_index] = entity_index
record_index += 1
示例3: MyTestCase
# 需要导入模块: from record import Record [as 别名]
# 或者: from record.Record import initialize_from_annotation [as 别名]
class MyTestCase(unittest.TestCase):
def setUp(self):
self._features_full = '9552601,neworleans,2014-01-30 02:41:11,Louisiana,New Orleans,8,' \
'0,haley,22,60/80/100,66,110.5,DD,30,26,29,caucasian,white,blue,brunette,' \
'rest_type,rest_ethnicity,res_age,9802534087;5182561877,NC;NY,charlotte;' \
'albany,[email protected],www.johnsmith.com,johnsmithmedia,' \
'Louisiana_2014_1_30_1391067671000_6_0.jpg;Louisiana_2014_1_30_1391067671000_6_1.jpg;' \
'Louisiana_2014_1_30_1391067671000_6_2.jpg;Louisiana_2014_1_30_1391067671000_6_3.jpg;' \
'Louisiana_2014_1_30_1391067671000_6_4.jpg;Louisiana_2014_1_30_1391067671000_6_5.jpg'
self._features_full = self._features_full.split(',')
feature_types = ('int,string,date,string,string,int,int,string,int,string,int,float,string,int,int,int,'
'string,string,string,string,,,,int,string,string,string,string,string,'
'string').split(',')
feature_descriptor = FeatureDescriptor('', feature_types, '', '', '')
feature_descriptor.number = len(feature_types)
self._r0 = Record(0, feature_descriptor)
self._r1 = Record(0, feature_descriptor)
def test_initialize_from_full_annotation(self):
self._r0.initialize_from_annotation(self._features_full)
self.assertSetEqual(self._r0.line_indices, {0})
self.assertSetEqual(self._r0.features[0], {9552601})
self.assertSetEqual(self._r0.features[1], {'neworleans'})
self.assertSetEqual(self._r0.features[2], {datetime.datetime(2014, 1, 30, 2, 41, 11)})
self.assertSetEqual(self._r0.features[3], {'Louisiana'})
self.assertSetEqual(self._r0.features[4], {'New Orleans'})
self.assertEqual(self._r0.features[5], {8})
self.assertEqual(self._r0.features[6], {0})
self.assertSetEqual(self._r0.features[7], {'haley'})
self.assertSetEqual(self._r0.features[8], {22})
self.assertSetEqual(self._r0.features[9], {'60/80/100'})
self.assertSetEqual(self._r0.features[10], {66})
self.assertSetEqual(self._r0.features[11], {110.5})
self.assertSetEqual(self._r0.features[12], {'DD'})
self.assertSetEqual(self._r0.features[13], {30})
self.assertSetEqual(self._r0.features[14], {26})
self.assertSetEqual(self._r0.features[15], {29})
self.assertSetEqual(self._r0.features[16], {'caucasian'})
self.assertSetEqual(self._r0.features[17], {'white'})
self.assertSetEqual(self._r0.features[18], {'blue'})
self.assertSetEqual(self._r0.features[19], {'brunette'})
self.assertSetEqual(self._r0.features[23], {9802534087, 5182561877})
self.assertSetEqual(self._r0.features[26], {'[email protected]'})
self.assertSetEqual(self._r0.features[27], {'www.johnsmith.com'})
self.assertSetEqual(self._r0.features[28], {'johnsmithmedia'})
self.assertSetEqual(self._r0.features[29], {'Louisiana_2014_1_30_1391067671000_6_0.jpg',
'Louisiana_2014_1_30_1391067671000_6_1.jpg',
'Louisiana_2014_1_30_1391067671000_6_2.jpg',
'Louisiana_2014_1_30_1391067671000_6_3.jpg',
'Louisiana_2014_1_30_1391067671000_6_4.jpg',
'Louisiana_2014_1_30_1391067671000_6_5.jpg'})
def test_eq(self):
self.assertEqual(self._r0, self._r1)
self._r0.initialize_from_annotation(self._features_full)
self.assertNotEqual(self._r0, self._r1)
self._r1.initialize_from_annotation(self._features_full)
self.assertEqual(self._r0, self._r1)
def test_initialize_from_empty_annotation(self):
annotation_empty = ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,'.split(',')
self._r0.initialize_from_annotation(annotation_empty)
self.assertEqual(self._r0, self._r1)
def test_merge(self):
self._r0.merge(self._r1)
self.assertEqual(self._r0, self._r1)
self._r0.initialize_from_annotation(self._features_full)
self._r0.merge(self._r1)
self.assertNotEqual(self._r0, self._r1)
self._r1.merge(self._r0)
self.assertEqual(self._r0, self._r1)