Beispiel #1
0
    def __init__(self,
                 frozen_graph_filename,
                 tokenizer_path,
                 maxlen=MAX_LEN,
                 input_tensor_name=INPUT_TENSOR_NAME,
                 output_tensor_name=OUTPUT_TENSOR_NAME,
                 learning_phase=LEARNING_PAHSE):
        print('Loading the graph')
        self.graph = load(frozen_graph_filename)
        self.X = self.graph.get_tensor_by_name("%s/%s" %
                                               (PREFIX, input_tensor_name))
        self.Y = self.graph.get_tensor_by_name("%s/%s" %
                                               (PREFIX, output_tensor_name))
        self.LF = self.graph.get_tensor_by_name("%s/%s" %
                                                (PREFIX, learning_phase))

        self.tokenizer = pickle.load(open(tokenizer_path, 'rb'))
        self.persistent_sess = tf.Session(graph=self.graph)

        self.maxlen = maxlen
Beispiel #2
0
def graph_load(path):
    try:
        return load(path)
    except:
        print("Graph not found.")
Beispiel #3
0
elif weight_type == "elo":
    weight_objw = weighting.elo(whiteelo)
    weight_objb = weighting.elo(blackelo)
elif weight_type == "wl":
    weight_obj = weighting.static()
elif weight_type == "lightblue":
    weight_obj = weighting.static()
elif weight_type == "static":
    weight_obj = weighting.static()
else: 
    raise "invalid weight type"
mvlst = []

# loads graph
graph.initialize()
graph.load("Carlsen100" + weight_type)

# initializes board
current_game = ch.Game()
current_game.setup()
color = 'w'
quit = False

# prints starting position
print "Here is the board:"
print current_game.board

# first recommend
lst = graph.firstrecommend()
lstlen = len(lst)
if lstlen == 1:
Beispiel #4
0
import graph
import das_sarma
import cohen

parser = argparse.ArgumentParser()
parser.add_argument("graph")
parser.add_argument("type", choices=["das_sarma", "cohen"])
parser.add_argument("param", type=int)
args = parser.parse_args()

datadir = "data"
graphfile = "%s/%s.graph" % (datadir, args.graph)
type = args.type
param = args.param
sketchfile = "%s/%s-%s-param%d.sketch" % (datadir, args.graph, type, param)

# load the graph
g = graph.load(graphfile)

# generate the sketches
sketch = None
if type == "das_sarma":
    sketch = das_sarma.sketches(g, param)
else:
    sketch = cohen.sketches(g, param)

# save the sketches
with open(sketchfile, 'wb') as output:
    pickle.dump(sketch, output, pickle.HIGHEST_PROTOCOL)
import graph
import trim

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help='input file to trim')
    parser.add_argument('max_vertices',
                        help='maximum vertices per edge',
                        type=int)
    args = parser.parse_args()

    graph = graph.Graph()

    print('loading graph from disk...')
    graph.load(args.input)

    print('updating neighbours map...')
    bar = progressbar.ProgressBar(max_value=len(graph.edges))

    trimmed_graph = trim.GraphTrimmer().trim(graph,
                                             args.max_vertices,
                                             on_status_update=bar.update)

    bar.finish()

    print('saving graph to disk...')
    filename_without_ext, ext = args.input.rsplit('.', 1)
    filename_without_ext = '{0}_trim_{1}'.format(filename_without_ext,
                                                 args.max_vertices)
    trimmed_filename = '{0}.{1}'.format(filename_without_ext, ext)
Beispiel #6
0
         len(triangles) - len(triangulated), "triangles from", len(triangles))

    with open("d%i_triangulation.triangles" % depth, "w") as fd:
        triangulation.write(triangulated, fd)

triangulation_edges = triangulation.edges_of(triangulated)

########################################################################
# VORONOÏ
########################################################################

voronoi_graph = {}

if ask_for.voronoi:
    with open(ask_for.voronoi) as fd:
        voronoi_graph = graph.load(fd)

