def main(): parser = argparse.ArgumentParser() parser.add_argument('--method', type=str, default='mean') parser.add_argument('--level', type=int, default=0) parser.add_argument('--seed', type=int, default=0) parser.add_argument('--log_dir', type=str, default='0') subparsers = parser.add_subparsers() add_uci_subparser(subparsers) add_mc_subparser(subparsers) args = parser.parse_args() print(args) seed = args.seed np.random.seed(seed) torch.manual_seed(seed) if args.domain == 'uci': from uci.uci_data import load_data data = load_data(args) elif args.domain == 'mc': from mc.mc_data import load_data data = load_data(args) log_path = './{}/test/{}/{}_{}/'.format(args.domain, args.data, args.method, args.log_dir) os.makedirs(log_path) cmd_input = 'python ' + ' '.join(sys.argv) + '\n' with open(osp.join(log_path, 'cmd_input.txt'), 'a') as f: f.write(cmd_input) baseline_mdi(data, args, log_path)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--domain', type=str, default='uci') # 'uci' parser.add_argument('--data', type=str, default='housing') # 'pks', 'cancer', 'housing', 'wine' parser.add_argument('--method', type=str, default='mean') parser.add_argument('--train_edge', type=float, default=0.7) parser.add_argument('--train_y', type=float, default=0.7) parser.add_argument('--log_dir', type=str, default='lry0') parser.add_argument('--load_dir', type=str, default='0') parser.add_argument('--seed', type=int, default=0) args = parser.parse_args() seed = args.seed np.random.seed(seed) torch.manual_seed(seed) if args.domain == 'uci': from uci.uci_data import load_data data = load_data(args) log_path = './{}/test/{}/{}_{}/'.format(args.domain,args.data,args.method,args.log_dir) os.mkdir(log_path) cmd_input = 'python ' + ' '.join(sys.argv) + '\n' with open(osp.join(log_path, 'cmd_input.txt'), 'a') as f: f.write(cmd_input) load_path = './{}/test/{}/{}/'.format(args.domain,args.data,args.load_dir) linear_regression(data, args, log_path, load_path)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--domain', type=str, default='uci') parser.add_argument('--data', type=str, default='housing') parser.add_argument('--train_edge', type=float, default=0.7) parser.add_argument('--split_sample', type=float, default=0.) parser.add_argument('--split_by', type=str, default='y') # 'y', 'random' parser.add_argument('--split_train', action='store_true', default=False) parser.add_argument('--split_test', action='store_true', default=False) parser.add_argument('--train_y', type=float, default=0.7) parser.add_argument( '--node_mode', type=int, default=0) # 0: feature onehot, sample all 1; 1: all onehot parser.add_argument('--method', type=str, default=None) parser.add_argument('--level', type=int, default=0) parser.add_argument('--seed', type=int, default=0) parser.add_argument('--best_level', action='store_true', default=False) parser.add_argument('--comment', type=str, default='v1') args = parser.parse_args() # device is cpu by default np.random.seed(args.seed) torch.manual_seed(args.seed) best_levels = {'mean': 0, 'knn': 2, 'svd': 2, 'mice': 0, 'spectral': 1} ## new for args.data in [ 'concrete', 'energy', 'housing', 'kin8nm', 'naval', 'power', 'protein', 'wine', 'yacht' ]: for args.method in [ 'gnn', 'gnn_mdi', 'mean', 'knn', 'svd', 'mice', 'spectral' ]: data = load_data(args) if args.best_level and (not args.method.startswith('gnn')): args.level = best_levels[args.method] print("using best level {} for {}".format( args.level, args.method)) log_path = './uci/y_results/results/{}_{}/{}/{}/'.format( args.method, args.comment, args.data, args.seed) if not os.path.isdir(log_path): os.makedirs(log_path) if args.method == 'gnn': load_path = './uci/y_results/results/gnn_{}/{}/{}/'.format( args.comment, args.data, args.seed) elif args.method == 'gnn_mdi': load_path = './uci/mdi_results/results/gnn_mdi_{}/{}/{}/'.format( args.comment, args.data, args.seed) else: load_path = '' linear_regression(data, args, log_path, load_path)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--domain', type=str, default='uci') parser.add_argument('--data', type=str, default=None) parser.add_argument('--train_edge', type=float, default=0.7) parser.add_argument('--train_y', type=float, default=0.7) parser.add_argument( '--node_mode', type=int, default=0) # 0: feature node onehot, sample node all 1; 1: all onehot parser.add_argument('--model_types', type=str, default='EGSAGE_EGSAGE') parser.add_argument( '--post_hiddens', type=str, default=None, ) # default to be 1 hidden of node_dim parser.add_argument('--concat_states', action='store_true', default=False) parser.add_argument( '--norm_embs', type=str, default=None, ) # default to be all true parser.add_argument( '--aggr', type=str, default='mean', ) parser.add_argument('--node_dim', type=int, default=16) parser.add_argument('--edge_dim', type=int, default=16) parser.add_argument('--edge_mode', type=int, default=1) # 0: use it as weight 1: as input to mlp parser.add_argument('--gnn_activation', type=str, default='relu') parser.add_argument('--impute_hiddens', type=str, default='') parser.add_argument('--impute_activation', type=str, default='relu') parser.add_argument('--predict_hiddens', type=str, default='') parser.add_argument('--epochs', type=int, default=20000) parser.add_argument('--opt', type=str, default='adam') parser.add_argument('--opt_scheduler', type=str, default='none') parser.add_argument('--opt_restart', type=int, default=0) parser.add_argument('--opt_decay_step', type=int, default=1000) parser.add_argument('--opt_decay_rate', type=float, default=0.9) parser.add_argument('--dropout', type=float, default=0.) parser.add_argument('--weight_decay', type=float, default=0.) parser.add_argument('--lr', type=float, default=0.001) parser.add_argument('--known', type=float, default=0.7) # 1 - edge dropout rate parser.add_argument('--valid', type=float, default=0.) # valid-set ratio parser.add_argument('--seed', type=int, default=0) parser.add_argument('--comment', type=str, default='v1') args = parser.parse_args() print(args) # select device if torch.cuda.is_available(): cuda = auto_select_gpu() os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ['CUDA_VISIBLE_DEVICES'] = str(cuda) print('Using GPU {}'.format(os.environ['CUDA_VISIBLE_DEVICES'])) device = torch.device('cuda:{}'.format(cuda)) else: print('Using CPU') device = torch.device('cpu') np.random.seed(args.seed) torch.manual_seed(args.seed) ## new for args.data in [ 'concrete', 'energy', 'housing', 'kin8nm', 'naval', 'power', 'protein', 'wine', 'yacht' ]: data = load_data(args) log_path = './uci/y_results/results/gnn_{}/{}/{}/'.format( args.comment, args.data, args.seed) if not os.path.isdir(log_path): os.makedirs(log_path) # if os.path.isdir(log_path): # if len(os.listdir(log_path))>0: # print('Directory exists, skip training') # continue # else: # print('Directory exists, no content, re-initialize training') # shutil.rmtree(log_path) train_gnn_y(data, args, log_path, device)
parser = argparse.ArgumentParser() parser.add_argument('--seed', type=int, default=0) subparsers = parser.add_subparsers() add_uci_subparser(subparsers) add_mc_subparser(subparsers) args = parser.parse_args() print(args) seed = args.seed np.random.seed(seed) torch.manual_seed(seed) if args.domain == 'uci': from uci.uci_data import load_data data = load_data(args) elif args.domain == 'mc': from mc.mc_data import load_data data = load_data(args) # print(data) print('node dim: ', data.num_node_features, ' edge dim: ', data.edge_attr_dim) for i, key in enumerate(data.keys): if torch.is_tensor(data[key]): print(key, ': ', data[key].shape) # else: # print(key,': ',data[key]) if hasattr(args, 'split_sample') and args.split_sample > 0.: lower_y = data.y[data.lower_y_index] higher_y = data.y[data.higher_y_index]
def main(): parser = argparse.ArgumentParser() parser.add_argument('--model_types', type=str, default='EGSAGE_EGSAGE_EGSAGE') parser.add_argument( '--post_hiddens', type=str, default=None, ) # default to be 1 hidden of node_dim parser.add_argument('--concat_states', action='store_true', default=False) parser.add_argument( '--norm_embs', type=str, default=None, ) # default to be all true parser.add_argument( '--aggr', type=str, default='mean', ) parser.add_argument('--node_dim', type=int, default=64) parser.add_argument('--edge_dim', type=int, default=64) parser.add_argument('--edge_mode', type=int, default=1) # 0: use it as weight; 1: as input to mlp parser.add_argument('--gnn_activation', type=str, default='relu') parser.add_argument('--impute_hiddens', type=str, default='64') parser.add_argument('--impute_activation', type=str, default='relu') parser.add_argument('--epochs', type=int, default=20000) parser.add_argument('--opt', type=str, default='adam') parser.add_argument('--opt_scheduler', type=str, default='none') parser.add_argument('--opt_restart', type=int, default=0) parser.add_argument('--opt_decay_step', type=int, default=1000) parser.add_argument('--opt_decay_rate', type=float, default=0.9) parser.add_argument('--dropout', type=float, default=0.) parser.add_argument('--weight_decay', type=float, default=0.) parser.add_argument('--lr', type=float, default=0.001) parser.add_argument('--known', type=float, default=0.7) # 1 - edge dropout rate parser.add_argument('--auto_known', action='store_true', default=False) parser.add_argument( '--loss_mode', type=int, default=0 ) # 0: loss on all train edge, 1: loss only on unknown train edge parser.add_argument('--valid', type=float, default=0.) # valid-set ratio parser.add_argument('--seed', type=int, default=0) parser.add_argument('--log_dir', type=str, default='0') parser.add_argument('--save_model', action='store_true', default=False) parser.add_argument('--save_prediction', action='store_true', default=False) parser.add_argument('--transfer_dir', type=str, default=None) parser.add_argument('--transfer_extra', type=str, default='') parser.add_argument('--mode', type=str, default='train') # debug subparsers = parser.add_subparsers() add_uci_subparser(subparsers) add_mc_subparser(subparsers) args = parser.parse_args() print(args) # select device if torch.cuda.is_available(): cuda = auto_select_gpu() os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ['CUDA_VISIBLE_DEVICES'] = str(cuda) print('Using GPU {}'.format(os.environ['CUDA_VISIBLE_DEVICES'])) device = torch.device('cuda:{}'.format(cuda)) else: print('Using CPU') device = torch.device('cpu') seed = args.seed np.random.seed(seed) torch.manual_seed(seed) if args.domain == 'uci': from uci.uci_data import load_data data = load_data(args) elif args.domain == 'mc': from mc.mc_data import load_data data = load_data(args) log_path = './{}/test/{}/{}/'.format(args.domain, args.data, args.log_dir) os.makedirs(log_path) cmd_input = 'python ' + ' '.join(sys.argv) + '\n' with open(osp.join(log_path, 'cmd_input.txt'), 'a') as f: f.write(cmd_input) train_gnn_mdi(data, args, log_path, device)