示例#1
0
文件: main.py 项目: kmruan-whu/SDNE
        options.config_file = 'config.ini'

    config = Config(options.config_file)

    origin_graph_data = Graph(config.origin_graph_file, config.ng_sample_ratio)
    train_graph_data = Graph(config.train_graph_file, config.ng_sample_ratio)

    #train_graph_data = origin_graph_data

    if config.label_file:
        #load label for classification
        origin_graph_data.load_label_data(config.label_file)

    config.struct[0] = train_graph_data.N

    model = SDNE(config)
    model.do_variables_init(train_graph_data, config.DBN_init)

    epochs = 0
    batch_n = 0

    tt = time.ctime().replace(' ', '-')
    path = "./result/" + config.embedding_filename + '-' + tt
    os.system("mkdir " + path)
    fout = open(path + "/log.txt", "w")
    model.save_model(path + '/epoch0.model')

    while (True):
        mini_batch = train_graph_data.sample(config.batch_size)
        loss = model.fit(mini_batch)
        batch_n += 1
示例#2
0
    config = Config(options.config_file)

    train_graph_data = Graph(config.train_graph_file, config.ng_sample_ratio)

    if config.origin_graph_file:
        origin_graph_data = Graph(config.origin_graph_file,
                                  config.ng_sample_ratio)

    if config.label_file:
        #load label for classification
        train_graph_data.load_label_data(config.label_file)

    config.struct[0] = train_graph_data.N

    model = SDNE(config)
    model.do_variables_init(train_graph_data)
    embedding = None
    while (True):
        mini_batch = train_graph_data.sample(config.batch_size,
                                             do_shuffle=False)
        if embedding is None:
            embedding = model.get_embedding(mini_batch)
        else:
            embedding = np.vstack((embedding, model.get_embedding(mini_batch)))
        if train_graph_data.is_epoch_end:
            break

    epochs = 0
    batch_n = 0
示例#3
0
文件: main.py 项目: faychu/SDNE
# -*- coding: utf-8 -*-

from config import Config
from graph import Graph
from model.sdne import SDNE
from utils.utils import *
import time
import scipy.io as sio

if __name__ == "__main__":
    config = Config()

    graph_data = Graph(config.file_path, config.ng_sample_ratio)
    config.struct[0] = graph_data.N

    model = SDNE(config)
    model.do_variables_init(config.DBN_init)

    last_loss = np.inf
    converge_count = 0
    time_consumed = 0
    epochs = 0
    while (True):
        mini_batch = graph_data.sample(config.batch_size)
        st_time = time.time()
        model.fit(mini_batch)
        time_consumed += time.time() - st_time

        if graph_data.is_epoch_end:
            epochs += 1
            loss = 0
示例#4
0
文件: main.py 项目: sherwin29/SDNE
from config import Config
from graph import Graph
from model.sdne import SDNE
from utils.utils import *
import scipy.io as sio
import time
import copy

if __name__ == "__main__":
    for config in Config().combination():

        graph_data = Graph(config.file_path, config.ng_sample_num)
        #graph_data.load_label_data(config.label_file_path)
        config.struct[0] = graph_data.N

        model = SDNE(config)
        model.do_variables_init(graph_data, config.DBN_init)

        epochs = 0
        batch_n = 0

        origin_data = copy.deepcopy(graph_data)
        #graph_data = graph_data.subgraph(config.sample_method, config.sample_ratio)
        fout = open(config.embedding_filename + "-log.txt", "w")
        while (True):
            #graph_data.N = int(config.rN * graph_data.N)
            mini_batch = graph_data.sample(config.batch_size)
            loss = model.fit(mini_batch)
            batch_n += 1
            print "Epoch : %d, batch : %d, loss: %.3f" % (epochs, batch_n,
                                                          loss)
