mcxstatus mcxIOexpectNum ( mcxIO* xf , long* lngp , mcxOnFail ON_FAIL ) { int n_read = 0 ; int n_conv = 0 ; mcxstatus status = STATUS_OK ; if (inbuffer(xf)) buffer_spout(xf, "mcxIOexpectNum") ; mcxIOskipSpace(xf) /* keeps accounting correct */ ; errno = 0 ; n_conv = fscanf(xf->fp, "%ld%n", lngp, &n_read) ; xf->bc += n_read /* fixme do fscanf error handling */ ; xf->lo += n_read ; if (1 != n_conv) mcxErr("mcxIOexpectNum", "parse error: expected to find integer") , status = STATUS_FAIL ; else if (errno == ERANGE) mcxErr("mcxIOexpectNum", "range error: not in allowable range") , status = STATUS_FAIL ; if (status) { mcxIOpos(xf, stderr) ; if (ON_FAIL == EXIT_ON_FAIL) mcxExit(1) ; } return status ; }
static mcxstatus cttyArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : mcxIOnewName(xfmx_g, val) ; break ; case MY_OPT_ABC : xfabc_g = mcxIOnew(val, "r") ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_OUT : out_g = val ; break ; case MY_OPT_INCLUDE_ENDS : include_ends_g = TRUE ; break ; case MY_OPT_LIST_NODES : break ; case MY_OPT_littleG : i_group = atoi(val) ; break ; case MY_OPT_G : n_group_G = atoi(val) ; break ; case MY_OPT_T : n_thread_l = (unsigned) atoi(val) ; break ; case MY_OPT_MOD : mod_up = TRUE ; break ; default : mcxExit(1) ; ; } return STATUS_OK ; }
int mcxIOexpect ( mcxIO *xf , const char *str , mcxOnFail ON_FAIL ) { const char* s = str ; int c = 0 ; int d = 0 ; int n_trailing /* * no functional behaviour yet attached to this state change * fixme: semantics for STDIN agree between stdlib and us? */ ; while ( c = (uchar) s[0] , ( c && ( d = mcxIOstep(xf) , c == d ) ) ) s++ ; n_trailing = strlen(s) /* truncintok */ ; if (c && ON_FAIL == EXIT_ON_FAIL) { mcxErr("mcxIOexpect", "parse error: expected to see <%s>", str) ; mcxIOpos(xf, stderr) ; mcxExit(1) ; } return n_trailing ; }
void mcxDiagnosticsAttractor ( const char* ffn_attr , const mclMatrix* clus2elem , const mcxDumpParam dumpParam ) { int n_nodes = clus2elem->n_range ; int n_written = dumpParam->n_written ; mclMatrix* mtx_Ascore = mclxAllocZero(n_written, n_nodes) ; mcxIO* xfOut = mcxIOnew(ffn_atr, "w") ; dim d = 0 ; if (mcxIOopen(xfOut, RETURN_ON_FAIL) == STATUS_FAIL) { mclxFree(&mtx_Ascore) ; mcxIOfree(&xfOut) ; return ; } ; for(d=0; d<n_written; d++) { mclMatrix* iterand = *(dumpParam->iterands+d) ; mclVector* vec_Ascore = NULL ; if (iterands->n_cols != n_nodes || iterand->n_range != n_nodes) { fprintf(stderr, "mcxDiagnosticsAttractor: dimension error\n") ; mcxExit(1) ; } vec_Ascore = mcxAttractivityScale(iterand) ; mclvRenew((mtx_Ascore->cols+d), vec_Ascore->ivps, vec_Ascore->n_ivps) ; mclvFree(&vec_Ascore) ; } mclxbWrite(mtx_Ascore, xfOut, RETURN_ON_FAIL) ; mclxFree(mtx_Ascore) ; }
mcxstatus mcxIOexpectReal ( mcxIO* xf , double* dblp , mcxOnFail ON_FAIL ) { int n_read = 0 ; int n_conv = 0 ; if (inbuffer(xf)) buffer_spout(xf, "mcxIOexpectReal") ; mcxIOskipSpace(xf) /* keeps accounting correct */ ; n_conv = fscanf(xf->fp, " %lf%n", dblp, &n_read) ; xf->bc += n_read /* fixme do fscanf error handling */ ; xf->lo += n_read ; if (1 != n_conv) { if (ON_FAIL == EXIT_ON_FAIL) { mcxIOpos(xf, stderr) ; mcxErr("parseReal", "parse error: expected to find real") ; mcxExit(1) ; } return STATUS_FAIL ; } return STATUS_OK ; }
void mclvRuntime ( const mclVector* vec , const char* caller ) { if (!vec) mcxErr(caller, "void vector argument") , mcxExit(1) ; }
static mcxstatus collectArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_OUT : out_g = val ; break ; case MY_OPT_PASTE : collect_g = 'p' ; break ; case MY_OPT_NO_HEADER : header_g = FALSE ; break ; case MY_OPT_TRANSFORM : transform_spec = mcxTingNew(val) ; break ; case MY_OPT_MATRIX_MAX : collect_g = 'm' ; fltop_g = fltMax ; break ; case MY_OPT_MATRIX_ADD : collect_g = 'm' ; break ; case MY_OPT_2COLUMN : collect_g = 'c' ; break ; case MY_OPT_SUMMARY : summary_g = 1 ; break ; default : mcxExit(1) ; } ; return STATUS_OK ; }
int main ( int argc , const char* argv[] ) { int a = 0 ; mcxTing* argtxt = mcxTingEmpty(NULL, 10) ; if (0) mclxIOsetQMode("MCLXIOVERBOSITY", MCL_APP_VB_NO) ; opInitialize() /* symtable etc */ ; globInitialize() /* hdltable etc */ ; if (argc == 1) { mcxTing* ops = mcxTingEmpty(NULL, 20) ; mcxIO *xfin = mcxIOnew("-", "r") ; mcxIOopen(xfin, EXIT_ON_FAIL) ; fprintf ( stdout , "At your service: " "'[/<op>] help', '[/<str>] grep', 'ops', 'info', and 'quit'.\n" ) ; while (1) { int ok ; mcxTing* line = mcxTingEmpty(NULL, 30) ; fprintf(stdout, "> ") ; fflush(stdout) ; if (STATUS_OK != mcxIOreadLine(xfin, line, MCX_READLINE_BSC)) { fprintf(stdout, "curtains!\n") ; mcxTingFree(&line) ; break ; } mcxTingAppend(ops, line->str) ; mcxTingFree(&line) ; ok = zsDoSequence(ops->str) ; if (ok && (v_g & V_STACK)) zsList(0) ; mcxTingEmpty(ops, 20) ; } } else { for (a=1;a<argc;a++) { mcxTingWrite(argtxt, argv[a]) ; if (!zgUser(argtxt->str)) mcxExit(1) ; } } mcxTingFree(&argtxt) ; return 0 ; }
static mcxstatus erdosArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : xfmx_g = mcxIOnew(val, "r") ; break ; case MY_OPT_PATH : path_g = val ; break ; case MY_OPT_STEP : step_g = val ; break ; case MY_OPT_OUT : out_g = val ; break ; case MY_OPT_ABC : xfabc_g = mcxIOnew(val, "r") ; break ; case MY_OPT_ISUNDIRECTED : input_status = 'u' ; break ; case MY_OPT_ISDIRECTED : input_status = 'd' ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_QUERY : mcxIOnewName(xq_g, val) ; break ; default : mcxExit(1) ; ; } return STATUS_OK ; }
double mclvNorm ( const mclVector* vec , double power ) { if(power > 0.0) mcxErr("mclvNorm", "pbd: negative power argument <%f>", (double) power) , mcxExit(1) ; return pow((double) mclvPowSum(vec, power), 1.0 / power) ; }
int main ( int argc , const char* argv[] ) { const char* fn_input = argc > 1 ? argv[1] : "" ; mclAlgParam* mlp = NULL ; const char* me = "mcl" ; mcxstatus status = STATUS_OK ; srandom(mcxSeed(315)) ; signal(SIGALRM, mclSigCatch) ; if (signal(SIGUSR1, mcxLogSig) == SIG_ERR) mcxErr(me, "cannot catch SIGUSR1!") ; mcxLogLevel = MCX_LOG_AGGR | MCX_LOG_MODULE | MCX_LOG_IO | MCX_LOG_GAUGE | MCX_LOG_WARN ; mclx_app_init(stderr) ; if (argc < 2) { mcxTell ( me , "usage: mcl <-|file name> [options]," " do 'mcl -h' or 'man mcl' for help" ) ; mcxExit(0) ; } status = mclAlgInterface (&mlp, (char**) (argv+2), argc-2, fn_input, NULL, ALG_DO_IO) ; if (status == ALG_INIT_DONE) return 0 ; else if (status) mcxDie(STATUS_FAIL, me, "no tango") ; if ((status = mclAlgorithm(mlp)) == STATUS_FAIL) mcxDie(STATUS_FAIL, me, "failed") ; if (mlp->n_assimilated) mcxLog(MCX_LOG_MODULE, me, "%lu nodes will assimilate", (ulong) mlp->n_assimilated) ; if (mlp->mx_start) mcxLog(MCX_LOG_MODULE, me, "cached matrix with %lu columns", (ulong) N_COLS(mlp->mx_start)) ; mclAlgParamFree(&mlp, TRUE) ; helpful_reminder() ; return STATUS_OK ; }
static mcxstatus get_interface ( mclAlgParam** mlpp , const char* fn_input /* Use this as input or mx_input */ , const char* arg_shared , const char* arg_extra , mclx* mx_input /* Use this as input or fn_input */ , mcxbits CACHE , mcxOnFail ON_FAIL ) { mcxTing* spec = mcxTingNew(arg_shared) ; int argc1 = 0 ; char** argv1 ; mcxstatus status ; mclAlgParam* mymlp = NULL ; mclAlgParam** mymlpp = mlpp ? mlpp : &mymlp ; if (arg_extra) mcxTingPrintAfter(spec, " %s", arg_extra) /* warning this clobbers spec->str */ ; argv1 = mcxOptParseString(spec->str, &argc1, ' ') ; status = mclAlgInterface ( mymlpp , argv1 , argc1 , fn_input , mx_input , CACHE ) ; if (status && ON_FAIL == EXIT_ON_FAIL) mcxExit(1) ; mcxFree(argv1) ; mcxTingFree(&spec) /* fixfixfixmefixmefffixme: mclAlgInterface might use opt->val * which points to somewhere in spec->str. Check. */ ; if (!mlpp) mclAlgParamFree(mymlpp, TRUE) ; return status ; }
static mcxstatus convertArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_BINARY : mclxSetBinaryIO() ; break ; case MY_OPT_CAT : docat = TRUE /* unused, idling */ ; main_mode = 'l' /* level(s) */ ; break ; case MY_OPT_RO : test_read = TRUE ; break ; case MY_OPT_CATMAX : catmax = atoi(val) ; break ; case MY_OPT_S2C : main_mode = 's' /* stack to cone */ ; break ; case MY_OPT_C2S : main_mode = 'c' /* cone to stack */ ; break ; default : mcxExit(1) ; } return STATUS_OK ; }
static mclx* get_base ( const char* fn_input , mclx* mx_input , const char* b1opts , const char* b2opts ) { mclAlgParam* mlp = NULL ; mcxstatus status = STATUS_FAIL ; mclx* mxbase = NULL ; get_interface ( &mlp , fn_input , b2opts ? b2opts : b1opts , NULL , mx_input , b2opts ? ALG_CACHE_EXPANDED : ALG_CACHE_START , EXIT_ON_FAIL ) ; if (b2opts) { mlp->mpp->mainLoopLength = 1 ; mlp->mpp->mainInflation = 1.0 ; mlp->expand_only = TRUE ; mcxLog(MCX_LOG_APP, me, "computing expanded matrix") ; if ((status = mclAlgorithm(mlp)) == STATUS_FAIL) { mcxErr(me, "failed") ; mcxExit(1) ; } mcxLog(MCX_LOG_APP, me, "done computing expanded matrix") ; mxbase = mclAlgParamRelease(mlp, mlp->mx_expanded) ; } else { if (mclAlgorithmStart(mlp, FALSE)) mcxDie(1, me, "-b1 option start-up failed") ; mxbase = mclAlgParamRelease(mlp, mlp->mx_start) ; start_col_sums_g = mclvClone(mlp->mx_start_sums) ; } mclAlgParamFree(&mlp, TRUE) ; return mxbase ; }
static mcxstatus alterArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : mcxIOnewName(xfmx_g, val) ; break ; case MY_OPT_ABC : xfabc_g = mcxIOnew(val, "r") ; break ; case MY_OPT_O : mcxIOnewName(xfout_g, val) ; break ; case MY_OPT_CANONICAL : canonical_g = atoi(val) ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_TRANSFORM : transform_spec = mcxTingNew(val) ; break ; default : mcxExit(1) ; ; } return STATUS_OK ; }
mcxstatus mcxIOopen ( mcxIO* xf , mcxOnFail ON_FAIL ) { const char* fname = xf->fn->str ; if (!xf) { mcxErr("mcxIOnew PBD", "received void object") ; if (ON_FAIL == RETURN_ON_FAIL) return STATUS_FAIL ; exit(1) ; } if (mcxIOwarnOpenfp(xf, "mcxIOopen PBD")) return STATUS_OK ; if (!strcmp(fname, "-")) { if (strchr(xf->mode, 'r')) xf->fp = stdin ; else if (strchr(xf->mode, 'w') || strchr(xf->mode, 'a')) xf->fp = stdout ; } else if ( !strcmp(fname, "stderr") && (strchr(xf->mode, 'w') || strchr(xf->mode, 'a')) ) xf->fp = stderr ; else if ((xf->fp = fopen(fname, xf->mode)) == NULL) { if (ON_FAIL == RETURN_ON_FAIL) return STATUS_FAIL ; mcxIOerr(xf, "mcxIOopen", "cannae be opened") ; mcxExit(1) ; } return STATUS_OK ; }
int main ( int argc , const char* argv[] ) { mcxIO* xf1, *xf2 ; mclx* mx1, *mx2 ; mcxbits modes = 0 ; mcxLogLevel = MCX_LOG_AGGR | MCX_LOG_MODULE | MCX_LOG_IO | MCX_LOG_GAUGE | MCX_LOG_WARN ; mclx_app_init(stdout) ; if (argc < 4) mcxUsage(stdout, me, usagelines) , mcxExit(0) ; modes = atoi(argv[1]) ; xf1 = mcxIOnew(argv[2], "r") ; xf2 = mcxIOnew(argv[3], "r") ; mx1 = mclxRead(xf1, EXIT_ON_FAIL) ; mx2 = mclxRead(xf2, EXIT_ON_FAIL) ; pairwise_setops(mx1, mx2, modes) ; if (modes & MMM_DUMPMX) { mcxIO* xo = mcxIOnew("out.mmm", "w") ; mclxWrite(mx1, xo, MCLXIO_VALUE_GETENV, RETURN_ON_FAIL) ; } mclxFree(&mx1) ; mclxFree(&mx2) ; mcxIOfree(&xf1) ; mcxIOfree(&xf2) ; return 0 ; }
static mcxstatus meetMain ( int argc , const char* argv[] ) { mcxIO **xfmcs = NULL ; mclMatrix *lft = NULL ; mclMatrix *rgt = NULL ; mclMatrix *dst = NULL ; int a = 0 ; int n_mx = 0 ; int j ; dim o, m, e ; mclxIOsetQMode("MCLXIOVERBOSITY", MCL_APP_VB_YES) ; mclx_app_init(stderr) ; xfmcs = (mcxIO**) mcxAlloc ( (argc)*sizeof(mcxIO*) , EXIT_ON_FAIL ) ; mcxIOopen(xfout, EXIT_ON_FAIL) ; for(j=a;j<argc;j++) { xfmcs[n_mx] = mcxIOnew(argv[j], "r") ; n_mx++ ; } if (!n_mx) mcxDie(1, me, "at least one clustering matrix required") /* Fixme: do a decent initialization with lft = clmTop() *before* * this loop (removing the need for ugly tmp assignment), but that requires * we know the correct domain to pass to it. For that, we need to peak into * the first matrix. */ ; for (j=0;j<n_mx;j++) { mclMatrix* tmp = mclxRead (xfmcs[j], EXIT_ON_FAIL) ; if (clmEnstrict(tmp, &o, &m, &e, ENSTRICT_SPLIT_OVERLAP)) report_partition("clmmeet", tmp, xfmcs[j]->fn, o, m, e) , mcxExit(1) ; if (!lft) { lft = tmp ; continue ; } else rgt = tmp ; if (!MCLD_EQUAL(lft->dom_rows, rgt->dom_rows)) mcxDie ( 1 , me , "domains not equal (files %s/%s)" , xfmcs[j-1]->fn->str , xfmcs[j]->fn->str ) ; mcxIOclose(xfmcs[j]) ; dst = clmMeet(lft, rgt) ; lft = dst ; mclxFree(&rgt) ; } mclxColumnsRealign(lft, mclvSizeRevCmp) ; mclxWrite(lft, xfout, MCLXIO_VALUE_NONE, EXIT_ON_FAIL) ; mclxFree(&lft) ; mcxIOfree(&xfout) ; free(xfmcs) ; return STATUS_OK ; }
int main ( int argc , const char* argv[] ) { mcxIO *xfcl = NULL , *xfctrl = NULL , *xfcoarse= NULL , *xfbase = NULL , *xfcone = NULL , *xfstack = NULL ; mclx* mxbase, *cl, *cl_coarse, *clprev, *clctrl = NULL ; mcxTing* shared = mcxTingNew("-I 4 -overlap split") ; mcxbool root = TRUE ; mcxbool have_bootstrap = FALSE ; const char* plexprefix = NULL ; const char* stem = "mcl" ; mcxbool same = FALSE ; mcxbool plex = TRUE ; mcxbool add_transpose = FALSE ; const char* b2opts = NULL ; const char* b1opts = NULL ; mcxbits write_modes = 0 ; mclAlgParam* mlp = NULL ; mcxstatus status = STATUS_OK ; mcxstatus parse_status = STATUS_OK ; int multiplex_idx = 1 ; int N = 0 ; int n_ite = 0 ; dim n_components = 0, n_cls = 0 ; int a = 1, i= 0 ; int n_arg_read = 0 ; int delta = 0 ; mcxOption* opts, *opt ; mcxTing* cline = mcxOptArgLine(argv+1, argc-1, '\'') ; mclgTF* transform = NULL ; mcxTing* transform_spec = NULL ; double iaf = 0.84 ; mclx_app_init(stderr) ; if (0) mcxLogLevel = MCX_LOG_AGGR | MCX_LOG_MODULE | MCX_LOG_IO | MCX_LOG_GAUGE | MCX_LOG_WARN ; else mcxLogLevelSetByString("xf4g1") ; mcxOptAnchorSortById(options, sizeof(options)/sizeof(mcxOptAnchor) -1) ; if (argc == 2 && argv[1][0] == '-' && mcxOptIsInfo(argv[1], options)) delta = 1 ; else if (argc < 2) { help(options, shared) ; exit(0) ; } opts = mcxOptExhaust (options, (char**) argv, argc, 2-delta, &n_arg_read, &parse_status) ; if (parse_status != STATUS_OK) { mcxErr(me, "initialization failed") ; exit(1) ; } ; for (opt=opts;opt->anch;opt++) { mcxOptAnchor* anch = opt->anch ; switch(anch->id) { case MY_OPT_HELP : help(options, shared) ; exit(0) ; case MY_OPT_APROPOS : help(options, shared) ; exit(0) ; break ; case MY_OPT_NMAX : N = atoi(opt->val) ; break ; case MY_OPT_Z : help(NULL, shared) ; exit(0) ; break ; case MY_OPT_SHARED : mcxTingPrintAfter(shared, " %s", opt->val) ; break ; case MY_OPT_TRANSFORM : transform_spec = mcxTingNew(opt->val) ; break ; case MY_OPT_B1 : b1opts = opt->val ; break ; case MY_OPT_B2 : b2opts = opt->val ; break ; case ALG_OPT_SETENV : mcxSetenv(opt->val) ; break ; case ALG_OPT_QUIET : mcxLogLevelSetByString(opt->val) ; break ; case MY_OPT_HDP : hdp_g = atof(opt->val) ; break ; case MY_OPT_ADDTP : add_transpose = TRUE ; break ; case MY_OPT_ANNOT /* only used in command-line copying */ : break ; case MY_OPT_IAF : iaf = atof(opt->val) / 100 ; break ; case MY_OPT_WRITE : if (strstr(opt->val, "stack")) write_modes |= OUTPUT_STACK ; if (strstr(opt->val, "cone")) write_modes |= OUTPUT_CONE ; if (strstr(opt->val, "levels")) write_modes |= OUTPUT_STEPS ; if (strstr(opt->val, "coarse")) write_modes |= OUTPUT_COARSE ; if (strstr(opt->val, "base")) write_modes |= OUTPUT_BASE ; break ; case MY_OPT_BASENAME : xfbase = mcxIOnew(opt->val, "w") ; break ; case MY_OPT_COARSE : xfcoarse = mcxIOnew(opt->val, "w") ; break ; case MY_OPT_CONE : xfcone = mcxIOnew(opt->val, "w") ; break ; case MY_OPT_ROOT : root = strchr("1yY", (u8) opt->val[0]) ? TRUE : FALSE ; break ; case MY_OPT_STACK : xfstack = mcxIOnew(opt->val, "w") ; break ; case MY_OPT_STEM : stem = opt->val ; break ; case MY_OPT_MULTIPLEX : plex = strchr("yY1", (unsigned char) opt->val[0]) ? TRUE : FALSE ; break ; case MY_OPT_DISPATCH : dispatch_g = TRUE ; break ; case MY_OPT_INTEGRATE : integrate_g = TRUE ; break ; case MY_OPT_CONTRACT : break ; case MY_OPT_SUBCLUSTERX : subclusterx_g = TRUE, subcluster_g = TRUE ; break ; case MY_OPT_SUBCLUSTER : subcluster_g = TRUE ; break ; case MY_OPT_CONTROL : xfctrl = mcxIOnew(opt->val, "r") ; break ; case MY_OPT_CL : xfcl = mcxIOnew(opt->val, "r") ; have_bootstrap = TRUE ; break ; case MY_OPT_VERSION : app_report_version(me) ; exit(0) ; default : mcxExit(1) ; } } mcxOptFree(&opts) ; a = 2 + n_arg_read ; if (a < argc) { if (strcmp(argv[a], "--")) mcxDie ( 1 , me , "trailing %s options require standalone '--' separator (found %s)" , integrate_g ? "integrate" : "mcl" , argv[a] ) ; a++ ; } if (subcluster_g + dispatch_g + integrate_g > 1) mcxDie(1, me, "too many modes!") ; if (N && N < argc-a) mcxErr(me, "-n argument leaves spurious option specifications") ; srandom(mcxSeed(89315)) ; signal(SIGALRM, mclSigCatch) ; if (dispatch_g) plexprefix = "dis" ; else if (!write_modes || (write_modes & OUTPUT_STEPS)) plexprefix = stem ; { mcxTing* tg = mcxTingEmpty(NULL, 30) ; if ((write_modes & OUTPUT_COARSE) && !xfcoarse) mcxTingPrint(tg, "%s.%s", stem, "coarse") , xfcoarse = mcxIOnew(tg->str, "w") ; if ((write_modes & OUTPUT_BASE) && !xfbase) mcxTingPrint(tg, "%s.%s", stem, "base") , xfbase = mcxIOnew(tg->str, "w") ; if ( (!write_modes || (write_modes & OUTPUT_CONE)) && !xfcone ) { mcxTingPrint(tg, "%s.%s", stem, "cone") ; xfcone = mcxIOnew(tg->str, "w") ; mcxIOopen(xfcone, EXIT_ON_FAIL) ; fprintf(xfcone->fp, "# %s %s\n", argv[0], cline->str) ; } if ((write_modes & OUTPUT_STACK) && !xfstack) { mcxTingPrint(tg, "%s.%s", stem, "stack") ; xfstack = mcxIOnew(tg->str, "w") ; mcxIOopen(xfstack, EXIT_ON_FAIL) ; fprintf(xfstack->fp, "# %s %s\n", argv[0], cline->str) ; } mcxTingFree(&tg) ; } if (integrate_g) { for (i=a;i<argc;i++) { mcxIO* xf = mcxIOnew(argv[i], "r") ; mclx* cl = mclxRead(xf, EXIT_ON_FAIL) ; mclxCatPush(&stck_g, cl, NULL, NULL, mclxCBdomStack, NULL, "dummy-integrate", n_cls++) ; } integrate_results(&stck_g) ; if (xfstack) mclxCatWrite(xfstack, &stck_g, MCLXIO_VALUE_NONE, RETURN_ON_FAIL) ; if (xfcone) mclxCatConify(&stck_g) , mclxCatWrite(xfcone, &stck_g, MCLXIO_VALUE_NONE, RETURN_ON_FAIL) ; return 0 ; } for (i=a;i<argc;i++) { if (get_interface(NULL, argv[1], shared->str, argv[i], NULL, 0, RETURN_ON_FAIL)) mcxDie(1, me, "error while testing mcl options viability (%s)", argv[i]) ; } mcxLog(MCX_LOG_APP, me, "pid %ld", (long) getpid()) /* make sure clusters align with this cluster * status: does not seem promising. */ ; if (xfctrl) clctrl = mclxRead(xfctrl, EXIT_ON_FAIL) ; /* * Below: compute cl and mxbase. */ ; if (xfcl) { cl = mclxRead(xfcl, EXIT_ON_FAIL) ; write_clustering (cl, NULL, xfcone, xfstack, plexprefix, multiplex_idx++, NULL) ; if (subcluster_g || dispatch_g) mclxCatPush(&stck_g, cl, NULL, NULL, mclxCBdomStack, NULL, "dummy-mclcm", n_cls++) ; mcxIOfree(&xfcl) ; if (!b1opts && !b2opts) b1opts = "" ; mxbase = get_base(argv[1], NULL, b1opts, b2opts) ; } else { mcxbits CACHE = b1opts || b2opts ? ALG_CACHE_INPUT /* cache, transform later */ : ALG_CACHE_START ; get_interface ( &mlp , argv[1] , shared->str , a < argc ? argv[a] : NULL , NULL , CACHE , EXIT_ON_FAIL ) ; if (a < argc) a++ ; if ((status = mclAlgorithm(mlp)) == STATUS_FAIL) { mcxErr(me, "failed at initial run") ; exit(1) ; } cl_coarse = mclAlgParamRelease(mlp, mlp->cl_result) ; cl_coarse = control_test(cl_coarse, clctrl) ; write_clustering (cl_coarse, NULL, xfcone, xfstack, plexprefix, multiplex_idx++, mlp) ; if (subcluster_g || dispatch_g) mclxCatPush(&stck_g, cl_coarse, NULL, NULL, mclxCBdomStack, NULL, "dummy-mclcm", n_cls++) ; cl = cl_coarse ; n_ite++ ; if (b1opts || b2opts) { mclx* mx_input = mclAlgParamRelease(mlp, mlp->mx_input) ; mxbase = get_base(NULL, mx_input, b1opts, b2opts) /* ^ get_base frees mx_input */ ; } else mxbase = mclAlgParamRelease(mlp, mlp->mx_start) ; } clprev = cl ; mclAlgParamFree(&mlp, TRUE) ; if (xfbase) { dim nre = mclxNrofEntries(mxbase) ; mcxLog(MCX_LOG_APP, me, "base has %lu entries", (ulong) nre) ; mclxaWrite(mxbase, xfbase, MCLXIO_VALUE_GETENV, EXIT_ON_FAIL) ; mcxIOclose(xfbase) ; } if (subcluster_g || dispatch_g) iaf = iaf ? 1/iaf : 1.414 ; while ( (!dispatch_g && (!N || n_ite < N)) || (dispatch_g && a < argc) ) { mclx* mx_coarse = NULL, *clnext = NULL ; dim dist_new_prev = 0, dist_prev_new = 0 ; mclx* clnew = NULL ; mcxbool faith = FALSE ; double inflation = -1.0 ; if (subcluster_g) mx_coarse = subclusterx_g ? mclxBlockPartition(mxbase, clprev, 50) : mclxBlockUnion(mxbase, clprev) /* have to copy mxbase as mx_coarse is freed. * Even if it were not freed, it is probably transformed. */ ; else if (dispatch_g) mx_coarse = mclxCopy(mxbase) ; else { mx_coarse = get_coarse(mxbase, clprev, add_transpose) ; if (n_ite == 1) { mclx* cc = clmUGraphComponents(mx_coarse, NULL) /* fixme; mx_coarse garantueed UD ? */ ; n_components = N_COLS(cc) ; mclxFree(&cc) ; } } if (xfcoarse) write_coarse(xfcoarse, mx_coarse) ; get_interface ( &mlp , NULL , shared->str , a < argc ? argv[a] : NULL , mx_coarse , ALG_CACHE_START , EXIT_ON_FAIL ) ; inflation = mlp->mpp->mainInflation ; BIT_OFF(mlp->modes, ALG_DO_SHOW_PID | ALG_DO_SHOW_JURY) ; if ((status = mclAlgorithm(mlp)) == STATUS_FAIL) { mcxErr(me, "failed") ; mcxExit(1) ; } cl_coarse = mclAlgParamRelease(mlp, mlp->cl_result) ; if (xfcoarse) mclxaWrite(cl_coarse, xfcoarse, MCLXIO_VALUE_NONE, RETURN_ON_FAIL) ; if (dispatch_g || subcluster_g) clnext = cl_coarse ; else clnext = mclxCompose(clprev, cl_coarse, 0) , clnext = control_test(clnext, clctrl) , mclxFree(&cl_coarse) ; clmSJDistance (clprev, clnext, NULL, NULL, &dist_prev_new, &dist_new_prev) ; if (dist_prev_new + dist_new_prev) { write_clustering (clnext, clprev, xfcone, xfstack, plexprefix, multiplex_idx++, mlp) ; clnew = clnext ; if (subcluster_g || dispatch_g) mclxCatPush(&stck_g, clnext, NULL, NULL, mclxCBdomStack, NULL, "dummy-mclcm", n_cls++) ; else mclxFree(&clprev) ; clprev = clnew ; } else if ( N_COLS(clnext) > n_components && inflation * iaf > 1.2 && inflation * iaf < 10 ) { mclxFree(&clnext) ; inflation *= iaf ; mcxTingPrintAfter(shared, " -I %.2f", inflation) ; mcxLog(MCX_LOG_APP, me, "setting inflation to %.2f", inflation) ; faith = TRUE ; } /* i.e. vanilla mode, contraction */ else if (!subcluster_g && !dispatch_g) { mclx* cc ; mclxFree(&clnext) ; mclxAddTranspose(mx_coarse, 1.0) ; cc = clmUGraphComponents(mx_coarse, NULL) ; if (N_COLS(cc) < N_COLS(clprev)) { mclx* ccback = mclxCompose(clprev, cc, 0) ; write_clustering (ccback, clprev, xfcone, xfstack, plexprefix, multiplex_idx++, NULL) ; mclxFree(&clprev) ; clprev = ccback ; mcxTell(me, "connected components added as root clustering") ; } if (root && N_COLS(cc) > 1) { mclx* root = mclxCartesian ( mclvCanonical(NULL, 1, 0) , mclvCopy(NULL, mxbase->dom_cols) , 1.0 ) ; write_clustering (root, clprev, xfcone, xfstack, plexprefix, multiplex_idx++, NULL) ; mclxFree(&clprev) ; mcxTell(me, "universe added as root clustering") ; clprev = root ; clnew = NULL ; } mclxFree(&cc) ; } else if (subcluster_g || dispatch_g) mclxFree(&clnext) ; mclAlgParamFree(&mlp, TRUE) /* frees mx_coarse */ ; if (!clnew && !faith) { same = TRUE ; break ; } a++ ; if (dispatch_g && a == argc) break ; n_ite++ ; } if (same) mcxLog(MCX_LOG_MODULE, me, "no further contraction: halting") ; if (dispatch_g) integrate_results(&stck_g) ; else if (subcluster_g) mclxCatReverse(&stck_g) ; if (dispatch_g || subcluster_g) { dim j ; if (xfstack) mclxCatWrite(xfstack, &stck_g, MCLXIO_VALUE_NONE, RETURN_ON_FAIL) ; if (xfcone && ! mclxCatConify(&stck_g)) mclxCatWrite(xfcone, &stck_g, MCLXIO_VALUE_NONE, RETURN_ON_FAIL) ; for (j=0;j<stck_g.n_level;j++) { mclxAnnot* an = stck_g.level+j ; mclxFree(&an->mx) ; } mcxFree(stck_g.level) ; } mcxIOfree(&xfcoarse) ; mcxIOfree(&xfbase) ; mcxIOfree(&xfcone) ; mcxIOfree(&xfstack) ; mcxTingFree(&shared) ; if (!dispatch_g && !subcluster_g) /* fixme fixme fixme */ mclxFree(&clprev) ; mclxFree(&mxbase) ; mclvFree(&start_col_sums_g) ; mcxTingFree(&cline) ; helpful_reminder() ; return STATUS_OK ; }
static mcxstatus diameterArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : mcxIOnewName(xfmx_g, val) ; break ; case MY_OPT_LIST_NODES : list_nodes = TRUE ; break ; case MY_OPT_T : n_thread_l = (unsigned) atoi(val) ; break ; case MY_OPT_LIST_MAX : list_nodes = FALSE ; break ; case MY_OPT_ROUGH : rough = TRUE ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_OUT : out_g = val ; break ; case MY_OPT_littleG : i_group = atoi(val) ; break ; case MY_OPT_G : n_group_G = atoi(val) ; break ; case MY_OPT_ABC : xfabc_g = mcxIOnew(val, "r") ; break ; default : mcxExit(1) ; ; } return STATUS_OK ; }
mcxstatus sharedArgHandle ( int optid , const char* val , mcxDispHook* hook , mcxDispBundle* bundle ) { mcxTing* full_syntax = mcxTingPrint(NULL, "%s %s", "clm", hook->syntax) ; switch(optid) { case CLM_DISP_HELP : case CLM_DISP_APROPOS : case CLM_DISP_AMOIXA : mcxOptApropos ( stdout , hook->name , full_syntax->str , 15 , 0 , bundle->disp_shared ) ; mcxOptApropos ( stdout , hook->name , NULL , 15 , MCX_OPT_DISPLAY_SKIP | ( optid == CLM_DISP_AMOIXA ? MCX_OPT_DISPLAY_HIDDEN : 0 ) , hook->options ) ; mcxExit(0) ; break ; case CLM_DISP_VERSION : bundle->disp_version(hook->name) ; mcxExit(0) ; break ; case CLM_DISP_NOP : NOTHING ; break ; case CLM_DISP_TEST : mcx_test_g = TRUE ; break ; case CLM_DISP_PROGRESS : mcx_progress_g = atoi(val) ; break ; case CLM_DISP_PROGRESS2 : mcx_progress_g = 1 ; break ; case CLM_DISP_DEBUG : mcx_debug_g = atoi(val) ; break ; case CLM_DISP_DEBUG2 : mcx_debug_g = -1u ; break ; case CLM_DISP_SET : mcxSetenv(val) ; break ; default : break ; } mcxTingFree(&full_syntax) ; return STATUS_OK ; }
static mcxstatus qArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : mcxIOnewName(xfmx_g, val) ; user_imx = TRUE ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_ICL : xfcl_g = mcxIOnew(val, "r") ; break ; case MY_OPT_TRANSFORM : transform_spec = mcxTingNew(val) ; break ; case MY_OPT_DIMENSION : mode_get = 'd' ; break ; case MY_OPT_TESTCYCLE : mode_get = 'c' ; break ; case MY_OPT_TESTCYCLE_N : n_limit = atoi(val) ; mode_get = 'c' ; break ; case MY_OPT_CLCF : doclcf_g = TRUE ; break ; case MY_OPT_KNNREDUCE : knnexact_g = FALSE ; break ; case MY_OPT_THREAD : n_thread_g = atoi(val) ; break ; case MY_OPT_NODE : mode_get = 'n' ; break ; case MY_OPT_FOUT : mcxIOnewName(xfout_g, val) ; break ; case MY_OPT_WEIGHT_SCALE : weight_scale = atof(val) ; break ; case MY_OPT_OUTPUT_TABLE : output_table = TRUE ; break ; case MY_OPT_MYTH : weefreemen = TRUE ; break ; case MY_OPT_EDGEWEIGHTS : mode_get = 'e' ; break ; case MY_OPT_EDGEWEIGHTS_HIST : mode_get = 'H' ; if (4 != sscanf(val, "%d,%d,%d,%d", &vary_a, &vary_z, &vary_s, &vary_n)) mcxDie(1, me, "failed to parse argument as integers start,end,step,norm") ; break ; case MY_OPT_EDGEWEIGHTS_SORTED : mode_get = 'E' ; break ; case MY_OPT_DIVIDE : divide_g = atoi(val) ; break ; case MY_OPT_VARY_CORRELATION : vary_a = 4 ; vary_z = 20 ; vary_s = 1 ; vary_n = 20 ; weight_scale = 100 ; mode_vary = 'c' ; break ; case MY_OPT_VARY_KNN : if (4 != sscanf(val, "%d,%d,%d,%d", &vary_a, &vary_z, &vary_s, &vary_n)) mcxDie(1, me, "failed to parse argument as integers start,end,step,norm") ; mode_vary = 'k' ; break ; case MY_OPT_VARY_THRESHOLD : if (4 != sscanf(val, "%u,%u,%u,%u", &vary_a, &vary_z, &vary_s, &vary_n)) mcxDie(1, me, "failed to parse argument as integers start,end,step,norm") ; mode_vary = 't' ; break ; default : mcxExit(1) ; ; } if (mode_vary && 1000 * vary_s < vary_z - vary_a) mcxDie(1, me, "argument leads to more than one thousand steps") ; if (!vary_n) mcxDie(1, me, "need nonzero scaling factor (last component)") ; return STATUS_OK ; }
static mcxstatus qArgHandle ( int optid , const char* val ) { switch(optid) { case MY_OPT_IMX : mcxIOnewName(xfmx_g, val) ; user_imx = TRUE ; break ; case MY_OPT_ABC : xfabc_g = mcxIOnew(val, "r") ; break ; case MY_OPT_TAB : xftab_g = mcxIOnew(val, "r") ; break ; case MY_OPT_ICL : xfcl_g = mcxIOnew(val, "r") ; break ; case MY_OPT_TRANSFORM : transform_spec = mcxTingNew(val) ; break ; case MY_OPT_DIMENSION : mode_get = 'd' ; break ; case MY_OPT_TESTMETRIC : mode_get = 'm' ; break ; case MY_OPT_TESTCYCLE : mode_get = 'c' ; break ; case MY_OPT_TESTCYCLE_N : n_limit = atoi(val) ; mode_get = 'c' ; break ; case MY_OPT_INFO : compute_flags |= COMPUTE_EFF ; break ; case MY_OPT_CLCF : compute_flags |= COMPUTE_CLCF ; break ; case MY_OPT_REDUCE : rebase_g = FALSE ; break ; case MY_OPT_THREAD : n_thread_l = atoi(val) ; break ; case MY_OPT_NODE : mode_get = 'n' ; break ; case MY_OPT_FOUT : mcxIOnewName(xfout_g, val) ; break ; case MY_OPT_WEIGHT_SCALE : weight_scale = atof(val) ; break ; case MY_OPT_OUTPUT_NOLEGEND : output_flags ^= OUTPUT_KEY ; break ; case MY_OPT_OUTPUT_TABLE : output_flags |= OUTPUT_TABLE ; break ; case MY_OPT_SCALEFREE : weefreemen = TRUE ; break ; case MY_OPT_EDGEWEIGHTS : mode_get = 'e' ; break ; case MY_OPT_EDGEWEIGHTS_HIST : mode_get = 'H' ; if (4 != sscanf(val, "%d,%d,%d,%d", &vary_a, &vary_z, &vary_s, &vary_n)) mcxDie(1, me, "failed to parse argument as integers start,end,step,norm") ; break ; case MY_OPT_EDGEWEIGHTS_SORTED : mode_get = 'E' ; break ; case MY_OPT_DIVIDE : divide_g = atoi(val) ; break ; case MY_OPT_VARY_CORRELATION : vary_a = 4 ; vary_z = 20 ; vary_s = 1 ; vary_n = 20 ; weight_scale = 100 ; mode_vary = 'c' ; break ; case MY_OPT_VARY_CEIL : case MY_OPT_VARY_KNN : case MY_OPT_VARY_N : case MY_OPT_VARY_THRESHOLD : if (4 != sscanf(val, "%d,%d,%d,%d", &vary_a, &vary_z, &vary_s, &vary_n)) mcxDie(1, me, "failed to parse argument as integers start,end,step,norm") ; mode_vary = optid == MY_OPT_VARY_THRESHOLD ? 't' : optid == MY_OPT_VARY_KNN ? 'k' : optid == MY_OPT_VARY_CEIL ? 'n' : optid == MY_OPT_VARY_N ? 'l' : 'X' ; break ; default : mcxExit(1) ; ; } if (mode_vary && 1000 * vary_s < vary_z - vary_a) mcxDie(1, me, "argument leads to more than one thousand steps") ; if (!vary_n) mcxDie(1, me, "need nonzero scaling factor (last component)") ; return STATUS_OK ; }
mcxstatus mclvCheck ( const mclVector* vec , long min , long max , mcxbits bits , mcxOnFail ON_FAIL ) { mclIvp* ivp = vec->ivps ; mclIvp* ivpmax = vec->ivps+vec->n_ivps ; long last = -1 ; const char* me = "mclvCheck" ; mcxbool ok = TRUE ; if (vec->n_ivps && !vec->ivps) mcxErr(me, "deadly: NULL ivps and %ld n_ivps", (long) vec->n_ivps) , ok = FALSE ; else if (vec->n_ivps && min >= 0 && MCLV_MINID(vec) < min) mcxErr (me, "daemons: MINID %ld less than %ld", (long) MCLV_MINID(vec), min) , ok = FALSE ; while (ok && ivp<ivpmax) { if (ivp->idx <= last) { mcxErr(me, "deadly: index %s <%ld, %ld> at ivp <%ld>" , ivp->idx == last ? "repeat" : "descent" , (long) last , (long) ivp->idx , (long) (ivp - vec->ivps) ) ; ok = FALSE ; break ; } if ( (bits & MCLV_CHECK_POSITIVE && ivp->val < 0.0) || (bits & MCLV_CHECK_NONZERO && ivp->val == 0.0) ) { mcxErr(me, "error: value <%f> at ivp <%ld>" , (double) ivp->val , (long) (ivp - vec->ivps) ) ; ok = FALSE ; break ; } last = ivp->idx ; ivp++ ; } if (ok && max >= 0 && last > max) { mcxErr ( me , "deadly: index <%ld> tops range <%ld> at ivp <%ld>" , (long) last , (long) max , (long) (ivp - 1 - vec->ivps) ) ; ok = FALSE ; } if (!ok && (ON_FAIL == EXIT_ON_FAIL)) mcxExit(1) ; return ok ? STATUS_OK : STATUS_FAIL ; }
double mclvKBar ( mclVector *vec , dim k , double ignore /* ignore elements relative to this */ , int mode ) { int have_even = (k+1) % 2 ; dim n_inserted = 0 ; double ans = 0.0 ; mclIvp * vecivp = vec->ivps ; mclIvp* vecmaxivp = vecivp + vec->n_ivps ; pval * heap /* can select everything */ ; if (k >= vec->n_ivps) return mode == KBAR_SELECT_LARGE ? -FLT_MAX : FLT_MAX /* let's select nothing, it might even help */ ; if (!(heap = mcxAlloc ((k+have_even)*sizeof(pval), RETURN_ON_FAIL))) return mode == KBAR_SELECT_LARGE ? FLT_MAX : -FLT_MAX ; if (mode == KBAR_SELECT_LARGE) { if (have_even) *(heap+k) = PVAL_MAX ; while(vecivp < vecmaxivp) { pval val = vecivp->val ; if (val >= ignore) NOTHING ; else if (n_inserted < k) { dim d = n_inserted ; while (d != 0 && *(heap+(d-1)/2) > val) { *(heap+d) = *(heap+(d-1)/2) ; d = (d-1)/2 ; } *(heap+d) = val ; n_inserted++ ; } else if (val > *heap) { dim root = 0 ; dim d ; while((d = 2*root+1) < k) { if (*(heap+d) > *(heap+d+1)) d++ ; if (val > *(heap+d)) { *(heap+root) = *(heap+d) ; root = d ; } else break ; } *(heap+root) = val ; } vecivp++ ; } } else if (mode == KBAR_SELECT_SMALL) { if (have_even) *(heap+k) = -PVAL_MAX ; while(vecivp < vecmaxivp) { pval val = vecivp->val ; if (val < ignore) NOTHING ; else if (n_inserted < k) { dim d = n_inserted ; while (d != 0 && *(heap+(d-1)/2) < val) { *(heap+d) = *(heap+(d-1)/2) ; d = (d-1)/2 ; } *(heap+d) = val ; n_inserted++ ; } else if (val < *heap) { dim root = 0 ; dim d ; while((d = 2*root+1) < k) { if (*(heap+d) < *(heap+d+1)) d++ ; if (val < *(heap+d)) { *(heap+root) = *(heap+d) ; root = d ; } else break ; } *(heap+root) = val ; } vecivp++ ; } } else { mcxErr("mclvKBar PBD", "invalid mode") ; mcxExit(1) ; } ans = *heap ; mcxFree(heap) ; return ans ; }
int main ( int argc , const char* argv[] ) { mcxIO *xf_cl = NULL, *xf_mx = NULL ; mclx *cl = NULL, *elcl = NULL ; int a = 1 ; dim i ; mcxLogLevel = MCX_LOG_AGGR | MCX_LOG_MODULE | MCX_LOG_IO | MCX_LOG_GAUGE | MCX_LOG_WARN ; mclxIOsetQMode("MCLXIOVERBOSITY", MCL_APP_VB_YES) ; mclx_app_init(stderr) ; while(a < argc) { if (!strcmp(argv[a], "-icl")) { if (a++ + 1 < argc) xf_cl = mcxIOnew(argv[a], "r") ; else goto arg_missing ; } else if (!strcmp(argv[a], "-h")) { help : mcxUsage(stdout, me, usagelines) ; mcxExit(STATUS_FAIL) ; } else if (!strcmp(argv[a], "--version")) { app_report_version(me) ; exit(0) ; } else if (!strcmp(argv[a], "-imx")) { if (a++ + 1 < argc) xf_mx = mcxIOnew(argv[a], "r") ; else goto arg_missing ; } else if (!strcmp(argv[a], "-h")) { goto help ; } else if (0) { arg_missing: ; mcxErr ( me , "flag <%s> needs argument; see help (-h)" , argv[argc-1] ) ; mcxExit(1) ; } else { mcxErr ( me , "unrecognized flag <%s>; see help (-h)" , argv[a] ) ; mcxExit(1) ; } a++ ; } if (!xf_cl) mcxErr(me, "need cluster file") , mcxExit(1) ; cl = mclxRead(xf_cl, EXIT_ON_FAIL) ; elcl = mclxTranspose(cl) ; for (i=0; i<N_COLS(elcl); i++) { mclv* vec = elcl->cols+i ; if (vec->n_ivps > 1) fprintf(stdout, "%ld\n", (long) vec->vid) ; } return 0 ; }