This commit is contained in:
shoney.arickathil 2023-09-15 11:38:05 +02:00
parent fb614d55b6
commit 04015cca97
4 changed files with 159 additions and 83 deletions

View file

@ -4,12 +4,12 @@
\section{Probability Distribution}
A probability distribution is the information of how likely a random variable or set of variables is to take each of its possible states. The way the probability distribution is described depended on whether the variables are discrete (finite set of variables) or continuous \parencite[Page 54]{Goodfellow-et-al-2016}.
A probability distribution is the information of how likely a random variable or set of variables is to take each of its possible states. The way the probability distribution is described depended on whether the variables are discrete or continuous. A discrete random variable has finite or countably infinite number of states. \parencite[Page 54]{Goodfellow-et-al-2016}.
In this paper, the finite number of categories to be predicted indicate that the probability distribution variable is of discrete type. The probability that variable $X = x$ is denoted by $ P(x) $, with a probability of 1 indicating that $x-x$ is certain and probability of 0 indicating an impossible event \parencite[Page 55]{Goodfellow-et-al-2016}.
In this project, the random variables are vector-valued product features denoted as $ \textbf{x} $ and its value as $ x $. The probability that variable $\textbf{x} = x$ is denoted by $ P(x) $, with a probability of 1 indicating that $\textbf{x}-x$ is certain and probability of 0 indicating an impossible event \parencite[Page 55]{Goodfellow-et-al-2016}.
The probability values ranging between 0 and 1 are called \acf{PMF} denoted as $ P $. To ensure that \acs*{PMF} provides valid probabilities the function $P$ must satisfy following propertise.
The probability values ranging between 0 and 1 are called \acf{PMF} denoted as capital $ P $. To ensure that \acs*{PMF} provides valid probabilities the function $P$ must satisfy following properties.
\begin{itemize}
@ -34,4 +34,82 @@ The probability values ranging between 0 and 1 are called \acf{PMF} denoted as
\label{tab:probability-distribution}
\end{table}
where \(P_i > 0\), \(i=1\) to \(n\) and \(P_1 + P_2 + P_3 + \ldots + P_n =1\) \\
where \(P_i > 0\), \(i \equiv 1\) to \(n\) and \(P_1 + P_2 + P_3 + \ldots + P_n = 1\) \\
\subsection*{Multinoulli Distribution or Categorical Distribution}
Multinoulli or Categorical distribution is a type of probability distribution over a single discrete variable with $ k $ different states or categories, where $ k $ is finite and probability of each category is separately specified.
\begin{itemize}
\item A multinoulli distribution is parametrized by a vector $\mathbf{p} \in [0, 1]^{k-1}$, where each element of $\mathbf{p}$ represents the probability of the $i$-th state.
\item The probability of the final, $k$-th state is given by $1 - \sum_{i=1}^{k-1} p_i$.
\item $\sum_{i=1}^{k-1} p_i \leq 1$ hence, the probabilities do not exceed 1.
\end{itemize}
Multinoulli distributions are often employed to model distributions over categories of objects. In this context, we do not assume that state 1 has a numerical value of 1, and so forth. The values in $\mathbf{p}$ represent probabilities associated with different categories or states, and they do not carry a numerical interpretation.
Moreover, when working with multinoulli-distributed random variables, it is typically unnecessary to compute expectations or variances since these distributions are used to describe categorical outcomes where numerical operations may not be meaningful \parencite[Page 60,61]{Goodfellow-et-al-2016}.
\section{Softmax}
The softmax function is often used to predict the probabilities associated with a multinoulli distribution \parencite[Page 79]{Goodfellow-et-al-2016}.
\begin{align}
\text{Softmax}(x_i) = \frac{{\exp(x_i)}}{{\sum_{j=1}^n \exp(x_j)}} \label{eq:softmax_matth}
\end{align}
Equation \ref{eq:softmax_matth} is the formula for Softmax function. It applies the standard exponential function to each element $ x_i $ of the input vector $ \mathbf{x} $ and normalizes these values by dividing by the sum of all these exponential.
\begin{lstlisting}[language=Python,caption={Python example for softmax},label=code:sample_softmax]
>>> import numpy as np
>>> a = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0]
>>> np.exp(a) / np.sum(np.exp(a))
array([0.02364054, 0.06426166, 0.1746813 , 0.474833 , 0.02364054,
0.06426166, 0.1746813 ])
>>> sm_val =np.exp(a) / np.sum(np.exp(a))
>>> np.sum(sm_val)
0.9999999999999999
>>>
\end{lstlisting}
Listing \ref{code:sample_softmax} is an example of applying Softmax function to an array of positive integers. It is important to note that the sum of all the softmax value is approximately equal to 1. The output has most of its weight where the ``4'' was in the original input. This is what the function is normally used for: to highlight the largest values and suppress values which are significantly below the maximum value.
\subsection*{Why to apply log to Softmax function } \label{sec:Logsoft}
\begin{align}
\log(\text{Softmax}(x_i)) = \log\left(\frac{{\exp(x_i)}}{{\sum_{j=1}^n \exp(x_j)}}\right) \label{eq:log_softmax}
\end{align}
Equation \eqref{eq:log_softmax} shows the logarithm of the Softmax function applied to the element \(x_i\) in the vector \(\mathbf{x}\).
Applying logarithm to the fraction:
\begin{align}
\log\left(\frac{a}{b}\right) = \log(a) - \log(b)
\end{align}
Substituting \(a = \exp(x_i)\) and \(b = \sum_{j=1}^n \exp(x_j)\) in equation \eqref{eq:log_softmax}, we get:
\begin{align}
\log(\text{Softmax}(x_i)) = \log(\exp(x_i)) - \log\left(\sum_{j=1}^n \exp(x_j)\right)
\end{align}
\begin{itemize}
\item Reduce large numbers: The softmax function normalizes any value from [-infy, +infy] by applying an exponential function. Exponential functions can lead to a very large numbers, resulting in Nan as output. Applying logarithm effectively reduce these large numbers to manageable range.
\item Numerical Stability: When dealing with very small probabilities, the product of multiple probabilities can become exceedingly close to zero, leading to numerical underflow. Similarly, when dealing with very large probabilities, the product can exceed the representation range of standard floating-point numbers, causing numerical overflow. By taking the logarithm, these issues are avoided, and the values are represented in a more stable and manageable range \parencite[Page 79]{Goodfellow-et-al-2016}.
\item Log Probabilities and Addition: Log probabilities are additive when events are independent.\\ For example, if we have two independent events \(A\) and \(B\) with probabilities \(P(A) = p\) and \(P(B) = q\), the probability of both events occurring (\(P(A \cap B)\)) is \(P(A) \times P(B) = p \times q\). Taking the logarithm, we get \(\log(P(A \cap B)) = \log(p \times q) = \log(p) + \log(q)\). This additive property simplifies calculations involving multiple independent events.
\item Logarithms and Multiplication: Logarithms convert multiplication to addition. Probabilities of independent events, represented as \(P(A \cap B \cap C \cap \ldots)\). Logarithm of the product of these probabilities simplifies the computation to a sum.
\end{itemize}
\section{Summary}
In this chapter, the mathematical theories and formulas related to multi level classification task is described. Author discusses the approach for numerical stability to avoid overflow and underflow of value resulting into a not-a-number values. In this chapter, an overview of the Probability Distribution and one of its type Multinoulli Distribution is given. Author illustrates the relationship between the task of product feature classification into category and the mathematical formulas.

