예제 #1
0
    def __init__(self, vocab, pos, rels, enum_word, options, onto, cpos):
        super(HybridModel, self).__init__()
        random.seed(2)
        dims = options.wembedding_dims + options.pembedding_dims + options.cembedding_dims + options.oembedding_dims
        self.shared = nn.LSTM(dims,
                              options.lstm_dims,
                              batch_first=True,
                              bidirectional=True)
        model0 = GraphModel(vocab, pos, rels, enum_word, options, onto, cpos,
                            self.shared)
        model1 = TransitionModel(vocab, pos, rels, enum_word, options, onto,
                                 cpos, self.shared)
        self.graphModel = model0.cuda() if torch.cuda.is_available(
        ) else model0
        self.transitionModel = model1.cuda() if torch.cuda.is_available(
        ) else model1

        self.graphTrainer = get_optim(options.optim,
                                      self.graphModel.parameters())
        self.transitionTrainer = get_optim(options.optim,
                                           self.transitionModel.parameters())

        classifier = LinearClassifier(options.lstm_dims * 4)
        self.classifier = classifier.cuda() if torch.cuda.is_available(
        ) else classifier
        self.loss = nn.CrossEntropyLoss()
        self.optimizer = optim.Adam(classifier.parameters(), lr=0.01)
예제 #2
0
파일: gui.py 프로젝트: olavvatne/agac
def init_display(problem_file):
    app.visualizer.reset()
    temp = problem_file.readline().split()
    nr_vertices = eval(temp[0])
    nr_edges = eval(temp[1])
    max_x = 0
    max_y = 0
    min_x = 0
    min_y = 0
    graphModel = GraphModel()

    #The vertices are read in first from file, and the min and max of coordinates are registered
    for l in range(nr_vertices):
        vertex = problem_file.readline().split()
        x = float(vertex[1])
        y = float(vertex[2])
        nodeModel = NodeModel( int(vertex[0]) , x , y )
        graphModel.add_vertex(nodeModel)

        if max_x < x: max_x = x
        if max_y < y: max_y = y
        if min_x > x: min_x = x
        if min_y > y: min_y = y

    #The edges are read and the vertices it connects put into an edgemodel
    for e in range(nr_edges):
        edge = problem_file.readline().split()
        edgeModel = EdgeModel(graphModel.get_vertex("N" + str(edge[0])), graphModel.get_vertex("N" + str(edge[1]) ))
        graphModel.add_edge(edgeModel)

    problem_file.close()
    app.visualizer.set_dimension(max_x, max_y, min_x, min_y)
    return graphModel
예제 #3
0
    def __init__(self, keyword, src_id, dst_id, in_dim, hid_c, src_len,
                 n_layers, device):
        super(PredictModel, self).__init__()

        self.oneHotEmbed = OneHotProcess(in_dim, hid_c)

        if keyword == "Graph":
            self.model = GraphModel(src_id, dst_id, src_len * hid_c,
                                    src_len * hid_c, device)
        elif keyword == "SG":
            self.model = SGModel(src_id, dst_id, src_len * hid_c,
                                 src_len * hid_c, n_layers, device)
        elif keyword == "SAGE":
            self.model = SAGEModel(src_id, dst_id, src_len * hid_c,
                                   src_len * hid_c, n_layers, device)
        else:
            raise KeyError("Keyword is not defined! ")

        self.linear = nn.Linear(src_len * hid_c, in_dim)
 def _getGraph():
     loader = getLoaderPrimaryForm()
     g = GraphModel(loader, degree)
     g.processGraphs(slice(51555))
     return g
예제 #5
0
파일: test.py 프로젝트: caedesvvv/pynoded
from graph import GraphModel
from metamodel.yamlserializer import SaveModel, LoadModel

if __name__ == "__main__":
    print "run test"
    graphmodel = GraphModel()
    newnode = graphmodel.new("GraphNodeModel")
    # subscribe
    class myevh(object):
        def propertychange(self, name, value):
            print " *- propertychanged!", name, value

        def addchild(self, child):
            print " *- addchild", child

        def delchild(self, child):
            print " *- delchild", child

    graphmodel.subscribe(myevh())
    newnode.subscribe(myevh())
    # change property
    newnode.setProperty("name", "bla")
    # add/remove node to graph
    graphmodel.addChild(newnode)
    graphmodel.delChild(newnode)
    graphmodel.addChild(newnode)
    # add/remove connectors to graph
    newconnector = graphmodel.new("GraphNodeConnectorModel")
    newconnector.subscribe(myevh())
    newconnector.setProperty("name", "bla")
    assert newconnector.getProperty("name") == "bla"