def optimal_options_from_betweenness(env, count): g = env.to_graph() gr = g.reverse() """Create an option that takes a state to a random set of nodes""" maximas = find_betweenness_maxima(g) options = util.progressMap(lambda n: optimal_point_option(g, gr, n, 16), maximas[:count]) return options
def optimal_options_from_betweenness( env, count ): g = env.to_graph() gr = g.reverse() """Create an option that takes a state to a random set of nodes""" maximas = find_betweenness_maxima( g ) options = util.progressMap( lambda n: optimal_point_option( g, gr, n, 16 ), maximas[ :count ] ) return options
def optimal_options_from_random_nodes( env, count ): """Create an option that takes a state to a random set of nodes""" g = env.to_graph() gr = g.reverse() nodes = gr.nodes() random.shuffle( nodes ) options = util.progressMap( lambda n: optimal_point_option( g, gr, n, 16 ), nodes[:count] ) return options
def learn_options_from_betweenness( epoch_budget, count, env, env_args, agent_type, agent_args ): """Create an option that takes a state to a random set of nodes""" g = env.to_graph() maximas = find_betweenness_maxima( g )[:count] # Evenly divide the epoch budget epochs = epoch_budget / len(maximas) options = util.progressMap( lambda n: learn_point_option( env, n, epochs, agent_type, agent_args ), maximas ) return options
def optimal_options_from_random_nodes(env, count): """Create an option that takes a state to a random set of nodes""" g = env.to_graph() gr = g.reverse() nodes = gr.nodes() random.shuffle(nodes) options = util.progressMap(lambda n: optimal_point_option(g, gr, n, 16), nodes[:count]) return options
def learn_options_from_betweenness(epoch_budget, count, env, env_args, agent_type, agent_args): """Create an option that takes a state to a random set of nodes""" g = env.to_graph() maximas = find_betweenness_maxima(g)[:count] # Evenly divide the epoch budget epochs = epoch_budget / len(maximas) options = util.progressMap( lambda n: learn_point_option(env, n, epochs, agent_type, agent_args), maximas) return options
def optimal_options_from_random_paths( env, count ): """Create an option that takes a state to a random set of nodes""" g = env.to_graph() gr = g.reverse() # Get all the edges in the graph nodes = g.nodes() random.shuffle( nodes ) paths = [] for node in nodes: if len( paths ) > count: break neighbours = g.successors( node ) if len( neighbours ) == 0: continue dest = random.choice( neighbours ) paths.append( (node, dest) ) options = util.progressMap( lambda (node, dest): optimal_path_option( g, gr, node, dest ), paths ) return options
def optimal_options_from_small_world( env, count, r ): """Create an option that takes a state to a random nodes as per a power-law dist""" g = env.to_graph() gr = g.reverse() S = len( g.nodes() ) states = range(S) # Get all the edges in the graph max_length = np.power( 16, 1.0/r ) # fn of r path_lengths = nx.all_pairs_shortest_path_length( g, cutoff=max_length ).items() random.shuffle(states) paths = [] for s in states: if len( paths ) > count: break s_ = choose_small_world( path_lengths, s, r ) if not s_: continue paths.append( (s,s_) ) options = util.progressMap( lambda (node, dest): optimal_path_option( g, gr, node, dest ), paths ) return options
def optimal_options_from_ultra_small_world( env, count, r ): """Create an option that takes a state to a random nodes as per a power-law dist""" g = env.to_graph() gr = g.reverse() S = len( g.nodes() ) states = range(S) random.shuffle(states) """ # Get all the edges in the graph max_length = np.power( 16, 1.0/r ) # fn of r path_lengths = nx.all_pairs_shortest_path_length( g, cutoff=max_length ).items() random.shuffle(states) paths = [] for s in states: if len( paths ) > count: break s_ = choose_small_world( path_lengths, s, r ) if not s_: continue paths.append( (s,s_) ) """ gamma=2.5 alpha=1.5 degreeRange=15 #Generate hidden variables for the expected node degrees expectedDegrees={} for s in states: expectedDegrees[s]=gammaDistribution(gamma,4,degreeRange) path_lengths = nx.all_pairs_shortest_path_length(g) probConnection={} degree = [0 for _ in states] for s1 in states: probConnection[s1]={} for s2 in states: if path_lengths[s1][s2]<=1 or s1==s2: probConnection[s1][s2]=0.0 else: d=path_lengths[s1][s2] d_c=expectedDegrees[s1]*expectedDegrees[s2] probConnection[s1][s2]=(1+((d+0.0)/(d_c+0.0)))**(-alpha) paths=[] print degree for s1 in states: for s2 in states: #if len( paths )>count: # break if path_lengths[s1][s2]<=1 or s1==s2: continue else: coinToss=random.random() if coinToss<probConnection[s1][s2]: paths.append((s1,s2)) degree[s1] += 1 degree[s2] += 1 #if len( paths )>count: # break print degree degree = [x for x in degree] degrees = range(0,np.max(degree)+1) print np.min(degree), np.max(degree) degreefreq = [0 for _ in range(np.max(degree)+1)] expecteddegfreq = [np.power(k,-gamma) for k in range(np.max(degree)+1)] for i in degree: degreefreq[i] += 1 print np.sum(degreefreq) plt.plot(degrees, degreefreq) plt.show() plt.plot(degrees, expecteddegfreq) plt.show() exit() random.shuffle(paths) paths=paths[:count] options = util.progressMap( lambda (node, dest): optimal_path_option( g, gr, node, dest ), paths ) return options