View file

@ -246,35 +246,6 @@ As per \parencite{Book-Bishop-Neural} the term softmax is used because this acti
\clearpage
\subsection{Why to apply log to Softmax Equation \eqref{eq:softmax} } \label{sec:Logsoft}
\begin{align}
\log(\text{Softmax}(x_i)) = \log\left(\frac{{\exp(x_i)}}{{\sum_{j=1}^n \exp(x_j)}}\right) \label{eq:log_softmax}
\end{align}
Equation \eqref{eq:log_softmax} shows the logarithm of the Softmax function applied to the element \(x_i\) in the vector \(\mathbf{x}\).
Applying logarithm to the fraction:
\begin{align}
\log\left(\frac{a}{b}\right) = \log(a) - \log(b)
\end{align}
Substituting \(a = \exp(x_i)\) and \(b = \sum_{j=1}^n \exp(x_j)\) in Equation \eqref{eq:log_softmax}, we get:
\begin{align}
\log(\text{Softmax}(x_i)) = \log(\exp(x_i)) - \log\left(\sum_{j=1}^n \exp(x_j)\right)
\end{align}
1. Reduce large numbers: The softmax function normalizes any value from [-infy, +infy] by applying an exponential function. Exponential functions can lead to a very large numbers, resulting in Nan as output. Applying logarithm effectively reduce these large numbers to manageable range.
2. Logarithms and Multiplication: Logarithms convert multiplication to addition. Probabilities of independent events, represented as \(P(A \cap B \cap C \cap \ldots)\). Logarithm of the product of these probabilities simplifies the computation to a sum.
3. Numerical Stability: When dealing with very small probabilities, the product of multiple probabilities can become exceedingly close to zero, leading to numerical underflow. Similarly, when dealing with very large probabilities, the product can exceed the representation range of standard floating-point numbers, causing numerical overflow. By taking the logarithm, these issues are avoided, and the values are represented in a more stable and manageable range.
4. Log Probabilities and Addition: Log probabilities are additive when events are independent.\\ For example, if we have two independent events \(A\) and \(B\) with probabilities \(P(A) = p\) and \(P(B) = q\), the probability of both events occurring (\(P(A \cap B)\)) is \(P(A) \times P(B) = p \times q\). Taking the logarithm, we get \(\log(P(A \cap B)) = \log(p \times q) = \log(p) + \log(q)\). This additive property simplifies calculations involving multiple independent events.
In summary, using log-softmax over softmax is the use of log probabilities over probabilities, a log probability is simply a logarithm of a probability. The use of log probabilities means representing probabilities on a logarithmic scale. Working with log probabilities allows for more stable and efficient computations, especially when dealing with products of probabilities of very small or large numbers.
\section{\acf{ALL}}