示例#5
0
    if options.config_file is None:
        raise IOError("no config file specified")

    config = Config(options.config_file)
    train_graph_data = Graph(config.train_graph_file, config.ng_sample_ratio,
                             config.T, config.tao, config.walk_times,
                             config.walk_length, config.restart_ratio)

    if config.origin_graph_file:
        origin_graph_file = Graph(config.origin_graph_file,
                                  config.ng_sample_ratio)

    config.struct[0] = train_graph_data.N

    model = SDNE(config)
    model.do_variables_init(train_graph_data)

    epochs = 0
    batch_n = 0

    walks = train_graph_data.walks

    while (True):
        '''
        one epoch train
        '''
        for walk in walks:
            mini_batch = train_graph_data.get_mini_batch_by_walk(walk)
            model.fit(mini_batch)
        '''
示例#6
0
        raise IOError("no config file specified")

    config = Config(options.config_file)
    
    train_graph_data = Graph(config.train_graph_file, config.ng_sample_ratio)
   
    if config.origin_graph_file:
        origin_graph_data = Graph(config.origin_graph_file, config.ng_sample_ratio)

    if config.label_file:
        #load label for classification
        train_graph_data.load_label_data(config.label_file)
    
    config.struct[0] = train_graph_data.N
    
    model = SDNE(config)
    model.do_variables_init(train_graph_data)
    embedding = None
    norm_weights = None
    while (True):
        mini_batch, index = train_graph_data.sample(config.batch_size, do_shuffle = False) #insert index
        if embedding is None:
            embedding = model.get_embedding(mini_batch, index)
        else:
            embedding = np.vstack((embedding, model.get_embedding(mini_batch, index)))
        if train_graph_data.is_epoch_end:
            break

    epochs = 0
    batch_n = 0
示例#7
0
try:
    graph.init_from_mat(graph_path)
except:
    graph.init_from_file(node_path,edge_path,label_path,is_weighted,is_directed)
    graph.save_to_mat(graph_path)
logger.info("Graph Construct Done")


struct_t = [graph.node_number]
struct_t.extend(struct)
struct = struct_t

model = SDNE(
    struct,alpha1,alpha2,
    beta,nu1,nu2,batch_size,
    epochs,min_re_err,learning_rate,
    learning_decay,learning_decay_rate,
    learning_decay_steps,logger.info,
    model_path,embedding_path)
try:
    model.restore_model(model_path)
    logger.info("Model Init From Model File Succ")
except:
    logger.info("Model Init From Model File Fail")
logger.info("Model Training Begin")
model.train(sdne_sample,graph, batch_size)

w = model.get_w()
b = model.get_b()
for i in w:
    print(i, w[i].shape, w[i])
示例#8
0
文件: main.py 项目: crockwell/SDNE
  
  path = os.path.join("result", config.embedding_filename, options.experiment_name)
  try: os.makedirs(path)
  except OSError: pass
  
  train_graph_data = Graph(config.train_graph_file, config.ng_sample_ratio)
 
  if config.origin_graph_file:
      origin_graph_data = Graph(config.origin_graph_file, config.ng_sample_ratio)
      
  if config.label_file:
      train_graph_data.load_label_data(config.label_file)
  
  config.struct[0] = train_graph_data.N
      
  model = SDNE(config)
  restored = model.do_variables_init(train_graph_data)
  embedding = None   
  
  fout = open(os.path.join(path, "log.txt"),"a+")  
  model.save_model(os.path.join(path, 'epoch' + '.model'))
  with open('GraphData/future_500_node_ids.txt', 'r') as f:
      test_ids = f.readlines()
  test_ids = np.array(test_ids).astype(int)
  #test_ids = set(test_ids)
  
  epochs = int(config.start_epoch)
  batch_n = 0
  print "training SDNE..."
  while (True):
      # validate
from config import Config
from graph import Graph
from model.sdne import SDNE
from utils.utils import *
import scipy.io as sio
import time
import scipy.io as sio

if __name__ == "__main__":
    config = Config()

    graph_data = Graph(config.file_path, config.ng_sample_ratio)
    graph_data.load_label_data(config.label_file_path)
    config.struct[0] = graph_data.N

    model = SDNE(config)
    model.do_variables_init(config.DBN_init)

    last_loss = np.inf
    converge_count = 0
    time_consumed = 0
    epochs = 0
    batch_n = 0
    while (True):
        mini_batch = graph_data.sample(config.batch_size)
        st_time = time.time()
        model.fit(mini_batch)
        batch_n += 1
        time_consumed += time.time() - st_time
        #print ("Mini-batch : %d fit time: %.2f" % (batch_n, time_consumed))
        if graph_data.is_epoch_end:
示例#10
0
from config import Config
from graph import Graph
from model.sdne import SDNE
from utils.utils import *
import scipy.io as sio
import time
import copy

if __name__ == "__main__":
    config = Config()

    graph_data = Graph(config.file_path, config.ng_sample_ratio)
    graph_data.load_label_data(config.label_file_path)
    config.struct[0] = graph_data.N

    model = SDNE(config)
    model.do_variables_init(graph_data.sample(graph_data.N).X, config.DBN_init)

    last_loss = np.inf
    converge_count = 0
    time_consumed = 0
    epochs = 0
    batch_n = 0

    origin_data = copy.deepcopy(graph_data)
    graph_data = graph_data.subgraph(config.sample_method, config.sample_ratio)

    while (True):
        #graph_data.N = int(config.rN * graph_data.N)
        mini_batch = graph_data.sample(config.batch_size)
        mini_time = model.fit(mini_batch)
示例#11
0
from model.sdne import SDNE
from graph.graph import Graph

if __name__ == "__main__":
    logger = Logger("SDNE", "sdne.log", "None")
    logger.info("Config Begin")
    config = Config()
    config.parse_from_inifile(
        "D:\\Code\\Python3\\sdne\\\config\\Blogcatalog.ini")
    logger.info("Config Done")

    edge_path = config.edge_path
    ndoe_path = config.node_path
    graph_path = config.graph_path
    batch_size = config.batch_size

    logger.info("Graph Construct Begin")
    graph = Graph(edge_path=edge_path,
                  node_path=ndoe_path,
                  graph_path=graph_path,
                  logger=logger.info)
    logger.info("Graph Construct Done")

    if config.struct[0] == -1:
        config.struct[0] = graph.node_number

    model = SDNE(config, logger=logger.info)
    # model.rbm_init(graph)
    model.train(graph)
    model.save_model(config.model_path)