Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ce089
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Walmes Marques Zeviani
ce089
Commits
54729dd2
Commit
54729dd2
authored
6 years ago
by
Walmes Marques Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Adiciona método da aceitação e rejeição.
parent
37c49307
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_site.yml
+4
-0
4 additions, 0 deletions
_site.yml
slides/05-met-ac-rej.Rnw
+205
-0
205 additions, 0 deletions
slides/05-met-ac-rej.Rnw
with
209 additions
and
0 deletions
_site.yml
+
4
−
0
View file @
54729dd2
...
...
@@ -33,12 +33,16 @@ navbar:
href
:
slides/03-gna-uniforme.pdf
-
text
:
"
GNA
de
v.a.
não
uniformes"
href
:
slides/04-gna-nao-uniforme.pdf
-
text
:
"
GNA
com
o
met.
da
aceitação-rejeição"
href
:
slides/05-met-ac-rej.pdf
-
text
:
"
----------"
-
text
:
"
Arquivos
complementares"
-
text
:
"
GNA
Uniformes
(2015)"
href
:
http://leg.ufpr.br/~walmes/ensino/ce089-2015-02/aula02_gna-2015-02.html
-
text
:
"
MTIP
(2015)"
href
:
http://www.leg.ufpr.br/~walmes/ensino/ce089-2015-02/aula03_tip-2015-02.html
-
text
:
"
Met.
ac-rej
(2017)"
href
:
./tutoriais/06-met-ac-rej.html
# - text: "Estruturas de controle"
# href: slides/01-estru-repet.html
# - text: "Teorema da Transformação da Probabilidade"
...
...
This diff is collapsed.
Click to expand it.
slides/05-met-ac-rej.Rnw
0 → 100644
+
205
−
0
View file @
54729dd2
%-----------------------------------------------------------------------
\documentclass[serif, professionalfont, usenames, dvipsnames]{beamer}
\usepackage[T1]{fontenc}
% ATTENTION: preamble.tex contains all style definitions.
\input{config/preamble.tex}
% \usepackage[backend=bibtex, style=authoryear]{biblatex}
\addbibresource{config/refs.bib}
<<include = FALSE>>=
source("config/setup.R")
@
%-----------------------------------------------------------------------
\title{GNA pelo método da aceitação e rejeição}
\subtitle{Importância, algorítmo e implementação}
\date{\small{ \Sexpr{sprintf('Atualizado em %s', Sys.Date())}}}
%-----------------------------------------------------------------------
\begin{document}
{\setbeamertemplate{footline}{}
\frame{\titlepage} %--------------------------------------------------
}
\begin{frame}{}
{\large Justificativas}
\begin{itemize}
\item A GNA pelo MTIP nem sempre é possível por causa da não
existência de $F_X^{-1}(.)$.
\item O métoda da aceitação-rejeição é aplicável quando a se possui a
função de densidade de probabilidade ou de probabibilidade.
\end{itemize}
{\large Objetivos}
\begin{itemize}
\item Apresentar o método da aceitação-rejeição.
\item Descrever e implementar o algorítmo.
\end{itemize}
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}{O algoritmo}
Objetivo: obter uma amostra aleatória da variável aleatória $X$ que
tem distribuição representada pela função de densidade é $f_{X}(x)$.
\begin{enumerate}
\item Encontrar uma v.a. $Y$ candidata, com função de densidade
$f_{Y}(y)$, da qual se possui GNA e cujo suporte contenha o suporte
de $X$.
\item Encontrar o valor $M$ tal que $f_{X}(x) \leq M f_{Y}(x)$ para
todo valor de $x$ no suporte de $X$.
\item Gerar uma realização de $y$ da distribuição candidata cuja
função de densidade é $f_{Y}(y)$.
\item Gerar uma realização de $u$ da distribuição $U(0, 1)$.
\item Se $u \leq f_{X}(y)/(M f_{Y}(y))$, fazer com que $x = y$, caso contrário, repetir de 3--5.
\item Repetir 3--5 o número necessário de vezes para ter uma amostra
de $X$ de tamanho $n$.
\end{enumerate}
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}{Exemplo: Gerar números da triangular usando a uniforme}
\begin{itemize}
\item Considere que $X$ tenha distribuição triangular com função de
densidade
\begin{equation}
f_X(x, a, b, c) = \begin{cases}
\dfrac{2 (x - a)}{(b - a) (c - a)}, & a < x \leq c \\
\dfrac{2 (b - x)}{(b - a) (b - c)}, & c < x < b \\
0 & \text{casos contr\'arios}.
\end{cases}
\end{equation}
\item Gerar números de $X \sim f_{X}(x, a = -b, b = 1, c = 0)$ usando
como v.a. candidata $Y \sim U(t, v)$ cuja densidade é
\begin{equation}
f_Y(y) = \frac{1}{v - t} \cdot I(t < y < v)
\end{equation}
\item Para que o suporte de $Y$ contenha o suporte de $X$, $t = -b$ e
$v = b$.
\item Para que $f_{X}(x) \leq Mf_{Y}(x)$ para todo $x$, o valor de $M = 2$.
\end{itemize}
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}[fragile, allowframebreaks]{Implementação em R}
<<include = TRUE, eval = FALSE>>=
# Densidade da X, distribuição alvo.
f_X <- function(x, r) {
b <- r; a <- -r; c <- 0
f <- 0 + 2 * (x - a)/((b - a) * (c - a)) * (x <= c) * (x > a) +
2 * (b - x)/((b - a) * (b - c)) * (x > c) * (x < b)
return(f)
}
# Densidade da Y, distribuição candidata.
f_Y <- function(y, r) {
f <- 1/(2 * r) * (y > -r) * (y < r)
return(f)
}
# Gráficos.
curve(f_X(x, r = 1), from = -1, to = 1)
curve(f_Y(y, r = 1), xname = "y", add = TRUE, col = 2, lty = 2)
curve(2 * f_Y(y, r = 1), xname = "y", add = TRUE, col = 2)
@
\framebreak
<<eval = FALSE>>=
M <- 2
n <- 10000
x <- numeric(n)
i <- 1
k <- 1
while (i <= n) {
y <- runif(1, min = -1, max = 1)
u <- runif(1)
ratio <- f_X(y, r = 1)/(M * f_Y(y, r = 1))
if (u < ratio) {
x[i] <- y
i <- i + 1
}
k <- k + 1
}
n/k # Proporção de aceitação.
plot(ecdf(x)) # Acumulada empírica.
plot(density(x, from = -1, to = 1)) # Dens. empírica.
curve(f_X(x, r = 1), add = TRUE, col = 2) # Dens. teórica.
@
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}{Complementos}
\begin{itemize}
\item Exercício: Gerar de $X \sim \text{Triangular}$ usando $Y \sim \text{Beta}$.
\item Exercício: Gerar de $X \sim \text{Cauchy}$ usando $Y \sim \text{Normal}$.
\item Veja a animação que ilustra o método: \url{http://leg.ufpr.br/~walmes/ensino/EC2/tutoriais/06-met-ac-rej.html}.
\end{itemize}
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}{Questões}
\begin{itemize}
\item O que considerar ao escolher uma v.a. candidata?
\item Como melhorar a taxa de aceitação do método?
\item Como fazer para v.a. discretas?
\end{itemize}
\end{frame}
%-----------------------------------------------------------------------
{
\usebackgroundtemplate{\includegraphics[height=\paperheight, width=\paperwidth]{../img/looking-ahead.jpg}}
% \setbeamersize{text margin left=30mm}
\begin{frame}[b]{}
\hspace*{0.5\linewidth}
\begin{minipage}[t]{0.5\linewidth}
\hi{Próxima aula}
\begin{itemize}
\item Métodos derivados da aceitação e rejeição.
\item Alternativas para GNA baseado em relações entre v.a.
\end{itemize}
\hi{Avisos}
\begin{itemize}
\item Sabatina 04 com o conteúdo desta semana.
\end{itemize}
\vspace{3em}
\end{minipage}
\end{frame}
}
% %-----------------------------------------------------------------------
% \begin{frame}[t, fragile, allowframebreaks]
% \frametitle{Referências bibliográficas}
%
% \printbibliography[heading=none]
% \end{frame}
%-----------------------------------------------------------------------
\end{document}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment