\doxysection{Random\+\_\+\+Sampler.\+h}
\hypertarget{_random___sampler_8h_source}{}\label{_random___sampler_8h_source}\index{src/Random\_Sampler.h@{src/Random\_Sampler.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ <cmath>}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ <random>}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <tuple>}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <functional>}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00009\ T\ random\_sampler\_1D(T\ (*pdf)(T,\ std::vector<T>),\ std::vector<T>\ parameters,\ T\ x0,\ T\ size,\ T\ domain\_x[])\ \{}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ steps\ =\ 100;}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \ \ \ \ T\ x\ =\ x0;}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \ \ \ \ std::random\_device\ rd;}
\DoxyCodeLine{00016\ \ \ \ \ std::seed\_seq\ fullSeed\{rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd()\};}
\DoxyCodeLine{00017\ \ \ \ \ std::mt19937\ rng(fullSeed);}
\DoxyCodeLine{00018\ \ \ \ \ std::uniform\_real\_distribution<T>\ uniformDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00019\ \ \ \ \ std::normal\_distribution<T>\ normDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00021\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ steps;\ i\ ++)\ \{}
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00023\ \ \ \ \ \ \ \ \ T\ step\ =\ normDist(rng)\ *\ size;}
\DoxyCodeLine{00024\ \ \ \ \ \ \ \ \ T\ u\_sample\ =\ uniformDist(rng);}
\DoxyCodeLine{00025\ \ \ \ \ \ \ \ \ T\ x\_p\ =\ x\ +\ step;}
\DoxyCodeLine{00026\ \ \ \ \ \ \ \ \ T\ acceptance\ =\ 0.0;}
\DoxyCodeLine{00027\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(x\_p\ >=\ domain\_x[0]\ \&\&\ x\_p\ <=\ domain\_x[1])\ \{}
\DoxyCodeLine{00028\ \ \ \ \ \ \ \ \ \ \ \ \ T\ acceptance\ =\ std::min(1.0,\ *pdf(x\_p,\ parameters)\ /\ *pdf(x,\ parameters));}
\DoxyCodeLine{00029\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00030\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(acceptance\ >=\ u\_sample)\ \{}
\DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ \ \ \ \ x\ =\ x\_p;}
\DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00033\ \ \ \ \ \}}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keywordflow}{return}\ x;}
\DoxyCodeLine{00036\ \}}
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00039\ std::tuple<T,\ T>\ random\_sampler\_2D(T\ (*pdf)(T,\ T,\ std::vector<T>),\ std::vector<T>\ parameters,\ T\ x0,\ T\ y0,\ T\ size\_x,\ T\ size\_y,\ T\ domain\_x[],\ T\ domain\_y[])\ \{}
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ steps\ =\ 100;}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \ \ \ \ T\ x\ =\ x0;}
\DoxyCodeLine{00044\ \ \ \ \ T\ y\ =\ y0;}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \ \ \ \ std::random\_device\ rd;}
\DoxyCodeLine{00047\ \ \ \ \ std::seed\_seq\ fullSeed\{rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd()\};}
\DoxyCodeLine{00048\ \ \ \ \ std::mt19937\ rng(fullSeed);}
\DoxyCodeLine{00049\ \ \ \ \ std::uniform\_real\_distribution<T>\ uniformDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00050\ \ \ \ \ std::normal\_distribution<T>\ normDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ steps;\ i\ ++)\ \{}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ T\ step\_x\ =\ normDist(rng)\ *\ size\_x;}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ T\ step\_y\ =\ normDist(rng)\ *\ size\_y;}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ T\ u\_sample\ =\ uniformDist(rng);}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ T\ x\_p\ =\ x\ +\ step\_x;}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ T\ y\_p\ =\ y\ +\ step\_y;}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ T\ acceptance\ =\ 0.0;}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(x\_p\ >=\ domain\_x[0]\ \&\&\ x\_p\ <=\ domain\_x[1]\ \&\&\ y\_p\ >=\ domain\_y[0]\ \&\&\ y\_p\ <=\ domain\_y[1])\ \{}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \ \ \ \ T\ acceptance\ =\ std::min(1.0,\ *pdf(x\_p,\ y\_p,\ parameters)\ /\ *pdf(x,\ y,\ parameters));}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(acceptance\ >=\ u\_sample)\ \{}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \ \ \ \ x\ =\ x\_p;}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \ \ \ \ y\ =\ y\_p;}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00067\ \ \ \ \ \}}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keywordflow}{return}\ std::make\_tuple(x,\ y);}
\DoxyCodeLine{00070\ \}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00073\ std::tuple<T,\ T>\ random\_sampler\_angles(T\ (*pdf)(T,\ T,\ std::vector<T>),\ std::vector<T>\ parameters,\ T\ theta\_r1,\ T\ theta\_r2,\ T\ size\_x,\ T\ size\_y,\ T\ domain\_x[],\ T\ domain\_y[])\ \{}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ steps\ =\ 100;}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \ \ \ \ std::random\_device\ rd;}
\DoxyCodeLine{00078\ \ \ \ \ std::seed\_seq\ fullSeed\{rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd()\};}
\DoxyCodeLine{00079\ \ \ \ \ std::mt19937\ rng(fullSeed);}
\DoxyCodeLine{00080\ \ \ \ \ std::uniform\_real\_distribution<T>\ uniformDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00081\ \ \ \ \ std::normal\_distribution<T>\ normDist(0.0f,\ 1.0f);}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ steps;\ i\ ++)\ \{}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00085\ \ \ \ \ \ \ \ \ T\ step\_x\ =\ normDist(rng)\ *\ size\_x;}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ T\ step\_y\ =\ normDist(rng)\ *\ size\_y;}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ T\ u\_sample\ =\ uniformDist(rng);}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ T\ theta\_r1\_p\ =\ theta\_r1\ +\ step\_x;}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \ \ T\ theta\_r2\_p\ =\ theta\_r2\ +\ step\_y;}
\DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ T\ acceptance\ =\ 0.0;}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(theta\_r1\_p\ <\ 0.0)\ \{}
\DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r1\_p\ =\ std::abs(theta\_r1\_p);}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r2\_p\ +=\ M\_PI;}
\DoxyCodeLine{00094\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00095\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(theta\_r2\_p\ <\ 0.0)\ \{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r2\_p\ +=\ 2.0\ *\ M\_PI;}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(theta\_r2\_p\ >\ 2.0\ *\ M\_PI)\ \{}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r2\_p\ -\/=\ 2.0\ *\ M\_PI;}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(theta\_r1\_p\ <\ domain\_x[1])\ \{}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \ \ \ \ T\ acceptance\ =\ std::min(1.0,\ *pdf(theta\_r1\_p,\ theta\_r2\_p,\ parameters)\ /\ *pdf(theta\_r1,\ theta\_r2,\ parameters));}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(acceptance\ >=\ u\_sample)\ \{}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r1\ =\ theta\_r1\_p;}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ \ \ \ \ theta\_r2\ =\ theta\_r2\_p;}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00110\ \ \ \ \ \}}
\DoxyCodeLine{00111\ }
\DoxyCodeLine{00112\ \ \ \ \ \textcolor{keywordflow}{return}\ std::make\_tuple(theta\_r1,\ theta\_r2);}
\DoxyCodeLine{00113\ \}}

\end{DoxyCode}