View file

@ -1,31 +0,0 @@
% makeindex style file created by the glossaries package
% for document 'index' on 2023-5-29
actual '?'
encap '|'
level '!'
quote '"'
keyword "\\glossaryentry"
preamble "\\glossarysection[\\glossarytoctitle]{\\glossarytitle}\\glossarypreamble\n\\begin{theglossary}\\glossaryheader\n"
postamble "\%\n\\end{theglossary}\\glossarypostamble\n"
group_skip "\\glsgroupskip\n"
item_0 "\%\n"
item_1 "\%\n"
item_2 "\%\n"
item_01 "\%\n"
item_x1 "\\relax \\glsresetentrylist\n"
item_12 "\%\n"
item_x2 "\\relax \\glsresetentrylist\n"
delim_0 "\{\\glossaryentrynumbers\{\\relax "
delim_1 "\{\\glossaryentrynumbers\{\\relax "
delim_2 "\{\\glossaryentrynumbers\{\\relax "
delim_t "\}\}"
delim_n "\\delimN "
delim_r "\\delimR "
headings_flag 1
heading_prefix "\\glsgroupheading\{"
heading_suffix "\}\\relax \\glsresetentrylist "
symhead_positive "glssymbols"
numhead_positive "glsnumbers"
page_compositor "."
suffix_2p ""
suffix_3p ""

View file

