diff options
| Commit | a1ddf90dd755b7e862882bd7304ecccd228a1712 (patch) | |
|---|---|---|
| Author | 2024-04-16 12:52:51 +0300 | |
| Committer | 2024-04-16 12:52:51 +0300 | |
| Files | c204c572c61c68788fe70c6841550d2fa9f3d987 | |
| uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.tar uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.tar.gz uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.zip | ||
| Parent | c146d10ae0462a47d4caaec7bc86bd1f18280409 (diff) | |
[S/hw1] Solved homework
6 files changed, 144 insertions, 0 deletions
| -rw-r--r-- | Year 3/Statistics/hw1-ex2-plot120.png | bin | 0 -> 10287 bytes | |||
| -rw-r--r-- | Year 3/Statistics/hw1-ex2-plot200.png | bin | 0 -> 10761 bytes | |||
| -rw-r--r-- | Year 3/Statistics/hw1-ex2-plot30.png | bin | 0 -> 10232 bytes | |||
| -rw-r--r-- | Year 3/Statistics/hw1.pdf | bin | 0 -> 78116 bytes | |||
| -rw-r--r-- | Year 3/Statistics/hw1.r | 38 | ||||
| -rw-r--r-- | Year 3/Statistics/hw1.tex | 106 |
diff --git a/Year 3/Statistics/hw1-ex2-plot120.png b/Year 3/Statistics/hw1-ex2-plot120.png Binary files differnew file mode 100644 index 0000000..912a2a7 --- /dev/null +++ b/Year 3/Statistics/hw1-ex2-plot120.png diff --git a/Year 3/Statistics/hw1-ex2-plot200.png b/Year 3/Statistics/hw1-ex2-plot200.png Binary files differnew file mode 100644 index 0000000..a806df8 --- /dev/null +++ b/Year 3/Statistics/hw1-ex2-plot200.png diff --git a/Year 3/Statistics/hw1-ex2-plot30.png b/Year 3/Statistics/hw1-ex2-plot30.png Binary files differnew file mode 100644 index 0000000..e2b61ce --- /dev/null +++ b/Year 3/Statistics/hw1-ex2-plot30.png diff --git a/Year 3/Statistics/hw1.pdf b/Year 3/Statistics/hw1.pdf Binary files differnew file mode 100644 index 0000000..dd012be --- /dev/null +++ b/Year 3/Statistics/hw1.pdf diff --git a/Year 3/Statistics/hw1.r b/Year 3/Statistics/hw1.r new file mode 100644 index 0000000..3112182 --- /dev/null +++ b/Year 3/Statistics/hw1.r @@ -0,0 +1,38 @@ +ex1 <- function(total = 24, marked = 4, boxes = 4, iterations = 10000) { + perbox <- total %/% boxes + successes <- 0 + + for (i in 1:iterations) { + apples <- sample(append(rep("marked", each=marked), rep("normal", each=total - marked))) + + current <- 0 + for (b in 1:boxes) { + current <- current + (sum(apples[1:perbox + (b-1)*perbox] == "marked") == 1) + } + + successes <- successes + (current == 4) + } + + return (successes / iterations) +} + +ex1() + +ex2 <- function(n, lambda = 1/5, N = 10000, mu = 5, sigma = 5 / sqrt(n)) { + xdash <- replicate(N, sum(rexp(n, rate=lambda)) / n) + + fchapeau <- function(t) { + return (1 / N * sum(xdash <= t)) + } + + t <- seq(0, 10, by=0.1) + Fpoints <- sapply(t, fchapeau) + Npoints <- sapply(t, function(t) { return (dnorm(t, mu, sigma)) }) + + plot(t, Fpoints, type="l", ylim=c(0, 1.1)) + lines(t, Npoints, lty=2) +} + +ex2(30) +ex2(120) +ex2(200)
\ No newline at end of file diff --git a/Year 3/Statistics/hw1.tex b/Year 3/Statistics/hw1.tex new file mode 100644 index 0000000..0f5af15 --- /dev/null +++ b/Year 3/Statistics/hw1.tex @@ -0,0 +1,106 @@ +% Document MUST be built with XeLaTeX! +\documentclass[11pt,a4paper]{article} + +\usepackage[margin=1.5cm]{geometry} + +% Поддръжка на български език +% Thanks to https://tex.stackexchange.com/a/136926 +\usepackage{fontspec} +\defaultfontfeatures{Ligatures=TeX}\setmainfont{CMU Serif} +\setsansfont{CMU Sans Serif} + +\usepackage[bulgarian,english]{babel} + +\usepackage{amsmath} % Математически символи +\usepackage{extarrows} +\usepackage{amsfonts} % Още математически символи +\usepackage{cancel} % Зачертаване +\usepackage[dvipsnames]{xcolor} % Цветни кутийки + допълнителни цветове +\usepackage{graphicx} % Изображения + +\usepackage{textcomp} +\usepackage{listings} +\newfontfamily{\lstsansserif}[Scale=1]{DejaVuSansMono} +\lstset{ + basicstyle=\lstsansserif\footnotesize, % the size of the fonts that are used for the code + breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace + breaklines=true, % sets automatic line breaking + frame=single, % adds a frame around the code + keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible) + numbers=left, % where to put the line-numbers; possible values are (none, left, right) + numbersep=10pt, % how far the line-numbers are from the code + showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces' + showstringspaces=false, % underline spaces within strings only + showtabs=false, % show tabs within strings adding particular underscores + literate = {-}{-}1{"}{\textquotedbl}1{*}{\normalfont{*}}1, +} + +\usepackage{enumitem} +\setlist[enumerate]{label=\arabic*.} + +\usepackage[pdfauthor={Камен Димитров Младенов, }, + pdftitle={Решения на задачи от Домашно 1 по ВИС практикум}, + pdfsubject={}, + pdfkeywords={}, + colorlinks=true, + urlcolor=blue]{hyperref} + +\title{\vspace{-1.5cm}Решения на задачи от Домашно 1 по ВИС практикум} +\author{Камен Димитров Младенов, FN} +\date{16.04.2024} + +\begin{document} + +\maketitle + +\paragraph{Задача 1.} + +Имаме $24$ ябълки, от които $4$ са червиви. Разпределяме ябълките в $4$ кутии, така че да са с равен брой ябълки. С помощта на симулации намерете приближение на вероятността във всяка кутия да има по една червива ябълка. + +\subparagraph{Решение} \hfill + +\lstinputlisting[language=R, firstline=1, lastline=19, caption=Сорс-код]{hw1.r} + +\begin{lstlisting}[language=R, caption=Получен резултат] +[1] 0.1238 +\end{lstlisting} + +Вероятността във всяка кутия да има по една червива ябълка е приблизително 12\%. + +\vfill + +\paragraph{Задача 2.} + +За $\,n=30, 120, 200\,$ генерирайте случайни числа $\,x_1, \ldots, x_n\,$ от експоненциално разпределение с параметър $\,\lambda=1/5\,$ и пресметнете $\,\overline{x} = (x_1 + \ldots + x_n)/n$. +Повторете $\,N=10000\,$ пъти и ще получите $\,\overline{x}_1, \ldots, \overline{x}_{10000}$. Нека + +$$ \widehat{F}(t) = \frac{1}{N} \sum_{i=1}^{N} \mathbb{I}(\overline{x}_i \leq t) ,$$ +където $\,\mathbb{I}(a)\,$ е единица, ако $\,a\,$ е вярно и нула, в противен случай. + +\begin{itemize} +\item Направете графика на $\,\widehat{F}(t)$. +Може да използвате функцията `plot(x, y, type="l")`. + +\item На същата картинка добавете графика на функцията на разпределение на $\,\mathcal{N}(\mu=5, \, \sigma=5/\sqrt{n})$. Двете графики трябва да са с различен цвят или едната да е с пунктирана линия. + +\item Трябва да получите три картинки -- по една за всяка стойност на $\,n$. +\end{itemize} + + +\subparagraph{Решение} \hfill + +\lstinputlisting[language=R, firstline=21, caption=Сорс-код]{hw1.r} + +Получен резултат при $n = 30$: \newline +\includegraphics[scale=0.5]{hw1-ex2-plot30.png} + +Получен резултат при $n = 120$: \newline +\includegraphics[scale=0.5]{hw1-ex2-plot120.png} + +\newpage + +Получен резултат при $n = 200$: \newline +\includegraphics[scale=0.5]{hw1-ex2-plot200.png} + + +\end{document}
\ No newline at end of file |
