diff --git a/facetnet_evol.py b/facetnet_evol.py index 39d0160..727b845 100644 --- a/facetnet_evol.py +++ b/facetnet_evol.py @@ -1,88 +1,91 @@ """ Modified by Matthias Rüegg (matthias.ruegg@unil.ch) on August 13 2019 Based on a program created by created by github.com/blmoistawinde (https://github.com/blmoistawinde/facetnet-python) Copyright 2019 __UNIL__. All rights reserved. This file is part of facetnet-python-unil. facetnet-python-unil is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. facetnet-python-unil is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with facetnet-python-unil. If not, see . """ import argparse import sys +import logging import facetnet as fn import numpy as np import pandas as pd if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("t_steps", help="number of networks", type=int) parser.add_argument( "alpha", help="alpha cost weight (0.0, 1.0] for gamma = CS*alpha + CT*(1-alpha)", type=float) parser.add_argument("m_cluster", help="number of clusters", type=int) parser.add_argument( "nw_folder", help="folder holding the network data in edgelist.X form", type=str) parser.add_argument("res_folder", help="path to results folder, where" "xcap.dat, lcap.dat, idmap.dat, idmap_inv.dat, soft_comm.csv" "will be saved", type=str) parser.add_argument( "--show", help="show convergence plot of gamma", type=bool, default=False) args = parser.parse_args() + logging.basicConfig(filename="{}/alpha{}.log".format(args.res_folder, args.alpha) + if args.alpha <= 0.0 or args.alpha > 1.0: - print("Alpha value must be in (0.0, 1.0], terminate script") + logging.error("Alpha value must be in (0.0, 1.0], terminate script") sys.exit(1) - print("Analyzing networks from: {}".format(args.nw_folder)) - print("# time-steps: {}, alpha: {}, # communities: {}".format(args.t_steps, + logging.info("Analyzing networks from: {}".format(args.nw_folder)) + logging.info("# time-steps: {}, alpha: {}, # communities: {}".format(args.t_steps, args.alpha, args.m_cluster)) for t in range(args.t_steps): - print("time-step:", t) + logging.info("time-step:", t) - edge_list = "{}/{}.edgelist".format(args.nw_folder, t) + edge_list="{}/{}.edgelist".format(args.nw_folder, t) if t == 0: - idmap, idmap_inv, xc, lc, qc_s, soft_comm, comm_net, evol_net, m_eff, _ = fn.facetnet_step( + idmap, idmap_inv, xc, lc, qc_s, soft_comm, comm_net, evol_net, m_eff, _=fn.facetnet_step( edge_list, args.alpha, args.m_cluster, weighted=True, show_plot=args.show) else: - idmap, idmap_inv, xc, lc, qc_s, soft_comm, comm_net, evol_net, m_eff, _ = fn.facetnet_step( + idmap, idmap_inv, xc, lc, qc_s, soft_comm, comm_net, evol_net, m_eff, _=fn.facetnet_step( edge_list, args.alpha, args.m_cluster, weighted=True, show_plot=args.show, xc_prev=xc, lc_prev=lc, idmap0=idmap, idmap_inv0=idmap_inv) - print("Soft modularity Qc={}".format(qc_s)) + logging.info("Soft modularity Qc={}".format(qc_s)) # Save results for analysis - clusters = [] + clusters=[] for i in range(m_eff): clusters.append("cluster_{}".format(i)) - evol_net_df = pd.DataFrame(data=evol_net, columns=clusters) + evol_net_df=pd.DataFrame(data=evol_net, columns=clusters) evol_net_df.to_csv("{}/evol_net_alpha{}_nw{}.csv".format(args.res_folder, args.alpha, t), index=False) - soft_comm_df = pd.DataFrame(data=soft_comm, columns=clusters) + soft_comm_df=pd.DataFrame(data=soft_comm, columns=clusters) soft_comm_df.insert(0, column="id", value=idmap) soft_comm_df.to_csv("{}/soft_comm_alpha{}_nw{}.csv".format(args.res_folder, args.alpha, t), index=False) - comm_net_df = pd.DataFrame(data=comm_net, columns=clusters) + comm_net_df=pd.DataFrame(data=comm_net, columns=clusters) comm_net_df.to_csv("{}/comm_net_alpha{}_nw{}.csv".format(args.res_folder, args.alpha, t), index=False) - lc_df = pd.DataFrame(data=lc, columns=clusters) + lc_df=pd.DataFrame(data=lc, columns=clusters) lc_df.to_csv("{}/lc_alpha{}_nw{}.csv".format(args.res_folder, args.alpha, t), index=False) - print("Results written to: {}".format(args.nw_folder)) + logging.info("Results written to: {}".format(args.nw_folder))