mclMatrix* mclDiagOrdering ( const mclMatrix* M , mclVector** vecp_attr ) { int n_cols = N_COLS(M) ; mclMatrix* diago = mclxAllocZero(NULL, NULL) ; long col ; if (*vecp_attr != NULL) mclvFree(vecp_attr) ; *vecp_attr = mclvResize(NULL, n_cols) ; for (col=0;col<n_cols;col++) { ofs offset = -1 ; double selfval = mclvIdxVal(M->cols+col, col, &offset) ; double center = mclvPowSum(M->cols+col, 2.0) /* double maxval = mclvMaxValue(M->cols+col) */ ; double bar = MCX_MAX(center, selfval) - dpsd_delta ; mclIvp* ivp = (*vecp_attr)->ivps+col ; ivp->idx = col ; ivp->val = center ? selfval / center : 0 ; if (offset >= 0) /* take only higher valued entries */ mclvSelectGqBar(diago->cols+col, bar) ; } ; return diago ; }
int mclDagTest ( const mclMatrix* dag ) { mclv* v_transient = mclvCopy(NULL, dag->dom_cols) ; mclx* m_transient = NULL ; int maxdepth = 0 ; dim d ; mclvMakeCharacteristic(v_transient) ; for (d=0;d<N_COLS(dag);d++) { mclv* col = dag->cols+d ; if (mclvGetIvp(col, col->vid, NULL)) /* deemed attractor */ mclvInsertIdx(v_transient, col->vid, 0.25) ; } mclvSelectGqBar(v_transient, 0.5) ; m_transient = mclxSub(dag, v_transient, v_transient) ;if(0)mclxDebug("-", m_transient, 3, "transient") ; maxdepth = calc_depth(m_transient) ; mclxFree(&m_transient) ; mclvFree(&v_transient) ; return maxdepth ; }
void mclvSelectHighest ( mclVector* vec , dim max_n_ivps ) { double f ; if (vec->n_ivps <= max_n_ivps) return ; f = vec->n_ivps >= 2 * max_n_ivps ? mclvKBar (vec, max_n_ivps, PVAL_MAX, KBAR_SELECT_LARGE) : mclvKBar (vec, vec->n_ivps - max_n_ivps + 1, -PVAL_MAX, KBAR_SELECT_SMALL) ; mclvSelectGqBar(vec, f) ; if (vec->n_ivps > max_n_ivps) mclvSelectGqBar(vec, f * (1.0 + PVAL_EPSILON)) ; }
mclv* reduce_v ( const mclv* u ) { mclv* v = mclvClone(u) ; dim n = v->n_ivps ; double s = mclvSum(v) ; double sq = mclvPowSum(v, 2.0) ; if (s) mclvSelectGqBar(v, 0.25 * sq / s) ;fprintf(stderr, "from %d to %d entries\n", (int) n, (int) v->n_ivps) ; return v ; }
mclMatrix* mclInterpret ( mclMatrix* dag ) { mclv* v_attr = mclvCopy(NULL, dag->dom_cols) ; mclx* m_attr = NULL, *m_cls = NULL, *m_clst = NULL ; dim d ; mclvMakeCharacteristic(v_attr) ; for (d=0;d<N_COLS(dag);d++) { mclv* col = dag->cols+d ; if (mclvGetIvp(col, col->vid, NULL)) /* deemed attractor */ mclvInsertIdx(v_attr, col->vid, 2.0) ; } mclvSelectGqBar(v_attr, 1.5) ; m_attr = mclxSub(dag, v_attr, v_attr) ; mclxAddTranspose(m_attr, 1.0) ; m_cls = clmUGraphComponents(m_attr, NULL) /* attractor systems as clusters */ ; mclvCopy(m_cls->dom_rows, dag->dom_cols) /* add all nodes to this cluster matrix */ ; m_clst = mclxTranspose(m_cls) /* nodes(columns) with zero neighbours need to be classified */ ; mclgUnionvReset(dag) /* make mx->dom-rows characteristic */ ; mclxFree(&m_cls) ; for (d=0;d<N_COLS(dag);d++) { mclv* closure, *clsids ; if (mclvGetIvp(v_attr, dag->cols[d].vid, NULL)) continue /* attractor already classified */ ; closure = get_closure(dag, dag->cols+d) /* take all [neighbours of [neighbours of [..]]] */ ; clsids = mclgUnionv(m_clst, closure, NULL, SCRATCH_READY, NULL) ; mclvAdd(m_clst->cols+d, clsids, m_clst->cols+d) ; mclvFree(&clsids) ; mclvFree(&closure) ; } m_cls = mclxTranspose(m_clst) ; mclxFree(&m_attr) ; mclxFree(&m_clst) ; mclvFree(&v_attr) ; return m_cls ; }
double get_score ( const mclv* c , const mclv* d , const mclv* c_start , const mclv* d_start , const mclv* c_end , const mclv* d_end ) { mclv* vecc = mclvClone(c) ; mclv* vecd = mclvClone(d) ; mclv* meet_c = mcldMeet(vecc, vecd, NULL) ; mclv* meet_d = mcldMeet(vecd, meet_c, NULL) ; mclv* cwid = mclvBinary(c_end, c_start, NULL, fltSubtract) ; mclv* dwid = mclvBinary(d_end, d_start, NULL, fltSubtract) ; mclv* rmin = mclvBinary(c_end, d_end, NULL, fltMin) ; mclv* lmax = mclvBinary(c_start, d_start, NULL, fltMax) ; mclv* delta = mclvBinary(rmin, lmax, NULL, fltSubtract) ; mclv* weightc, *weightd ; double ip, cd, csn, meanc, meand, mean, euclid, meet_fraction, score, sum_meet_c, sum_meet_d, reduction_c, reduction_d ; int nmeet = meet_c->n_ivps ; int nldif = vecc->n_ivps - nmeet ; int nrdif = vecd->n_ivps - nmeet ; mclvSelectGqBar(delta, 0.0) ; weightc= mclvBinary(delta, cwid, NULL, mydiv) ; weightd= mclvBinary(delta, dwid, NULL, mydiv) #if 0 ;if (c != d)mclvaDump ( cwid , stdout , 5 , "\n" , 0) ,mclvaDump ( dwid , stdout , 5 , "\n" , 0) #endif ; sum_meet_c = 0.01 + mclvSum(meet_c) ; sum_meet_d = 0.01 + mclvSum(meet_d) ; mclvBinary(meet_c, weightc, meet_c, fltMultiply) ; mclvBinary(meet_d, weightd, meet_d, fltMultiply) ; reduction_c = mclvSum(meet_c) / sum_meet_c ; reduction_d = mclvSum(meet_d) / sum_meet_d ; ip = mclvIn(meet_c, meet_d) ; cd = sqrt(mclvPowSum(meet_c, 2.0) * mclvPowSum(meet_d, 2.0)) ; csn = cd ? ip / cd : 0.0 ; meanc = meet_c->n_ivps ? mclvSum(meet_c) / meet_c->n_ivps : 0.0 ; meand = meet_d->n_ivps ? mclvSum(meet_d) / meet_d->n_ivps : 0.0 ; mean = MCX_MIN(meanc, meand) ; euclid = 0 ? 1.0 : ( mean ? sqrt(mclvPowSum(meet_c, 2.0) / mclvPowSum(vecc, 2.0)) : 0.0 ) ; meet_fraction = pow((meet_c->n_ivps * 1.0 / vecc->n_ivps), 1.0) ; score = mean * csn * euclid * meet_fraction * 1.0 ; mclvFree(&meet_c) ; mclvFree(&meet_d) ; fprintf ( stdout , "%10d%10d%10d%10d%10d%10g%10g%10g%10g%10g%10g%10g\n" , (int) c->vid , (int) d->vid , (int) nldif , (int) nrdif , (int) nmeet , score , mean , csn , euclid , meet_fraction , reduction_c , reduction_d ) ; return score ; }