@ -1,15 +1,16 @@
\documentclass[15pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage[nohyperlinks, printonlyused, withpage, smaller]{acronym}
\usepackage[sorting=nyt,backend=biber,style=authoryear]{biblatex}
\usepackage[backend=biber, sorting=nyt, style=ext-authoryear-icomp,dashed=false]{biblatex}
\usepackage[inkscapeformat=png]{svg}
\usepackage{booktabs,multirow,array}
\usepackage{listings}
@ -21,6 +22,8 @@
\usepackage{tocloft}
\usepackage{enumitem}
\usepackage{appendix}
\usepackage{mathrsfs}
\usetikzlibrary{shapes,arrows,positioning,arrows.meta}
\captionsetup[table]{skip=5pt}
@ -75,16 +78,69 @@
\graphicspath{ {images/} }
\renewbibmacro*{url+urldate}{%
\printfield{url}%
\iffieldundef{urlyear}
{}
{\setunit*{\addspace}%
\printtext[urldate]{\printurldate}}}
% \renewbibmacro*{url+urldate}{%
% \printfield{url}%
% \iffieldundef{urlyear}
% {}
% {\setunit*{\addspace}%
% \printtext[urldate]{\printurldate}}}
\DeclareFieldFormat{url}{Available at\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{Accessed on\addcolon\space{#1}}
\DeclareFieldFormat{urldate}{\\Accessed on\addcolon\space#1}
\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat{nameyeardelim}{\addcomma\space}% comma before the year
% \DeclareFieldFormat{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
% \DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
% \renewbibmacro*{url+urldate}{% changes the default order of the fields url and urldate
% \usebibmacro{urldate}%
% \newunit
% \usebibmacro{url}%
% }
% \makeatletter
% \setlength{\bibitemsep}{0.5\baselineskip plus 0.5\baselineskip}
% \newsavebox\ay@labelbox
% \newlength{\labwidthsameline}
% \setlength{\labwidthsameline}{6em}
% % \newbibmacro{labelwidthbib}{%
% % \begingroup
% % \delimcontext{parencite}%
% % \DeclareFieldFormat{bibhyperref}{##1}%
% % \csuse{blx@hook@cite}%
% % \csuse{blx@hook@citekey}%
% % \global\undef\cbx@lasthash
% % \global\undef\cbx@lastyear
% % \citetrackerfalse\pagetrackerfalse\backtrackerfalse
% % \defcounter{maxnames}{\blx@maxcitenames}%
% % \printtext[brackets]{\usebibmacro{cite}}%
% % \endgroup
% % }
% %-----------------------
% \newbibmacro{kicklabel}{%
% \sbox\ay@labelbox{\usebibmacro{labelwidthbib}}%
% \global\togglefalse{blx@insert}%
% \ifdim\wd\ay@labelbox>\labwidthsameline
% \leavevmode\newline
% \fi
% }
% \defbibenvironment{bibliography}%
% {\list
% {\usebibmacro{labelwidthbib}}%
% {\setlength{\labelwidth}{\labwidthsameline}%
% \setlength{\leftmargin}{\labelwidth}%
% \setlength{\labelsep}{\biblabelsep}%
% \addtolength{\leftmargin}{\labelsep}%
% \setlength{\itemsep}{\bibitemsep}%
% \setlength{\parsep}{\bibparsep}%
% \renewcommand*{\makelabel}[1]{##1\hss}}}%
% {\endlist}%
% {\item\usebibmacro{kicklabel}}
% \makeatother
\addbibresource{References.bib}
@ -133,7 +189,6 @@ chapters/appendix%
\include{chapters/training-hypertuning}
\include{chapters/math-behind}
\include{chapters/building-kg}
\include{chapters/conclusion}
\pagenumbering{roman}
@ -149,8 +204,6 @@ chapters/appendix%
\listoftables
\lstlistoflistings
\include{preliminary/acronyms}
\clearpage
@ -158,15 +211,20 @@ chapters/appendix%
% \printglossary
\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography[title={References}]
\defbibheading{bibempty}{}
\let\oldbib\thebibliography
\let\endoldbib\endthebibliography
\renewenvironment{thebibliography}
{\vspace{\baselineskip}\begin{oldbib}}
{\end{oldbib}\vspace{\baselineskip}}
% \defbibheading{bibempty}{}
% \let\oldbib\thebibliography
% \let\endoldbib\endthebibliography
% \renewenvironment{thebibliography}
% {\vspace{\baselineskip}\begin{oldbib}}
% {\end{oldbib}\vspace{\baselineskip}}
\addcontentsline{toc}{chapter}{Appendices}
\appendix