PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/unuran-1.8.0/src/methods/mcorr.h

#
C Header | 150 lines | 3 code | 9 blank | 138 comment | 0 complexity | 466c181358bc7ff95bc24a7a9f5ab31b MD5 | raw file
Possible License(s): GPL-2.0
  1. /*****************************************************************************
  2. * *
  3. * UNURAN -- Universal Non-Uniform Random number generator *
  4. * *
  5. *****************************************************************************
  6. * *
  7. * FILE: mcorr.h *
  8. * *
  9. * PURPOSE: *
  10. * function prototypes for method MCORR *
  11. * (Matrix - CORRelation matrix) *
  12. * *
  13. * USAGE: *
  14. * only included in unuran.h *
  15. * *
  16. *****************************************************************************
  17. * *
  18. * Copyright (c) 2000-2006 Wolfgang Hoermann and Josef Leydold *
  19. * Department of Statistics and Mathematics, WU Wien, Austria *
  20. * *
  21. * This program is free software; you can redistribute it and/or modify *
  22. * it under the terms of the GNU General Public License as published by *
  23. * the Free Software Foundation; either version 2 of the License, or *
  24. * (at your option) any later version. *
  25. * *
  26. * This program is distributed in the hope that it will be useful, *
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  29. * GNU General Public License for more details. *
  30. * *
  31. * You should have received a copy of the GNU General Public License *
  32. * along with this program; if not, write to the *
  33. * Free Software Foundation, Inc., *
  34. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA *
  35. * *
  36. *****************************************************************************/
  37. /*
  38. =METHOD MCORR Random CORRelation matrix
  39. =UP Methods_for_MATR
  40. =REQUIRED Distribution object for random correlation matrix
  41. =OPTIONAL
  42. =SPEED Set-up: fast,
  43. Sampling: depends on dimension
  44. =REINIT supported
  45. =REF [DLa86: Sect.6.1; p.605] [MOa84]
  46. =DESCRIPTION
  47. MCORR generates a random correlation matrix
  48. (Pearson's correlation).
  49. Two methods are used:
  50. @enumerate
  51. @item
  52. When a random correlation matrix having given eigenvalues is
  53. sought, the method of Marsaglia and Olkin [MOa84] is used.
  54. In this case, the correlation matrix @unurmath{R}
  55. is given as @unurmath{R=PDP'} where @unurmath{D} is a diagonal
  56. matrix containing the eigenvalues and @unurmath{P} is a random
  57. orthonormal matrix. In higher dimensions, the rounding-errors
  58. introduced in the previous matrix multiplications could lead
  59. to a non-symmetric correlation matrix. Therefore the symmetric
  60. correlation matrix is computed as @unurmath{R=(PDP'+P'DP)/2}.
  61. @item
  62. A matrix @unurmath{H} is generated where all rows are
  63. independent random vectors of unit length uniformly on a sphere.
  64. Then @unurmath{HH'} is a correlation matrix (and vice versa if
  65. @unurmath{HH'} is a correlation matrix then the rows of
  66. @unurmath{H} are random vectors on a sphere).
  67. @end enumerate
  68. Notice that due to round-off errors the generated matrices might
  69. not be positive definite in extremely rare cases
  70. (especially when the given eigenvalues are amost 0).
  71. There are many other possibilites (distributions) of sampling
  72. the random rows from a sphere. The chosen methods are simple but
  73. does not result in a uniform distriubution of the random
  74. correlation matrices.
  75. It only works with distribution objects of random correlation
  76. matrices (@pxref{correlation,,Random Correlation Matrix}).
  77. =HOWTOUSE
  78. Create a distibution object for random correlation matrices by a
  79. @code{unur_distr_correlation} call
  80. (@pxref{correlation,,Random Correlation Matrix}).
  81. When a correlation matrix with given eigenvalues should be
  82. generated, these eigenvalues can be set by a
  83. unur_mcorr_set_eigenvalues() call.
  84. Otherwise, a faster algorithm is used that generates
  85. correlation matrices with random eigenstructure.
  86. Notice that due to round-off errors,
  87. there is a (small) chance that the resulting matrix is
  88. not positive definite for a Cholesky decomposition algorithm,
  89. especially when the dimension of the distribution is high.
  90. It is possible to change the given eigenvalues using
  91. unur_mcorr_chg_eigenvalues() and run unur_reinit() to
  92. reinitialize the generator object.
  93. =END
  94. */
  95. /*---------------------------------------------------------------------------*/
  96. /* Routines for user interface */
  97. /* =ROUTINES */
  98. UNUR_PAR *unur_mcorr_new( const UNUR_DISTR *distribution );
  99. /*
  100. Get default parameters for generator.
  101. */
  102. int unur_mcorr_set_eigenvalues( UNUR_PAR *par, const double *eigenvalues );
  103. /*
  104. Sets the (optional) eigenvalues of the correlation matrix.
  105. If set, then the Marsaglia and Olkin algorithm will be used
  106. to generate random correlation matrices with given eigenvalues.
  107. Important: the given eigenvalues of the correlation matrix must be
  108. strictly positive and sum to the dimension of the matrix.
  109. If non-positive eigenvalues are attempted, no eigenvalues are set
  110. and an error code is returned.
  111. In case, that their sum is different from the dimension, an implicit
  112. scaling to give the correct sum is performed.
  113. */
  114. int unur_mcorr_chg_eigenvalues( UNUR_GEN *gen, const double *eigenvalues );
  115. /*
  116. Change the eigenvalues of the correlation matrix.
  117. One must run unur_reinit() to reinitialize the generator
  118. object then.
  119. */
  120. /* =END */
  121. /*---------------------------------------------------------------------------*/