def __init__(self, classified_data_list, kernel, svm_constructor=LibSvmClassifier, ensemble_size=3): self._classifiers = [] for _ in range(ensemble_size): data = classified_data_list.copy() util.shuffle(data) util.take_n(data, 10) self._classifiers.append(svm_constructor(data, kernel))
def interleave_tileset(data): tile_size = 8*8 tiles = [] for planar_tile in take_n(data, tile_size): tiles.append(interleave_planar(planar_tile)) return tiles
def flip_image(image, image_w, hflip=False, vflip=False): if not hflip and not vflip: return image rows = list(take_n(image, image_w)) if vflip: rows.reverse() if hflip: for row in rows: row.reverse() # flatten list of arrays back return array('B', (pixel for row in rows for pixel in row))
def parse_objects(world_data, num_objects): objects_data = world_data[:num_objects * ObjectType.ENTRY_SIZE] return (ObjectType(obj_data) for obj_data in take_n(objects_data, ObjectType.ENTRY_SIZE))
def unpack_palette(data): pal = [] for r,g,b in util.take_n(data, 3): pal.append((r, g, b)) return pal
def unpack_palette(data): pal = [] for r, g, b in util.take_n(data, 3): pal.append((r, g, b)) return pal
# Devices # ########### # 16 hosts per /24 devices = fx.generate_devices(16 * len(networks)) # Create Device objects site.devices.post(devices) print 'Populated Devices.' ############## # Interfaces # ############## # Get list of device ids dev_resp = site.devices.get() device_ids = [dev['id'] for dev in dev_resp['data']['devices']] # Get list of IP addreses and make them an iterable for take() ip_list = [a['cidr'] for a in addresses] ip_iter = iter(ip_list) # 16 interfaces per host interfaces = [] for device_id in device_ids: my_ips = fx.take_n(16, ip_iter) my_interfaces = fx.generate_interfaces(device_id, address_pool=my_ips) interfaces.extend(my_interfaces) # Create Interface objects site.interfaces.post(interfaces) print 'Populated Interfaces.'
########### # 16 hosts per /24 devices = fx.generate_devices(16 * len(networks)) # Create Device objects site.devices.post(devices) print 'Populated Devices.' ############## # Interfaces # ############## # Get list of device ids dev_resp = site.devices.get() device_ids = [dev['id'] for dev in dev_resp['data']['devices']] # Get list of IP addreses and make them an iterable for take() ip_list = [a['cidr'] for a in addresses] ip_iter = iter(ip_list) # 16 interfaces per host interfaces = [] for device_id in device_ids: my_ips = fx.take_n(16, ip_iter) my_interfaces = fx.generate_interfaces(device_id, address_pool=my_ips) interfaces.extend(my_interfaces) # Create Interface objects site.interfaces.post(interfaces) print 'Populated Interfaces.'