src/fisher.cpp
// Here np means number of parameters, while df means degrees of freedom. For
// example, K81 has np = 4 and df = 3. SSM has np = 8 and df = 6. The fact that SSM has two
// stochastic constraints instead of one, means that SSM must be treated separately.
Here np means number of parameters, while df means degrees of freedom. For
example, K81 has np = 4 and df = 3. SSM has np = 8 and df = 6. The fact that SSM has two
stochastic constraints instead of one, means that SSM must be treated separately.
Here np means number of parameters while df means degrees of freedom . For example K81 has np = 4 and df = 3 . SSM has np = 8 and df = 6 . The fact that SSM has two stochastic constraints instead of one means that SSM must be treated separately .
void Fisher_information_free(Tree &T, Model &Mod, Array2 &Imod, Array2 &Ifree) {
  long i, j, e, p, l;
  long l1, l2;
  long nfreepar = Mod.df*T.nedges + Mod.rdf;
  long nmodpar = Mod.np*T.nedges + Mod.rdf + 1;
  Ifree.resize(nfreepar);
  for(i=0; i < nfreepar; i++) {
    Ifree[i].resize(nfreepar);
    for(j=0; j < nfreepar; j++) {
      Ifree[i][j] = 0;
    }
  }
  std::vector<double> coeff;
  coeff.resize(nmodpar);
  for(i=0; i < nmodpar; i++) {
    coeff[i] = 0;
  }
  for(e=0; e < T.nedges; e++) {
    for(i=0; i < T.nalpha; i++) {
      for(j=0; j < T.nalpha; j++) {
        p = erc2param(Mod, e, i, j);
        coeff[p] = coeff[p] + 1;  
      }
    }
  }
  for (i=0; i < T.nalpha; i++) {
    p = root2param(T, Mod, i);
    coeff[p] = coeff[p] + 1;
  }
  std::vector<long> modpar;     
  std::vector<long> modparkill; 
  modpar.resize(nfreepar);
  modparkill.resize(nfreepar);
  for(e=0; e < T.nedges; e++) {
    for(i=0; i < T.nalpha; i++) {
      for(j=0; j < T.nalpha; j++) {
        l = erc2freeparam(T, Mod, e, i, j);
        if (l < 0) continue;   
        modpar[l] = erc2param(Mod, e, i, j);
        modparkill[l] = erc2param(Mod, e, i, i);
      }
    }
  }
  if (Mod.rdf > 0) {
    for(i=0; i < T.nalpha; i++) {
      l = root2freeparam(T, Mod, i);
      if (l < 0) continue;   
      modpar[l] = root2param(T, Mod, i);
      modparkill[l] = root2param(T, Mod, 0);
    }
  }
  double c1, c2;
  for(l1=0; l1 < nfreepar ; l1++) {
    c1 = coeff[modpar[l1]]/coeff[modparkill[l1]];
    for(l2=0; l2 < nfreepar; l2++) {
      c2 = coeff[modpar[l2]]/coeff[modparkill[l2]];
      Ifree[l1][l2] = Imod[modpar[l1]][modpar[l2]]
           - c1 * Imod[modparkill[l1]][modpar[l2]]
           - c2 * Imod[modpar[l1]][modparkill[l2]]
           + c1*c2 * Imod[modparkill[l1]][modparkill[l2]];
    }
  }
}
void Fisher_information_free ( Tree & T , Model & Mod , Array2 & Imod , Array2 & Ifree ) { long i , j , e , p , l ; long l1 , l2 ; long nfreepar = Mod . df * T . nedges + Mod . rdf ; long nmodpar = Mod . np * T . nedges + Mod . rdf + 1 ; Ifree . resize ( nfreepar ) ; for ( i = 0 ; i < nfreepar ; i ++ ) { Ifree [ i ] . resize ( nfreepar ) ; for ( j = 0 ; j < nfreepar ; j ++ ) { Ifree [ i ] [ j ] = 0 ; } } std :: vector < double > coeff ; coeff . resize ( nmodpar ) ; for ( i = 0 ; i < nmodpar ; i ++ ) { coeff [ i ] = 0 ; } for ( e = 0 ; e < T . nedges ; e ++ ) { for ( i = 0 ; i < T . nalpha ; i ++ ) { for ( j = 0 ; j < T . nalpha ; j ++ ) { p = erc2param ( Mod , e , i , j ) ; coeff [ p ] = coeff [ p ] + 1 ; } } } for ( i = 0 ; i < T . nalpha ; i ++ ) { p = root2param ( T , Mod , i ) ; coeff [ p ] = coeff [ p ] + 1 ; } std :: vector < long > modpar ; std :: vector < long > modparkill ; modpar . resize ( nfreepar ) ; modparkill . resize ( nfreepar ) ; for ( e = 0 ; e < T . nedges ; e ++ ) { for ( i = 0 ; i < T . nalpha ; i ++ ) { for ( j = 0 ; j < T . nalpha ; j ++ ) { l = erc2freeparam ( T , Mod , e , i , j ) ; if ( l < 0 ) continue ; modpar [ l ] = erc2param ( Mod , e , i , j ) ; modparkill [ l ] = erc2param ( Mod , e , i , i ) ; } } } if ( Mod . rdf > 0 ) { for ( i = 0 ; i < T . nalpha ; i ++ ) { l = root2freeparam ( T , Mod , i ) ; if ( l < 0 ) continue ; modpar [ l ] = root2param ( T , Mod , i ) ; modparkill [ l ] = root2param ( T , Mod , 0 ) ; } } double c1 , c2 ; for ( l1 = 0 ; l1 < nfreepar ; l1 ++ ) { c1 = coeff [ modpar [ l1 ] ] / coeff [ modparkill [ l1 ] ] ; for ( l2 = 0 ; l2 < nfreepar ; l2 ++ ) { c2 = coeff [ modpar [ l2 ] ] / coeff [ modparkill [ l2 ] ] ; Ifree [ l1 ] [ l2 ] = Imod [ modpar [ l1 ] ] [ modpar [ l2 ] ] - c1 * Imod [ modparkill [ l1 ] ] [ modpar [ l2 ] ] - c2 * Imod [ modpar [ l1 ] ] [ modparkill [ l2 ] ] + c1 * c2 * Imod [ modparkill [ l1 ] ] [ modparkill [ l2 ] ] ; } } }
Here np means number of parameters, while df means degrees of freedom.
Here np means number of parameters while df means degrees of freedom .
// Counts the number of times a parameter appears in the the transition matrices and root dist. // adds one to the corresponding parameter index. // translation between free parameters and model parameters. // corresponding model parameter index // corresponding model parameter which is killed. // Transition matrices // negative l means the parameter is killed. // Root // negative l means the parameter is killed.