else:
    LOGN("Compute the Voronoï diagram of the triangulation")
    # Changing the neighborhood to be on vertices instead of edges will not compute the true Voronoï dual graph,
    # but we want this graph to represent the relations on vertices of the tiles.
    voronoi_tri_graph = voronoi.dual(triangulated,
                                     neighborhood=voronoi.vertices_neighbours)
    # voronoi_tri_edges   = graph.edges_of(voronoi_tri_graph)
    # voronoi_tri_centers = graph.nodes_of(voronoi_tri_graph)

    LOGN("\tMerge nodes that are both located within a single diamond")
    LOG("\t\tMerge", len(voronoi_tri_graph), "nodes")
    with open("d%i_voronoi_dual.graph" % depth, "w") as fd:
        graph.write(voronoi_tri_graph, fd)
    voronoi_graph = voronoi.merge_enclosed(voronoi_tri_graph, penrose_segments)
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('groups', help='json file describing seed groups')
    args = parser.parse_args()

    # load group from file
    with open(args.groups, 'rb') as f:
        groups = json.loads(f.read())

    # load template from file
    with open('descender.html.jinja', 'rb') as f:
        template = jinja2.Template(f.read())

    # load graph from file
    graph = graph.Graph()
    graph.load('./graph.pickle')

    # find neighbours using the given groups and weight vector
    for group in groups:
        group['neighbours'] = graph.get_joint_neighbours(group['members'],
                                                         group_size=50)
        group['neighbours'] = [
            ''.join([c for c in x if ord(c) < 128])
            for x in group['neighbours']
        ]

    # generate output file
    with open('/tmp/descender.results.html', 'wb') as f:
        f.write(template.render({'groups': groups}))

    # open it
Beispiel #8
0
#

import argparse

import graph

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('graph',
                        help='file containing the graph information',
                        default='graph.pickle')
    args = parser.parse_args()

    # load graph from file
    graph = graph.Graph()
    graph.load(args.graph)

    # main loop
    while True:
        query = input('query> ')

        # break the loop
        if query == 'exit':
            break

        # return all relevant edges which contain the query's string
        elif query[0] == '~':
            results = [x for x in graph.edges if query[1:] in x.lower()]
            print(', '.join(results))

        # return all relevant edges which contain the query's string
Beispiel #9
0
import graph

graph.initialize()
graph.load("Carlsen20")

lst = graph.firstrecommend()
(x,y) = lst[0]

print "You should make this move:", x
print "It should give you:"
print y
Beispiel #10
0
    with open("d%i_triangulation.triangles" % depth, "w") as fd:
        triangulation.write( triangulated, fd )

triangulation_edges = triangulation.edges_of( triangulated )


########################################################################
# VORONOÏ
########################################################################

voronoi_graph = {}

if ask_for.voronoi:
    with open(ask_for.voronoi) as fd:
        voronoi_graph = graph.load( fd )

else:
    LOGN( "Compute the Voronoï diagram of the triangulation" )
    # Changing the neighborhood to be on vertices instead of edges will not compute the true Voronoï dual graph,
    # but we want this graph to represent the relations on vertices of the tiles.
    voronoi_tri_graph = voronoi.dual(triangulated, neighborhood = voronoi.vertices_neighbours)
    # voronoi_tri_edges   = graph.edges_of(voronoi_tri_graph)
    # voronoi_tri_centers = graph.nodes_of(voronoi_tri_graph)

    LOGN("\tMerge nodes that are both located within a single diamond" )
    LOG("\t\tMerge",len(voronoi_tri_graph),"nodes")
    with open("d%i_voronoi_dual.graph" % depth, "w") as fd:
        graph.write( voronoi_tri_graph, fd )
    voronoi_graph = voronoi.merge_enclosed( voronoi_tri_graph, penrose_segments )
    LOGN("as",len(voronoi_graph),"enclosed nodes")
Beispiel #11
0
    plt.ylabel("Number of nodes")
    plt.ylim(0, max_y+20)
    plt.bar(range(len(xs)), xs, tick_label=labels, color='#8ebad9')
    plt.savefig(os.path.join(output, 'flaws_barplot.png'))


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Plot multiple bar plots with the same size of axes.')
    parser.add_argument('paths', type=str, nargs='+', help='Paths to graphs.')
    args = parser.parse_args()

    graphs_paths = list()
    max_k, max_v = 0, 0
    for path in args.paths:
        # Load
        G = load(os.path.join(path, 'graph.net'))

        # Get connected graph
        G = connected(G, strategy="connect")

        # Get flaws counter
        flaw_counter = Counter([node[1]['flaws'] for node in G.nodes(data=True)])

        # Get max k,v
        max_k = max(max_k, max(flaw_counter.keys()))
        max_v = max(max_v, max(flaw_counter.values()))

        # Append to list
        graphs_paths.append([G, flaw_counter, path])

    for G, flaw_counter, path in graphs_paths: