Exemple #1
0
static int calc_depth
(  mclx* m_transient
)
{   mclx* m_inverse = mclxTranspose(m_transient)
                      ;
    dim c, depth = 0

                   ;
    if(0)puts("")

        ;
    for (c=0; c<N_COLS(m_inverse); c++)
    {   dim this_depth = 0
                         ;
        if (!m_inverse->cols[c].n_ivps)    /* no incoming nodes */
        {   mclv* next = mclxGetVector(m_transient, m_inverse->cols[c].vid, RETURN_ON_FAIL, NULL)
                         ;
            if (!next)
                continue
                ;
            mclgUnionvInitList(m_transient, next)
            ;
            do
            {   mclv* next2 = mclgUnionv(m_transient, next, NULL, SCRATCH_UPDATE, NULL)
                              ;
                if (0 && next->ivps)
                    fprintf(stdout, "chain %d ->\n", (int) m_inverse->cols[c].vid)
                    ,  mclvaDump(next, stdout, -1, " ", 0)
                    ;
                if (this_depth)   /* otherwise starting vector in matrix */
                    mclvFree(&next)
                    ;
                next = next2
                       ;
                this_depth++
                ;
            }
            while (next->n_ivps)
                ;
            mclvFree(&next)      /* did loop at least once, so not the starting vector */
            ;
            mclgUnionvReset(m_transient)
            ;
        }
        if (this_depth > depth)
            depth = this_depth
                    ;
    }

    mclxFree(&m_inverse)
    ;
    return depth
           ;
}
Exemple #2
0
void pairwise_setops
(  mclx* mx1
,  mclx* mx2
,  mcxbits modes
)
   {  dim t, u, n_tst = 0
   ;  mclv* cache   = mclvInit(NULL)
   ;  mclv* meet    = mclvInit(NULL)
   ;  mclv* join    = mclvInit(NULL)
   ;  mclv* diff    = mclvInit(NULL)
   ;  mcxbool overwrite = modes & MMM_OVERWRITE
   ;  dim n_zero_meet = 0, n_plus_meet = 0

   ;  mclv* (*fn_meet)(const mclv* lft, const mclv* rgt, mclv* dst)  =  mcldMeet
   ;  mclv* (*fn_minus)(const mclv* lft, const mclv* rgt, mclv* dst) =  mcldMinus1

   ;  if (modes & MMM_MEET2)
         fn_meet = mcldMeet2
      ,  fn_minus = mcldMinus

                                                      /* the point of overwrite is to have
                                                       * a lft == dst or rgt == dst pattern.
                                                      */
   ;  for (t=0;t<N_COLS(mx1);t++)
      {  for (u=0;u<N_COLS(mx2);u++)
         {  mclv* dst = overwrite ? (modes & MMM_RIGHT ? mx1->cols+u : mx2->cols+t) : diff
         ;  if (overwrite)
            mclvCopy(cache, dst)                      /* cache column, reinstate later */

         ;  if (modes & MMM_BINARY)
            mclvBinary(mx1->cols+t, mx2->cols+u, dst, fltLaNR)
         ;  else
            fn_minus(mx1->cols+t, mx2->cols+u, dst)  /* compute t / u */

         ;  if (overwrite)
               mclvCopy(diff, dst)
            ,  mclvCopy(dst, cache)                   /* reinstate column */
                                                      /* diff contains t / u */

         ;  dst = overwrite ? dst : meet              /* cache column, same as above */

         ;  if (modes & MMM_BINARY)
            mclvBinary(mx1->cols+t, mx2->cols+u, dst, fltLaR)
         ;  else
            fn_meet(mx1->cols+t, mx2->cols+u, dst)

         ;  if (overwrite)
               mclvCopy(meet, dst)
            ,  mclvCopy(dst, cache)                   /* meet contains t /\ u */

         ;  mcldMerge(diff, meet, join)               /* join should be identical to column t */

         ;  if (meet->n_ivps)
            n_plus_meet++
         ;  else
            n_zero_meet++

         ;  if (modes & MMM_CHECK)
            {  mclv* dediff = mclvClone(mx1->cols+t)
            ;  mclv* demeet = mclvClone(mx1->cols+t)
               
            ;  dim nd = mclvUpdateMeet(dediff, diff, fltSubtract)
            ;  dim nm = mclvUpdateMeet(demeet, meet, fltSubtract)

            ;  if
               (  diff->n_ivps + meet->n_ivps != mx1->cols[t].n_ivps
               || !mcldEquate(join, mx1->cols+t, MCLD_EQT_EQUAL)
               || diff->n_ivps != nd
               || meet->n_ivps != nm
               )
               {  mclvaDump(mx1->cols+t, stdout, -1, " ", MCLVA_DUMP_HEADER_ON)
               ;  mclvaDump(mx2->cols+u, stdout, -1, " ", MCLVA_DUMP_HEADER_ON)
               ;  mclvaDump(meet, stdout, -1, " ", MCLVA_DUMP_HEADER_ON)
               ;  mclvaDump(diff, stdout, -1, " ", MCLVA_DUMP_HEADER_ON)
               ;  mcxDie(1, me, "rats")
            ;  }

               mclvFree(&dediff)
            ;  mclvFree(&demeet)
         ;  }

            n_tst++
      ;  }
      }

      fprintf
      (  stdout
      ,  "meet was nonempty %.2f\n"
      ,  (double) (n_plus_meet * 1.0f / n_tst)
      )

   ;  fprintf
      (  stdout
      ,  "%d successful tests in %s%s %s mode (checked: %s)\n"
      ,  (int) n_tst
      ,  overwrite ? "overwrite" : "create"
      ,  overwrite ? ( modes & MMM_RIGHT ? "-right" : "-left" ) : ""
      ,     modes & MMM_BINARY
         ?  "generic"
         :  "update"
      ,  (modes & MMM_CHECK ? "yes" : "no")
      )
  ;   fprintf
      (  stdout
      ,  "meet-can: %10lu\n"
         "meet-zip: %10lu\n"
         "meet-s/l: %10lu\n"
         "diff-can: %10lu\n"
         "diff-zip: %10lu\n"
         "diff-s/l: %10lu\n"
      ,  (ulong) nu_meet_can
      ,  (ulong) nu_meet_zip
      ,  (ulong) nu_meet_sl
      ,  (ulong) nu_diff_can
      ,  (ulong) nu_diff_zip
      ,  (ulong) nu_diff_sl
      )

   ;  mclvFree(&cache)
   ;  mclvFree(&meet)
   ;  mclvFree(&join)
   ;  mclvFree(&diff)
;  }
Exemple #3
0
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
;  }