Esempio n. 1
0
//Function to return the calculate substitution matrix for the given length
double* F84Model::GetSubstitutionMatrix(double length) {
    //Multiply Rate Matrix by time (length)
    double RateMatrixTemp[16];
    for (int i=0;i<16;i++){
        RateMatrixTemp[i] = RateMatrix[i]*length;
    }

    //Estimate Matrix Exponential of RateMatrixTemp
    double *MatrixExponential = expm2 ( 4, RateMatrixTemp );

    return MatrixExponential;
}
Esempio n. 2
0
//Function to estimate the substitution probability between the given nucleotides at length time
double F84Model::GetProbability(Alphabet a, Alphabet b, double length) const{
    //Multiply Rate Matrix by time (length)
    double RateMatrixTemp[16];
    for (int i=0;i<16;i++){
        RateMatrixTemp[i] = RateMatrix[i]*length;
    }

    //Estimate Matrix Exponential of RateMatrixTemp
    double *MatrixExponential = expm2 ( 4, RateMatrixTemp );

    return MatrixExponential[GetAlphabetPair(a, b)];
}
Esempio n. 3
0
//Function to set the length of the model and calculate substitution matrix
void F84Model::SetLength(double length) {
    //Multiply Rate Matrix by time (length)
    double RateMatrixTemp[16];
    for (int i=0;i<16;i++){
        RateMatrixTemp[i] = RateMatrix[i]*length;
    }

    //Estimate Matrix Exponential of RateMatrixTemp
    double *MatrixExponential = expm2 ( 4, RateMatrixTemp );

    for (int i=0;i<16;i++){
        SubMatrix[i] = MatrixExponential[i];
    }
}
void matrix_exponential_test01 ( void )

/******************************************************************************/
/*
  Purpose:

    MATRIX_EXPONENTIAL_TEST01 compares matrix exponential algorithms.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    02 December 2011

  Author:

    John Burkardt
*/
{
  double *a;
  double *a_exp;
  int n;
  int test;
  int test_num;

  printf ( "\n" );
  printf ( "MATRIX_EXPONENTIAL_TEST01:\n" );
  printf ( "  EXPM is MATLAB's matrix exponential function\n" );
  printf ( "  EXPM11 is an equivalent to EXPM\n" );
  printf ( "  EXPM2 uses a Taylor series approach\n" );
  printf ( "  EXPM3 relies on an eigenvalue calculation.\n" );

  test_num = mexp_test_num ( );

  for ( test = 1; test <= test_num; test++ )
  {
    printf ( "\n" );
    printf ( "  Test #%d\n", test );

    mexp_story ( test );

    n = mexp_n ( test );

    printf ( "  Matrix order N = %d\n", n );

    a = mexp_a ( test, n );

    r8mat_print ( n, n, a, "  Matrix:" );

    a_exp = expm11 ( n, a );
    r8mat_print ( n, n, a_exp, "  EXPM1(A):" );
    free ( a_exp );

    a_exp = expm2 ( n, a );
    r8mat_print ( n, n, a_exp, "  EXPM2(A):" );
    free ( a_exp );
/*
    a_exp = expm3 ( n, a );
    r8mat_print ( n, n, a_exp, "  EXPM3(A):" );
    free ( a_exp );
*/
    a_exp = mexp_expa ( test, n );
    r8mat_print ( n, n, a_exp, "  Exact Exponential:" );
    free ( a_exp );

    free ( a );
  }

  return;
}