Changeset 3075 in Sophya for trunk/SophyaLib/NTools/perandom.cc


Ignore:
Timestamp:
Sep 14, 2006, 11:43:30 AM (19 years ago)
Author:
cmv
Message:

remplacement nbrandom.h (obsolete) -> srandgen.h cmv 14/09/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/perandom.cc

    r2870 r3075  
    66#include <iostream>
    77
     8
    89////////////////////////////////////////////////////////////////////////////
    9 //++
    10 // Class        FunRan
    11 // Lib  Outils++
    12 // include      perandom.h
    13 //
    14 //      Tirage aleatoire sur un histogramme 1D.
    15 //--
    16 
    17 //++
     10/*!
     11  \class SOPHYA::FunRan
     12  \ingroup NTools
     13  Classe for generating random variables from 1D function
     14*/
     15
     16
     17/********* Methode *********/
     18/*! Createur. f is a probability density function (PDF).
     19 Le tirage aleatoire est fait sur un histogramme
     20 Histo(xMin,xMax,nBin) (voir convention dans Histo).
     21 Chaque bin de l'histogramme contient la valeur de la PDF
     22 au centre du bin.
     23 Les valeurs retournees sont les valeurs du centre des bins.
     24 Si binw est la largeur du bin, les valeurs retournees
     25 vont de xmin+binw/2 a xmax-binw/2.
     26*/
    1827FunRan::FunRan(FunRan::Func f, r_8 xMin, r_8 xMax, int_4 nBin)
    19 //
    20 //      Createur. f is a probability density function (PDF).
    21 // Le tirage aleatoire est fait sur un histogramme
    22 // Histo(xMin,xMax,nBin) (voir convention dans Histo).
    23 // Chaque bin de l'histogramme contient la valeur de la PDF
    24 // au centre du bin.
    25 // Les valeurs retournees sont les valeurs du centre des bins.
    26 // Si binw est la largeur du bin, les valeurs retournees
    27 // vont de xmin+binw/2 a xmax-binw/2.
    28 //--
    2928: Histo(xMin,xMax,nBin)
    3029{
     
    4241}
    4342
    44 //++
     43/********* Methode *********/
     44/*! Createur. tab is a probability density function.
     45The return random values will be between 0 and nBin-1.
     46See FunRan::FunRan(FunRan::Func...) for further comments.
     47*/
    4548FunRan::FunRan(r_8 *tab, int_4 nBin)
    46 //
    47 //      Createur. tab is a probability density function
    48 // The return random values will be between 0 and nBin-1
    49 // See FunRan::FunRan(FunRan::Func...) for further comments.
    50 //--
    5149: Histo(-0.5,nBin-0.5,nBin)
    5250{
     
    6361}
    6462
    65 //++
     63/********* Methode *********/
     64/*! Createur. tab is a probability density function
     65The content of tab is identified has the content of
     66an Histogram define by Histo(xMin,xMax,nBin).
     67See FunRan::FunRan(FunRan::Func...) for further comments.
     68*/
    6669FunRan::FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax)
    67 //
    68 //      Createur. tab is a probability density function
    69 // The content of tab is identified has the content of
    70 // an Histogram define by Histo(xMin,xMax,nBin).
    71 // See FunRan::FunRan(FunRan::Func...) for further comments.
    72 //--
    7370: Histo(xMin,xMax,nBin)
    7471{
     
    8582}
    8683
    87 //++
    88 //      Createur.
    89 // If pdf=true, h is a probability density fonction.
    90 // If pdf=false, h is a distribution function (not necessarly normalized to 1).
    91 // See FunRan::FunRan(FunRan::Func...) for further comments.
    92 //--
     84/********* Methode *********/
     85/*! Createur.
     86If pdf=true, h is a probability density fonction.
     87If pdf=false, h is a distribution function (not necessarly normalized to 1).
     88See FunRan::FunRan(FunRan::Func...) for further comments.
     89*/
    9390FunRan::FunRan(Histo &h, bool pdf)
    9491: Histo(h)
     
    107104}
    108105
    109 //++
     106/********* Methode *********/
     107/*! Tirage avec retour du numero de bin entre 0 et mBins-1.
     108It returns the first bin whose content is greater or equal
     109to the random uniform number (in [0,1])
     110*/
    110111int_4 FunRan::BinRandom()
    111 //
    112 //      Tirage avec retour du numero de bin entre 0 et mBins-1.
    113 // It returns the first bin whose content is greater or equal
    114 // to the random uniform number (in [0,1])
    115 //--
    116112{
    117113 // recherche du premier bin plus grand ou egal a z
     
    121117}
    122118
    123 //++
     119/********* Methode *********/
     120/*! Tirage avec retour abscisse du bin non interpole. */
    124121r_8 FunRan::Random()
    125 //
    126 //      Tirage avec retour abscisse du bin non interpole.
    127 //--
    128122{
    129123 r_8 z=drand01();
     
    138132
    139133////////////////////////////////////////////////////////////////////////////
    140 //++
    141 // Class        FunRan2D
    142 // Lib  Outils++
    143 // include      perandom.h
    144 //
    145 //      Tirage aleatoire sur un histogramme 2D.
    146 //--
    147 
    148 //++
     134/*!
     135  \class SOPHYA::FunRan2D
     136  \ingroup NTools
     137  Classe for generating random variables from 2D function
     138*/
     139
     140/********* Methode *********/
     141/*! Creator for random from a table */
    149142FunRan2D::FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY)
    150 //
    151 //      Createur.
    152 //--
    153143{
    154144  // Tirage en X, somme sur les Y.
     
    171161}
    172162
    173 //++
     163/********* Methode *********/
     164/*! Creator for random from a table */
    174165FunRan2D::FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY)
    175 //
    176 //      Createur.
    177 //--
    178166{
    179167  // Tirage en X, somme sur les Y.
     
    198186}
    199187
     188/********* Methode *********/
     189/*! Destructor */
    200190FunRan2D::~FunRan2D()
    201191{
     
    208198}
    209199
    210 //++
     200/********* Methode *********/
     201/*! Tirage avec retour du numeros de bin. */
    211202void FunRan2D::BinRandom(int_4& x, int_4& y)
    212 //
    213 //      Tirage avec retour du numeros de bin.
    214 //--
    215203{
    216204  x = ranX->BinRandom();
     
    218206}
    219207
    220 //++
     208/********* Methode *********/
     209/*! Tirage avec retour abscisse et ordonnee du bin interpole. */
    221210void FunRan2D::Random(r_8& x, r_8& y)
    222 //
    223 //      Tirage avec retour abscisse et ordonnee
    224 //      du bin interpole.
    225 //--
    226211{
    227212  x = ranX->Random();
     
    229214  y = ranY[i]->Random();
    230215}
     216
     217
     218
     219/////////////////////////////////////////////////////////////////
     220/*
     221--- Remarque sur complex< r_8 > ComplexGaussRan(double sig)
     222x = r cos(t) tire gaussien: pdf f(x) = 1/(sqrt(2Pi) Sx) exp(-(x-Mx)^2/(2 Sx^2))
     223y = r sin(t) tire gaussien: pdf f(y) = 1/(sqrt(2Pi) Sy) exp(-(y-My)^2/(2 Sy^2))
     224x,y independants --> pdf f(x,y) = f(x) f(y)
     225- On cherche la pdf g(r,t) du module et de la phase
     226  (r=sqrt(x^2+y^2,t=atan2(y,x)) --> (x,y): le Jacobien = r
     227  g(r,t) = r f(x,y) = r f(x) f(y)
     228         = r/(2Pi Sx Sy) exp(-(x-Mx)^2/(2 Sx^2)) exp(-(y-My)^2/(2 Sy^2))
     229- Le cas general est complique
     230  (cf D.Pelat cours DEA "bruits et signaux" section 4.5)
     231- Cas ou "Mx = My = 0" et "Sx = Sy = S"
     232  g(r,t) = r/(2Pi S^2) exp(-r^2/(2 S^2))
     233  La distribution de "r" est donc:
     234    g(r) = Integrate[g(r,t),{t,0,2Pi}]
     235         = r/S^2 exp(-r^2/(2 S^2))
     236  La distribution de "t" est donc:
     237    g(t) = Integrate[g(r,t),{r,0,Infinity}]
     238         = 1 / 2Pi  (distribution uniforme sur [0,2Pi[)
     239  Les variables aleatoires r,t sont independantes:
     240    g(r,t) = g(r) g(t)
     241*/
Note: See TracChangeset for help on using the changeset viewer.