def __iter__(self): speaker_generator = iter(random_cycle(self._speakers)) speaker_utterances_generator = { s: iter(random_cycle(us)) for s, us in self._speaker_utterances.items() } while True: speakers = [] for _ in range(self.speakers_per_batch): speakers.append(next(speaker_generator)) utterances = [] for s in speakers: us = speaker_utterances_generator[s] for _ in range(self.utterances_per_speaker): utterances.append(next(us)) yield utterances
population, mc_sol_int = pickle.load( open(filename_controller,'rb') ) print "int solution has prefix mc bounds ", prefix_maxmin(G, mc_sol_int['states'], mode) print "int solution has suffix mc bounds ", suffix_maxmin(G, mc_sol_int['cycles'], mode, mc_sol_int['assignments']) else: population = [TCL(22 + 1 * np.random.rand(1)) for i in range(pop_size)] init = np.zeros(len(G)) for tcl in population: init[ order_fcn(ab.point_to_midx(tcl.state) ) ] += 1 # generate a set of random cycles cycle_set = [] c_quot_set = set([]) while len(cycle_set) < 100: c = random_cycle(G, [], 5, 0.8) c_quot = cyclequot(G,c,mode) if c_quot not in c_quot_set: cycle_set.append(c) c_quot_set.add(c_quot) print "Min cycle ratio: ", min(c_quot_set) print "Max cycle ratio: ", max(c_quot_set) # non-integer mode-counting synthesis data_nonint = {} data_nonint['graph'] = G data_nonint['init'] = init data_nonint['horizon'] = T data_nonint['mode'] = mode
print len(forbidden_nodes) # randomize an initial condition init = np.zeros(len(ab)) j = 0 while j < 10000: i = np.random.randint(len(ab), size=1) if ab.idx_to_node(i) not in forbidden_nodes: init[i] += 1 j += 1 # some random cycles cycle_set = [] c_quot_set = set([]) for i in range(500): c = random_cycle(ab.graph, forbidden_nodes, 5, 0.8) c_quot = cyclequot(ab.graph, c, 1) if c_quot not in c_quot_set: cycle_set.append(c) c_quot_set.add(c_quot) print len(cycle_set) # mode counting synthesis parameters prob_data = {} prob_data['graph'] = ab.graph prob_data['init'] = init prob_data['horizon'] = 10 prob_data['mode'] = 1 prob_data['lb_suffix'] = 7000 prob_data['ub_suffix'] = 7000
# randomize an initial condition init = np.zeros(len(G)) np.random.seed(0) j = 0 while j < 10000: i = np.random.randint( len(G), size=1) if ab.idx_to_node(i) not in forbidden_nodes: init[i] += 1 j += 1 # some random cycles cycle_set = [] c_quot_set = set([]) while len(cycle_set) < 100: c = random_cycle(G, forbidden_nodes, 5, 0.8) c_quot = cyclequot(G,c,1) if c_quot not in c_quot_set: cycle_set.append(c) c_quot_set.add(c_quot) # mode counting synthesis parameters prob_data = {} prob_data['graph'] = ab.graph prob_data['init'] = init prob_data['horizon'] = 10 prob_data['mode'] = 1 prob_data['lb_suffix'] = 6750 prob_data['ub_suffix'] = 6750 prob_data['cycle_set'] = cycle_set