예제 #1
0
/* For Island model, we have no split time, but two periods that are separated
 * by the imaginary split. We have also imaginary population tree where ancestor
 * population resides in the imaginary last period and descendents in the first
 * period.
 * ---------------------------------------------------------------------------
 * numsplittimes: This tells us number of popoulation splits. If we consider a
 * binary population tree, then it would be one less than the number of
 * populations: npops - 1. If we consider Island model of [[npops]] populations,
 * it would be 0. Function [[read_datafile_top_lines]] sets the value.
 * lastperiodnumber: This would be the same as [[numsplittimes]] if we consider
 * a binary population tree. We have the imaginary split time for Island model.
 * It would 1 for Island model. Function [[read_datafile_top_lines]] sets the 
 * value.
 * numtreepops: The number of nodes of a population tree. For Island model, it
 * would be [[npops]] plus one. For a binary population tree, it would be twice
 * the [[npops]] minus one. Function [[read_datafile_top_lines]] sets the value
 * after reading the number of populations from an input file.
 * numpopsizeparams: The number of nodes of a population tree. For Island model,
 * it would be [[npops]]. For a binary population tree, it would be twice the
 * [[npops]] minus one, which is equal to [[numtreepops]].
 */
void
init_genealogy_weights (struct genealogy_weights *gweight)
{
  int i;
  gweight->cc = malloc ((numsplittimes + 1) * sizeof (int *));
  gweight->hcc = malloc ((numsplittimes + 1) * sizeof (double *));
  gweight->fc = malloc ((numsplittimes + 1) * sizeof (double *));
  for (i = 0; i < numsplittimes + 1; i++)
  {
    gweight->cc[i] = malloc ((npops - i) * sizeof (int));
    gweight->hcc[i] = malloc ((npops - i) * sizeof (double));
    gweight->fc[i] = malloc ((npops - i) * sizeof (double));
  }
  
  if (modeloptions[NOMIGRATION] == 0)
  {
    gweight->mc = malloc (lastperiodnumber * sizeof (int **));
    gweight->fm = malloc (lastperiodnumber * sizeof (double **));
    for (i = 0; i < npops - 1; i++)
    {
      gweight->mc[i] = alloc2Dint (npops - i, npops - i);
      gweight->fm[i] = alloc2Ddouble (npops - i, npops - i);
    }
  }
  setzero_genealogy_weights (gweight);
}
예제 #2
0
/* let u refer to the more recent time  and d to the older time  */
int
changet_RY1 (int ci, int timeperiod)    // after Rannala and Yang (2003)  - rubberband method
{
  double metropolishastingsterm, newt, oldt;
  double pdgnew[MAXLOCI + MAXLINKED], pdgnewsum, pdgoldsum, probgnewsum,
    temppdg;
  double t_u_hterm, t_d_hterm, tpw;
  int li, i, j, ecd, ecu, emd, emu, ai, ui;
  double U;
  struct genealogy *G;
  struct edge *gtree;
  double t_d, t_u, t_u_prior, t_d_prior;
  double holdt[MAXPERIODS];


  if (assignmentoptions[POPULATIONASSIGNMENTCHECKPOINT] == 1)
  {
    assertgenealogy (ci);
  }

  t_u = (timeperiod == 0) ? 0 : C[ci]->tvals[timeperiod - 1];
  t_d =
    (timeperiod ==
     (lastperiodnumber - 1)) ? TIMEMAX : C[ci]->tvals[timeperiod + 1];
  t_d_prior = DMIN (T[timeperiod].pr.max, t_d);
  t_u_prior = DMAX (T[timeperiod].pr.min, t_u);
  oldt = C[ci]->tvals[timeperiod];
  newt = getnewt (timeperiod, t_u_prior, t_d_prior, oldt, 1);
  
  t_u_hterm = (newt - t_u) / (oldt - t_u);
  if (timeperiod == lastperiodnumber - 1)
  {
    t_d_hterm = 1;
  }
  else
  {
    t_d_hterm = (t_d - newt) / (t_d - oldt);
  }

  copy_treeinfo (&holdallgweight_t_RY, &C[ci]->allgweight);  // try turning this off and forcing all recalculations
  copy_probcalc (&holdallpcalc_t_RY, &C[ci]->allpcalc);
  for (i = 0; i < lastperiodnumber; i++)
    holdt[i] = C[ci]->tvals[i];


  pdgoldsum = C[ci]->allpcalc.pdg;
  setzero_genealogy_weights (&C[ci]->allgweight);
  ecd = ecu = emd = emu = 0;
  pdgnewsum = 0;
  probgnewsum = 0;
  storegenealogystats_all_loci (ci, 0);
  C[ci]->tvals[timeperiod] = newt;
  for (i = 0; i < nurates; i++)
    pdgnew[i] = 0;
  for (li = 0; li < nloci; li++)
  {
    G = &(C[ci]->G[li]);
    gtree = G->gtree;
    copy_treeinfo (&holdgweight_t_RY[li], &G->gweight);
    for (i = 0; i < L[li].numlines; i++)
    {
      if (gtree[i].down != -1)
      {
        if (gtree[i].time <= oldt && gtree[i].time > t_u)

        {
          //assert (skipflag[li][i] == 0);turn off 9/19/10
          gtree[i].time =
            beforesplit (timeperiod, oldt, newt, /* t_d, */ t_u, gtree[i].time);
          assert (gtree[i].time != newt);
          ecu++;
        }
        else
        {
          if (gtree[i].time > oldt && gtree[i].time < t_d)
          {
           // assert (skipflag[li][i] == 0); turn off 9/19/10
            gtree[i].time =
              aftersplit (timeperiod, oldt, newt, t_d, /* t_u, */ gtree[i].time);
            assert (gtree[i].time != newt);
            ecd++;
          }
          //else  do not change the time
        }
        j = 0;
        while (gtree[i].mig[j].mt > -0.5)
        {
          assert (gtree[i].mig[j].mt < C[0]->tvals[lastperiodnumber]);
          if (gtree[i].mig[j].mt <= oldt && gtree[i].mig[j].mt > t_u)
          {
            gtree[i].mig[j].mt =
              beforesplit (timeperiod, oldt, newt, /* t_d, */ t_u,
                           gtree[i].mig[j].mt);
            emu++;
          }
          else
          {
            assert (oldt < C[0]->tvals[lastperiodnumber]);
            if (gtree[i].mig[j].mt > oldt && gtree[i].mig[j].mt < t_d)
            {
              gtree[i].mig[j].mt =
                aftersplit (timeperiod, oldt, newt, t_d, /* t_u, */
                            gtree[i].mig[j].mt);
              emd++;
            }
            // else no need to change the time
          }
          j++;
        }
      }
    }
    if (G->roottime <= oldt && G->roottime > t_u
        /* && skipflag[li][G->root] == 0 turn off 9/19/10*/)
      G->roottime =
        beforesplit (timeperiod, oldt, newt, /* t_d, */ t_u, G->roottime);
    else if (G->roottime > oldt && G->roottime < t_d
            /* && skipflag[li][G->root] == 0 turn off 9/19/10*/)
      G->roottime =
        aftersplit (timeperiod, oldt, newt, t_d, /* t_u, */ G->roottime);
    setzero_genealogy_weights (&G->gweight);
        
    treeweight (ci, li);

    sum_treeinfo (&C[ci]->allgweight, &G->gweight);
    ai = 0;
    ui = L[li].uii[ai];

    switch (L[li].model)
    {
      assert (pdgnew[ui] == 0);
    case HKY:
      if (assignmentoptions[JCMODEL] == 1)
      {
        temppdg = pdgnew[ui] =
          likelihoodJC (ci, li, G->uvals[0]);
      }
      else
      {
        temppdg = pdgnew[ui] =
          likelihoodHKY (ci, li, G->uvals[0], G->kappaval, -1, -1, -1, -1);
      }
      break;
    case INFINITESITES:
      temppdg = pdgnew[ui] = likelihoodIS (ci, li, G->uvals[0]);
      break;
    case STEPWISE:
      temppdg = 0;
      for (; ai < L[li].nlinked; ai++)
      {
        ui = L[li].uii[ai];
        assert (pdgnew[ui] == 0);
        pdgnew[ui] = likelihoodSW (ci, li, ai, G->uvals[ai], 1.0);
        temppdg += pdgnew[ui];
      }
      break;
    case JOINT_IS_SW:
      temppdg = pdgnew[ui] = likelihoodIS (ci, li, G->uvals[0]);
      for (ai = 1; ai < L[li].nlinked; ai++)
      {
        ui = L[li].uii[ai];
        assert (pdgnew[ui] == 0);
        pdgnew[ui] = likelihoodSW (ci, li, ai, G->uvals[ai], 1.0);
        temppdg += pdgnew[ui];
      }
      break;
    }
    pdgnewsum += temppdg;
  }

  assert (!ODD (ecd));
  assert (!ODD (ecu));
  ecd /= 2;
  ecu /= 2;
  integrate_tree_prob (ci, &C[ci]->allgweight, &holdallgweight_t_RY,
                       &C[ci]->allpcalc, &holdallpcalc_t_RY, &holdt[0]);   // try enforcing full cacullation
  tpw = gbeta * (pdgnewsum - pdgoldsum);
/* 5/19/2011 JH adding thermodynamic integration */
  if (calcoptions[CALCMARGINALLIKELIHOOD])
  {
    metropolishastingsterm = beta[ci] * tpw + (C[ci]->allpcalc.probg - holdallpcalc_t_RY.probg) + (ecd + emd) * log (t_d_hterm) + (ecu + emu) * log (t_u_hterm);
  }
  else
  {
  tpw += C[ci]->allpcalc.probg - holdallpcalc_t_RY.probg;
    metropolishastingsterm = beta[ci] * tpw + (ecd + emd) * log (t_d_hterm) +   (ecu + emu) * log (t_u_hterm);
  }
  //assert(metropolishastingsterm >= -1e200 && metropolishastingsterm < 1e200);
  U = log (uniform ());
  if (U < DMIN(1.0, metropolishastingsterm))  //9/13/2010 
  //if (metropolishastingsterm >= 0.0 || metropolishastingsterm > U)
  {
    for (li = 0; li < nloci; li++)
    {
      C[ci]->G[li].pdg = 0;
      for (ai = 0; ai < L[li].nlinked; ai++)
      {
        C[ci]->G[li].pdg_a[ai] = pdgnew[L[li].uii[ai]];
        C[ci]->G[li].pdg += C[ci]->G[li].pdg_a[ai];
      }
      if (L[li].model == HKY)
      {
        storescalefactors (ci, li);
        copyfraclike (ci, li);
      }
    }
    C[ci]->allpcalc.pdg = pdgnewsum;
    C[ci]->poptree[C[ci]->droppops[timeperiod + 1][0]].time =
      C[ci]->poptree[C[ci]->droppops[timeperiod + 1][1]].time = newt;

    if (assignmentoptions[POPULATIONASSIGNMENTCHECKPOINT] == 1)
    {
      assertgenealogy (ci);
    }
    return 1;
  }
  else
  {
    copy_treeinfo (&C[ci]->allgweight, &holdallgweight_t_RY);
    copy_probcalc (&C[ci]->allpcalc, &holdallpcalc_t_RY);
    assert (pdgoldsum == C[ci]->allpcalc.pdg);
    C[ci]->tvals[timeperiod] = oldt;
    for (li = 0; li < nloci; li++)
    {
      G = &(C[ci]->G[li]);
      gtree = G->gtree;
      storegenealogystats_all_loci (ci, 1);
      copy_treeinfo (&G->gweight, &holdgweight_t_RY[li]);
      for (i = 0; i < L[li].numlines; i++)
      {
        if (gtree[i].down != -1)
        {
          if (gtree[i].time <= newt && gtree[i].time > t_u)
          {
           // assert (skipflag[li][i] == 0); turned off 9/19/10
            gtree[i].time =
              beforesplit (timeperiod, newt, oldt, /* t_d, */ t_u, gtree[i].time);
            //cecu++;
          }

          else
          {
            if (gtree[i].time > newt && gtree[i].time < t_d)
            {
             //assert (skipflag[li][i] == 0); turned off 9/19/10
              gtree[i].time =
                aftersplit (timeperiod, newt, oldt, t_d, /* t_u, */ gtree[i].time);
              //cecl++;
            }
          }
          j = 0;
          while (gtree[i].mig[j].mt > -0.5)
          {
            if (gtree[i].mig[j].mt <= newt && gtree[i].mig[j].mt > t_u)
            {
              gtree[i].mig[j].mt =
                beforesplit (timeperiod, newt, oldt, /* t_d, */
                             t_u, gtree[i].mig[j].mt);
              //cemu++;
            }
            else if (gtree[i].mig[j].mt > newt && gtree[i].mig[j].mt < t_d)
            {
              gtree[i].mig[j].mt =
                aftersplit (timeperiod, newt, oldt, t_d, /* t_u, */
                            gtree[i].mig[j].mt);
              //ceml++;
            }
            j++;
          }
        }
      }
//        assert(fabs(C[ci]->G[li].gtree[  C[ci]->G[li].gtree[C[ci]->G[li].root].up[0]].time - C[ci]->G[li].roottime) < 1e-8);    
    }
    /*    assert(ecu==cecu/2);
       assert(ecd==cecl/2);
       assert(emu==cemu);
       assert(emd==ceml); */
    for (li = 0; li < nloci; li++)
    {
      if (L[li].model == HKY)
        restorescalefactors (ci, li);
      /* have to reset the dlikeA values in the genealogies for stepwise model */
      if (L[li].model == STEPWISE)
        for (ai = 0; ai < L[li].nlinked; ai++)
          likelihoodSW (ci, li, ai, C[ci]->G[li].uvals[ai], 1.0);
      if (L[li].model == JOINT_IS_SW)
        for (ai = 1; ai < L[li].nlinked; ai++)
          likelihoodSW (ci, li, ai, C[ci]->G[li].uvals[ai], 1.0);
      // assert(fabs(C[ci]->G[li].gtree[  C[ci]->G[li].gtree[C[ci]->G[li].root].up[0]].time - C[ci]->G[li].roottime) < 1e-8);    
    }
    if (assignmentoptions[POPULATIONASSIGNMENTCHECKPOINT] == 1)
    {
      assertgenealogy (ci);
    }
    return 0;
  }
}                               /* changet_RY1 */
예제 #3
0
파일: update_gtree.c 프로젝트: goshng/Peach
//prune this   9/21/2010
int
updategenealogy (int ci, int li, int *topolchange, int *tmrcachange)
{
  int ai, mpart, i;
  int edge, oldsis, newsis, freededge, accp;
  double newpdg, newplg, newpdg_a[MAXLINKED];
  double migweight, metropolishastingsterm, U;
  double tpw;
  double Aterm[MAXLINKED], Atermsum;
  double slidedist;
  double tlengthpart;
  double slideweight, holdslidedist, slidestdv;
  struct genealogy *G = &(C[ci]->G[li]);
  struct edge *gtree = G->gtree;
  int rejectIS;
  double like;
  double holdt[MAXPERIODS];

  if (assignmentoptions[POPULATIONASSIGNMENTCHECKPOINT] == 1)
  {
    assertgenealogyloc (ci, li);
  }
// initialize and make copies structures that hold quantities for calculating prob of genealogy
  copy_treeinfo (&holdgweight_updategenealogy, &G->gweight);
  copy_treeinfo (&holdallgweight_updategenealogy, &C[ci]->allgweight);
  // store summary stats of the genealogy
  storegenealogystats (ci, li, 0);
  for (i = 0; i < lastperiodnumber; i++)
    holdt[i] = C[ci]->tvals[i];  // JH is this actually necessary ? 
  *tmrcachange = 0;
  *topolchange = 0;
  // Atermsum only used for Stepwise mutation model
  Atermsum = 0;

/* pick an edge, identify freedup edge (the down edge) and the sister edge */
  do
  {
    edge = randposint (L[li].numlines);
  } while (gtree[edge].down == -1);
  freededge = gtree[edge].down;
  if ((oldsis = gtree[freededge].up[0]) == edge)
    oldsis = gtree[freededge].up[1];

  /* copy information on the edge,  and if it connects to the root, then the sister edge as well */
  if (gtree[edge].down == G->root)
  {
    fillmiginfo (ci, li, gtree, edge, oldsis);
  }
  else
  {
    fillmiginfo (ci, li, gtree, edge, -1);
  }

  /* store information on the genealogy before changing it */
  storeoldedges (ci, li, edge, oldsis, freededge);
// remove any migrations  from the slidingedge 
  gtree[edge].mig[0].mt = -1;
/* slide edge, pick a distance and slide it  */
  slidestdv = DMIN (SLIDESTDVMAX, G->roottime/3 );
  holdslidedist = slidedist = normdev (0.0, slidestdv); 

// join the sister and the down branches at the point where edge used to connect, this frees up the down branch 
  joinsisdown (ci, li, oldsis, tmrcachange);

  //gtree[edge].down = -1;  // not necessary but makes gtreeprint() output easier to read for intermediate stages
  //gtree[freededge].down = -1; // not necessary but makes gtreeprint() output easier to read for intermediate stages

// do the slide and identify the new sister branch and where new connection point for the edge is 
  newsis = oldsis;
  if (modeloptions[NOMIGRATION])
    slider_nomigration (ci, li, edge, &newsis, &(gtree[edge].time),&slidedist);
  else
    slider (ci, li, edge, &newsis, &(gtree[edge].time), &slidedist);
  *topolchange += (oldsis != newsis);

// now separate the new sister branch into a shorter sis branch and a down branch 
  splitsisdown (ci, li, edge, freededge, newsis);

  if (rootmove)
  {
    slideweight = -log (normprob (0.0, slidestdv, holdslidedist));
    slidestdv = DMIN (SLIDESTDVMAX, G->roottime / 3); 
    slideweight += log (normprob (0.0, slidestdv, holdslidedist)); 
  }
  else
  {
    slideweight = 0;
  }

// add migration events 
  if (modeloptions[NOMIGRATION])
  {
    migweight = 0;
  }
  else
  {
    migweight = addmigration (ci, li, mpart, tlengthpart, &mpart, &tlengthpart);
  }

  // copy the migration info in newedgemig and newsismig  to the genealogy
  copynewmig_to_gtree (ci, li);

// determine all the weights needed for calculating the probability of the genealogy
  setzero_genealogy_weights (&G->gweight);
  treeweight (ci, li);
  sum_subtract_treeinfo (&C[ci]->allgweight, &G->gweight,
                         &holdgweight_updategenealogy);

/* calculate P(D|G)  for new genealogy */
  rejectIS = 0;                 /* use this to catech when P(D|G) for IS model is zero */
  newpdg = 0;
  newplg = 0;

  switch (L[li].model)
  {
  case HKY:
    if (assignmentoptions[JCMODEL] == 1)
    {
      newpdg_a[0] = likelihoodJC (ci, li, G->uvals[0]);
      newpdg = newpdg_a[0];
    }
    else
    {
      newpdg = newpdg_a[0] =
        likelihoodHKY (ci, li, G->uvals[0], G->kappaval, edge,
                       freededge, oldsis, newsis);
    }
    break;
  case INFINITESITES:
    newpdg = newpdg_a[0] = like = likelihoodIS (ci, li, G->uvals[0]);
    rejectIS = (like == REJECTINFINITESITESCONSTANT);
    break;
  case STEPWISE:
    {
      for (ai = 0, newpdg = 0; ai < L[li].nlinked; ai++)
      {
        newpdg_a[ai] =
          G->pdg_a[ai] + finishSWupdateA (ci, li, ai, edge, freededge,
                                          oldsis, newsis,
                                          G->uvals[ai], &Aterm[ai]);

        newpdg += newpdg_a[ai];
        Atermsum += Aterm[ai];
      }

//            checklikelihoodSW(ci, li,G->u[ai].mcinf.val);  
      break;
    }
  case JOINT_IS_SW:
    newpdg = newpdg_a[0] = likelihoodIS (ci, li, G->uvals[0]);
    rejectIS = (newpdg == REJECTINFINITESITESCONSTANT);
    for (ai = 1; ai < L[li].nlinked; ai++)
    {
      newpdg_a[ai] =
        G->pdg_a[ai] + finishSWupdateA (ci, li, ai, edge, freededge,
                                        oldsis, newsis,
                                        G->uvals[ai], &Aterm[ai]);
      newpdg += newpdg_a[ai];
      Atermsum += Aterm[ai];
    }

    //checklikelihoodSW(ci, li,Q[ci]->us[li]);  
    break;
  }
  accp = 0;

/* final weight calculation */
/* tpw is the ratio of new and old prior probability of the genealogies.  It is actually the ratio of the total across all loci,  but
since only genealogy li is being changed at the present time,  the ratio works out to just be the ratio for genealogy li */
  copy_probcalc (&holdallpcalc_updategenealogy, &C[ci]->allpcalc);
  /* Find all internal node sequences and mutations of a full genealogy. */
  if (assignmentoptions[POPULATIONASSIGNMENTCHECKPOINT] == 1)
  {
    if (L[li].model == INFINITESITES)
    {
      accp = IMA_genealogy_findIntSeq (ci, li);
      if (accp == 0)
      {
        rejectIS = 1;
      }
      accp = 0;
    }
  }
  if (rejectIS == 0)
  {
    // the metropolis term includes p(D|G) and p(G),  
    tpw = -C[ci]->allpcalc.probg;
    integrate_tree_prob (ci, &C[ci]->allgweight,
                         &holdallgweight_updategenealogy, &C[ci]->allpcalc,
                         &holdallpcalc_updategenealogy, &holdt[0]);
    tpw += C[ci]->allpcalc.probg;
    metropolishastingsterm = tpw + gbeta*(newpdg - G->pdg);
    U = uniform ();
    metropolishastingsterm = exp (beta[ci] * metropolishastingsterm + migweight + slideweight + Atermsum);
    if (U < DMIN(1.0, metropolishastingsterm))  //9/13/2010 
    {
      /* accept the update */
      C[ci]->allpcalc.pdg -= G->pdg;
      C[ci]->allpcalc.pdg += newpdg;
      G->pdg = newpdg;
      for (ai = 0; ai < L[li].nlinked; ai++)
        G->pdg_a[ai] = newpdg_a[ai];
      if (L[li].model == HKY)
      {
        copyfraclike (ci, li);
        storescalefactors (ci, li);
      }
      accp = 1;
    }
  }
  /* reject the update */
  if (accp == 0)
  {
    // put the edges back 
    restoreedges (ci, li, edge, oldsis, freededge, newsis);

    // copy summary stats back
    storegenealogystats (ci, li, 1);

    // reset HKY terms
    if (L[li].model == HKY)
      restorescalefactors (ci, li);
    // copy back all the weights and results associated with calculating the probability of the genealogy 
    copy_probcalc (&C[ci]->allpcalc, &holdallpcalc_updategenealogy);
    copy_treeinfo (&C[ci]->allgweight, &holdallgweight_updategenealogy);
    copy_treeinfo (&G->gweight, &holdgweight_updategenealogy);
    *topolchange = 0;
    *tmrcachange = 0;
  }
  
/* do updates at nodes for stepwise loci, regardless of whether slide update was accepted.  This could go somewhere else  */
  
  return accp;
}
예제 #4
0
파일: mcmcfile.c 프로젝트: goshng/Peach
void
init_p (void)
{
  int ci, li, ai;
  for (ci = 0; ci < numchains; ci++)
  {
    setzero_genealogy_weights (&C[ci]->allgweight);
    C[ci]->allpcalc.pdg = 0;
    for (li = 0; li < nloci; li++)
    {
      setzero_genealogy_weights (&C[ci]->G[li].gweight);
      treeweight (ci, li);
      switch (L[li].model)
      {
      case INFINITESITES:
        C[ci]->G[li].pdg = C[ci]->G[li].pdg_a[0] =
          likelihoodIS (ci, li, C[ci]->G[li].uvals[0]);
        break;
      case HKY:
        if (assignmentoptions[JCMODEL] == 1)
        {
          C[ci]->G[li].pdg = C[ci]->G[li].pdg_a[0] =
            likelihoodJC (ci, li, C[ci]->G[li].uvals[0]);
        }
        else
        {
          C[ci]->G[li].pdg = C[ci]->G[li].pdg_a[0] =
            likelihoodHKY (ci, li, C[ci]->G[li].uvals[0],
                           C[ci]->G[li].kappaval, -1, -1, -1, -1);
          copyfraclike (ci, li);
          storescalefactors (ci, li);
        }
        break;
      case STEPWISE:
        somestepwise = 1;
        C[ci]->G[li].pdg = 0;
        for (ai = 0; ai < L[li].nlinked; ai++)
        {
          C[ci]->G[li].pdg_a[ai] = likelihoodSW (ci, li, ai, C[ci]->G[li].uvals[ai], 1.0);
          C[ci]->G[li].pdg += C[ci]->G[li].pdg_a[ai];
        }
        break;
      case JOINT_IS_SW:
        somestepwise = 1;
        // JH  fixed bug here on 6/1/09  these two lines should not have been included here 
        //makeJOINT_IS_SW (ci, li);
        //treeweight (ci, li);
        C[ci]->G[li].pdg = C[ci]->G[li].pdg_a[0] =
          likelihoodIS (ci, li, C[ci]->G[li].uvals[0]);
        for (ai = 1; ai < L[li].nlinked; ai++)
        {
          C[ci]->G[li].pdg_a[ai] = likelihoodSW (ci, li, ai, C[ci]->G[li].uvals[ai], 1.0);
          C[ci]->G[li].pdg += C[ci]->G[li].pdg_a[ai];
        }
        break;
      }
      sum_treeinfo (&(C[ci]->allgweight), &(C[ci]->G[li].gweight));
      C[ci]->allpcalc.pdg += C[ci]->G[li].pdg;
    }
    initialize_integrate_tree_prob (ci, &(C[ci]->allgweight),
                                    &C[ci]->allpcalc);
  }

}                               // init_p