{"text": "\n\\subsection{Curl in tensor form}\nThe curl of a vector function can be expressed in tensor form as\n$$\\mathop{\\rm curl}{\\bf F}=\\epsilon_{ijk}\\,{\\partial F_k\\over\\partial x_j}$$\nwhere $\\epsilon_{ijk}$ is the Levi-Civita tensor.\nThe following script demonstrates that this formula is equivalent\nto computing curl the old fashioned way.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Define epsilon\nepsilon = zero(3,3,3)\nepsilon[1,2,3] = 1\nepsilon[2,3,1] = 1\nepsilon[3,1,2] = 1\nepsilon[3,2,1] = -1\nepsilon[1,3,2] = -1\nepsilon[2,1,3] = -1\n-- F is a generic vector function\nF = (FX(),FY(),FZ())\n-- A is the curl of F\nA = outer(epsilon,d(F,(x,y,z)))\nA = contract(A,3,4) --sum across k\nA = contract(A,2,3) --sum across j\n-- B is the curl of F computed the old fashioned way\nBX = d(F[3],y)-d(F[2],z)\nBY = d(F[1],z)-d(F[3],x)\nBZ = d(F[2],x)-d(F[1],y)\nB = (BX,BY,BZ)\n-- Are A and B equal? Subtract to find out.\nA-B\n\\end{Verbatim}\n\nHere is the result when the script runs.\n\n$\\displaystyle \\begin{bmatrix}0\\\\0\\\\0\\end{bmatrix}$\n\nThe following is a variation on the previous script.\nThe product $\\epsilon_{ijk}\\,\\partial F_k/\\partial x_j$\nis computed in just one line of code.\nIn addition, the outer product and the contraction across $k$\nare now computed with a dot product.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nF = (FX(),FY(),FZ())\nepsilon = zero(3,3,3)\nepsilon[1,2,3] = 1\nepsilon[2,3,1] = 1\nepsilon[3,1,2] = 1\nepsilon[3,2,1] = -1\nepsilon[1,3,2] = -1\nepsilon[2,1,3] = -1\nA = contract(dot(epsilon,d(F,(x,y,z))),2,3)\nBX = d(F[3],y)-d(F[2],z)\nBY = d(F[1],z)-d(F[3],x)\nBZ = d(F[2],x)-d(F[1],y)\nB = (BX,BY,BZ)\n-- Are A and B equal? Subtract to find out.\nA-B\n\\end{Verbatim}\n\nThis is the result when the script runs.\n\n$\\displaystyle \\begin{bmatrix}0\\\\0\\\\0\\end{bmatrix}$\n", "meta": {"hexsha": "276741d86d8bbf802e89b56812f20ba1db7c4032", "size": 1781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/curl-in-tensor-form.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/curl-in-tensor-form.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/curl-in-tensor-form.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.828125, "max_line_length": 76, "alphanum_fraction": 0.6636720943, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639694252315, "lm_q2_score": 0.9219218327098192, "lm_q1q2_score": 0.8957060352873362}} {"text": "\\subsection{Method} \\label{subsec:method_logistic_regression}\n\nThe goal of classification is to assign an input vector $\\bold{x}$ to one of K classes $\\mathcal{C}_k$ where $k=0,1,...,K$. Linear regression can be extended to binary classification by two changes \\cite{murphy_machine_2012}. First is the change of the Gaussian distribution for $y$ with a Bernoulli distribution, for the case of binary response, $y_i \\in \\{0,1\\}$. \n\n\\begin{align}\n p(y \\mid \\mathbf{x}, \\boldsymbol{\\beta})&=Ber(y \\mid p(y=1\\mid \\boldsymbol{x},\\boldsymbol{\\beta}))) \\\\\n &= p^{y}\\left(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} \\right)\\left(1-p(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} )\\right)^{1-y}\n\\end{align}\n\nSecond is to pass the linear combination of the inputs and parameters to a function that outputs in the range $[0,1]$. This is achieved by using a logit function also known as sigmoid function, $p(y=1\\mid \\bold{x}, \\boldsymbol{\\beta}) = sigm(\\boldsymbol{\\beta}^T \\bold{x})$. \n\\newline\\newline\nWe define sigmoid function as,\n\\begin{equation}\n sigm(z ) = \\frac{1}{1 + e^{-z}}\n\\end{equation}\n\n\nPutting these two steps together we get,\n\\begin{equation}\n p(y \\mid \\mathbf{x}, \\boldsymbol{\\beta})=Ber(y|sigm(\\boldsymbol{\\beta}^T \\mathbf{x})))\n\\end{equation}\nFor a multivariate set of data $\\mathcal{D} = \\{y_i, \\mathbf{x_i}\\}$ with $y_i$ being a binary response $y_i \\in \\{0,1\\}$ and $\\mathbf{x_i}$ is a vector of size $1\\times n$ where n is the number of features, the likelihood for all possible outcome is, \n\\begin{equation}\\label{eq:likelihood}\n P(\\mathcal{D}\\mid \\boldsymbol{\\beta}) = \\Pi_i p(y_i \\mid \\mathbf{x}_i, \\boldsymbol{\\beta})\n\\end{equation}\n\nFrom maximum likelihood estimation principle, the most probable observed data can be obtained from the maximum log-likelihood function where we maximizes with respect to $\\boldsymbol\\beta$. The log-likelihood for equation (\\ref{eq:likelihood}) is given by,\n\\begin{equation}\n \\mathrm{LL}(\\boldsymbol{\\beta}) =\\sum_{i=1}^{N}\\left[y_{i} \\log p(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} )+\\left(1-y_{i}\\right) \\log \\left(1-p(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} )\\right)\\right]\n\\end{equation}\n\nFor logistic regression, the cost function is just the negative log-likelihood. We want a cost function to be minimized hence a negative sign on the log-likelihood.\n\n\\begin{align}\n C(\\boldsymbol{\\beta}) =-\\sum_{i=1}^{N}\\left[y_{i} \\log p(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} )+\\left(1-y_{i}\\right) \\log \\left(1-p(y=1\\mid \\mathbf{x}, \\boldsymbol{\\beta} )\\right)\\right]\n\\end{align}\n\nThis is also known as the cross-entropy error function. Unlike linear regression, the maximum likelihood estimate (MLE) for the parameters is no longer in closed form, so we need an optimization algorithm to compute it. One famous simple algorithm for unconstrained optimization is gradient descent, also known as steepest descent. It is given as follows,\n\n\n\\begin{align}\n g_k &= -\\mathbf{X}^T(\\mathbf{y}-\\mathbf{\\mu}) \\\\\n \\beta_{k+1} &= \\beta_k - \\eta_k g_k\n\\end{align}\n\nwhere $\\eta_k$ is the learning rate, and $g_k$ is the gradient of the loss function with respect to $\\mathcal{\\beta}$. Several hyperparameters can be utilized in controlling the training. We use the following tuning parameters in our code: learning rate, number of epochs, and number of batches. Learning rate is just the step size on each iteration as it approaches the minimum of the cost function. The number of batches is the number of samples processed before updating the learnable parameter. And the number of the epoch is a complete cycle over the training data. After completing one epoch, the optimal parameter $\\boldsymbol{\\beta}$ can be obtained. This can be used to calculate a continuous response $t =\\boldsymbol{X}^T \\boldsymbol\\beta$. If we set a threshold value for $t$ we can create a decision rule. In our case, we use the following decision rule:\n\n\\begin{equation}\n \\hat{y}=\\begin{cases}\n 1 & \\text{ if } t \\geq 0 \\\\\n 0 & \\text{ if } t < 0\n \\end{cases}\n\\end{equation}\n\n\n\n\n\n\nThere are limitations of gradient descent. It can get stuck in local minima, it is sensitive to the initial condition, and for a large dataset, it is computationally expensive \\cite{mehta2019high}. It is alleviated through stochasticity, for instance, by only taking the gradient of a subset of data called mini-batches. \n\n\\subsubsection{Stochastic Gradient descent with mini-batches}\\label{subsec:SGD}\nIf there are n samples in total, and the mini-batch size set is M, there are n/M possible mini-batches $B_k $ where $k \\in (1,2,..n/M)$. In this case, the gradient descent is approximated in each cycle over the mini-batches using a single mini-batch. The approximated gradient descent over a single batch , $c_i(\\mathbf{x_i},\\beta)$, is the gradient used to update the parameter. We denote the approximated gradient by $\\nabla_\\beta C^{MB}(\\beta)$ written as, \n\n\\begin{equation}\n \\nabla_{\\beta} C^{MB}(\\beta) = \\sum_{i\\in B_k} \\nabla_\\beta c_i(\\textbf{x}_i, \\beta)\n\\end{equation}\n\n\nThe SGD with mini-batches equation is given by, \n\n\\begin{align}\n g_k &= \\nabla_{\\beta} C^{MB}(\\beta)\\\\\n\\beta_{k+1} &= \\beta_k - \\eta_k g_k\n\\end{align}\n\n\n\\subsubsection{Support Vector Machine}\\label{subsubsec:SVM}\nFundamentally support vector machine (SVM) is a two-class classifier. Since the problem at hand consists of two classes, benign and malignant, the Wisconsin breast cancer data is a good candidate to test SVM. SVM classifier determines a decision boundary by choosing parameters that maximize the margin. This constraint optimization problem is solved using Lagrange multipliers that follow Karush-Kuhn-Tucker conditions \\cite{bishop2006pattern}. A dual representation of the Lagrangian form is expressed in terms of the kernel and obtained by taking the gradient of the Lagrangian form with respect to the parameters and setting this gradient to zero. The new data points are classified using the trained model by evaluating the signs of the output. To test SVM, we use scikit's built-in functionality. ", "meta": {"hexsha": "f10a53a2b7ae750dc21a3c4f225d86e48a3fa0bd", "size": 6044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/report/sections/method_logistic_regression.tex", "max_stars_repo_name": "am-kaiser/CompSci-Project-1", "max_stars_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documentation/report/sections/method_logistic_regression.tex", "max_issues_repo_name": "am-kaiser/CompSci-Project-1", "max_issues_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-11-01T08:32:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-16T19:51:18.000Z", "max_forks_repo_path": "documentation/report/sections/method_logistic_regression.tex", "max_forks_repo_name": "am-kaiser/CompSci-Project-1", "max_forks_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-17T10:51:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T10:51:25.000Z", "avg_line_length": 76.5063291139, "max_line_length": 867, "alphanum_fraction": 0.7352746525, "num_tokens": 1695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561721629777, "lm_q2_score": 0.9219218364639713, "lm_q1q2_score": 0.893209661509946}} {"text": "\\chapter{Separation of Variables}\nSeparation of variables is a technique which can be used to solve both ODEs and PDEs. The basic idea for an equation in two variables is to rewrite the equation so that each of the two variables is located on different sides of an equality sign, and since both sides of the equation depend on different variables, the two sides must be equal to a constant. We introduce this idea with the simple first order linear ODE\n\\begin{eqnarray}\\label{eq:simpleode}\n\\ \\frac{dy}{dt}=y.\n\\end{eqnarray}\nAs long as $y(t) \\neq 0$ for any value of $t$, we can formally separate variables and rewrite eq.\\ \\eqref{eq:simpleode} as\n\\begin{eqnarray}\n\\ \\frac{dy}{y}=dt.\n\\end{eqnarray}\nNow we can solve for $y(t)$ by integrating both sides\n\\begin{eqnarray}\n\\int{\\frac{dy}{y}}&=&\\int{dt} \\\\\n\\ln{y}+a&=&t+b \\\\\ne^{\\ln{y}+a}&=&e^{t+b} \\\\\ne^{\\ln{y}}e^{a}&=&e^te^b \\\\\ny&=&\\frac{e^b}{e^a} e^t \\\\\ny(t)&=&c e^t.\n\\end{eqnarray}\nWhere $a$, $b$, and $c$ are arbitrary constants of integration. \n\nWe now perform a similar example for a linear partial differential equation. The heat equation is \n\\begin{equation}\nu_t=-u_{xx}.\n\\end{equation}\nWe suppose that $u=X(x)T(t)$, so that we obtain\n\\begin{equation}\nX(x)\\frac{\\mathrm{d}T}{\\mathrm{d}t}(t)=-\\frac{\\mathrm{d}^2X}{\\mathrm{d}x^2}(x)T(t).\n\\end{equation}\nWe can rewrite this as\n\\begin{equation}\n\\frac{\\frac{\\mathrm{d}T}{\\mathrm{d}t}(t)}{T(t)}=\\frac{\\frac{\\mathrm{d}^2X}{\\mathrm{d}x^2}(x)}{X(x)}=-C,\n\\end{equation}\nwhere $C$ is a constant independent of $x$ and $t$. The two sides can be integrated separately to get $T(t)=\\exp(-Ct)$ and either $X(x)=\\sin(\\sqrt{C}x)$ or $X(x)=\\cos(\\sqrt{C}x)$. Since the heat equation is linear, one can then add different solutions to the heat equation and still obtain a solution of the heat equation. Hence solutions of the heat equation can be found by\n\\begin{equation}\n\\sum_n \\alpha_n\\exp(-C_nt)\\sin(\\sqrt{C_n}x) + \\beta_n\\exp(-C_nt)\\cos(\\sqrt{C_n}x)\n\\end{equation}\nwhere the constants $\\alpha_n$, $\\beta_n$ and $C_n$ are appropriately chosen. Convergence of such series to an actual solution is studied in mathematics courses on analysis (see for example Evans~\\cite{Eva10} or Renardy and Rogers~\\cite{RenRog04}), however the main ideas necessary to choose the constants, $\\alpha_n$, $\\beta_n$ and $C_n$ and hence construct such solutions are typically encountered towards the end of a calculus course or at the beginning of a differential equations course, see for example Courant and John~\\cite{CouJoh98} or Boyce and DiPrima~\\cite{BoyDip10}. Here, we consider the case where $x\\in[0,2\\pi]$, and for which we have periodic boundary conditions. In this case $\\sqrt{C_n}$ must be integers, which we choose to be non-negative to avoid redundancies. At time $t=0$, we shall suppose that the initial condition is given by \n\\begin{equation}\nu(x,t=0)=f(x).\n\\end{equation}\nNow, \n\\begin{align}\n&{} \\int_0^{2\\pi}\\sin(nx)\\sin(mx)=\\left\\{{\\pi\\quad m=n}\\atop{0 \\quad m\\ne n}\\right.,\n\\\\&{} \\int_0^{2\\pi}\\cos(nx)\\cos(mx)=\\left\\{{\\pi\\quad m=n}\\atop{0 \\quad m\\ne n}\\right.,\n\\end{align}\nand\n\\begin{align}\n&{} \\int_0^{2\\pi}\\cos(nx)\\sin(mx)=0.\n\\end{align}\nThus we can consider the trigonometric polynomials as being orthogonal vectors. It can be shown that a sum of these trigonometric polynomials can be used to approximate a wide class of periodic functions on the interval $[0,2\\pi]$; for well behaved functions, only the first few terms in such a sum are required to obtain highly-accurate approximations. Thus, we can suppose that\n\\begin{equation}\nf(x)=\\sum_n \\alpha_n\\sin(\\sqrt{C_n}x) + \\beta_n\\cos(\\sqrt{C_n}x).\n\\end{equation}\nMultiplying the above equation by either $\\sin(\\sqrt{C_n}x)$ or $\\cos(\\sqrt{C_n}x)$ and using the orthogonality of the functions, we deduce that\n\\begin{equation}\n\\alpha_n=\\frac{\\int_0^{2\\pi}f(x)\\sin(\\sqrt{C_n}x)\\mathrm{d}x}{\\int_0^{2\\pi}\\sin^2(\\sqrt{C_n}x)\\mathrm{d}x}\n\\end{equation}\nand\n\\begin{equation}\n\\beta_n=\\frac{\\int_0^{2\\pi}f(x)\\cos(\\sqrt{C_n}x)\\mathrm{d}x}{\\int_0^{2\\pi}\\cos^2(\\sqrt{C_n}x)\\mathrm{d}x}.\n\\end{equation}\n\nMost ODEs and PDEs of practical interest will not be separable. However, the ideas behind separation of variables can be used to allow one to find series solutions to a wide class of PDEs. These series solutions can also be found numerically and are what we will use to find approximate solutions to PDEs, and so the ideas behind this simple examples are quite useful.\n\n%%%%%%%\n% Section\n%%%%%%%\n\\section{Exercises}\n\\begin{enumerate}\n\\item[1)] Solve the ordinary differential equation\n$$u_t=u(u-1)\\quad u(t=0)=0.8$$\nusing separation of variables.\n\\item[2)] \n\\begin{enumerate}\n\\item[a)] Use separation of variables to solve the partial differential equation \n$$u_{tt}=u_{xx}$$\nwith\n$$u(x=0,t)=u(x=2\\pi,t),$$\n$$u(x,t=0)=\\sin(6x)+\\cos(4x)$$\nand\n$$u_t(x,t=0)=0.$$\n\\item[b)] Create plots of your solution at several different times and/or create an animation of the solution you have found.\\footnote{Your solution should involve only a few modes and so you should be able to use a wide variety of software to create plots, for example a graphing calculator, a spreadsheet program such as Excel, Mathematica, Wolfram Alpha, Matlab, Maple, Python, Sage etc. You can use Wolfram Alpha and Sage online.} \n\\item[c)] The procedure required to find the coefficients in the Fourier series expansion for the initial condition can become quite tedious/intractable. Consider the initial condition $u(x,t=0)=\\exp(\\sin(x))$. Explain why it would be difficult to compute the Fourier coefficients for this by hand. Also explain why it would be nice to have an algorithm or computer program that does this for you.\n\\end{enumerate}\n\\end{enumerate}\n", "meta": {"hexsha": "65fe3abec8c6b40c935df6aa29f2404b8eb3f241", "size": 5661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SeparationOfVariables/SeparationOfVariables.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "SeparationOfVariables/SeparationOfVariables.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "SeparationOfVariables/SeparationOfVariables.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 65.8255813953, "max_line_length": 854, "alphanum_fraction": 0.7286698463, "num_tokens": 1760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620539235895, "lm_q2_score": 0.9304582632076909, "lm_q1q2_score": 0.8930185337863892}} {"text": "\\section{Random Vectors}\n\n\nA random vector $\\mathbf X= \\left(X^{(1)},\\dots ,X^{(d)}\\right)^ T$ of dimension $d \\times 1$ is a vector-valued function from a probability space $\\omega$ to $\\mathbb {R}^ d$:\\\\\n\n$ \\mathbf{X}\\, \\, :\\, \\Omega \\longrightarrow \\mathbb {R}^ d$\\\\\n\n$ \\omega \\longrightarrow \\begin{pmatrix} X^{(1)}(\\omega ) \\\\ X^{(2)}(\\omega )\\\\ \\vdots \\\\ X^{(d)}(\\omega )\\end{pmatrix}$\\\\\n\nwhere each $\\, X^{(k)}\\ $, is a (scalar) random variable on $\\Omega$. \\\\\n\nPDF of $\\mathbf X$: joint distribution of its components $X^{(1)},\\, \\ldots ,\\, X^{(d)}$. \\\\\n\nCDF of $\\mathbf X$:\\\\\n\n$\\mathbb {R}^ d \\rightarrow [0,1]$\\\\\n\n$ \\mathbf{x} \\mapsto \\mathbf{P}(X^{(1)}\\leq x^{(1)},\\ldots ,\\, X^{(d)}\\leq x^{(d)}).$\\\\\n\nThe sequence $\\mathbf{X}_1, \\mathbf{X}_2,\\ldots$ converges in probability to $\\mathbf{X}$ if and only if each component of the sequence $\\, X_1^{(k)},X_2^{(k)},\\ldots \\,$ converges in probability to $\\, X^{(k)}$.\n\n\n\\subsection*{Expectation of a random vector}\nThe expectation of a random vector is the elementwise expectation. Let $\\mathbf X$ be a random vector of dimension $d \\times 1$.\\\\\n\n$ \\mathbb E[\\mathbf X] = \\begin{pmatrix} \\mathbb E[X^{(1)}]\\\\ \\vdots \\\\ \\mathbb E[X^{(d)}]\\end{pmatrix}.$\\\\\n\nThe expectation of a random matrix is the expected value of each of its elements. Let $X=\\{X_{ij}\\}$ be an $n \\times p$ random matrix. Then $\\mathbb{E}[X]$, is the $n \\times p$ matrix of numbers (if they exist):\\\\\n\n$\\mathbb{E}[X]= \\begin{bmatrix}\n \\mathbb{E}[X_{11}] & \\mathbb{E}[X_{12}] & \\dots & \\mathbb{E}[X_{1p}] \\\\\n \\mathbb{E}[X_{21}] & \\mathbb{E}[X_{22}] & \\dots & \\mathbb{E}[X_{2p}] \\\\\n \\vdots & \\vdots &\\ddots & \\vdots \\\\\n \\mathbb{E}[X_{n1}] & \\mathbb{E}[X_{n2}] & \\dots & \\mathbb{E}[X_{np}] \\\\\n\\end{bmatrix}$\\\\\n\nLet $X$ and $Y$ be random matrices of the same dimension, and let $A$ and $B$ be conformable matrices of constants.\\\\\n\n$\\mathbb{E}[X + Y] = \\mathbb{E}[X] + \\mathbb{E}[Y]$\\\\\n$\\mathbb{E}[AXB] = A \\mathbb{E}[X] B$\\\\\n\n\n\\subsection*{Covariance Matrix}\nLet $X$ be a random vector of dimension $d \\times 1$ with expectation $\\mu _{X}$. \n\nMatrix outer products!\\\\ \n\n$\\Sigma =\\mathbb E[(X- \\mu _{X})(X- \\mu _{X})^ T] =$\\\\\n\n$\\mathbb{E} \\begin{pmatrix} \\begin{bmatrix} \n\nX_1 - \\mu_1\\\\\nX_2 - \\mu_2\\\\\n\\ldots\\\\\nX_d - \\mu_d\\\\\n\n\\end{bmatrix} \\begin{bmatrix} X_1 - \\mu_1, X_2 - \\mu_2,\\ldots, X_d - \\mu_d \\end{bmatrix} \\end{pmatrix}$\\\\\n\n$\\Sigma = Cov (X) = \\begin{bmatrix}\n\\sigma_{11} & \\sigma_{12} &\\ldots & \\sigma_{1d} \\\\\n\\sigma_{21} & \\sigma_{22} &\\ldots & \\sigma_{2d} \\\\\n\\vdots & \\vdots &\\ddots & \\vdots \\\\\n\\sigma_{d1} & \\sigma_{d2} &\\ldots & \\sigma_{dd} \\\\\n\n\\end{bmatrix}$\\\\\n\nThe covariance matrix $\\Sigma$ is a $d \\times d$ matrix. It is a table of the pairwise covariances of the elemtents of the random vector. Its diagonal elements are the variances of the elements of the random vector, the off-diagonal elements are its covariances. Note that the covariance is commutative e.g. $\\sigma_{12} = \\sigma_{21}$ \\\\\n\nAlternative forms:\\\\\n\n$\\Sigma = \\mathbb {E}[XX^ T] - \\mathbb {E}[X]\\mathbb {E}[X]^ T =\\\\ = \\mathbb {E}[XX^ T] - \\mu _{X}\\mu _{X}^ T$\\\\\n\nLet the random vector $X \\in \\mathbb{R}^d$ and $A$ and $B$ be conformable matrices of constants.\\\\\n\n$Cov(AX + B) = Cov(AX) = A Cov(X) A^T = A \\Sigma A^T$\n\nEvery Covariance matrix is positive definite.\\\\\n\n$\\Sigma \\prec 0$\\\\\n\n\\subsection*{Gaussian Random Vectors}\n\n\nA random vector $\\mathbf{X}=(X^{(1)},\\ldots ,X^{(d)})^ T\\,$ is a Gaussian vector, or multivariate Gaussian or normal variable, if any linear combination of its components is a (univariate) Gaussian variable or a constant (a “Gaussian\" variable with zero variance), i.e., if $\\alpha ^ T \\mathbf{X}$ is (univariate) Gaussian or constant for any constant non-zero vector $\\alpha \\in \\mathbb {R}^ d$.\n\n\\subsection*{Multivariate Gaussians}\n\nThe distribution of, $X$ the $d$-dimensional Gaussian or normal distribution, is completely specified by the vector mean $\\mu =\\mathbb E[\\mathbf{X}]= (\\mathbb E[X^{(1)}],\\ldots ,\\mathbb E[X^{(d)}])^ T$ and the $d \\times d$ covariance matrix $\\Sigma$. If $\\Sigma$ is invertible, then the pdf of $X$ is:\\\\\n\n$ f_{\\mathbf X}(\\mathbf x) = \\frac{1}{\\sqrt{\\left(2\\pi \\right)^ d \\text {det}(\\Sigma )}}e^{-\\frac{1}{2}(\\mathbf x-\\mu )^ T \\Sigma ^{-1} (\\mathbf x-\\mu )}, ~ ~ ~ \\\\ \\mathbf x\\in \\mathbb {R}^ d$\\\\\n\n\nWhere $\\text {det}(\\Sigma )$ is the determinant of $\\Sigma$, which is positive when $\\Sigma$ is invertible.\n\nIf $\\mu = 0$ and $\\Sigma$ is the identity matrix, then $X$ is called a standard normal random vector .\n\nIf the covariant matrix $\\Sigma$ is diagonal, the pdf factors into pdfs of univariate Gaussians, and hence the components are independent.\\\\\n\nThe linear transform of a gaussian $X \\thicksim N_d(\\mu,\\Sigma)$ with conformable matrices $A$ and $B$ is a gaussian:\\\\ \n\n$AX + B = N_d(A\\mu + b, A \\Sigma A^T)$\n\n\\subsection*{Multivariate CLT}\n\nLet $X_1, \\ldots, X_d \\in \\mathbb{R}^d$ be independent copies of a random vector $X$\nsuch that $\\mathbb{E}[x] = \\mu$ ($d \\times 1$ vector of expectations) and $Cov(X)= \\Sigma$\\\\\n\n$\\sqrt(n)(\\bar{X_n}-\\mu) \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\Sigma)$\\\\\n\n$\\sqrt(n) \\Sigma^{-1/2} \\bar{X_n}-\\mu \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,I_d)$\\\\\n\nWhere $\\Sigma^{-1/2}$ is the $d \\times d$ matrix such that $\\Sigma^{-1/2} \\Sigma^{-1/2} = \\Sigma^{1}$ and $I_d$ is the identity matrix.\\\\\n\n\\subsection*{Multivariate Delta Method}\n\nGradient Matrix of a Vector Function:\\\\\n\nGiven a vector-valued function $f:\\mathbb {R}^ d \\to \\mathbb {R}^ k$, the gradient or the gradient matrix of $f$, denoted by $\\nabla f$ , is the $d \\times k$ matrix:\\\\\n\n$ \\nabla f =\\\\ = \\begin{pmatrix} |& |& |& |\\\\ \\nabla f_1& \\nabla f_2& \\ldots & \\nabla f_ k\\\\ |& |& |& |\\\\ \\end{pmatrix} = \\\\\n= \\begin{pmatrix} \\frac{\\partial f_1}{\\partial x_1}& \\ldots & \\frac{\\partial f_ k}{\\partial x_1}\\\\ \\vdots & \\ldots & \\vdots \\\\ \\frac{\\partial f_1}{\\partial x_ d}& \\ldots & \\frac{\\partial f_ k}{\\partial x_ d} \\end{pmatrix}.$\\\\\n\nThis is also the transpose of what is known as the Jacobian matrix $\\mathbf{J}_ f$ of $f$.\\\\\n\nGeneral statement, given\\\\\n\n\\begin{itemize}\n\t\\item $\\left(\\mathbf{T}_ n\\right)_{n\\geq 1}$ a sequence of random vectors \n\t\\item satisfying $\\, \\sqrt{n} \\left(\\mathbf{T}_ n - \\vec{\\theta } \\right) \\xrightarrow [n\\to \\infty ]{(d)} \\mathbf{T}$,\n\n\t\\item a function $\\mathbf{g}:\\mathbb {R}^ d\\to \\mathbb {R}^ k$ that is continuously differentiable at $\\vec{\\theta }$,\n\n\\end{itemize}\n\nthen\\\\\n\n$ \\sqrt{n} \\left(\\mathbf{g}(\\mathbf{T}_ n) - \\mathbf{g}(\\vec{\\theta }) \\right) \\xrightarrow [n\\to \\infty ]{(d)} \\nabla \\mathbf{g}(\\vec{\\theta })^ T\\, \\mathbf{T}\\qquad$\\\\\n\nWith multivariate Gaussians and Sample mean:\\\\\n\nLet $\\mathbf{T}_ n=\\overline{\\mathbf{X}}_ n$ where $\\overline{\\mathbf{X}}_ n$ is the sample average of $\\, \\mathbf{X}_1,\\ldots ,\\mathbf{X}_ n\\, \\stackrel{iid}{\\sim }\\mathbf{X},\\,$ and $\\, \\vec{\\theta }=\\mathbb E[\\mathbf{X}].\\, \\,$ The (multivariate) CLT then gives $\\, \\mathbf{T}\\sim \\mathcal{N}(\\mathbf{0},\\Sigma _\\mathbf{X})$ where $\\, \\Sigma _\\mathbf{X}\\,$ is the covariance of $\\mathbf{X}.\\, \\,$ In this case, we have:\\\\\n\n$\\sqrt{n} \\left(\\mathbf{g}(\\mathbf{T}_ n) - \\mathbf{g}(\\vec{\\theta }) \\right) \\xrightarrow [n\\to \\infty ]{(d)} \\nabla \\mathbf{g}(\\vec{\\theta })^ T\\mathbf{T}\\,$\\\\\n\n$\\nabla \\mathbf{g}(\\vec{\\theta })^ T\\mathbf{T} \\sim \\, \\mathcal{N}\\left(0, \\nabla \\mathbf{g}(\\vec{\\theta })^ T \\Sigma _{\\mathbf{X}} \\nabla \\mathbf{g}(\\vec{\\theta })\\right)\\qquad$\\\\\n\n$(\\mathbf{T}\\sim \\mathcal{N}(\\mathbf{0},\\Sigma _\\mathbf{X}))$\\\\", "meta": {"hexsha": "3d8882f37f46399938e53da38f96f3518187aa5f", "size": 7508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Multivariate_RV.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/Multivariate_RV.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/Multivariate_RV.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 51.074829932, "max_line_length": 424, "alphanum_fraction": 0.626265317, "num_tokens": 2815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025386, "lm_q2_score": 0.9273632956467158, "lm_q1q2_score": 0.8906036943387193}} {"text": "\\subsection{Motivation}\n\\begin{definition}\n\tA first order ordinary differential equation is called \\textit{separable} if it can be written in the form $y' = f\\p{t}g\\p{y}$.\n\\end{definition}\nSeparable equations appear relatively often in real life. One scenario is in radioactive decay of nuclei.\n\\par\\bigskip\nSuppose $N\\p{t}$ is the amount of a nuclei at a time $t$. In our model, we assume that the amount of decay is proportional to the amount of nuclei $N$ and the length of time $\\Delta t$. Then\n\\normalskip\n\\begin{align*}\n\t\\Delta N &= N\\p{t + \\Delta t} - N\\p{t} \\approx -\\lambda N\\p{t} \\Delta t \\\\\n\t\t N' &= \\lim_{\\Delta t\\to0} \\frac{N\\p{t + \\Delta t} - N\\p{t}}{\\Delta t} = -\\lambda N\n\\end{align*}\nThe equation can then be solved as follows:\n\\begin{align*}\n\tN' &= -\\lambda N \\\\\n\t\\frac{\\diff{N}}{\\diff{t}} &= -\\lambda N \\\\\n\t\\frac{\\diff{N}}{N} &= -\\lambda \\, \\diff{t}, \\qquad N \\neq 0\\text{, but note that it is a solution to the ODE} \\\\\n\t\\int \\frac{\\diff{N}}{N} &= \\int -\\lambda \\, \\diff{t} \\\\\n\t\\ln\\abs{N} &= -\\lambda t + C_0 \\\\\n\t\\abs{N} &= Ce^{-\\lambda t}, \\qquad C = e^{C_0} > 0 \\\\\n\tN &=\n\t\\begin{cases}\n\t\t\\phantom{-}Ce^{-\\lambda t}, & N\\p{t_0} > 0 \\\\\n\t\t-Ce^{-\\lambda t}, & N\\p{t_0} < 0\n\t\\end{cases}\n\\end{align*}\nIf we allow $C$ to take on any real value, then the general solution to the ODE can be written as \\[ N\\p{t} = Ce^{-\\lambda t}. \\]\n\\clearpage\n\\begin{example}\n\t\\noskip\n\t\\begin{flalign*}\n\t\ty' &= t^2y^2 \\\\\n\t\t\\frac{\\diff{y}}{y^2} &= t^2 \\, \\diff{t} \\\\\n\t\t\\int \\frac{\\diff{y}}{y^2} &= \\int t^2 \\, \\diff{t} \\\\\n\t\t-\\frac{1}{y} &= \\frac{1}{3}t^3 + C \\\\\n\t\ty &= -\\frac{1}{\\frac{1}{3}t^3 + C}\n\t\\end{flalign*}\n\tNote that $y\\p{t} = 0$ is also a solution.\n\\end{example}\n\n\\subsection{``Proof''}\nSuppose we have the separable ODE \\[ y' = \\frac{f\\p{t}}{g\\p{y}}. \\] Then\n\\normalskip\n\\begin{align*}\n\tg\\p{y} y' &= f\\p{t} \\\\\n\t\\int g\\p{y} y' \\, \\diff{t} &= \\int f\\p{t} \\, \\diff{t} \\\\\n\t\\int g\\p{y} \\, \\diff{y} &= \\int f\\p{t} \\, \\diff{t}, \\qquad y = y\\p{t} \\implies \\diff{y} = \\frac{\\diff{y}}{\\diff{t}} \\, \\diff{t}\n\\end{align*}\nwhich is the same result from using separation of variables.\n\n\\subsection{Using Definite Integration (Newton's Law of Cooling)}\nNewton's Law of Cooling states that the change in temperature of an object over time is directly proportional to the difference between the object's current temperature $T$ and the ambient temperature $A$. Mathematically, \\[ \\frac{\\diff{T}}{\\diff{t}} = -k\\p{T - A}. \\] Suppose we had the initial condition $T\\p{t_0} = T_0$. Then we can solve the IVP using separation of variables:\n\\begin{align*}\n\t\\frac{\\diff{T}}{\\diff{t}} &= -k\\p{T - A} \\\\\n\t\\frac{\\diff{T}}{T - A} &= -k \\, \\diff{t}\n\\end{align*}\nInstead of finding the general solution and then solving for the constant, we can use definite integration to get the particular solution directly. As time goes from $t_0$ to $t$, temperature goes from $T_0$ to $T\\p{t}$. Thus,\n\\begin{align*}\n\t\\int_{T_0}^{T\\p{t} }\\frac{\\diff{u}}{u - A} &= \\int_{t_0}^{t} -k \\, \\diff{v} \\\\\n\t\\ln\\abs{T - A} - \\ln\\abs{T_0 - A} &= -k\\p{t - t_0} \\\\\n\tT\\p{t} &= A + \\p{T_0 - A}e^{-k\\p{t - t_0}}\n\\end{align*}\n\n\\subsection{Implicitly Defined Solutions}\nSometimes, we are unable to find an explicit solution to an ODE. I.e., we are unable to get a solution in the form of $y\\p{t} = f\\p{t}$. Consider the separable differential equation \\[ y' = \\frac{g\\p{t}}{f\\p{y}} \\] and that $f\\p{y}$ and $g\\p{t}$ have antiderivatives $F\\p{y}$ and $G\\p{t}$, respectively. Separation of variables yields\n\\begin{align*}\n\t\\int f\\p{y} \\, \\diff{y} &= \\int g\\p{t} \\, \\diff{t} + C \\\\\n\tF\\p{y} &= G\\p{t} + C \\\\\n\ty &= F^{-1}\\p{G\\p{t} + C}\n\\end{align*}\nIf we are unable to find $F^{-1}$, then we will not be able to find an explicit solution for the differential equation.\n\\par\\pagebreak\n\\begin{example}\n\t\\noskip\n\t\\begin{align*}\n\t\tx' &= \\frac{x^2}{\\p{1 + x}t} \\\\\n\t\t\\int \\frac{1}{x^2} + \\frac{1}{x} \\, \\diff{x} &= \\int \\frac{1}{t} \\, \\diff{t} \\\\\n\t\t-\\frac{1}{x} + \\ln\\abs{x} &= \\ln\\abs{t} + C\n\t\\end{align*}\n\tWe are unable to solve for $x$, so we cannot find an explicitly defined solution.\n\\end{example}", "meta": {"hexsha": "ea2dd3d72b9822cd4d66c388e9bb947e4e1c1c54", "size": 4041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/separable.tex", "max_stars_repo_name": "stevenktruong/differential-equations-intro", "max_stars_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/separable.tex", "max_issues_repo_name": "stevenktruong/differential-equations-intro", "max_issues_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/separable.tex", "max_forks_repo_name": "stevenktruong/differential-equations-intro", "max_forks_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8888888889, "max_line_length": 380, "alphanum_fraction": 0.6159366493, "num_tokens": 1592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.9489172612371767, "lm_q1q2_score": 0.8884569983307066}} {"text": "\\section{Geometric meaning of transpose}\n\nLet's consider two vectors, $a$ and $b$ and an action $M$.\nWe apply the action $M$ to the first vector $a$ and\nconsider the scalar product $\\langle Ma, b\\rangle$.\nWhat should be the equivalent action $N$ on $b$ that whould result\nin exactly the same scalar product?\nThis action $N$ can be found from the equation\n\\[\n\\langle Ma, b \\rangle = \\langle a, Nb \\rangle.\n\\]\n\nWe call the action $N$ as transpose of the action $M$.\nOur definition explains immediately why it is called transpose:\nthe letter $M$ has changed its position.\nThis definition is consistent with classical one, as\n\\[\n\\langle Ma, b\\rangle = (Ma)^T b = a^T (M^T b) = \\langle a, M^T b \\rangle\n\\]\n\nLet's find some transposes using geometric approach.\n\nExample 1.\n\nConsider the action $R$ on $\\mathbb{R}^2$ that rotates arbitrary vector $a$ clockwise by the angle $\\alpha$.\nWhat is the equivalent action on vector $b$? We can compensate the clockwise rotation $R$ of $a$\nby a counterclockwise rotation of $b$. Under both rotations the lengths are preserved\nand the angle between $a$ and $b$ is changed in the same way.\n\nSo the transpose of clockwise rotation is the counterclockwise rotation by the same angle.\n\nExample 2.\n\nConsider the action $U$ on $\\mathbb{R}^3$ that reflects arbitrary vector $a$ across plane $\\alpha$.\nThe equivalent action on the other vector $b$ would be this reflection $U$ itself!\nConsider two scalar products, $\\langle Ua, b \\rangle$ and $\\langle a, Ub \\rangle$.\nWe see that vectors $a$ and $Ub$ are reflected vectors $Ua$ and $b$.\nSo the scalar products are equal.\n\nThe transpose of reflection is the same reflection, so $U^T=U$.\n\nExample 3.\n\n\nConsider the action $H$ on $\\mathbb{R}^3$ that projects arbitrary vector $a$ on the plane $\\alpha$.\nLet $\\hat a$ and $\\hat b$ be the projections of vectors $a$ and $b$.\nScalar product is a linear function, and $\\hat a$ is orthogonal to $b - \\hat b$, so\n\\[\n\\langle Ha, b \\rangle = \\langle \\hat a, \\hat b + (b-\\hat b) \\rangle = \\langle \\hat a, \\hat b \\rangle\n\\]\nBy the same reasoning $\\langle a, Hb \\rangle = \\langle \\hat a, \\hat b \\rangle$.\n\nAnd the transpose of projection is the same projection, $H^T=H$.\n\nThe equality $\\langle Ha, b\\rangle = \\langle \\hat a, \\hat b \\rangle$ holds only for orthogonal projection,\nand not for the oblique one.\nSo $H^T \\neq H$ for oblique projections.\n\n\nThe idea of a transpose may be also illustrated if one knows about singular value decomposition.\nFrom singular value decomposition $A = U\\Sigma V^T$ every action $A$ can be decomposed in rotation followed by scaling and\nsecond rotation.\nThe transpose of rotation is inverse rotation. The transpose of scaling is the same scaling.\nSo the transpose of every action $A$ is the inverse of second rotation, the same scaling and inverse of first rotation.\nIt follows by the way that $\\det A = \\det A^T$ as rotations do not change volume and scaling is unaffected by transpose.\n\nTODO: add pictures\n\nTODO: Why $H^2=H$ and $H^T=H$ is sufficient for projection?\n\n\\url{https://math.stackexchange.com/questions/598258}\n", "meta": {"hexsha": "ad1150cad62bfeb975544b7ce09c3dbb9f5db9d4", "size": 3068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/transpose.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/transpose.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/transpose.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 42.6111111111, "max_line_length": 122, "alphanum_fraction": 0.7314211213, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561730622296, "lm_q2_score": 0.9149009532527358, "lm_q1q2_score": 0.8864074362994314}} {"text": "\n\\subsection{The orthogonal projection}\n\nin inner product space, orthogonal projection\n\n\\(p_uv = \\dfrac{}{{v,v}}v\\)\n\nwe then know that \\(o=v-p_uv\\) is orthogonal to \\(u\\).\n\n\n\\subsection{Orthogonal set / Orthogonal basis}\n\nif a set of vectors are all orthogonal, they form an orthogonal set\nif the set spans the vector space, it is an orthogonal basis.\n\n\\subsection{The Gram-Schmidt process}\n\ncan we form an orthogonal basis from a non-orthogonal basis? yes, using gram schmidt\n\nwe have \\(x_1\\), \\(x_2\\) \\(x_3\\) etc\nwe want to make \\(v_1\\), \\(v_2\\) etc orthognal\n\n\\(v_1 = x_1\\)\n\\(v_2 = x_2 - p_{x_2}v_1\\)\n\\(v_3 = x_3 - p_{x_3}v_1 - p_{x_3}v_2v\\)\n\n", "meta": {"hexsha": "9afd7fee823eea6417e628e4a005aaf4c69cf259", "size": 651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-07-orthogonal_projection.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/04-07-orthogonal_projection.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/04-07-orthogonal_projection.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1111111111, "max_line_length": 84, "alphanum_fraction": 0.6927803379, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9740426412951847, "lm_q2_score": 0.9099070042057362, "lm_q1q2_score": 0.886288221709544}} {"text": "\n\\subsection{Softplus}\n\n\\subsubsection{The function}\n\n\\(a(z)=\\ln (1+e^z)\\)\n\n\\subsubsection{The derivative}\n\nIts derivative is the sigmoid function:\n\n\\(a'(z)=\\dfrac{1}{1+e^{-z}}\\)\n\n\\subsubsection{Notes}\n\nThe softplus function is a smooth approximation of the ReLU function.\n\nUnlike the ReLU function, Softplus does not induce sparcity.\n\n", "meta": {"hexsha": "49d03cb37ed045f7634ca1af446fa41acec2754c", "size": 336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-06-softPlus.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-06-softPlus.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-06-softPlus.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8, "max_line_length": 69, "alphanum_fraction": 0.7291666667, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9653811631528336, "lm_q2_score": 0.9161096227509861, "lm_q1q2_score": 0.8843949731868506}} {"text": "\\section{Calculus of Variations}\nExample: shortest path between two points\n$(x_1, y_1)$ and $(x_2, y-2)$.\nEach segment is of length\n\\begin{align}\n ds &= \\sqrt{dx^2 + dy^2}\\\\\n &= dx \\sqrt{1 + {\\left( \\frac{dy}{dx} \\right)}^2}\n\\end{align}\nso the total length is\n\\begin{align}\n L &=\n \\int ds\\\\\n &=\n \\int_{x_1}^{x_2} dx\\,\n \\sqrt{1 + {\\left( \\frac{dy}{dx} \\right)}^2}.\n\\end{align}\nThe question is:\nHow to find the $y(x)$ for which $L$ is smallest?\n\n\nFor any function $y(x)$ the integral will have some value,\nso $L$ is a function of the function $y(x)$.\nWe say that $L$ is a ``functional'' of $y(x)$.\nA functional is just a function of a function.\n\nLet $y=y_0(x)$ be the function that minimizes $L$.\nLet us consider infinitesimal deviations from the path\n\\begin{align}\n y(x) &= y_0(x) + \\epsilon \\eta(x)\n\\end{align}\nfor some arbitrary $y$ except that\n$\\eta(x_1) = \\eta(x_2) = 0$.\n\nBy definition $y_0$ is the shortest path,\nso any other path much be longer.\n\\begin{align}\n L\\left( y_0 + \\epsilon\\eta(x) \\right) > L(y_0)\n\\end{align}\nfor any $\\eta(x)$.\n\nExpanding out to first order in $\\epsilon$,\nwe have\n\\begin{align}\n L\\left( y_0 + \\epsilon\\eta \\right)\n &=\n \\int dx\\,\n \\sqrt{1 + {\\left[ y_0'(x) + \\epsilon\\eta'(x) \\right]}^2}\\\\\n &=\n \\int dx\\,\n \\sqrt{%\n 1 + y_0'^2 + 2\\epsilon y_0' \\eta'\n }\n + \\mathcal{O}\\left( \\epsilon^2 \\right)\n\\end{align}\nLet's write this in a more convenient form\n\\begin{align}\n L\\left( y_0 + \\epsilon \\eta \\right) &=\n \\int dx\\, \\sqrt{%\n 1 + {\\left( y_0' \\right)}^2\n }\n {\\left[\n 1 + \\frac{2\\epsilon y_0' \\eta'}{1 + y_0'^2}\n \\right]}^{1/2}\n\\end{align}\nNow we expand using the binomial theorem.\n\\begin{align}\n L\\left( y_0 + \\epsilon \\eta \\right) &=\n \\underbrace{%\n \\int dx\\, \\sqrt{%\n 1 + y_0'^2\n }\n }_{L(y_0(x))}\n +\n \\int dx\\,\n \\sqrt{1 + y_0'^2}\\left[ \n \\frac{\\epsilon y_0' \\eta'}{1 + y_0'^2}\n \\right]\\\\\n &=\n L[y_0(x)]\n +\n \\int_{x_1}^{x_2} dx\\,\n \\frac{\\epsilon y_0' \\eta'}{\\sqrt{1 + y_0'^2}}\n\\end{align}\nSo we have this thing depending on the derivative of $\\eta$,\nbut it is arbitrary except at the end points.\nSo the trick is to use integration by parts,\nand we know $\\eta$ vanishes at the boundaries.\nSo let's integrate this by parts.\nWe're moving the derivative to the other terms,\nand that leaves us with a boundary term that goes to zero when\n$\\eta(x_1)=\\eta(x_2)=0$.\nOnce we integrate by parts,\nthe first term doesn't change\n\\begin{align}\n L\\left( y_0 + \\epsilon \\eta \\right) &=\n L[y_0(x)]\n -\n \\epsilon\n \\int_{x_1}^{x_2} dx\\,\n \\frac{d}{dx}\\left[ \n \\frac{y_0'}{\\sqrt{1 + y_0'^2}}\n \\right]\\eta\n\\end{align}\nNow we have just evaluated this term\n$L\\left( y_0 + \\epsilon \\eta \\right)$\n\nNow what we are requiring is that\n$L\\left( y_0 + \\epsilon\\eta(x) \\right) > L(y_0)$.\nOn the other hand,\nwe have that it is $L(y_0)$ plus some small quantity with an $\\epsiilon$\nin it.\nAnd $\\epsilon$ can be either positive or negative,\nand if that integral was positive,\nthen I could choose $\\epsilon$ to be negative,\nand that inequality would be violated.\nConversely,\nif the integral was negative,\nthen I could choose $\\epsilon$ to be positive\nand that inequality would again be violated.\nSo the only way for the inequality to hold is that this is stationary with\nrespect to $\\epsilon$.\nThis means that the integral must be zero,\nand the $\\mathcal{O}\\left( \\epsilon^2 \\right)$\nterms are what gives you the extremising behaviour.\n\nRecall in ordinary calculus,\nif you have a function $y(x)$,\nyou can expand\n\\begin{align}\n y(x + \\Delta x) &=\n y(x) + \\Delta x \\frac{dy}{dx}\n + \\frac{1}{2}\\left( \\Delta x \\right)^2 \\frac{d^2y}{dx^2}\n\\end{align}\nand the only way this could be a maximum is if\n$\\frac{dy}{dx}=0$.\nOtherwise, I could always choose $\\Delta x$ to be the right sign\nto violate the fact that $x$ is the maximum.\nThat's why you must take the second derivative to determine whether it is a\nmaximum or a minimum.\n\nSomething similar is true here in the functional case.\nThe $\\epsilon^2$ does not depend on the sign of $\\epsilon$.\nThe only thing you can really be sure is that you have found an extremum.\nThe fact that it is a minimum comes from common sense.\n\nWhat we're going to do is require that the integral is equal to zero.\n\\begin{align}\n L\\left( y_0 + \\epsilon \\eta \\right) &=\n L[y_0(x)]\n -\n \\epsilon\n \\underbrace{\n \\int_{x_1}^{x_2} dx\\,\n \\frac{d}{dx}\\left[ \n \\frac{y_0'}{\\sqrt{1 + y_0'^2}}\n \\right]\\eta\n }_{=0}\\\\\n \\int_{x_1}^{x_2} dx\\,\n \\frac{d}{dx}\\left[ \n \\frac{y_0'}{\\sqrt{1 + y_0'^2}}\n \\right]\\eta\n &= 0\n\\end{align}\nLet me stop there now.\nI'm not actually proving it's a minimum,\nI'm just proving it's a stationary point.\nTo prove it's a minimum,\nyou need to show one more term.\nYou can do it,\nbut it will be more work,\nwhich is not necessary to do.\n\nIt's kind of similar to functions.\nThe first derivative tells you if it's an extremum,\nand to tell you if it's a maximum or minimum,\nyou need to evaluate one more derivative.\n\n\\begin{question}\n Technical question.\n Wouldn't it make more sens if you wrote the original inequality\n as a greater than or equal to sign?\n\\end{question}\nThe fact that I've dropped the $\\epsilon^2$ terms.\n\n\\begin{question}\n Is it useful to say that you found an extremum but not necessarily a\n minimum.\n\\end{question}\nIn this question,\nit's physical insight that tells us any extremum you find is a minimum.\nIn other cases it's not so obvious.\nIn this kind of problem,\nonce you've found your stationary point,\nto prove it's a maximum or minimum,\nyou need to evaluate the second term.\nIt's a lot more work and we usually never do it.\n\nThere's this famous story that may be appropriate.\nWhen they were designing the famous SR-71 blackbird,\nthey wanted to maximize the range.\nThey computed the stationary point for the configuration of the shape,\nbut they never bothered to compute the second derivative,\nand it turned out to be the least efficient.\nThese theoreticians.\nI'm not sure it's true though.\nIt's classified so we will never know.\nGood thing about working in the defence industry.\n\nSince the sign of $\\epsilon$ is arbitrary,\nthe second term can be either positive or negative\nand so\n\\begin{align}\n \\int_{x_1}^{x_2}dx\\,\n \\frac{d}{dx}\\left[ \n \\frac{y_0'}{\\sqrt{1 + \\left( y_0' \\right)^2}}\n \\eta(x)\n \\right]\n\\end{align}\nhas to be true for any arbitrary function $\\eta(x)$.\nThis is crucial.\nAnd the only way for this to be true for any arbitrary function\n$\\eta(x)$\nis if\n\\begin{align}\n \\frac{d}{dx}\\left[\n \\frac{y_0'}{\\sqrt{1 + \\left( y_0' \\right)^2}}\n \\right] = 0\n\\end{align}\nfor every point on the path.\n\nSo here's the logic.\nSuppose this was non-zero at some point.\nLet's say at that point,\nthis thing was non-zero.\nThen you could choose an $\\eta(x)$\nwhich is zero everywhere except that near point.\nThen this would be non-zero.\nSo any point where this thing is non-zero,\njust choose an $\\eta(x)$ that is non-zero at that point,\nthen you'll make it non-zero.\nYou have so much freedom.\nThat's why the only way this integral is zero\nis if this thing is zero at every single point.\n\nSo we have reduced the problem we started with\nto solving a one-dimensional differential equation\n\\begin{align}\n \\frac{d}{dx}\\left[ \n \\frac{y_0'}{\\sqrt{1 + \\left( y_0' \\right)^2}}\n \\right] = 0\n\\end{align}\nwhich we can integrate to get\n\\begin{align}\n \\frac{y_0'}{\\sqrt{1 + \\left( y_0' \\right)^2}}\n = C\n\\end{align}\nfor some constant $C$.\nAfter some algebra, you get\n\\begin{align}\n y_0''^2 &=\n C(1 + y_0'^2)\n\\end{align}\nand since $C$ is arbitrary,\nwe conclude\n\\begin{align}\n y_0'^2 &= \\text{constant}\\\\\n \\implies \\qquad y_0' &= \\text{constant} = m\n\\end{align}\nwhich means\n\\begin{align}\n \\frac{dy_0}{dx} = m\n\\end{align}\nand so\n\\begin{align}\n y_0 = mx + c\n\\end{align}\nwhere $m$ and $c$ are constants.\nAnd that's just a straight line!\nSo you have convinced yourself that the shortest path between two points is a\nstraight line.\n\n\\section{Euler-Lagrange Equations}\nConsider the integral\n\\begin{align}\n S &=\n \\int_{x_1}^{x_2}\n f\\left[\n y(x), y'(x), x\n \\right]\n \\,dx\n\\end{align}\nand you're integrating that over $x$,\nwhere $y(x)$ is a curve that connects\n$(x_1,y_1)$ and $(x_2,y_2)$.\nso that\n$y(x_1)=y_1$ and $y(x_2)=y_2$.\nIn other words,\nthe end points are fixed.\nThe question is:\nWhat is the function $y(x)$ that extremizes the functional $S$.\n\nSo $S$ is a functional and the question is,\nwhat is the function $y(x)$ on which this is extremized,\nsubject the conditions of the values of $y(x)$ on the boundaries.\nVery similar to the problem we just saw.\n\nIn the shortest path problem we just studied,\nthis $f$ was \n\\begin{align}\n f(x) &= \\sqrt{1 + \\left( y' \\right)^2}\n\\end{align}\nand it didn't depend on $y$ or $x$ explicitly.\n\nNow we are studying the general case.\nWe did the special case with the shortest path problem,\nnow we are doing it with a general function $f$.\n\nNow how do we extremize the problem?\nWe will just how to do it.\n\nLet $y=y_0(x)$ correspond to the extremum.\nConsider infinitesimal deformations \n\\begin{align}\n y(x) &= y_0(x) + \\epsilon \\eta(x)\n\\end{align}\nwhere $\\epsilon$ is an infinitesimal number\nand $\\eta(x)$ is an arbitrary function.\n\nIf $s$ is extremized for $y=y_0(x)$,\nthen $\\frac{ds}{dz}=0$\nat $\\epsilon = 0$\nfor arbitrary $\\eta(x)$.\n\nSo I'm going to call this thing\n\\begin{align}\n S(y_0 + \\epsilon\\eta) &=\n \\int dx\\, f\\left(y + \\epsilon\\eta, y' + \\epsilon\\eta', x\\right)\n\\end{align}\nThis is a crucial step.\nThis is $S$ for an arbitrary function $f$.\nIf I choose $y$ to be $y_0 + \\epsilon\\eta$,\nthen the above is true.\n\nNow,\n\\begin{align}\n f(y + \\epsilon\\eta, y' + \\epsilon\\eta', x) &=\n f(y, y', \\eta)\n + \\epsilon \\eta {\\left( \\frac{\\partial f}{\\partial y} \\right)}_{y',x'}\n + \\epsilon \\eta' {\\left( \\frac{\\partial f}{\\partial y'} \\right)}_{y, x}\n\\end{align}\nThen\n\\begin{align}\n S[y_0 + \\epsilon\\eta] - S[y_0] &=\n \\epsilon\\int dx\\, \\left.\n \\left[\n \\eta \\left( \\frac{\\partial f}{\\partial y} \\right)\n + \\eta'\\left( \\frac{\\partial f}{\\partial y'} \\right)\n \\right]\n \\right|_{y=y_0(x)}\n\\end{align}\nNow just like what we did before,\nwe integrate by parts\nand we end up with\n\\begin{align}\n S[y_0 + \\epsilon\\eta] - S[y_0] &=\n \\epsilon \\int dx\\,\n \\eta\n \\left[\n \\frac{\\partial f}{\\partial y}\n -\n \\frac{d}{dx}\\left(\n \\frac{\\partial f}{\\partial y'}\n \\right)\n \\right]\n =0\n\\end{align}\nSince $\\eta$ is arbitrary,\nit must be that at every point\n\\begin{align}\n \\frac{\\partial f}{\\partial y}\n -\n \\frac{d}{dx}\\left(\n \\frac{\\partial f}{\\partial y'}\n \\right)\n = 0\n\\end{align}\nand this equation has a name.\nIt is the famous \\emph{Euler-Lagrange equation}.\nThis is one of the equations you are going to have to know.\n\nThis is the equation that is satisfied by the function $f$\nthat extremizes the functional $S[f]$ subject to the boundary conditions.\n\nThe steps we went through are actually exactly the same as that for the shortest\npath straight line.\nWe're just following the problem more generally.\nPreviously we solved it when this $f(y,y',x) = \\sqrt{1 + (y')62}$.\nBut now we used an arbitrary function and applied the stationary point\ncondition.\n\nAny questions?\nI want to stop here before I give examples.\n\n\\begin{example}[Shortest path]\n We want the minimize the length\n \\begin{align}\n L &= \\int_{x_1}^{x_2} dx\\,\n \\sqrt{1 + (y')^2}.\n \\end{align}\n\\end{example}\n\\begin{proof}\n The function is\n \\begin{align}\n f\\left( y, y', x \\right) &=\n \\sqrt{1 + \\left( y' \\right)^2}.\n \\end{align}\n Taking derivatives,\n \\begin{align}\n \\left( \\frac{\\partial f}{\\partial y} \\right)_{y', x} &= 0\\\\\n \\left( \\frac{\\partial f}{\\partial y} \\right)_{y', x} &=\n \\frac{y'}{\\sqrt{1 + y'^2}}\n \\end{align}\n Then using the Euler-Lagrange equation,\n \\begin{align}\n \\frac{d}{dx}\\left\\{\n \\frac{y'}{\\sqrt{1 + y'^2}}\n \\right\\}\n = 0\n \\end{align}\n which is what we got before.\n\\end{proof}\n\n\\subsection{Brachistochrone problem}\nI want to show the Brachistochrone problem,\nwhich is the most famous problem in the calculus of variations.\nIt's famous because this is the problem that led to\nthe entire theory of the calculus of variations.\nBernoulli was trying the solve this problem and\nhe invented the calculus of variations for this problem.\n\nLet's say I have a particle that slides down under gravity along some path\nwithout friction.\nOut of all possible paths,\nwith end points fixed,\nwhat is the path that minimizes the time it takes to slide down?\n\nThis was a well known-problem 18th Century scientists were trying to solve.\nWhich is the time that it takes to get from A to B fastest.\nScientist were struggling to solve this problem,\nand the way Bernoulli solved it was by inventing the calculus of variations.\n\nLet's first write out the problem.\n\nGiven 2 points 1 and 2,\nwith 1 higher above the ground,\nwhat shape should a track be built so that a particle released from\npoint 1 reach point 2 in the shortest time?\n\nLet's make point 1 be the origin $(0, 0)$.\nThe total time is\n\\begin{align}\n T &=\n \\int \\frac{ds}{v}\n\\end{align}\nwhere $v$ is the velocity.\nYou can work it out from the conservation of energy with\n\\begin{align}\n \\frac{1}{2}mv^2 &= mgy\\\\\n v &= \\sqrt{2 gy}\n\\end{align}\nso the total time is\n\\begin{align}\n T &=\n \\int\n \\frac{dx\\sqrt{1 + y'^2}}{\\sqrt{2gy}},\n\\end{align}\nwhich should be easy to put into the Euler-Lagrange equation.\nThe function is\n\\begin{align}\n f &=\n \\sqrt{\\frac{1 + y'^2}{2gy}}\n\\end{align}\nwhich has derivatives\n\\begin{align}\n \\frac{\\partial f}{\\partial y'} &=\n \\frac{y'}{\\sqrt{2gy(1 + y'^2)}}\\\\\n \\frac{\\partial f}{\\partial y} &=\n -\\frac{1}{2}\n \\frac{\\sqrt{1 + y'^2}}{\\sqrt{2gy}}\n\\end{align}\nso the Euler-Lagrange equation is\n\\begin{align}\n \\frac{d}{dx}\\left[ \n \\frac{y'}{\\sqrt{y(1 + y'^2)}}\n \\right]\n +\n \\frac{\\sqrt{1 + y'^2}}{2\\sqrt{y^2}}\n &= 0\n\\end{align}\nwhich simplifies to\n\\begin{align}\n \\frac{y'^2}{1 + y'^2} =\n \\underbrace{\\text{constant}}_{-\\frac{1}{2a}}\\times y\n\\end{align}\nand after some algebra,\nyou get\n\\begin{align}\n \\frac{dy}{dx} &=\n \\sqrt{\\frac{2a - y}{y}}.\n\\end{align}\nThen if you do a change of coordinates,\nthe solution is\n\\begin{align}\n x &= a(\\theta - \\sin\\theta)\\\\\n y &= a ( 1 - \\cos\\theta)\n\\end{align}\nwhich is called a \\emph{cycloid}.\n", "meta": {"hexsha": "11bef522baba9ec62702046816f53aea1e400f30", "size": 14574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture11.tex", "max_stars_repo_name": "ehua7365/umdphysnotes", "max_stars_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-11T12:53:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T12:53:46.000Z", "max_issues_repo_path": "phys610/lecture11.tex", "max_issues_repo_name": "ehua7365/umdphysnotes", "max_issues_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys610/lecture11.tex", "max_forks_repo_name": "ehua7365/umdphysnotes", "max_forks_repo_head_hexsha": "00e4e2b6aba3d03baaec5caa36903e5135b014de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1351351351, "max_line_length": 80, "alphanum_fraction": 0.6549334431, "num_tokens": 4615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.930458253565792, "lm_q1q2_score": 0.8843177391509408}} {"text": "\\section{Softmax Regression}\nA softmax regression, also called a multiclass logistic regression, is\nused to generalize logistic regression when there are more than 2 outcome\nclasses.\n\\subsection{Softmax Function}\nThe softmax function creates a probability distribution over a set of $k$\nclasses for a training example $x$, with $\\theta_k$ denoting the set of\nparameters to be optimzed for the $k$-th class.\n\\begin{equation}\n p(y=k | x; \\theta) = \\frac{\\exp \\left(\\theta_k^T x \\right)}{\\sum_j \\exp \\left( \\theta_j^T x \\right)}\n\\end{equation}\n\\subsection{MLE and Cost Function}\nWe can write the maximum likelihood function for softmax regression as:\n\\begin{equation}\n L(\\theta) = \\prod_{i=1}^m \\prod_k p(y=k|x; \\theta)^{\\mathbf{1}\\{y_i=k\\}}\n\\end{equation}\nWhere $\\mathbf{1} \\{y_i=k\\}$ is the indicator function which is $1$ if its\nargument is true, $0$ otherwise.\nBy taking the negative log likelihood:\n\\begin{equation}\n \\begin{aligned}\n \\ell ( \\theta ) \\quad & = \\quad -\\log L ( \\theta ) \\\\\n & = \\quad - \\log \\prod_{i=1}^m \\prod_k p(y=k|x; \\theta)^{\\mathbf{1}\\{y_i=k\\}} \\\\\n & = \\quad -\\sum_{i=1}^m \\sum_k \\left( \\mathbf{1}\\{y_i=k\\} \\cdot \\left( \\theta^T_k x_i - \\log \\left( \\sum_j \\exp \\left( \\theta_j^T x_i \\right) \\right) \\right) \\right) \\\\\n & = \\quad \\sum_{i=1}^m -\\theta^T_{y_i} x_i + \\log \\left( \\sum_j \\exp \\left( \\theta_j^T x_i \\right) \\right) \\\\\n \\end{aligned}\n\\end{equation}\nThis is known as the cross-entropy loss function.\n\\subsection{Gradient Descent}\nTo perform gradient descent, we must take the derivative of our cost function,\nbut it is important to note that the derivative for the correct class is\ndifferent than the other classes.\n\\begin{equation}\n \\begin{aligned}\n \\nabla_{\\theta_j} \\ell(\\theta) \\quad & = \\quad \\nabla_{\\theta_j} \\left( \\sum_{i=1}^m -\\theta^T_{y_i} x_i + \\log \\left( \\sum_k \\exp \\left( \\theta_k^T x_i \\right) \\right) \\right) \\\\\n & = \\quad \\sum_{i=1}^m \\nabla_{\\theta_j} \\left( -\\theta^T_{y_i} x_i \\right) + \\nabla_{\\theta_j} \\left( \\log \\left( \\sum_k \\exp \\left( \\theta_k^T x_i \\right) \\right) \\right) \\\\\n & = \\quad \\sum_{i=1}^m \\mathbf{1}\\{y_i=j\\} \\cdot (-x_i) + \\frac{\\exp(\\theta_j^T x_i)}{\\sum_k \\exp(\\theta_k^T x_i)} \\cdot x_i \\\\\n & = \\quad \\sum_{i=1}^m \\left(\\frac{\\exp(\\theta_j^T x_i)}{\\sum_k \\exp(\\theta_k^T x_i)} - \\mathbf{1}\\{y_i=j\\} \\right) \\cdot x_i \\\\\n \\end{aligned}\n\\end{equation}\nAnd our update equation for the $j$-th parameter weights is:\n\\begin{equation}\n \\theta_{j} : = \\theta_{j} - \\alpha \\left( \\frac{\\exp(\\theta_j^T x_i)}{\\sum_k \\exp(\\theta_k^T x_i)} - \\mathbf{1}\\{y_i=j\\} \\right) \\cdot x_i\n\\end{equation}\nNote that since each class has a set of weights, our gradient is a matrix known\nas the jacobian $\\mathbf{J}$, with $k$ classes each with $n$ feature weights.\n\\begin{equation}\n \\mathbf{J}_{\\theta} =\n \\left[\n \\begin{array} { c c c } {\\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { 1 } } } & { \\cdots } & { \\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { k } } } \\end{array}\n \\right] = \\left[\n \\begin{array} { c c c } {\\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { 11 } } } & { \\cdots } & { \\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { k1} } } \\\\ { \\vdots } & { \\ddots } & { \\vdots } \\\\ { \\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { 1n } } } & { \\cdots } & { \\frac { \\partial \\ell(\\theta) } { \\partial \\theta _ { kn } } } \\end{array}\n \\right]\n\\end{equation}\n", "meta": {"hexsha": "6122d66631f9672a6b8cbb6b66db2b16000c15a0", "size": 3420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/softmax_regression.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/softmax_regression.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/softmax_regression.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.1818181818, "max_line_length": 372, "alphanum_fraction": 0.6362573099, "num_tokens": 1238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9752018434079934, "lm_q2_score": 0.9059898172105135, "lm_q1q2_score": 0.8835229398525638}} {"text": "\\lab{Algorithms}{Givens rotations}{Givens rotations}\n\\objective{Use orthogonal transformations to perform QR decomposition.}\n\nThe matrix $\\begin{pmatrix} cos(\\theta) & -sin(\\theta) \\\\ sin(\\theta) & cos(\\theta) \\end{pmatrix}$ rotates a vector counterclockwise by $\\theta$. Given a vector $x = \\begin{pmatrix} a \\\\ b \\end{pmatrix}$, we can rotate $x$ into the range of $e_1$ by choosing the correct $\\theta$. The problem is equivalent to solving for $c = cos(\\theta)$ and $s = sin(\\theta)$ in the system\n\\begin{equation}\n\\label{eq:Givens rotation system}\n\\begin{pmatrix} c & -s \\\\ s & c \\end{pmatrix} \\begin{pmatrix}a\\\\b\\end{pmatrix} \n= \\begin{pmatrix}r\\\\0\\end{pmatrix}\n\\end{equation}\n In fact, it's not necessary to compute $\\theta$; we solve for $c$ and $s$ directly. An obvious solution is $c = \\frac{a}{\\sqrt{a^2 + b^2}}$ and $s = \\frac{-b}{\\sqrt{a^2+b^2}}$.\n\n\\section*{Givens triangularization}\n\nLike Householder, the Givens $QR$ algorithm, \\emph{triangularizes} a matrix $A$ using \\emph{orthogonal transformations}. The Householder $QR$ algorithm worked one column at a time; Givens works one element at a time. Each nonzero below the main diagonal can be zeroed out with a Givens rotation. If we solve for $c$ and $s$ as above, the matrix\n\\begin{equation*}\nG(i,j,c,s) = \n\\begin{pmatrix}\n1 & \\cdots & 0 & \\cdots & 0 & \\cdots & 0 \\\\\n \\vdots & \\ddots & \\vdots & & \\vdots & & \\vdots \\\\\n0 & \\cdots & c & \\cdots & -s & \\cdots & 0 \\\\\n \\vdots & & \\vdots & \\ddots & \\vdots & & \\vdots \\\\\n 0 & \\cdots & s & \\cdots & c & \\cdots & 0 \\\\\n\\vdots & & \\vdots & & \\vdots & \\ddots & \\vdots \\\\\n0 & \\cdots & 0 & \\cdots & 0 & \\cdots & 1 \n\\end{pmatrix}\n\\end{equation*}\nwhere\n\\[ \\begin{array}{ll}\ng_{i\\, i} = c & g_{j\\, i}= -s \\\\\ng_{j\\, j} = c & g_{i\\, j}= s \\\\\n\\end{array}\\]\nrotates by $\\theta$ in the $i,j$ plane. Also, it's easy to check that $G(i,j,c,s)$ is orthogonal. Left-multiplying $A$ by $G(i,j,c,s)$ zeroes out $A_{i\\, j}$. For example, \n\n\\[\n\\begin{array}{ccccccc}\n\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n*&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(2,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,2)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&0&*\n\\end{pmatrix}\n\\end{array}\n\\]\n\nThe Givens QR method is often slower than Householder, because it works one element at a time. But it is faster than Householder when $A$ is sparse, and it is very parallelizable.\n\n\\begin{problem}\nWrite a script that uses Givens rotations to do $QR$ decomposition. By performing successive Givens rotations, triangularize $A$ to find $R$. You can find $Q$ using the chain of rotations.\n\nTo find each rotation, you will have to solve \\eqref{eq:Givens rotation system} for $c$ and $s$. Let $b$ be the element you want to zero out, say $A_{i\\,j}$. Then $a$ is in the same \\emph{column} as $b$, and in the \\emph{row} you want to rotate into (it's like we're squishing the whole vector into $a$'s spot.) You can choose $a$ to be the diagonal element above $b$.\n\\end{problem}\n\n\\begin{problem} \nCompare the MGS, Householder, and Givens algorithms for $QR$ decomposition on various matrices. Try different sizes and different levels of sparsity. Which is the fastest? Which is the most stable?\n\\end{problem}", "meta": {"hexsha": "130394dd00acd318bac8f46ea03c4a3f0825cb5d", "size": 3347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Givens/Givens.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Givens/Givens.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Givens/Givens.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.6266666667, "max_line_length": 375, "alphanum_fraction": 0.6492381237, "num_tokens": 1167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.9390248165754385, "lm_q1q2_score": 0.8834249232926109}} {"text": "\\section{Minkowski sum and difference}\n\nGiven two points $\\point{p_1} = (x_1, y_1, z_1)$ and $\\point{p_2} = (x_2, y_2, z_2)$ we define\ntheir sum as usual as the point \n$\\point{p_1} + \\point{p_2} = (x_1+x_2, y_1+y_2, z_1+z_2)$,\nand their difference as the point\n$\\point{p_1} - \\point{p_2} = (x_1-x_2, y_1-y_2, z_1-z_2)$.\nGiven two polytopes $P_1$ and $P_2$, the Minkowski sum is a polytope $P_1 \\oplus P_2$\ndefined as\n$$\nP_1 \\oplus P_2 = \\{ \\point{p_1} + \\point{p_2} \\ \\vert\\ \\point{p_1} \\in P_1, \\point{p_2} \\in P_2 \\}.\n$$\nSimilarly, the Minkowski difference is defined as\n$$\nP_1 \\ominus P_2 = \\{ \\point{p_1} - \\point{p_2} \\ \\vert\\ \\point{p_1} \\in P_1, \\point{p_2} \\in P_2 \\}.\n$$\nAn obvious property of the Minkowski difference is the following. \n\\begin{property}\n\\label{pro:mink}\nTwo polytopes $P_1$,$P_2$ \nare intersecting if and only if \n$\\point{0} \\in (P_1 \\ominus P_2).$\n\\end{property}\n\nConsider now translating $P_1$ and $P_2$ by\nrespectively vectors $\\point{v_1}$ and $\\point{v_2}$. \nWe have that $\\point{v_1}+P_1$ and $\\point{v_2}+P_2$\nintersect if and only if \n$\\point{0} \\in ((\\point{v_1}+P_1) \\ominus (\\point{v_2}+P_2))$.\nThe following chain of relations hold\n\\begin{eqnarray}\n\\nonumber\n& & \\point{0} \\in ((\\point{v_1}+P_1) \\ominus (\\point{v_2}+P_2)) \\\\\n\\nonumber\n& \\Leftrightarrow & \\point{0} \\in \\{ (\\point{p_1}+\\point{v_1}) - (\\point{p_2}+\\point{v_2}) \\ \\vert\\ (\\point{p_1} + \\point{v_1}) \\in P_1, (\\point{p_2} + \\point{v_2}) \\in P_2 \\} \\\\\n\\nonumber\n& \\Leftrightarrow & -\\point{v_1} \\in \\{ \\point{p_1} - (\\point{p_2}+\\point{v_2}) \\ \\vert\\ \\point{p_1} \\in P_1, (\\point{p_2} + \\point{v_2}) \\in P_2 \\} \\\\\n\\nonumber\n& \\Leftrightarrow & (\\point{v_2} - \\point{v_1}) \\in \\{ \\point{p_1} - \\point{p_2} \\ \\vert\\ \\point{p_1} \\in P_1, \\point{p_2} \\in P_2 \\} \\\\\n\\label{eq:chain}\n& \\Leftrightarrow & (\\point{v_2} - \\point{v_1}) \\in (P_1 \\ominus P_2)\n\\end{eqnarray}\nWe interpret (\\ref{eq:chain}) as follows: take two vectors \n$\\point{v_1}$, $\\point{v_2}$ for translating\n$P_1$ and $P_2$ respectively. The two translated polytopes \nintersect if and only if the difference\nvector is contained in the Minkowski difference.\n\n", "meta": {"hexsha": "32216b11993572abee4fc27dc2cd92bbdec87a3d", "size": 2121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/minkowski.tex", "max_stars_repo_name": "formalmethods/polytopepacking", "max_stars_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-07T13:54:39.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-07T13:54:39.000Z", "max_issues_repo_path": "report/minkowski.tex", "max_issues_repo_name": "bobosoft/polytopepacking", "max_issues_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-18T08:05:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-21T20:44:27.000Z", "max_forks_repo_path": "report/minkowski.tex", "max_forks_repo_name": "formalmethods/polytopepacking", "max_forks_repo_head_hexsha": "7879d1ceb252f731fa4bbc9d93341b832e62115d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.2857142857, "max_line_length": 178, "alphanum_fraction": 0.6581801037, "num_tokens": 944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.9381240095190062, "lm_q1q2_score": 0.883388375585619}} {"text": "\\textbf{Let $f(x)=3/(5-4\\cos(x))$. Compute its Fourier approximation for $N = 20 : 10 : 500$ and plot the error using \\textsl{loglog}. What is the largest strip around the real axis for which $f$ can be extended to an analytic function? How does this relate to the error bound for analytic functions derived in class?}\n\\newline\n\nIn this case the function $f$ is $2\\pi$-periodic, as we can see in figure 1, and analytic inside the strip $|\\Im(z)|\\leq a$. To determine the value of $a$, we solve\n\\begin{align*}\n5-4\\cos(z)=0 \\Rightarrow z=\\cos^{-1}(5/4)\\approx\\ln(2)i. \n\\end{align*}\nHence, $a\\approx \\ln(2)$. \n\\begin{figure}[H]\n\\centering %%% not \\center\n{\\includegraphics[scale=1]{P5_1.eps}}\n\\caption{Graph of the function to approximate.}\n\\end{figure}\n\nGiven that the function is $2\\pi$-periodic and analytic inside the strip $|\\Im(z)|\\leq a$, the error is bounded as follows\n\\begin{align*}\n\\left|\\mathcal{F}[u](x)-\\mathcal{F}_N[u](x)\\right|\\leq \\frac{4\\pi M}{a}e^{-aN} = \\frac{4\\pi M}{\\ln(2)}e^{-\\ln(2)N} = \\frac{4\\pi M}{\\ln(2)}2^{-N} \\propto 2^{-N},\n\\end{align*}\nwhere $M = \\max_{x\\in[0,2\\pi]}|f(x-ai)|$. We can check in the last figure how this convergence is much faster. The points that separate from the error bound are due to round-off errors.\n\\begin{figure}[H]\n\\centering %%% not \\center\n{\\includegraphics[scale=1]{P5_2.eps}}\n\\caption{Approximation error and its bound.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\\begin{verbatim}\n%% Problem 5\nclear variables; close all; clc\nfigformat='epsc';\n\n% Plot function\n\nx0 = -2*pi;\nxf = 2*pi;\nx = chebfun('x',[x0 xf]);\nf = 3./(5-4*cos(x));\n\nfigure\nplot(f,'b-','linewidth',2)\nhold on\nplot([0 0],[0 3.5],'r--')\ngrid on\nxlabel('$x$','interpreter','latex')\nylabel('$f(x)=\\frac{3}{5-4\\cos(x)}$','interpreter','latex')\nset(gca,'fontsize',14)\nset(gca,'XTick',x0:pi/2:xf) \nxticklabels({'-2\\pi','-3\\pi/2','-\\pi','-\\pi/2','0','\\pi/2','\\pi','3\\pi/2','2\\pi'})\ntxt='Latex/FIGURES/P5_1';\nsaveas(gcf,txt,figformat)\n\n%%\n% Approximation and error\nN = 20:10:500;\nx0 = 0;\nxf = 2*pi;\nx = chebfun('x',[x0 xf]);\nf = 3./(5-4*cos(x));\n\nparfor j = 1:length(N)\n A = exp(1i*x*(-N(j):N(j)));\n lambda = 1/(2*pi)*A'*f;\n fn = A*lambda;\n err(j) = norm(f-fn,Inf);\nend\n%%\nfigure\nloglog(N,err,'*','MarkerSize',12)\nhold on\nloglog(N,2.^(-abs(N)),'r','linewidth',2)\ngrid on\naxis([10 500 1e-16 1e-1])\nxlabel('$N$','interpreter','latex')\nylabel('Error','interpreter','latex')\nlegend('Approximation Error','Error Bound')\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P5_2';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}", "meta": {"hexsha": "5b0b969b492012d1d004bf9ac4bc602cf92bd831", "size": 2551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework1/Latex/problem5.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework1/Latex/problem5.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework1/Latex/problem5.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7051282051, "max_line_length": 318, "alphanum_fraction": 0.6515092121, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.9511422213778251, "lm_q1q2_score": 0.8830488051389128}} {"text": "\\section{Logistic Regression}\n\nLogistic Regression is a generalized linear model suitable for fitting probabilities, i.e. dependent variables that vary $y\\in (0,1)$. \n\n\\subsection{Binary Response Case}\nAssume that the dependent variable is a scalar and not a vector (i.e. only a single probability is being predicted). Then, assume that the dependence of that probability on the exogenous variable $\\mathbf{x}$ and the parameters of the model $\\mathbf{b}$ is given by:\n\n\\begin{equation}\np(\\mathbf{x}) = \\frac{1}{1+\\exp(\\mathbf{b\\cdot x})}\n\\end{equation}\n\nThis is, of course, the sigmoid function, which also shows up as the Fermi-Dirac distribution. It creates a symmetric mapping from the interval $(-\\infty,\\infty)$ to $(0,1)$. It amounts to treating the log-odds as a linear function of the coefficients: \n\n\\begin{equation}\n\\ln\\left(\\frac{p(\\mathbf{x})}{1-p(\\mathbf{x})}\\right) = \\mathbf{b \\cdot x}\n\\end{equation}\n\nEquivalently:\n\n\\begin{equation}\n\\frac{p(\\mathbf{x})}{1-p(\\mathbf{x})} = \\prod_j e^{b_j x_j}\n\\end{equation}\n\nSo the model assumes that different values of the independent variables will have a multiplicative effect on the likelihood ratio of the two binary outcomes. There is a deep reason for this choice of mapping, which is why it shows up as the Fermi-Dirac distribution in physics. In physics, it emerges from looking at the probability of energy levels being occupied by fermions. This is done by considering the number of equally possible configurations that correspond to a set of probabilities of a certain energy level being occupied. The Fermi-Dirac distribution is the distribution that maximizes the number of equally possible configurations, and so I suppose the sigmoid function has some maximum entropy property, which makes it the \"maximally naive guess\". \n\nAssuming that the data is generated by independent trials, the likelihood of observing the data is given by multiplying the probability of all the datapoints together:\n\n\\begin{equation}\n\\mathscr{L}(\\mathrm{data}|p(\\mathbf{x})) = \\prod_{y_i=1} p(\\mathbf{x_i}) \\prod_{y_i=0} (1-p(\\mathbf{x_i}))\n\\end{equation}\n\nStrictly speaking, I think there should be a factor of $1/N!$ here to account for the probability of seeing a specific permutation of the individual data points (which are distinguishable), but that factor will be independent of $p(\\mathbf{x})$ and so it will not matter to estimation. In the literature I haven't seen a factor show up.\n\nThe expression $-2 \\ln(\\mathscr{L})$ is called the \\textit{deviance}, which is the analog to residual sum of squares in ordinary linear regression. In OLS, the log likelihood is: $\\ln\\mathscr{L} = -\\sum|\\hat{y}-y|^2 + ...$, while the deviance is $-2\\ln\\mathscr{L} = -\\sum_i \\ln\\left[\\left(p(\\mathbf{x_i})^{y_i}(1-p(\\mathbf{x_i}))^{y_i-1}\\right)^2\\right]$.\n\nLogistic regression is then fit by finding the coefficients that minimize the deviance / maximize the likelihood.\n\nQuestion for another day: in OLS, there is an assumption that the data will deviate from the mean, where the probability of observing a certain deviation is given by a normal distribution. This has the consequence, for example, that outliers have an outsize impact on the fitted mean, because the normal distribution otherwise models them as exceedingly unlikely. If the normal distribution is the error distribution for OLS, what is the error distribution for logistic regression? I believe it looks like the Fermi-Dirac Distribution, where the Fermi-Energy is the 50\\% decision boundary. \n\n\\subsection{Pseudo-$R^2$}\nThe deviance can be used to create an error metric analogous to $R^2$ for OLS, named Pseudo-$R^2$. It compares the deviance to the deviance of simply assuming the average probability based on the class balance.\n\n\\begin{equation}\n\\mathrm{pseudo}-R^2 = 1 - \\frac{\\mathrm{deviance}}{\\mathrm{deviance\\ when\\ }p=\\mathrm{\\ average\\ class}}\n\\end{equation}\n", "meta": {"hexsha": "3b2b567bd0388721706a9b3d24e2a6040525c4d4", "size": 3878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/reg_logisticregression.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/reg_logisticregression.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/reg_logisticregression.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.3043478261, "max_line_length": 764, "alphanum_fraction": 0.7648272305, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377284730285, "lm_q2_score": 0.9207896780646392, "lm_q1q2_score": 0.8826116464134904}} {"text": "\\section{Gradient descent}\nGradient descent is a first-order optimization algorithm for finding the minimum of a function \\cite{??}. It works iteratively by taking steps proportional to the gradient of the function evaluated at each iteration.\\\\\n\nFor a differentiable function $F(x)$, the iterative scheme of gradient ascent is:\n\\begin{equation}\n\\bfx^{(t+1)} = \\bfx^{(t)} + \\rho^{(t)} \\nabla F(\\bfx^{(t)})\n\\end{equation}\nAt each iteration, the gradient is re-evaluated and a step is performed in the direction of the gradient $\\nabla F$. The step size is controlled by $\\rho^{(t)}$, a parameter called the learning rate, which can be adjusted at each iteration $t$. \\\\\nWith certain assumptions on the function $F$ and particular choices of $\\rho$ \\cite{??}, gradient descent is guaranteed to converge to a local minimum. Hence, if $f$ is not convex, the algorithm is sensible to the initialisation $\\bfx^0$. \\\\\n\nGradient descent is appealing because of its simplicity, but in practice other methods are more efficient, including conjugate gradients and quasi-Newton methods \\cite{Gill et al., 1981; Fletcher, 1987; Nocedal and Wright, 1999}. Additionally, Standard gradient ascent becomes prohibitive slow with large data sets \\cite{}, because of the computational cost (both in terms of time and memory) associated with the calculation of gradients at each iteration ~\\citep{Robbins-Monro1951, Bottou2011-by, Spall2003-fl} .\n\n\n\\section{Stochastic gradient descent}\nAssuming there is redundancy in the data set, an approximated yet fast gradient can be calculated using a random subset of the data (i.e. a minibatch). Under large N conditions, the stochastic version can converge faster than traditional gradient descent \\cite{??}. If the cost function is convex, stochastic gradient descent is also guaranteed to find a global minimum. \\\\\n\nAs in standard, gradient descent, the iterative training schedule proceeds by taking small steps of size $\\rho$ in the direction of the approximate gradient $\\hat{\\nabla}F$:\n\\begin{equation}\n\\bfx^{(t+1)} = \\bfx^{(t)} + \\rho^{(t)} \\hat{\\nabla} F(\\bfx^{(t)})\n\\end{equation}\nThe step size $\\rho^{(t)}$ can also be adjusted at each iteration $t$. When this series satisfies the Robbins-Monro conditions: $\\sum_t \\rho^{(t)} = \\infty \\text{ and } \\sum_t (\\rho^{(t)})^2 < \\infty$, $f$ is guaranteed to converge to a local minimum ~\\citep{Robbins-Monro1951}. \n\nThe computation of $\\hat{\\nabla}F$ requires an additional hyperparameter that establishes the size of the minibatch. A trade off exists between getting closer to the true gradient by increasing the size of the minibatch at the cost of speed and smoother convergence.\n\n", "meta": {"hexsha": "13870c18574a18f2470c03fc345a77caf9832fdb", "size": 2664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/old/gradient_descent.tex", "max_stars_repo_name": "rargelaguet/thesis", "max_stars_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-01-08T13:01:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T07:24:40.000Z", "max_issues_repo_path": "Chapter2/old/gradient_descent.tex", "max_issues_repo_name": "rargelaguet/thesis", "max_issues_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter2/old/gradient_descent.tex", "max_forks_repo_name": "rargelaguet/thesis", "max_forks_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-09T04:47:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T08:25:50.000Z", "avg_line_length": 106.56, "max_line_length": 513, "alphanum_fraction": 0.7571321321, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.9314625036384887, "lm_q1q2_score": 0.8824499188467326}} {"text": "\n\\subsection{Surface integrals}\nA surface integral is like adding up all the wind on a sail.\nIn other words, we want to compute\n$$\\int\\!\\!\\!\\int{\\bf F\\cdot n}\\,dA$$\nwhere ${\\bf F\\cdot n}$ is the amount of wind normal to a tiny parallelogram $dA$.\nThe integral sums over the entire area of the sail.\nLet $S$ be the surface of the sail parameterized by $x$ and $y$.\n(In this model, the $z$ direction points downwind.)\nBy the properties of the cross product we have the following for the unit normal $\\bf n$\nand for $dA$.\n$${\\bf n}=\\frac{{\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}}}\n{{\\left|\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}\\right|}}\\qquad\ndA=\\left|\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}\\right|\\,dx\\,dy$$\nHence\n$$\\int\\!\\!\\!\\int{\\bf F\\cdot n}\\,dA=\\int\\!\\!\\!\\int{\\bf F}\\cdot\n\\left({\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}}\\right)\\,dx\\,dy$$\n\n\\bigskip\n\\noindent\nThe following exercise is from\n{\\it Advanced Calculus} by Wilfred Kaplan, p.~313.\nEvaluate the surface integral\n$$\\int\\!\\!\\!\\int_S{\\bf F\\cdot n}\\,d\\sigma$$\n\n\\noindent\nwhere ${\\bf F}=xy^2z{\\bf i}-2x^3{\\bf j}+yz^2{\\bf k}$, $S$ is the surface\n$z=1-x^2-y^2$, $x^2+y^2\\le1$ and $\\bf n$ is upper.\n\n\\bigskip\n\\noindent\nNote that the surface intersects the $xy$ plane in a circle.\nBy the right hand rule, crossing $x$ into $y$ yields $\\bf n$ pointing upwards hence\n$${\\bf n}\\,d\\sigma=\\left({\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}}\\right)\\,dx\\,dy$$\n\n\\noindent\nThe following Eigenmath code computes the surface integral.\nThe symbols $f$ and $h$ are used as temporary variables.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nM1 = ((0,0,0),(0,0,-1),(0,1,0))\nM2 = ((0,0,1),(0,0,0),(-1,0,0))\nM3 = ((0,-1,0),(1,0,0),(0,0,0))\nM = (M1,M2,M3)\ncross(u,v) = dot(u,M,v)\nz = 1 - x^2 - y^2\nF = (x y^2 z,-2 x^3,y z^2)\nS = (x,y,z)\nf = dot(F,cross(d(S,x),d(S,y)))\nh = sqrt(1 - x^2)\ndefint(f,y,-h,h,x,-1,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{48}\\pi$\n", "meta": {"hexsha": "7c87cdc2ba967fcc12d9e34443791337d9634cd1", "size": 2034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/surface-integral.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/surface-integral.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/surface-integral.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 36.3214285714, "max_line_length": 108, "alphanum_fraction": 0.65093412, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.964321452198369, "lm_q2_score": 0.9149009526726545, "lm_q1q2_score": 0.8822586152989654}} {"text": "\\subsubsection{Defective Matrix}\r\nIf $A$ has an eigenvalue $\\lambda$ with multiplicity $k$ that does not generate $k$ corresponding linearly independent eigenvectors, the the matrix $A$ is defective.\r\nTo generate enough vectors, we need to extend eigenvectors.\r\n\\begin{definition}\r\n\tLet $A$ be a square matrix.\r\n\tA nonzero vector $\\vec{v}$ satisfying\r\n\t\\begin{equation*}\r\n\t\t(A-\\lambda I)^n \\vec{v} = \\vec{0}\r\n\t\\end{equation*}\r\n\tfor some eigenvalue $\\lambda$ and some positive integer $n$ is a generalized eigenvector or rank $n$.\r\n\\end{definition}\r\n\\noindent\r\nThese generalized eigenvectors also make up solutions.\r\n\\begin{theorem}\r\n\tLet $\\vec{v}$ be an generalized eigenvector of a square matrix $A$ corresponding to an eigenvalue $\\lambda$ with multiplicity $k$.\r\n\tThen\r\n\t\\begin{equation*}\r\n\t\te^{At}\\vec{v} = e^{\\lambda t}\\left(\\vec{v} + t(A-\\lambda I)\\vec{v} + \\frac{t^2}{2!}(A-\\lambda I)^2\\vec{v} + \\ldots\\right)\r\n\t\\end{equation*}\r\n\tis the corresponding fundamental solution.\r\n\tFurther, the above sequence will terminate after $k$ or fewer terms (all subsequent terms are 0).\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the system\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t1 & 0 & 0 \\\\\r\n\t\t\t1 & 3 & 0 \\\\\r\n\t\t\t0 & 1 & 1\r\n\t\t\\end{bmatrix} \\vec{x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nSince $A$ is diagonal, the eigenvalues are simply the diagonal entries\r\n\\begin{equation*}\r\n\t\\lambda = 3, 1 \\text{(double root)}.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = 3$,\r\n\\begin{equation*}\r\n\t(A - 3I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_1 \\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t2 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = 1$,\r\n\\begin{equation*}\r\n\t(A - I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_2 \\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nSince $\\lambda =1$ had multiplicity 2, we need to find a generalized eigenvector.\r\n\\begin{equation*}\r\n\t(A - I)^2\\vec{v} = \\vec{0} \\implies \\vec{v} = C_2 \\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_3 \\begin{bmatrix}\r\n\t\t-2 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nNote how then eigenvector showed up again as a generalized eigenvector of rank 2.\r\nThis is because the eigenvector makes $(A - I)\\vec{v} = 0$, so $(A - I)^2\\vec{v} = (A - I)\\vec{0} = \\vec{0}$.\r\nSo, our solution is\r\n\\begin{align*}\r\n\t\\vec{x} &= C_1e^{3t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t2 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_2e^{t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_3e^{t}\\left(\\begin{bmatrix}\r\n\t\t-2 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + (A - I)t\\begin{bmatrix}\r\n\t\t-2 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}\\right) \\\\\r\n\t&= C_1e^{3t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t2 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_2e^{t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_3e^{t}\\begin{bmatrix}\r\n\t\t-2 \\\\\r\n\t\t1 \\\\\r\n\t\tt\r\n\t\\end{bmatrix}.\r\n\\end{align*}\r\nWe can rewrite this a bit more cleanly as\r\n\\begin{equation*}\r\n\t\\vec{x} = \\begin{bmatrix}\r\n\t\t0 & 0 & -2e^t \\\\\r\n\t\t2e^{2t} & 0 & e^t \\\\\r\n\t\te^{3t} & e^t & te^t\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\tC_1 \\\\\r\n\t\tC_2 \\\\\r\n\t\tC_3\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nThis square matrix is called the fundamental matrix of the system.", "meta": {"hexsha": "4a67f5a6f9c241d478645b6965525b086d3ff29b", "size": 3166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 27.7719298246, "max_line_length": 166, "alphanum_fraction": 0.6178142767, "num_tokens": 1233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813488829418, "lm_q2_score": 0.9219218343187415, "lm_q1q2_score": 0.8813400787366665}} {"text": "\\subsection{Dynamical Systems and Eigenvectors}\n\nIn general, a discrete dynamical system can be modeled as:\n\n\\[\\boxed{\\tb{x}(t+1)=A\\tb{x}(t)}\\]\n\nwhere the transformation undergone by the system is $\\tb{x}(t)\\rightarrow\\tb{x}(t+1)$ with matrix $A$.\nAdditionally, note that $\\tb{x}(t)=\\begin{bmatrix}c(t)\\\\r(t)\\end{bmatrix}$ where $c(t)$ and $r(t)$ are some closed formulas.\n\nFinding $\\tb{x}(t)$ for an arbitrary integer $t>0$:\n\n\\[\\boxed{\\tb{x}(t)=A^t\\tb{x}(0)=A^t\\tb{x}_0}\\]\n\nRepeat definition of eigenvector from below:\n\n\\begin{framed}\n If $A$ is an $n\\times n$ matrix, an eigenvector of $A$ is a nonzero vector $\\tb{v}$\n that has the property that $\\tb{v}$ and $A\\tb{v}$ are parallel.\n Same as saying that $A\\tb{v}=\\lambda\\tb{v}$, so $\\lambda$ is an eigenvalue.\n\\end{framed}\n\n\\subsection{Dynamical Systems Example}\n\nFollowing equations model transformation from $t$ to $t+1$:\n\n\\[\\boxed{\n \\begin{array}{l}\n c(t+1)=0.86 c(t)+0.08 r(t) \\\\\n r(t+1)=-0.12 c(t)+1.14 r(t)\n \\end{array}\n}\\]\n\nIs discrete dynamical linear system: changed over discrete time interval and dynamic as\nvariables change according to $t$. As a matrix-vector equation:\n\n\\[\\left(\\begin{array}{cc}\n 0.86 & 0.08 \\\\\n -0.12 & 1.14\n \\end{array}\\right)\\left(\\begin{array}{l}\n c(t) \\\\\n r(t)\n \\end{array}\\right)=\\left(\\begin{array}{l}\n c(t+1) \\\\\n r(t+1)\n \\end{array}\\right)\\]\n\n$\\tb{x}(t)=\\left(\\begin{array}{l}c(t) \\\\r(t)\\end{array}\\right)$\nis the \\textbf{state vector} at time $t$. $\\tb{x}(0)=\\left(\\begin{array}{l}c_{0} \\\\r_{0}\\end{array}\\right)$\nis the \\textbf{initial state vector}. Calculating arbitrary state vector:\n\n\\[\\left(\\begin{array}{cc}\n 0.86 & 0.08 \\\\\n -0.12 & 1.14\n \\end{array}\\right)^{t} \\tb{x}_{0}=\\tb{x}(t)\\]\n\nIn this example, $c(t)=(100) 1.1^{t}$ and $r(t)=(300) 1.1^{t}$, so next\nstate vector is 1.1 times the current. However, for $\\tb{x}_{0}=\\left(\\begin{array}{c}1000 \\\\1000\\end{array}\\right)$\nthere exists no such scalar pattern. Can use the basis of 2 (scalar pattern respected) vectors:\n\n\\[\\mathfrak{B}=\\left\\{\\left(\\begin{array}{l}\n 100 \\\\\n 300\n \\end{array}\\right),\\left(\\begin{array}{l}\n 200 \\\\\n 100\n \\end{array}\\right)\\right\\}\\]\n\nWriting this state vector as a lin. combination:\n\n\\[\\left(\\begin{array}{l}\n 1000 \\\\\n 1000\n \\end{array}\\right)=2\\left(\\begin{array}{l}\n 100 \\\\\n 300\n \\end{array}\\right)+4\\left(\\begin{array}{l}\n 200 \\\\\n 100\n \\end{array}\\right)\\]\n\nAfter applying coefficient matrix to both sides and simplifying:\n\n\\[\\left(\\begin{array}{cc}\n 0.86 & 0.08 \\\\\n -0.12 & 1.14\n \\end{array}\\right)^{t}\\left(\\begin{array}{c}\n 1000 \\\\\n 1000\n \\end{array}\\right)=2(1.1)^{t}\\left(\\begin{array}{c}\n 100 \\\\\n 300\n \\end{array}\\right)+4(0.9)^{t}\\left(\\begin{array}{c}\n 200 \\\\\n 100\n \\end{array}\\right)\\]\n\nThus,\n\n\\[\\begin{array}{l}\n c(t)=200(1.1)^{t}+800(0.9)^{t} \\\\\n r(t)=600(1.1)^{t}+400(0.9)^{t}\n \\end{array}\\]\n\nDifferent trajectories for various initial state vectors:\n\n\\begin{center}\n \\includegraphics[scale=0.5]{state-vectors.png}\n\\end{center}\n\nCalled a \\textbf{phase portrait} for a discrete dynamical system.\nIndicates performing of system based on initial states.\nThe 2 state vectors in the basis are \\textbf{eigenvectors}.\n\n\\begin{framed}\n If $A$ is an $n\\times n$ matrix, an eigenvector of $A$ is a nonzero vector $\\tb{v}$\n that has the property that $\\tb{v}$ and $A\\tb{v}$ are parallel.\n Same as saying that $A\\tb{v}=\\lambda\\tb{v}$, so $\\lambda$ is an eigenvalue.\n\\end{framed}\n\nIf there exists an $n\\times n$ matrix $A$ with $\\lambda=0$, then kernel of $A$ must be nontrivial\nbecause $A\\tb{v}=\\tb{0}=0\\tb{v}$, therefore $A$ is singular.", "meta": {"hexsha": "e2eb6d49095410029ecff63c062c6f44266e56e8", "size": 3695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/17_intro-dynamical-systems.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/17_intro-dynamical-systems.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/17_intro-dynamical-systems.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5371900826, "max_line_length": 124, "alphanum_fraction": 0.6259810555, "num_tokens": 1319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361742, "lm_q2_score": 0.9334308045480275, "lm_q1q2_score": 0.8813237664725688}} {"text": "\\section{Inequalities for Probabilities}\n\n\\subsection{Markov's Inequality}\n\nFor any $t>0$: \n\\begin{equation}\n\\mathbb{P}(X > t) \\leq \\frac{\\mathbb{E}(X)}{t}\n\\end{equation}\n\nThis is a general result, independent of the distribution of $X$.\n\n\\subsection{Chebyshev's Inequality}\n\n\\begin{equation}\n\\mathbb{P}(|X-\\mu| \\geq t) \\leq \\frac{\\sigma^2}{t^2}\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\mathbb{P}(|Z| \\geq k) \\leq \\frac{1}{k^2}\n\\end{equation}\n\nwhere $Z = (X-\\mu)/\\sigma$. This is a general result that can be proven using Markov's inequality.\n\n\\subsection{Hoeffding's Inequality}\nLet $Y_1,...,Y_n$ be independent observations so that $\\mathbb{E}Y_i = 0$ and $a_i \\leq Y_i \\leq b_i$. Then, for any $t>0$,\n\n\\begin{equation}\n\\mathbb{P}\\left( \\sum_{i=1}^n Y_i \\geq \\epsilon \\right) \\leq e^{-t\\epsilon}\\prod_{i=1}^n e^{t^2 (b_i - a_i)^2/8}\n\\end{equation}\n\nHoeffding's inequality provides a sharper bound than Markov's inequality and relies on bounds of the random variables rather than their variance.\n\n\\subsubsection{Example: Bernoulli Random Variables}\nLet $X_1,...,X_n \\sim \\mathrm{Bernoulli}(p)$. Assume that the goal is to measure the parameter $p$, which is estimated by the sample mean. This could for example be the error rate of a binary classifier. For the Bernoulli Random variable, $0\\leq X_1 \\leq 1$, so that the probability that the estimate of the error rate is off by more than $\\epsilon$ is given by:\n\n\\begin{equation}\n\\mathbb{P}(|\\overline(X)_n - p| > \\epsilon) \\leq 2e^{-2n\\epsilon^2}\n\\end{equation}\n\n\\subsection{Mill's Inequality}\nMill's inequality is useful for normal random variables. Let $Z \\sim \\mathscr{N}(0,1)$, then the probability that $|Z|$ will be greater than some value $t$ is bounded by: \n\n\\begin{equation}\n\\mathbb{P}(|Z|>t) \\leq \\frac{2}{\\pi}\\frac{e^{-t^2/2}}{t}\n\\end{equation}\n\n\n\\section{Inequalities for Expectations}\n\n\\subsection{Cauchy-Schwarz Inequality}\n\n\\begin{equation}\n\\mathbb{E}|XY|\\leq \\sqrt{\\mathbb{E}(X^2) \\mathbb{E}(Y^2)}\n\\end{equation}\n\n\n\n\\subsection{Jensen's Inequality}\n\nJensen's inequality provides bounds for expectations for non-linear functions of a random variable. Given a random variable $X$ and a function $g(X)$, if $g(X)$ is convex:\n\n\\begin{equation}\n\\mathbb{E}g(X) \\geq g(\\mathbb{E}X)\n\\end{equation}\n\nIf $g(X)$ is concave:\n\n\\begin{equation}\n\\mathbb{E}g(X) \\leq g(\\mathbb{E}X)\n\\end{equation}\n\n\n", "meta": {"hexsha": "db0a930a5e4fe7e8fddbfe5dfe099b9c743c89d2", "size": 2349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_inequalities.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_inequalities.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_inequalities.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.32, "max_line_length": 362, "alphanum_fraction": 0.7092379736, "num_tokens": 812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9740426428022032, "lm_q2_score": 0.9046505421702797, "lm_q1q2_score": 0.8811682049079853}} {"text": "\n\\subsection{Stokes' theorem}\nStokes' theorem says that in typical problems a surface integral can be\ncomputed using a line integral.\n(There is some fine print regarding continuity and boundary conditions.)\nThis is a useful theorem because usually the line integral is easier to\ncompute.\nIn rectangular coordinates the equivalence between a line integral\non the left and a surface integral on the right is\n%\\bigskip\n%\\noindent\n%$\\displaystyle{\\oint_C P\\,dx+Q\\,dy+R\\,dz}$\n%$$=\n%\\int\\!\\!\\!\\int_S\n%\\left({\\partial Q\\over\\partial x}-{\\partial P\\over\\partial y}\\right)\\,dx\\,dy\n%+\n%\\left({\\partial R\\over\\partial y}-{\\partial Q\\over\\partial z}\\right)\\,dy\\,dz\n%+\n%\\left({\\partial P\\over\\partial z}-{\\partial R\\over\\partial x}\\right)\\,dz\\,dx\n%$$\n%\n%\\noindent\n%Curve $C$ is the perimeter around $S$.\n%The theorem can be also be written as\n\n$$\\oint P\\,dx+Q\\,dy+R\\,dz\n=\\int\\!\\!\\!\\int_S(\\mathop{\\rm curl}{\\bf F})\\cdot{\\bf n}\\,d\\sigma\n$$\n\nwhere ${\\bf F}=(P,Q,R)$.\nFor $S$ parametrized by $x$ and $y$ we have\n$${\\bf n}\\,d\\sigma=\\left(\n{\\partial S\\over\\partial x}\\times{\\partial S\\over\\partial y}\n\\right)dx\\,dy$$\n\nExample:\nLet ${\\bf F}=(y,z,x)$ and let $S$ be the part of the paraboloid\n$z=4-x^2-y^2$\nthat is above the $xy$ plane.\nThe perimeter of the paraboloid is the circle $x^2+y^2=2$.\nThe following script computes both the line and surface integrals.\nIt turns out that we need to use polar coordinates for the\nline integral so that {\\it defint} can succeed.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Surface integral\nz = 4-x^2-y^2\nF = (y,z,x)\nS = (x,y,z)\nf = dot(curl(F),cross(d(S,x),d(S,y)))\nx = r*cos(theta)\ny = r*sin(theta)\ndefint(f*r,r,0,2,theta,0,2pi)\n-- Line integral\nx = 2*cos(t)\ny = 2*sin(t)\nz = 4-x^2-y^2\nP = y\nQ = z\nR = x\nf = P*d(x,t)+Q*d(y,t)+R*d(z,t)\nf = circexp(f)\ndefint(f,t,0,2pi)\n\\end{Verbatim}\n\nThis is the result when the script runs.\nBoth the surface integral and the line integral\nyield the same result.\n\n$\\displaystyle -4\\pi$\n\n$\\displaystyle -4\\pi$\n", "meta": {"hexsha": "11568563ce3108edb420894394fa3fba925b146e", "size": 1978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/stokes-theorem.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/stokes-theorem.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/stokes-theorem.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.095890411, "max_line_length": 77, "alphanum_fraction": 0.6830131446, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966101527047, "lm_q2_score": 0.9230391664210672, "lm_q1q2_score": 0.8805480751474806}} {"text": "In this (sub)section we will explore a special kind of relation called an \\textbf{equivalence relation}. Suppose $A$ is a set. Roughly speaking, there are two useful ways of viewing an equivalence relation $A$.\n\\begin{itemize}\n\t\\item We can view the relation as a classifier. That is, the relation divides the elements of $A$ into groups and classifies them as being the same if they are in the same group.\n\t\\item Alternatively (and equivalently), the relation compares two elements $a$ and $b$ and determines whether the two elements are ``the same'' or not the same.\n\\end{itemize}\n\nIn this section we will see how these two views describe the same thing. In short this relationship can be more formally described as how we can use an equivalence relation to partition $A$ into several \\textit{equivalence classes}. We will fully define these terms more formally later. First we begin with the definition of an equivalence relation. \n\n\\begin{definition}\nLet $A$ be a set. An equivalence relation $\\sim \\subset A \\times A$ is a relation with the following properties:\n\\begin{enumerate}\n\t\\item For all $a \\in A$, $a \\sim a$.\n\t\\item If $a \\sim b$ for $a, b \\in A$, then $b \\sim a$.\n\t\\item If $a \\sim b$ and $b \\sim c$, then $a \\sim c$. \n\\end{enumerate}\n\nMoreover, these conditions have specific names.\n\\begin{enumerate}\n\t\\item Any relation satisfying the first condition is called \\textit{reflexive}.\n\t\\item Any relation satisfying the second condition is called \\textit{symmetric}.\n\t\\item Any relation satisfying the third condition is called \\textit{transitive}.\n\\end{enumerate}\n\\end{definition}\n\nLet us unpack the criterion for an equivalence relation $\\sim$ on $A$. The first condition simply states that every element in $a$ is related to itself. The second condition models the condition that if $a$ is related to $b$, then $b$ should be related to $a$ as well. The third condition asserts the \\textit{transitivity} of the relation $\\sim$. That is, if $a$ is related to $b$, and $b$ is related to $c$, then $a$ should be related to $c$; that is, we can chain relations to get other relations.\n\n\\begin{example}\nThe notion of object equality is an equivalence relation. More formally, the $=$ symbol can be seen as a relation on any set $A$. We check that this satisfies all the properties that an equivalence relation should satisfy:\n\\begin{enumerate}\n\t\\item $a = a$ for all $a \\in A$.\n\t\\item If $a = b$, then $b = a$ as well.\n\t\\item If $a = b$ and $b = c$, then $a = c$ as well.\n\\end{enumerate}\n\\end{example}\nThe verifications we made above are true because they are in fact properties of \\textit{equality} itself. In fact, the definition of an equivalence relation was formed to encode more general notions of equality. We will describe more examples of equivalence relations later in the section and explore for each relation in what way the elements are the same. \n\n\\begin{example}\\label{apt1_eqr}\nSuppose we have an apartment building $A$. Let $S$ be the set of all residents in $A$. We will define an equivalence relation $\\sim$ on $S$ as follows. For $s, t \\in S$ (ie, any two residents of the building), we say that $s \\sim t$ if $s$ and $t$ live at the same apartment number. We can verify that this is an equivalence relation by verifying the three properties an equivalence relation needs to satisfy:\n\\begin{enumerate}\n\t\\item For any $s \\in S$, $s \\sim s$ by default because they are the same person and hence they live at the same apartment number.\n\t\\item If $s$ and $t$ live in the same apartment number this is the same as saying that $t$ and $s$ live at the same apartment number. So if $s \\sim t$, then $t \\sim s$.\n\t\\item If $s \\sim t$ and $t \\sim r$, then $s$, $t$, and $r$ all live at the same apartment number. It follows that $s \\sim r$ as desired.\n\\end{enumerate}\n\\end{example}\n\n\\begin{example}\\label{even_odd_eqr}\nFor the set $\\mathbb{Z}$ define a relation $\\sim$ as follows. We have $a \\sim b$ if $a - b$ is even. We can verify that this relation is an equivalence relation below:\n\\begin{enumerate}\n\t\\item $a-a = 0$, which is even (it is $2 \\times 0$), so $a \\sim a$.\n\t\\item If $a \\sim b$, then $a - b$ is even. It follows that $b - a = -(a-b)$ is even as well. For if $a - b = 2m$ for some integer $m$ then $b - a = -(a-b) = -2m = 2(-m)$ can be seen to be an even integer. So $b \\sim a$.\n\t\\item If $a \\sim b$ and $b \\sim c$, then $a - b$ and $b - c$ are both even. So $a - b = 2m$ and $b - c = 2n$ for some integers $m$ and $n$. It can be seen that their sum must be even as well. But we have\n\t\\[a - c = (a - b) + (b - c) = 2m + 2n = 2(m + n)\\]\n\tso it follows that $a - c$ is even as well. Hence $a \\sim c$ and the relation is transitive.\n\\end{enumerate}\n\nSo it follows that $\\sim$ is an equivalence relation. We can verify that $a \\sim b$ only if $a$ and $b$ are both odd or both even. So in this case, $\\sim$ defines whether or not items are the same based on whether or not they have the same remainder when integer dividing by $2$.\n\nWe will also show that a similar looking relation is not an equivalence relation. Suppose instead we define $a \\sim b$ if $a \\sim b$ is odd. One can check that this relation is symmetric, but it is neither reflexive nor transitive.\n\\end{example}\n\n\\begin{example}\\label{modm_eqr}\nWe can generalize the previous example as follows. For the set $\\mathbb{Z}$ we can define a relation $\\sim$ with the property that $a \\sim b$ if $b - a$ is divisible by a positive integer $m$ (where $m$ is given in advance). One can check as above that this forms an equivalence relation.\n\\end{example}\n\nAt the beginning of this (sub)section we described two different ways of looking at an equivalence relation. We have made the second way (an equivalence relation as determining whether two elements are the ``same'' in some sense) above. We now make the first notion (an equivalence relation as a classifier) precise.\n\n\\begin{definition}\nSuppose $S$ is a set. Then a partition $P$ of $S$ is a collection of subsets $P_n$ (possibly infinite) where any two $P_i$ and $P_j$ are mutually disjoint and $\\bigcup_{j = 1}^nP_j = S$. \n\\end{definition}\n\nOne can use the word ``partition'' either as a noun indicating a set partition, as defined above, or as a verb describing the action of dividing a set into disjoint subsets. In the example below ``partition'' is used in its verb form.\n\n\\begin{example}\nWe can partition the set $S = \\{1, 2, 3, 4, 5, 6\\}$ into the even elements $E = \\{2, 4, 6\\}$ and odd elements $O = \\{1, 3, 5\\}$. One can easily see that $E$ and $O$ are disjoint and $E \\cup O = S$.\n\\end{example}\n\nNow we will describe how given an equivalence relation we can partition a set in a natural way. The idea is to include elements in the same subset if they are related to each other. A typical example is the previous example. If $\\sim$ represents the equivalence relation $a \\sim b$ if $a - b$ is even, then all the elements in $E$ are equivalent and all the elements in $O$ are equivalent. To generalize this notion to any equivalence relation, we will introduce the notion of an \\textit{equivalence class}.\n\n\\begin{definition}\nSuppose that $S$ is a set and $\\sim$ is an equivalence relation on $S$. Let $a \\in S$ be any element. We define \n\\[C_a = \\{s \\in S \\mid s \\sim a\\}.\\]\nIn other words, $C_a$ is the subset of $S$ whose elements are all equivalent to $a$.\n\\end{definition}\n\n\\begin{example}\\ref{even_odd2_eqr}\nIn example \\ref{even_odd_eqr} we defined an equivalence relation on $\\mathbb{Z}$ with $a \\sim b$ if $a - b$ was an even number. For this example we consider what $C_0$ is. If $a \\sim 0$, then $a - 0 = a$ is an even number, and conversely. So $C_0 = \\{\\dots,-4, -2, 0, 2, 4, \\dots,\\}$. Similarly, we see that $C_1 = \\{\\dots,-3, -1, 1, 3, \\dots\\}$. We might observe the following:\n\\begin{itemize}\n\t\\item $C_0$ and $C_1$ are disjoint. Their union is all of $\\mathbb{Z}$, so $C_0$ and $C_1$ form a partition of the integers.\n\t\\item We might notice that $C_4$, $C_2$, and $C_0$ are all the same sets. Indeed, we can convince ourselves that in this example, no matter what element $i$ we take from $C_0$, it will be the case that $C_i = C_0$. So an equivalence class seems to not depend on the \\textit{choice of representative}.\n\\end{itemize}\n\\end{example}\n\nLet's further explain what we mean by a \\textit{choice of representative}. In defining an equivalence class $C_a$, we make a choice of element $a$. But as the above example demonstrates, it seems like we can choose any element from an equivalence class and the resulting equivalence class will turn out to be same. In fact, this happens for any general equivalence relation and we will explain why below. The reasoning follows from a particular claim:\n\n\\begin{proposition}\nLet $S$ be a set, and let $\\sim$ be an equivalence relation on $S$. For any $a, b \\in S$, two possibilities happen.\n\\begin{enumerate}\n\t\\item $C_a \\cap C_b = \\varnothing$, or the two equivalence classes are disjoint.\n\t\\item $C_a = C_b$, ie, the two equivalence classes are the same. \n\\end{enumerate}\n\\end{proposition}\n\nTo show that this claim is true, we examine the two subsets $C_a$ and $C_b$. Maybe it is the case that $C_a \\cap C_b = \\varnothing$. Then this possibility has happened and there is nothing left to show. The other possibility is that $C_a \\cap C_b \\neq \\varnothing$. Then to show that the claim is true we need to show that in fact $C_a = C_b$.\n\nFirst we show that $a \\sim b$. Since $C_a \\cap C_b \\neq \\varnothing$ there is an element $c \\in C_a \\cap C_b$. By definition of set intersection, $c \\in C_a$, and also $c \\in C_b$. By definition of $C_a$ and $C_b$, we have that \n\\[c \\sim a, c \\sim b.\\]\nBy symmetry of the equivalence relation, $a \\sim c$, and hence by transitivity we have $a \\sim b$.\n\nNow that we know that $a \\sim b$ it is pretty easy to show that $C_a \\subset C_b$ and vice versa. To show that $C_a \\subset C_b$, suppose $d$ is any element of $C_a$. By definition, $d \\sim a$. But since $a \\sim b$, by transitivity, $d \\sim b$. So $d \\in C_b$. It follows that $d \\in C_b$. So $C_a \\subset C_b$ as desired. To show $C_b \\subset C_a$ is the same reasoning except we use the fact that $b \\sim a$ (which is true by the symmetry property, since $a \\sim b$).\n\n%%%still need to explain how this gives you a partition of S\nWe are almost done. Now we just need to answer the following question: how does this claim help us generate a partition of the set $S$? To answer this partially we might describe how to partition $S$ using an iterative process:\n\\begin{enumerate}\n\t\\item Choose any element $a \\in S$. We take $C_a$.\n\t\\item Choose any element $b \\in S$, $b \\not\\in C_a$. This ensures that $C_a \\cap C_b = \\varnothing$ (why?). \n\t\\item Choose any element $c \\in S$, $c \\not\\in C_a \\cup C_b$. This ensures that $C_c$ is disjoint from the first two sets. \n\t\\item Keep going like this until $S$ is exhausted of elements.\n\\end{enumerate}\nIn more informal terms, we think about $S$ as a big box of elements, and we keep taking out elements of $S$ in bags (which are the equivalence classes), until $S$ is empty. The reason why this is not quite complete is that of course $S$ may be infinite, and the equivalence classes finite, so of course one might never reach a complete partition of $S$ by doing this. But the idea is still the same.\n\nTo partition any general set $S$ with an equivalence relation $\\sim$ we first observe that the following identity holds:\n\\[S = \\bigcup_{a \\in S}C_a.\\]\nTo see why this is true, we first observe that since all the $C_a \\subset S$, then the backwards inclusion is true, ie $S \\supset \\bigcup_{a \\in S}C_a$. For the forwards inclusion we observe that for any $c \\in S$, $c \\in C_c$ because $c \\sim c$ by reflexivity. It follows that the forward inclusion holds, and hence the set equality holds.\n\nNow we are tempted to say that the collection $\\{C_a\\}_{a \\in S}$ is the required partition, because by the claim we showed above, the $C_a$ are either the same or disjoint. However, since some of the $C_a$ may be the same this is not generally a partition yet. What we do now is consider all collections $C_a, C_b, \\dots$ which are the same, and discard all but one of them. After this process is completed we have our required partition.\n\n\\begin{example}\\label{apt2_eqr}\nIn Example \\ref{apt1_eqr}, we showed that the equivalence relation $p \\sim q$ on two apartment building residents if $p$ and $q$ live at the same apartment number was an equivalence relation. The equivalence class $C_p$ consists of the set of all people who are roommates with $p$. In general, by our reasoning above, the collection of distinct and disjoint equivalence classes partitions the set of apartment residents $A$. Ignoring the representative of any equivalence class, we see that any subset used in our partition is just the collection of all the people living in a particular apartment number. \n\nIf we are to view this equivalence relation as a classifier, then roughly speaking this equivalence relation classifies people based on what apartment number they reside at. \n\\end{example}\n\n\\begin{example}\\label{mod2_classes_eqr}\nIn Example \\ref{even_odd2_eqr} we divided the integers $\\mathbb{Z}$ based on whether they were odd or even. So in terms of a classifier this equivalence relation classifies integers based on whether or not they are even or odd.\n\\end{example}\n\n\\subsubsection{Exercises}\n\n\\begin{enumerate}\n\t\\item \\input{Ch3/2_ex/problem_1}\n\t\\item \\input{Ch3/2_ex/problem_2}\n\t\\item Suppose Lily presents to you the following argument that a relation having the transitive and symmetric property is in fact reflexive: they explain that since $a \\sim b$, then by symmetry, $b \\sim a$. But then by transitivity, $a \\sim a$. So the relation must be reflexive. Is Lily right? If not, what is wrong with their argument? \n\t\\item \\input{Ch3/2_ex/problem_5}\n\t\\item \\input{Ch3/2_ex/problem_6}\n\\end{enumerate}", "meta": {"hexsha": "0565e3c3de9a08a6177955ae37648715ef6e36f3", "size": 13841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch3/eqr.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch3/eqr.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch3/eqr.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.4551724138, "max_line_length": 606, "alphanum_fraction": 0.729716061, "num_tokens": 3828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305328688783, "lm_q2_score": 0.9136765151867664, "lm_q1q2_score": 0.8800811165931287}} {"text": "\\subsection{Time Series Normalization} \\label{time_series_normalization} \n\nLiterature on time series mining \\cite{ding2008querying,spiegel2015diss} suggests to normalize all (sub-)sequences before measuring their pair-wise dissimilarity by means of a distance measure. There are multiple ways to normalize time series, where two common techniques \\cite{das1998rule} are compared in this study.\n\nGiven is a time series $Q = (q_1, \\dots, q_n)$ of length $n$, we can compute its mean $\\mu$ and standard deviation $\\sigma$ as followed:\n\n\\begin{equation*}\n\\mu = \\frac{1}{n} \\sum_{i=1}^{n} q_i \t\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; \t\\sigma = \\frac{1}{n} \\sum_{i=1}^{n} (q_i - \\mu)^2\n\\end{equation*}\n\nHaving defined the mean $\\mu$ and standard deviation $\\sigma$, we can normalize each data point $q_i$ (with $1\\leq i \\leq n$) of a time series $Q = (q_1, \\dots, q_n)$ in one of the two following ways \\cite{das1998rule}:\n\n\\begin{equation}\n\\eta(q_i) = q_i - \\mu\n\\end{equation}\n\n\\begin{equation}\nz(q_i) = \\frac{q_i - \\mu}{\\sigma}\n\\label{eqn:zscore}\n\\end{equation}\n\nEquation \\ref{eqn:zscore} is commonly known as the Z-score. For the sake of simplicity we refer to $\\eta$ and $z$ normalization \\cite{das1998rule} for the rest of the paper.\n\n\n", "meta": {"hexsha": "f3b855a25ef22f9b2a16e007dfa5f7228047a8c6", "size": 1229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background_and_notation/dynamic_time_warping/time_series_normalization.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "paper/background_and_notation/dynamic_time_warping/time_series_normalization.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/background_and_notation/dynamic_time_warping/time_series_normalization.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 49.16, "max_line_length": 319, "alphanum_fraction": 0.704637917, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269985, "lm_q2_score": 0.9263037262250327, "lm_q1q2_score": 0.8796822750262235}} {"text": "%% 5\n\\section{ Monoids. }\n\n\\subsection{Natural numbers.} Natural numbers form a monoid with respect to addition.\nTo prove that, we need to show that in $\\mathbb{N}$ we have an operation $+$ that has a left and right identity.\nThis identity element is zero, as indeed\n\\begin{align*}\n\\forall n \\in \\mathbb{N},&& 0 + n &= n && \\text{by definition of addition} \\\\\n && n + 0 &= n && \\text{Lemma 2.2.2 in Tao's {\\em Analysis I}}\n\\end{align*}\nAddition is associative, too, as per Proposition 2.2.5 (Exercise 2.2.1) in {\\em Analysis I}\\cite{tao2016}.\nWe omit the proof here, as in the next part of the question we'll need to prove the same for a list --- and we can always \nprove associativity of naturals by reduction to lists, if we choose a (length of) string of 1 as a representation of natural numbers.\n\n\\subsection{A string of 0 and 1.}\nStrings form a monoid with respect to concatenation. Concatenation of two strings is a string, so the type checks;\nconcatenation with an empty string is the original string; and, intuitively, concatenation seems to be associative. \n\n\\newcommand\\cat{+\\kern-1.3ex+\\kern0.8ex} % https://tex.stackexchange.com/questions/4194/how-to-typeset-haskell-operator-and-friends\nMore formally, concatenation is Haskell is defined\\cite{base-src} as (we omit compiler directives here for clarity)\n\\begin{minted}{haskell}\n(++) :: [a] -> [a] -> [a]\n(++) [] ys = ys\n(++) (x:xs) ys = x : xs ++ ys\n\\end{minted}\nIgnoring infinite lists for the sake of this exercise, we can see that from the first clause, \\mintinline{haskell}{[]} is indeed a left unit. \n\nRight unit is trickier, but we can follow Tao's Lemma 2.2.2: The base case, $[] \\cat [] = []$ holds as we know that \\mintinline{haskell}{[]} \nis a left unit. Now suppose inductively that $xs \\cat [] = xs.$ We wish to show that $(x:xs) \\cat [] = (x:xs)$. \nFrom the second clause in the function definition, $(x:xs) \\cat [] = x : (xs \\cat []) = x : xs,$ and that closes the induction.\n\nTao leaves the proof of associativity to the reader, so we cannot avoid proving that. Since the string, being a list in Haskell, is an inductive data type,\nit is natural to use induction again. We consider concatenation $as \\cat bs \\cat cs$ and would like to show that $as \\cat (bs \\cat cs) = (as \\cat bs) \\cat cs.$\nBase case, $[] \\cat (bs \\cat cs) = ([] \\cat bs) \\cat cs,$ is trivial as \\mintinline{haskell}{[]} is a left unit by definition of concatenation.\nNow suppose that associativity holds for $as \\cat (bs \\cat cs) = (as \\cat bs) \\cat cs.$ We want to show that $(a : as) \\cat (bs \\cat cs) = ((a : as) \\cat bs) \\cat cs:$\n\\begin{align*}\n(a : as) \\cat (bs \\cat cs) &= a : (as \\cat (bs \\cat cs)) = && \\text{second clause of definition} \\\\\n &= a : ((as \\cat bs) \\cat cs) = && \\text{from induction hypothesis} \\\\\n &= (a : (as \\cat bs)) \\cat cs = && \\text{reversed second clause} \\\\\n &= ((a : as) \\cat bs) \\cat cs && \\text{reversed second clause again} \n\\end{align*}\nand the induction is closed.\n\nNote that we never used the actual list elements here; indeed, the function definition is generic, and does not know what the element type is. \nSo if we use \\mintinline{haskell}{Either One Zero} for \\mintinline{haskell}{a}, our proof stays true for strings of ones and zeros. ", "meta": {"hexsha": "a7cc1b0cf40d9a39d6c3ec5b8b4f33dc6eecd797", "size": 3335, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1/ps1_q5.tex", "max_stars_repo_name": "alf239/procats", "max_stars_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1/ps1_q5.tex", "max_issues_repo_name": "alf239/procats", "max_issues_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1/ps1_q5.tex", "max_forks_repo_name": "alf239/procats", "max_forks_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.1111111111, "max_line_length": 167, "alphanum_fraction": 0.6695652174, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660936744719, "lm_q2_score": 0.9219218332461266, "lm_q1q2_score": 0.8794821699350154}} {"text": "\n\\subsection{Linear algebra}\nThe function $dot$ is used to multiply vectors and matrices.\nLet\n\n\\[\nA=\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}\n\\quad{\\rm and}\\quad x=\\begin{pmatrix}x_1\\\\x_2\\end{pmatrix}\n\\]\n\nThe following example computes $Ax$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((1,2),(3,4))\nx = (x1,x2)\ndot(A,x)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}x_1+2x_2\\\\3x_1+4x_2\\end{bmatrix}$\n\nThe following example shows how to use $dot$ and $inv$ to solve for\nthe vector $X$ in $AX=B$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((3,7),(1,-9))\nB = (16,-22)\nX = dot(inv(A),B)\nX\n\\end{Verbatim}\n\n$\\displaystyle X=\\begin{bmatrix}-\\frac{5}{17}\\\\ \\frac{41}{17}\\end{bmatrix}$\n\n%One might wonder why the $dot$ function is necessary.\n%Why not simply use $X=inv(A)*B$ like scalar multiplication?\n%The reason is that the software normally reorders factors internally to\n%optimize processing.\n%For example, $inv(A)*B$ in symbolic form is changed to $B*inv(A)$\n%internally.\n%Since the dot product is not commutative, this reordering would give the\n%wrong result.\n%Using a function to do the multiply avoids the problem because\n%function arguments are not reordered.\n\nThe $dot$ function can have more than two arguments.\nFor example, $dot(A,B,C)$ can be used for the dot product of three tensors.\n\nSquare brackets are used for component access.\nIndex numbering starts with 1.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((a,b),(c,d))\nA[1,2] = -A[1,1]\nA\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}a&-a\\\\c&d\\end{bmatrix}$\n\nThe following example demonstrates the relation\n$A^{-1}=\\mathop{\\rm adj}{A}/\\mathop{\\rm det}{A}$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((a,b),(c,d))\ninv(A)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}\\frac{d}{ad-bc} & -\\frac{b}{ad-bc}\\\\-\\frac{c}{ad-bc} & \\frac{a}{ad-bc}\\end{bmatrix}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nadj(A)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}d & -b\\\\-c & a\\end{bmatrix}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ndet(A)\n\\end{Verbatim}\n\n$\\displaystyle ad-bc$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ninv(A) - adj(A)/det(A)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}0 & 0\\\\0 & 0\\end{bmatrix}$\n\nSometimes a calculation will be simpler if it can be reorganized to use\n$adj$ instead of $inv$.\nThe main idea is to try to prevent the determinant from appearing as a\ndivisor.\nFor example, suppose for matrices $A$ and $B$ you want to check that\n$${A}-{B}^{-1}=0$$\nDepending on the complexity of $\\mathop{\\rm det}B$, the software\nmay not be able to find a simplification that yields zero.\nShould that occur, the following alternative formulation can be tried.\n$$(\\mathop{\\rm det}{B})\\cdot{A}-\\mathop{\\rm adj}{B}=0$$\n\nThe adjunct of a matrix is related to the cofactors as follows.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((a,b),(c,d))\nC = ((0,0),(0,0))\nC[1,1] = cofactor(A,1,1)\nC[1,2] = cofactor(A,1,2)\nC[2,1] = cofactor(A,2,1)\nC[2,2] = cofactor(A,2,2)\nC\n\\end{Verbatim}\n\n$\\displaystyle C=\\begin{bmatrix}d&-c\\\\-b&a\\end{bmatrix}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nadj(A) - transpose(C)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}0&0\\\\0&0\\end{bmatrix}$\n", "meta": {"hexsha": "7c6a151c24c82259890cca566d3e70e0edc78f79", "size": 3260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/linear-algebra.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/linear-algebra.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/linear-algebra.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1034482759, "max_line_length": 114, "alphanum_fraction": 0.7024539877, "num_tokens": 1108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377261041521, "lm_q2_score": 0.9173026573249611, "lm_q1q2_score": 0.8792692033015644}} {"text": "\\section{Linear Algebra and Calculus}\n\\subsection{General Notation}\nA vector $x \\in \\mathbb{R}^n$ has $n$ entries, and $x_i \\in \\mathbb{R}$ is the\n$i$-th entry:\n\\begin{equation}\n x=\\left(\\begin{array}{c}x_1\\\\x_2\\\\\\vdots\\\\x_n\\end{array}\\right)\\in\\mathbb{R}^n\n\\end{equation}\nWe denote a matrix $A \\in \\mathbb{R}^{m \\times n}$ with $m$ rows and $n$\ncolumns, and $A_{ij} \\in \\mathbb{R}$ is the entry in the $i$-th row and\n$j$-th column:\n\\begin{equation}\n A=\\left(\\begin{array}{ccc}A_{11}& \\cdots&A_{1n}\\\\\\vdots&& \\vdots\\\\A_{m1}& \\cdots&A_{mn}\\end{array}\\right)\\in\\mathbb{R}^{m\\times n}\n\\end{equation}\nVectors can be viewed as a $n \\times 1$ matrix.\n\\subsubsection{Indentity Matrix}\nThe identity matrix $I\\in\\mathbb{R}^{n\\times n}$ is a square matrix with ones\nalong the diagonal and zero everywhere else:\n\\begin{equation}\n I=\\left(\\begin{array}{cccc}1&0& \\cdots&0\\\\0& \\ddots& \\ddots& \\vdots\\\\\\vdots& \\ddots& \\ddots&0\\\\0& \\cdots&0&1\\end{array}\\right)\n\\end{equation}\nFor all matrices $A \\in \\mathbb{R}^{n \\times n}$ we have\n$A \\times I = I \\times A = A$.\n\\subsubsection{Diagonal Matrix}\nA diagonal matrix $D \\in \\mathbb{R}^{n \\times n}$\nis a square matrix with nonzero values along the diagonal and zero everywhere\nelse:\n\\begin{equation}\n D=\\left(\\begin{array}{cccc}d_1&0& \\cdots&0\\\\0& \\ddots& \\ddots& \\vdots\\\\\\vdots& \\ddots& \\ddots&0\\\\0& \\cdots&0&d_n\\end{array}\\right)\n\\end{equation}\nThe diagonal matrix $D$ is also written as $\\textrm{diag}(d_1,\\hdots,d_n)$.\n\\subsubsection{Orthogonal Matrix}\nTwo vectors $x, y \\in \\mathbb{R}^n$ are orthogonal if $x^T y = 0$. A vector\n$x \\in \\mathbb{R}^n$ is normalized if $||x||_2 = 1$.\nA square matrix $U\\in \\mathbb{R}^{n \\times n}$ is orthogonal if all its\ncolumns are orthogonal to each other and are normalized. Hence:\n\\begin{equation}\n U^TU = I = UU^T\n\\end{equation}\nHence the inverse of an orthogonal matrix is its transpose.m\n\\subsection{Matrix Operations}\n\\subsubsection{Vector-Vector Products}\nGiven two vectors $x$, $y \\in \\mathbb{R}^n$, the inner product is:\n\\begin{equation}\n x^T y = \\sum_{i=1}^n x_i y_i \\in \\mathbb{R}\n\\end{equation}\nThe outer product for a vector $x \\in \\mathbb{R}^m$, $y \\in \\mathbb{R}^n$ is:\n\\begin{equation}\n xy^T=\\left(\\begin{array}{ccc}x_1y_1& \\cdots&x_1y_n\\\\\\vdots&\\ddots& \\vdots\\\\x_my_1& \\cdots&x_my_n\\end{array}\\right)\\in\\mathbb{R}^{m\\times n}\n\\end{equation}\n\\subsubsection{Vector-Matrix Products}\nThe product of a matrix $A \\in \\mathbb{R}^{m \\times n}$ and vector\n$x \\in \\mathbb{R}^n$ is a vector $y = Ax \\in \\mathbb{R}^m$. If we write $A$\nby the rows, $Ax$ is expressed as:\n\\begin{equation}\n y = A x = \\left( \\begin{array} { c } { - \\,\\, a _ { 1 } ^ { T } \\,\\,- } \\\\ { - \\,\\,a _ { 2 } ^ { T }\\,\\, -} \\\\ { \\vdots } \\\\ { - \\,\\, a _ { m } ^ { T } \\,\\,-} \\end{array} \\right) x = \\left( \\begin{array} { c } { a _ { 1 } ^ { T } x } \\\\ { a _ { 2 } ^ { T } x } \\\\ { \\vdots } \\\\ { a _ { m } ^ { T } x } \\end{array} \\right)\n\\end{equation}\nHere, the $i$-th entry of $y$ is the inner product of the $i$-th row of $A$ and\n$x$, $y_i = a_i^T x$. If we write $A$ is column form:\n\\begin{equation}\n y = A x = \\left( \\begin{array} { c c c c } { | } & { | } & { } & { | } \\\\ { a _ { 1 } } & { a _ { 2 } } & { \\cdots } & { a _ { n } } \\\\ { | } & { | } & { } & { | } \\end{array} \\right) \\left( \\begin{array} { c } { x _ { 1 } } \\\\ { x _ { 2 } } \\\\ { \\vdots } \\\\ { x _ { n } } \\end{array} \\right) = a _ { 1 } x _ { 1 } + a _ { 2 } x _ { 2 } + \\ldots + a _ { n } x _ { n }\n\\end{equation}\nHere, $y$ is a linear combination of the columns of $A$, where the coefficients\nof the linear combination are given by the entries of $x$.\n\\subsubsection{Matrix-Matrix Products}\nGiven a matrix $A\\in \\mathbb{m \\times n}$ and matrix $B \\in \\mathbb{n \\times p}$,\nwe can define $C = AB$ as follows:\n\\begin{equation}\n C = AB = \\left( \\begin{array} { c c c c } { a _ { 1 } ^ { T } b _ { 1 } } & { a _ { 1 } ^ { T } b _ { 2 } } & { \\cdots } & { a _ { 1 } ^ { T } b _ { p } } \\\\ { a _ { 2 } ^ { T } b _ { 1 } } & { a _ { 2 } ^ { T } b _ { 2 } } & { \\cdots } & { a _ { 2 } ^ { T } b _ { p } } \\\\ { \\vdots } & { \\vdots } & { \\ddots } & { \\vdots } \\\\ { a _ { m } ^ { T } b _ { 1 } } & { a _ { m } ^ { T } b _ { 2 } } & { \\cdots } & { a _ { m } ^ { T } b _ { p } } \\end{array} \\right)\n\\end{equation}\nHence, each $(i,j)$-th entry of $C$ is equal to the inner product of the $i$-th\nrow of $A$ and the $j$-th column of $B$. Compactly:\n\\begin{equation}\n C_{ij} = a_i^T b_j = \\sum_{k=1}^n a_{ik} b_{kj}\n\\end{equation}\n\\subsubsection{The Transpose}\nThe transpose of a matrix $A\\in \\mathbb{R}^{m \\times n}$ is\n$A^T \\in \\mathbb{R}^{n \\times m}$ matrix whose entries are:\n\\begin{equation}\n (A^T)_{ij} = A_{ji}\n\\end{equation}\nProperties of the transpose:\n\\begin{enumerate}\n \\item $(A^T)^T = A$\n \\item $(AB)^T = B^T A^T$\n \\item $(A + B)^T = A^T + B^T$\n\\end{enumerate}\n\\subsubsection{The Trace}\nThe trace of a square matrix $A \\in \\mathbb{R}^{n \\times m}$ is denoted\n$\\operatorname{tr}(A)$. It is the sum of diagonal elements in the matrix:\n\\begin{equation}\n \\operatorname{tr}A = \\sum_{i=1}^n A_{ii}\n\\end{equation}\nProperties of the trace:\n\\begin{enumerate}\n \\item For $A \\in \\mathbb{R}^{n \\times n}$, $\\operatorname{tr}A=\\operatorname{tr}A^T$\n \\item For $A, B \\in \\mathbb{R}^{n \\times n}$, $\\operatorname{tr}(A+B)=\\operatorname{tr}A+\\operatorname{tr}B$\n \\item For $A \\in \\mathbb{R}^{n \\times n}$, $t\\in \\mathbb{R}$, $\\operatorname{tr}(tA)=t \\cdot \\operatorname{tr}A$\n \\item For $A, B$ such that $AB$ is square, $\\operatorname{tr}AB = \\operatorname{tr}BA$\n \\item For $A,B,C$ such that $ABC$ is square, $\\operatorname{tr}ABC=\\operatorname{tr}BCA = \\operatorname{tr}CAB$, and so on\n\\end{enumerate}\n\\subsubsection{The Inverse}\nThe inverse of a matrix $A$ is noted $A^{-1}$ and is the unique matrix\nsuch that:\n\\begin{equation}\n A^{-1}A=I=AA^{-1}\n\\end{equation}\nNot all square matrices are invertible. In addition, assuming\n$A, B \\in \\mathbb{R}^{n \\times n}$ are non-singular:\n\\begin{enumerate}\n \\item $(A^{-1})^{-1} = A$\n \\item $(AB)^{-1} = B^{-1}A^{-1}$\n \\item $(A^{-1})^T = (A^T)^{-1}$\n\\end{enumerate}\n\\subsubsection{The Determinant}\nThe determinant of a square matrix $A\\in\\mathbb{R}^{n\\times n}$, noted $|A|$\nor $\\textrm{det}(A)$ is expressed recursively in terms of\n$A_{\\backslash i, \\backslash j}$, which is the matrix $A$ without\nits $i$-th row and $j$-th column, as follows:\n\\begin{equation}\n \\textrm{det}(A)=|A|=\\sum_{j=1}^n(-1)^{i+j}A_{i,j}|A_{\\backslash i,\\backslash j}|\n\\end{equation}\nRemark that $A$ is invertible if and only if $|A| \\not= 0$. Also, $|AB|=|A||B|$\nand $|A^T|=|A|$.\n\\subsection{Matrix Properties}\n\\subsubsection{Norms}\nA norm of a vector $x$ is any function $f:\\mathbb{R}^{n} \\rightarrow \\mathbb{R}$\nthat satisfies 4 properties:\n\\begin{enumerate}\n \\item Non-negativity: For all $x \\in \\mathbb{R}^n$, $f(x) \\geq 0$\n \\item Definiteness: $f(x)=0$ if and only if $x=0$\n \\item Homogeneity: For all $x \\in \\mathbb{R}^n$, $t \\in \\mathbb{R}$,\n $f(tx) = |t| f(x)$\n \\item Triangle Inequality: For all $x, y \\in \\mathbb{R}^n$, $f(x+y) \\leq f(x) + f(y)$\n\\end{enumerate}\nHowever, most norms used come from the family of $\\ell_p$ norms:\n\\begin{equation}\n \\ell_p = ||x||_p = \\left( \\sum_{i=1}^n x_i^p \\right)^{\\frac{1}{p}}\n\\end{equation}\nThe $p$-norm is used in Holder's inequality. The Manhattan norm, used in\nLASSO regularization, is:\n\\begin{equation}\n \\ell_1 = ||x||_1 = \\sum_{i=1}^n |x_i|\n\\end{equation}\nThe euclidean norm, $\\ell_2$ is used in ridge regularization and\ndistance measures:\n\\begin{equation}\n \\ell_2 = || x ||_2 = \\sqrt{\\sum_{i=1}^n x_i^2}\n\\end{equation}\nFinally, the infinity norm is used in uniform convergence:\n\\begin{equation}\n \\ell_{\\infty} = || x ||_{\\infty} = \\underset{i}{\\textrm{max }}|x_i|\n\\end{equation}\nThe Frobenius norm of a matrix is analogous to the $\\ell_2$ norm of a vector:\n\\begin{equation}\n ||A||_F = \\sqrt{\\sum_{ij}A^2_{ij}}\n\\end{equation}\nThe dot product of two vectors can be expressed in terms of norms:\n\\begin{equation}\n x^T y = ||x||_2 ||y||_2 \\cos \\theta\n\\end{equation}\nwhere $\\theta$ is the angle between vectors $x$ and $y$.\n\\subsubsection{Linear Dependence and Rank}\nA set of vectors $\\{x_1, x_2, \\hdots, x_n\\} \\subset \\mathbb{R}^m$ is linearly\nindependent if no vector can be represented as a linear combination of the\nremaining vectors. Conversely, if one vector in the set can be represented\nas a linear combination of the remaining vectors, then the vectors are\nsaid to be linearly dependent. Formally, for scalar values\n$\\alpha_1, \\hdots, \\alpha_{n-1} \\in \\mathbb{R}$:\n\\begin{equation}\n x_n = \\sum_{i=1}^{n-1} \\alpha_i x_i\n\\end{equation}\nThe rank of a given matrix $A$ is noted $\\operatorname{rank}(A)$\nand is the dimension of the vector space generated by its columns.\nThis is equivalent to the maximum number of linearly independent columns of\n$A$. If $\\operatorname{rank}(A) = \\min(m,n)$, then $A$ is said to be full rank.m\n\\subsubsection{Span, Range, and Nullspace}\nThe span of a set of vectors $\\{x_1, x_2, \\hdots, x_n\\}$ is the set of all\nvectors that can be expressed as a linear combination of\n$\\{x_1, x_2, \\hdots, x_n\\}$. Formally,\n\\begin{equation}\n \\operatorname { span } \\left( \\left\\{ x _ { 1 } , \\ldots x _ { n } \\right\\} \\right) = \\left\\{ v : v = \\sum _ { i = 1 } ^ { n } \\alpha _ { i } x _ { i } , \\quad \\alpha _ { i } \\in \\mathbb { R } \\right\\}\n\\end{equation}\nThe projection of a vector $y \\in \\mathbb{R}^n$ onto the span of\n$\\{x_1, x_2, \\hdots, x_n\\}$ is the vector\n$v \\in \\operatorname { span } \\left( \\left\\{ x _ { 1 } , \\ldots x _ { n } \\right\\} \\right)$\nsuch that $v$ is as close as possible to $y$ as measured by the euclidean norm:\n\\begin{equation}\n \\operatorname { Proj } \\left( y ; \\left\\{ x _ { 1 } , \\ldots x _ { n } \\right\\} \\right) = \\operatorname { argmin } _ { v \\in \\operatorname { span } \\left( \\left\\{ x _ { 1 } , \\ldots , x _ { n } \\right\\} \\right) } \\| y - v \\| _ { 2 }\n\\end{equation}\nThe range of a matrix $A\\in \\mathbb{R}^{m \\times n}$ is the span of the columns\nof $A$:\n\\begin{equation}\n \\mathcal { R } ( A ) = \\left\\{ v \\in \\mathbb { R } ^ { m } : v = A x , x \\in \\mathbb { R } ^ { n } \\right\\}\n\\end{equation}\nThe nullspace of a matrix $A \\in \\mathbb{R}^{m \\times n}$ is the set of all\nvectors that equal $0$ when multiplied by $A$:\n\\begin{equation}\n \\mathcal { N } ( A ) = \\left\\{ x \\in \\mathbb { R } ^ { n } : A x = 0 \\right\\}\n\\end{equation}\n\\subsubsection{Symmetric Matrices}\nA square matrix $A \\in \\mathbb{R}^{n \\times n}$ is symmetric if $A=A^T$. It\nis anti-symmetric if $A=-A^T$. For any matrix $A\\in \\mathbb{R}^{n \\times n}$\nthe matrix $A+A^T$ is symmetric and the matrix $A-A^T$ is anti-symmetric.\nFrom this, any square matrix $A \\in \\mathbb{R}^{n \\times n}$ can be represented\nas a sum of a symmetric matrix and an anti-symmetric matrix:\n\\begin{equation}\n A=\\underbrace{\\frac{A+A^T}{2}}_{\\textrm{Symmetric}}+\\underbrace{\\frac{A-A^T}{2}}_{\\textrm{Antisymmetric}}\n\\end{equation}\n\\subsubsection{Positive Semidefinite Matrices}\nGiven a square matrix $A \\in \\mathbb{R}^{n \\times n}$ and a vector\n$x \\in \\mathbb{R}^n$, the scalar value $x^TAx$ is called the quadratic form:\n\\begin{equation}\n x^TAx = \\sum_{i=1}^n \\sum_{j=1}^n A_{ij} x_i x_j\n\\end{equation}\nA symmetric matrix $A$ is:\n\\begin{enumerate}\n \\item Positive definite (PD) if for all nonzero vectors, $x^TAx > 0$\n \\item Positive semidefinite (PSD) if for all nonzero vectors, $x^TAx \\geq 0$\n \\item Negative definite (ND) if for all nonzero vectors, $x^TAx < 0$\n \\item Negative semidefinite (NSD) if for all nonzero vectors, $x^TAx \\leq 0$\n \\item Indefinite if it is neiter PSD nor NSD, i.e. if there exists a $x_1, x_2$\n such that $x^T_1Ax_1 > 0$ and $x^T_2Ax_2 < 0$\n\\end{enumerate}\nGiven any matrix $A \\in \\mathbb{R}^{m \\times n}$, the gram matrix $G = A^T A$\nis always PSD. If $m \\geq n$ and $A$ is full rank, then $G$ is PD.\n\\subsubsection{Eigendecomposition}\nGiven a square matrix $A \\in \\mathbb{R}^{n \\times n}$, we say that\n$\\lambda \\in \\mathbb{C}$ is an eigenvalue of $A$ and $v \\in \\mathbb{C}$ is the\ncorresponding eigenvector if\n\\begin{equation}\n Av = \\lambda v, \\quad v \\not= 0\n\\end{equation}\nThe trace of $A$ is equal to the sum of its eigenvalues:\n\\begin{equation}\n \\operatorname{tr}A = \\sum_{i=1}^n \\lambda_i\n\\end{equation}\nThe determinant of $A$ is equal to the product of its eigenvalues:\n\\begin{equation}\n |A| = \\prod_{i=1}^n \\lambda_i\n\\end{equation}\nSuppose matrix $A$ has $n$ linearly independent eigenvectors\n$\\{v_1, \\hdots, v_n\\}$ with corresponding eigenvalues\n$\\{\\lambda_1, \\hdots, \\lambda_n\\}$. Let $V$ be a matrix with one eigenvalue\nper column: $V = \\left[ v_1, \\hdots, v_n \\right]$. Let\n$\\Lambda =\\textrm{diag}(\\lambda_1,\\hdots,\\lambda_n)$. Then the eigendecomposition\nof $A$ is given by:\n\\begin{equation}\n A = V \\Lambda V^{-1}\n\\end{equation}\nFor when $A$ is symmetric, then the eigenvalues of $A$ are real, the\neigenvectors of $A$ are orthonormal, and hence $V$ is an orthogonal matrix\n(henceforth renamed $U$). Hence $A = U \\Lambda U^T$.\nA matrix whose eigenvalues are all positive is called positive definite.\nA matrix whose eigenvalues are all positive or zero valued is called positive\nsemidefinite. Likewise, if all eigenvalues are negative, the matrix is\nnegative definite, and if all eigenvalues are negative or zero valued,\nit is negative semidefinite. In addition, assuming sorted eigenvalues,\nfor the following optimization problem:\n\\begin{equation}\n \\max _ { x \\in \\mathbb { R } ^ { n } } x ^ { T } A x \\quad \\text { subject to } \\| x \\| _ { 2 } ^ { 2 } = 1\n\\end{equation}\nThe solution is $v_1$ the eigenvector corresponding to $\\lambda_1$. For\nthe minimization problem:\n\\begin{equation}\n \\min _ { x \\in \\mathbb { R } ^ { n } } x ^ { T } A x \\quad \\text { subject to } \\| x \\| _ { 2 } ^ { 2 } = 1\n\\end{equation}\nthe optimal solution for $x$ is $v_n$, the eigenvector corresponding to\neigenvalue $\\lambda_n$.\n\\subsubsection{Singlular Value Decomposition}\nThe singular value decomposition provides a way to factorize a $m \\times n$\nmatrix $A$ into singular vectors and singular values. It is defined as:\n\\begin{equation}\n A = U D V^T\n\\end{equation}\nSuppose $A \\in \\mathbb{R}^{m \\times n}$ matrix. Then\n$U \\in \\mathbb{R}^{m \\times m}$, $D \\in \\mathbb{R}^{m \\times n}$,\n$ V \\in \\mathbb{R}^{n \\times n}$ matrices. The matricies $U$ and $V$ are\northogonal, and matrix $D$ is diagonal. The elements along the diagonal of $D$\nare known as the singular values of matrix $A$. The columns of $U$ are known\nas the left-singular vectors while the columns of $V$ are the right-singular\nvectors. The left-singular vectors of $A$ are the eigenvectors of $AA^T$.\nThe right-singular vectors of $A$ are the eigenvectors of $A^TA$. We can use\nSVD to partially generalize matrix inversion to nonsquare matrices.\n\\subsubsection{The Moore-Penrose Pseudoinverse}\nMatrix inversion is not defined for matrices that are not square.\nNote that for nonsingular $A$:\n\\begin{equation}\n A A^{-1}A = A\n\\end{equation}\nHowever, if the inverse is not defined, we seek to find a matrix $A^{+}$ such\nthat:\n\\begin{equation}\n A A^{+}A = A\n\\end{equation}\nThe moore-penrose pseudoinverse $A^+$ is defined as follows:\n\\begin{equation}\n A^+ = \\lim_{\\alpha \\to 0} (A^TA + \\alpha I)^{-1}A^T\n\\end{equation}\nPractical algorithms use the singular value decomposition of $A$ such that:\n\\begin{equation}\n A^+ = V D^+ U^T\n\\end{equation}\nwhere $U, D, V$ are from the SVD of $A$, and the pseudoinverse of $D^+$ is\nobtained by taking the reciprocal of the nonzero diagonal elements of $D$.\nIf $A$ has more columns than rows, then using the pseudoinverse to solve a\nlinear equation $Ax=y$ provides one of many solutions, but provides $x = A^+ y$\nwith minimal euclidean norm $||x||_2$. When $A$ has more rows than columns,\nthe pseudoinverse gives us the $x$ for which $Ax$ is as close as possible\nto $y$, i.e. minimizing $||Ax-y||_2$.\n\\subsection{Matrix Calculus}\n\\subsubsection{The Gradient}\nLet $f:\\mathbb{R}^{m\\times n}\\rightarrow\\mathbb{R}$ be a function and\n$A \\in \\mathbb{R}^{m \\times n}$ be a matrix. The gradient of $f$ with respect to\n$A$ is a $m \\times n$ matrix noted as $\\nabla_A f(A)$ such that:\n\\begin{equation}\n \\nabla _ { A } f ( A ) \\in \\mathbb { R } ^ { m \\times n } = \\left(\n \\begin{array} { c c c c } { \\frac { \\partial f ( A ) } { \\partial A _ { 11 } } } & { \\frac { \\partial f ( A ) } { \\partial A _ { 12 } } } & { \\cdots } & { \\frac { \\partial f ( A ) } { \\partial A _ { 1 } } } \\\\ { \\frac { \\partial f ( A ) } { \\partial A _ { 21 } } } & { \\frac { \\partial f ( A ) } { \\partial A _ { 22 } } } & { \\cdots } & { \\frac { \\partial f ( A ) } { \\partial A _ { 2 n } } } \\\\ { \\vdots } & { \\vdots } & { \\ddots } & { \\vdots } \\\\ { \\frac { \\partial f ( A ) } { \\partial A _ { m 1 } } } & { \\frac { \\partial f ( A ) } { \\partial A _ { m 2 } } } & { \\cdots } & { \\frac { \\partial f ( A ) } { \\partial A _ { m n } } } \\end{array} \\right)\n\\end{equation}\nOr compactly for each $ij$ entry:\n\\begin{equation}\n \\nabla _ { A } f ( A ) _ { i j } = \\frac { \\partial f ( A ) } { \\partial A _ { i j } }\n\\end{equation}\nHowever, the gradient of a vector $x \\in \\mathbb{R}^n$ is:\n\\begin{equation}\n \\nabla _ { x } f ( x ) = \\left( \\begin{array} { c } { \\frac { \\partial f ( x ) } { \\partial x _ { 1 } } } \\\\ { \\frac { \\partial f ( x ) } { \\partial x _ { 2 } } } \\\\ { \\vdots } \\\\ { \\frac { \\partial f ( x ) } { \\partial x _ { n } } } \\end{array} \\right)\n\\end{equation}\n\\subsubsection{The Hessian}\nLet $f:\\mathbb{R}^{n}\\rightarrow\\mathbb{R}$ be a function and\n$x \\in \\mathbb{R}^{n}$ be a vector. The hessian of $f$ with respect to\n$x$ is a $n \\times n$ symmetric matrix noted as $H = \\nabla_x^2 f(x)$ such that:\n\\begin{equation}\n \\nabla _ { x } ^ { 2 } f ( x ) \\in \\mathbb { R } ^ { n \\times n } = \\left( \\begin{array} { c c c c } { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 1 } ^ { 2 } } } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 2 } } } & { \\cdots } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 1 } \\partial x _ { n } } } \\\\ { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 2 } \\partial x _ { 1 } } } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 2 } ^ { 2 } } } & { \\cdots } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { 2 } \\partial x _ { n } } } \\\\ { \\vdots } & { \\vdots } & { \\ddots } & { \\vdots } \\\\ { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { n } \\partial x _ { 1 } } } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { n } \\partial x _ { 2 } } } & { \\cdots } & { \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { n } ^ { 2 } } } \\end{array} \\right)\n\\end{equation}\nOr compactly:\n\\begin{equation}\n \\nabla _ { x } ^ { 2 } f ( x ) _ { i j } = \\frac { \\partial ^ { 2 } f ( x ) } { \\partial x _ { i } \\partial x _ { j } }\n\\end{equation}\nNote that the hessian is only defined when $f(x)$ is real-valued.\n\\subsubsection{Gradient Properties}\nFor matrices $A, B, C$ and vectors $x, b$:\n\\begin{enumerate}\n \\item $\\nabla_x b^Tx = b$\n \\item $\\nabla_x x^TAx = 2Ax$ (if $A$ symmetric)\n \\item $\\nabla^2_x x^TAx = 2A$ (if $A$ symmetric)\n \\item $\\nabla_A\\textrm{tr}(AB)=B^T$\n \\item $\\nabla_{A^T}f(A)=\\left(\\nabla_Af(A)\\right)^T$\n \\item $\\nabla_A\\textrm{tr}(ABA^TC)=CAB+C^TAB^T$\n \\item $\\nabla_A|A|=|A|(A^{-1})^T$\n\\end{enumerate}\n", "meta": {"hexsha": "664ce38cc74262a19c3c4bc9fc5709813e123887", "size": 19127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/linear_algebra.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/linear_algebra.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/linear_algebra.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.6485714286, "max_line_length": 909, "alphanum_fraction": 0.626235165, "num_tokens": 7250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.96741025335478, "lm_q2_score": 0.908617900644622, "lm_q1q2_score": 0.8790062734653021}} {"text": "\\subsection{More properties of inverses}\n\n% ======================================================================\n\nIn this section, we will use elementary matrices to prove a useful\ntheorem about the inverse of a square matrix. We start with an\nobservation about the {\\ef} of a right invertible matrix.\n\n\\begin{lemma}{{\\Ef} of a right invertible matrix}{no-zero-row}\n Suppose that $A$ is right invertible. Then the {\\rref} of $A$ does\n not have a row of zeros.\n\\end{lemma}\n\n\\begin{proof}\n Let $R$ be the {\\rref} of $A$. Then by Theorem~\\ref{thm:form-rua},\n we can write $R=UA$ for some invertible square matrix $U$. By\n assumption, we have $AB=I$, and therefore\n \\begin{equation*}\n R(BU^{-1})\n ~=~\n (UA)(BU^{-1})\n ~=~\n U(AB)U^{-1}\n ~=~\n UIU^{-1}\n ~=~\n UU^{-1}\n ~=~\n I.\n \\end{equation*}\n If $R$ had a row of zeros, then so would the product\n $R(BU^{-1})$. But since the identity matrix $I$ does not have a row\n of zeros, neither does $R$.\n\\end{proof}\n\n\\begin{theorem}{Right invertible square matrices are invertible}{right-square-left}\n Suppose $A$ and $B$ are square matrices such that $AB=I$. Then it\n follows that $BA=I$, and therefore $B=A^{-1}$. In particular, a\n square matrix is right invertible if and only if it is left\n invertible if and only if it is invertible.\n\\end{theorem}\n\n\\begin{proof}\n Assume $A$ and $B$ are square matrices such that $AB=I$. Let $R$ be\n the {\\rref} of $A$. Then by Theorem~\\ref{thm:form-rua}, we can write\n $R=UA$ where $U$ is an invertible matrix. Since $AB=I$, we know by\n Lemma~\\ref{lem:no-zero-row} that $R$ does not have a row of\n zeros. Since $R$ is a square {\\rref} with no row of zeros, each\n column must be a pivot column, and it follows that $R=I$. Hence,\n $UA=I$, and therefore $A$ is left invertible. Moreover, we have\n \\begin{equation*}\n B ~=~ IB ~=~ (UA)B ~=~ U(AB) ~=~ UI ~=~ U,\n \\end{equation*}\n and therefore $B=U$. It follows that $BA=UA=I$, as claimed.\n\n To prove the last claim, note that we just proved that for square\n matrices, $AB=I$ implies $BA=I$. Therefore, every right inverse of\n $A$ is also a left inverse, and therefore an inverse. But of course,\n we also have that $BA=I$ implies $AB=I$. This is just the same\n theorem, with the roles of $A$ and $B$ interchanged. Therefore,\n every left inverse of $A$ is also a right inverse.\n\\end{proof}\n\nThis theorem is very useful, because it allows us to test only one of\nthe products $AB$ or $BA$ in order to check that $B$ is the inverse of\n$A$, saving us half of the work. It is important to stress, however,\nthat this only works for {\\em square} matrices. As we saw in\nExample~\\ref{exa:right-inverse}, non-square matrices can be right\ninvertible without being left invertible, or vice versa.\n\n", "meta": {"hexsha": "d5a2c2a022c98c9b31319fa7693444c219b7c83f", "size": 2769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices-MoreInverses.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices-MoreInverses.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices-MoreInverses.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.0, "max_line_length": 83, "alphanum_fraction": 0.6590827013, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.9425067226126712, "lm_q1q2_score": 0.8788435156616378}} {"text": "\n\\subsection{Variance}\n\n\\subsubsection{Definition}\n\nThe variance of a random variable is given by:\n\n\\(Var(x)=E((x-E(x))^2)\\)\n\n\\(Var(x)=E(x^2+E(x)^2-2xE(x))\\)\n\n\\(Var(x)=E(x^2)+E(E(x)^2)-E(2xE(x))\\)\n\n\\(Var(x)=E(x^2)+E(x)^2-2E(x)^2\\)\n\n\\(Var(x)=E(x^2)-E(x)^2\\)\n\n\\subsubsection{Variance of a constant}\n\n\\(Var(c)=E(c^2)-E(c)^2\\)\n\n\\(Var(c)= c^2-c^2\\)\n\n\\(Var(c)=0\\)\n\n\\subsubsection{Variance of multiple}\n\n\\(Var(cx)=E((cx)^2)-E(cx)^2\\)\n\n\\(Var(cx)=E(c^2x^2)-[\\sum_i cx P(x_i)]^2\\)\n\n\\(Var(cx)=c^2E(x^2)-c^2[\\sum_i x P(x_i)]^2\\)\n\n\\(Var(cx)=c^2[E(x^2)- E(x)^2]\\)\n\n\\(Var(cx)=c^2Var(x)\\)\n\n\\subsubsection{Link between variance of expectation}\n\n\\(E(x)^2+Var(x)=E(x)^2+E((x-E(x))^2)\\)\n\n\\(E(x)^2+Var(x)=E(x)^2+E(x^2+E(x)^2-2xE(x))\\)\n\n\\(E(x)^2+Var(x)=E(x)^2+E(x^2)+E(E(x)^2)-E(2xE(x))\\)\n\n\\(E(x)^2+Var(x)=E(x)^2+E(x^2)+E(x)^2-2E(x)E(x))\\)\n\n\\(E(x)^2+Var(x)=E(x^2)\\)\n\n\\subsubsection{Covariance}\n\n\\(Var(x+y)=E((x+y)^2)-E(x+y)^2\\)\n\n\\(Var(x+y)=E(x^2+y^2+2xy)-E(x+y)^2\\)\n\n\\(Var(x+y)=E(x^2)+E(y^2)+E(2xy)-E(x+y)^2\\)\n\n\\(Var(x+y)=E(x^2)+E(y^2)+E(2xy)-[E(x)+E(y)]^2\\)\n\n\\(Var(x+y)=E(x^2)+E(y^2)+E(2xy)-E(x)^2-E(y)^2-2E(x)E(y)]\\)\n\n\\(Var(x+y)=[E(x^2)-E(x)^2]+[E(y^2)-E(y)^2]+E(2xy)-2E(x)E(y)\\)\n\n\\(Var(x+y)=Var(x) +Var(y)+2[E(xy)-E(x)E(y)]\\)\n\nWe then define:\n\n\\(Cov(x,y):=E(xy)-E(x)E(y)\\)\n\nNoting that:\n\n\\(Cov(x,x)=E(xx)-E(x)E(x)\\)\n\n\\(Cov(x,x)=Var(x) \\)\n\nSo:\n\n\\(Var(x+y)=Var(x)+Var(y)+2Cov(x,y)\\)\n\n\\(Var(x+y)=Cov(x,x)+Cov(x,y)+Cov(y,x)+Cov(y,y) \\)\n\n\\(Cov(x,c)=E(xc)-E(x)E(c)\\)\n\n\\(Cov(x,c)=cE(x)-cE(x)\\)\n\n\\(Cov(x,c)=0\\)\n\n", "meta": {"hexsha": "11a05afeb202534a60f53e1b122eb11f2374fbfe", "size": 1485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMomentsVariance/01-01-singleVariance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityMomentsVariance/01-01-singleVariance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityMomentsVariance/01-01-singleVariance.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.875, "max_line_length": 61, "alphanum_fraction": 0.4962962963, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214491222695, "lm_q2_score": 0.9111797124237604, "lm_q1q2_score": 0.8786701406952934}} {"text": "\\lab{Public Key Cryptography}{RSA}\n\\label{lab:RSA}\n\n\\objective{Implement the RSA cryptosystem as an example of public key cryptography.}\n\nA \\emph{public key cryptosystem} uses separate keys for encryption and decryption.\nIf Alice wishes to send Bob a message, she encrypts it using Bob's \\emph{public key}, which is available to everyone.\nThen Bob decrypts it with his \\emph{private key}, which only he knows.\nAs long as it is difficult to find the private key from the public key, this is a secure system.\n\nPublic key cryptosystems are advantageous because for $n$ people to have secure communications with each other, they need exactly $n$ public-private key pairs.\nA symmetric cryptosystem would require on the order of $n^2$ keys.\nAlso, they eliminate the need for secure key sharing algorithms like the Diffie-Hellman key exchange (see Lab \\ref{lab:DiffieHellman}).\n\nOne of the oldest and most popular public key cryptosystems is RSA cryptography.\\\\\n\nAll material in this lab through the section ``Security of RSA'' is required. \nAfter that, all sections and subsections are independent of each other and may be covered as desired.\n\n\\section*{The RSA system}\nSuppose Alice wants to receive secret messages using RSA.\nTo do so, she first needs to generate a public key (for encryption) and a private key (for decryption).\nAlice does this by choosing two prime numbers, $p$ and $q$, and setting $n=pq$.\nThen she sets $\\phi(n) = (p-1)(q-1)$.\\footnote{\nThe function $\\phi: \\mathbb{Z} \\rightarrow \\mathbb{N}$ is called the \\emph{Euler phi function}. In general $\\phi(n)$ is the number of positive integers less than $n$ that are relatively prime to $n$.}\nAlice chooses her encryption exponent to be some integer $e$ that is relatively prime to $\\phi(n)$.\nThen she uses the Extended Euclidean Algorithm to find $d'$ such that $ed' + \\phi(n)x' = 1$, and adds or subtracts multiples of $\\phi(n)$ until $d = d'+k\\phi(n)$ is between 0 and $\\phi(n)$.\nAlice publishes her public key $(e, n)$ for the world to see and keeps her private key $(d,n)$ a secret.\n\nNow imagine Bob wants to send Alice a message, which he represents as an integer $m>> p = 1000003\n>>> q = 608609\n>>> n = p*q\n>>> phi_n = (p-1)*(q-1)\n\\end{lstlisting}\n\nNow we choose an encryption exponent $e = 1234567891$ and compute $d = 589492582555$ using the Extended Euclidean Algorithm.\n\\begin{lstlisting}\n>>> e = 1234567891\n>>> d = 589492582555\n\\end{lstlisting}\n\nFinally we are ready to encrypt the message. \nNote that $m>> m = long(190503180520)\n>>> c = pow(m, e, n)\n\\end{lstlisting}\n\nWe decript the message by raising $c$ to the $d^{th}$ power.\n\\begin{lstlisting}\n>>> m == pow(c, d, n)\nTrue\n\\end{lstlisting}\n\n\\begin{problem}\nImplement the RSA cryptosystem with three functions: one to generate keys, one to encrypt messages, and one to decrypt messages.\n\\begin{lstlisting}\ndef keys(p, q, e):\n '''Create a pair of RSA keys from primes `p' and `q' and encryption \n exponent `e'.\n \n Return [(e, n), (d, n)] where (e, n) is the public key and (d, n) is \n the private key.\n '''\n \ndef encrypt(message, e, n):\n '''Encrypt the `message' using the public key (e, n).'''\n \ndef decrypt(ciphertext):\n '''Decrypt the `ciphertext' using your private key.'''\n\\end{lstlisting}\n\\label{prob:rsa1}\n\\end{problem}\n\\subsection*{Security of RSA}\nSuppose an enemy Eve wants to read the message that Bob sent to Alice.\nLike Bob, she has access to Alice's public key $(e, n)$.\nLet's assume she has also intercepted the ciphertext $c$.\n\nOne way for Eve to read Bob's message is to directly find $m$ such that $m^e \\equiv c \\pmod{n}$.\nSuch a computation is known as taking a \\emph{discrete logarithm}.\nWhen $n$ is very large, this computation is essentially impossible.\n\nAnother option is for Eve to compute $(d, n)$ and then find $c^d$.\nHowever, computing $d$ means computing $\\phi(n)$.\nComputing $\\phi(n)$ from $n$ directly requires factoring $n$.\nWhen $n$ has hundreds of digits, finding its factors with known algorithms can take years.\n\n\n\n\\subsection*{Logistical considerations (Optional)}\nThe cryptosystem you wrote in Problem \\ref{prob:rsa1} is not particularly easy to use, since you must convert your message to an integer and back again by hand.\nThe appendix to this lab contains some functions you can use to fix this problem.\nThe function \\li{string_to_int()} turns any string into an integer (using a mapping more complicated than $A=01, B=02$), and the function \\li{int_to_string()} changes it back again.\n\n\\begin{lstlisting}\n>>> string_to_int('SECRET')\n91556947314004\n\\end{lstlisting}\n\nAt this point we have a problem, because the message 91556947314004 is larger than $n=608610825827$.\nWe can only use RSA to encrypt messages that are smaller than $n.$\nIn fact, the function \\li{string_size()} provided in the appendix tells us the maximum number of characters we can encrypt with this choice of $n$.\n\n\\begin{lstlisting}\n>>> string_size(608610825827)\n4\n\\end{lstlisting}\n\nThe function \\li{partition()}, also in the appendix, will break our message into pieces of length 4.\nWe specify the ``fill value'' \\li{x} that will be used to make all pieces the same length.\n\n\\begin{lstlisting}\n>>> partition('SECRET', 4, 'x')\n['SECR', 'ETxx']\n\\end{lstlisting}\nNow we can proceed to encrypt and decrypt the strings \\li{'SECR'} and \\li{'ETxx'} as before.\n\n\\begin{problem}[Optional]\nModify your solution to Problem \\ref{prob:rsa1}, making it simpler to use, by writing the following functions.\n\\begin{lstlisting}\ndef encrypt(message, e, n):\n '''Encrypt `message' using the public key (e, n).\n \n INPUTS:\n message - A string.\n (e, n) - A pair of integers. Should be an RSA public key.\n \n OUTPUTS:\n Partition `message' into pieces of sufficiently small size, padding if \n necessary. Return a list of the encryptions of the pieces.\n '''\n \ndef decrypt(ciphertext):\n '''Decrypt `ciphertext' using your private key.\n \n INPUTS:\n ciphertext - A list of integers.\n \n OUTPUTS:\n Decrypt each integer in `cipertext' and return a single string.\n '''\n\\end{lstlisting}\n\nYou can test your cryptosystem on the example in this lab and also on this larger example:\n\\begin{itemize}\n\\item message: \\emph{Simon sells seashells by the seashore.}\n\\item $p=83285677$, $q=2848968679$, $e=65593$\n\\end{itemize}\n\\label{rsa2}\n\\end{problem}\n\n\\section*{Digital Signatures (Optional)}\nSuppose Bob wants Alice to be able to verify that \\emph{he} sent her a message, not Eve.\nBob can do this using a \\emph{digital signature}.\n\n\\subsection*{Method 1}\nOne way for Bob to digitally sign a message is to apply his \\emph{private key} (his ``signature'') to the message and then apply Alice's public key.\nWhen Bob applies his private key to a message, we say he \\emph{signs} the message.\nWhen Alice receives this message, she first applies her private key and then Bob's public key. \nIf the message makes sense, she knows it must be from Bob, since he is the only person with his private key.\n\nSymbolically, let $e_B()$ and $d_B()$ be Bob's encryption and decryption functions (these are inverse functions), and let $e_A()$ and $d_A()$ be the corresponding functions for Alice.\nThen Bob sends $e_A(d_B(m))$ to Alice, and Alice computes \n\\[e_B(d_A(e_A(d_B(m)))) = e_B(d_B(m)) = m.\\]\n\nThis method requires twice as many RSA encryptions as sending an unsigned message.\nModular exponentiation can be an expensive operation, so if the message is long (and must be broken into several pieces) this is a serious slow-down.\n\n\n\\subsection*{Method 2: hashes}\nA more efficient method (which also turns out to be more cryptographically secure) is to ``hash the message, and then sign the hash.''\nA hash is a function that takes a string of any size to a fixed number of bytes.\nA cryptographically secure hash satisfies two properties:\n\\begin{itemize}\n\\item If $m_1$ is different from $m_2$ then hash($m1$) is (almost certainly) different from hash($m2$).\n\\item Given hash($m$), it is essentially impossible to find $m$.\n\\end{itemize}\nFor example, the MD5 hash will map any string to 16 bytes (a character like \\li{'a'} is one byte of data).\\footnote{\nThe hash MD5 is not cryptographically secure, but is often used in non-cryptographic applications. \nBecause of its small digest size we use it as an example here.}\nSigning the hash will be faster than signing the original message, if the original message is more than 16 characters.\n\nIn Python, hashes are implemented in the \\li{hashlib} library. \nHere we use MD5 to hash the string \\li{'SECRET'}.\n\\begin{lstlisting}\n>>> import hashlib\n>>> hash = hashlib.md5('SECRET')\n\\end{lstlisting}\nWe view the hash with the \\li{digest()} method.\n\\begin{lstlisting}\n>>> hash.digest()\n'D\\xc7\\xbeH\"n\\xba\\xd5\\xdc\\xa8!ft\\xca\\xd6+'\n\\end{lstlisting}\nThe output is 16 bytes, some represented as characters (e.g. \\li{'D'}) and some as two hexidecimal digits (e.g. \\li{'\\\\xc7'}).\nHere we separate the digest into its bytes.\n\\begin{lstlisting}\n>>> [byte for byte in hash.digest()]\n['D', '\\xc7', '\\xbe', 'H', '\"', 'n', '\\xba', '\\xd5', '\\xdc', '\\xa8', '!', 'f', 't', '\\xca', '\\xd6', '+']\n\\end{lstlisting}\n\nSo when Bob sends Alice a message, he hashes the message and then signs the hash (applies his private key).\nThen he encrypts the message with Alice's public key. \nWhen Alice receives the message and signature, she decrypts the message with her private key.\nAfter reading the message, she hashes it and compares the result to Bob's public key applied to the signature.\nIf they agree, then she knows the message came from Bob.\n\n\\begin{problem}\nRewrite your RSA cryptosystem to include digital signatures. \nThat is, write the following functions, using the same hash in each.\n\\begin{lstlisting}\ndef encrypt(message, e, n):\n '''Encrypt `message' using the public key (e, n) and sign it.\n \n INPUTS:\n message - A string.\n (e, n) - A pair of integers. Should be an RSA public key.\n \n OUTPUTS:\n ciphertext - A list of the encrypted pieces of `message.'\n signatures - The hash of `message', signed with your private key.\n '''\n \ndef decrypt(ciphertext, e, n):\n '''Decrypt `ciphertext' using your private key and verify the \n signature matches the public key (e, n).\n \n INPUTS:\n ciphertext - A list of integers.\n (e, n) - A public key.\n \n OUTPUTS:\n message - The decrypted `ciphertext' as a single string.\n verified - A Boolean value indicating whether the digital signature \n was verified.\n '''\n\\end{lstlisting}\n\\end{problem}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section*{Making RSA feasible (Optional)}\n\nFor RSA to be a reasonably fast cryptosystem, we need a fast algorithm for modular exponentiation.\nThis algorithm, known as \\emph{binary exponentiation}, was discussed in Lab \\ref{lab:DiffieHellman}.\n\nIn addition, the security of RSA depends on the use of large prime numbers for $p$ and $q$.\nFor RSA to be a practical cryptosystem, we need a fast way to find such numbers.\n\n\n\\subsection*{Finding large primes}\nIt is very slow to check that a large number is prime by finding its factors.\nIn fact, it is the difficulty of factoring that makes RSA secure.\n\nHowever, there exist fast algorithms that determine when a number is ``probably prime.''\nOne such algorithm comes from a special case of Theorem \\ref{thm:fermat} known as \\emph{Fermat's Little Theorem}:\n\\[\na^{p-1} \\equiv 1 \\pmod{p}\n\\]\nfor all primes $p$ and integers $a$ that are not divisible by $p$.\nTherefore, to check if a fixed number $p$ is likely a prime, we can compute $a^{p-1} \\pmod{p}$ for several values of $a$.\nIf we ever get something different than 1, then we know that $p$ is composite.\nThe value of $a$ that proved $p$ was composite is called a \\emph{witness number}.\nIn fact, the converse is true: if $a^{p-1} \\equiv 1 \\pmod{p}$ for every $a>> from Crypto.PublicKey import RSA\n>>> from Crypto import Random\n>>> keypair = RSA.generate(2048) #generate a 2048-bit RSA key\n>>> publickey = keypair.publickey()\n>>> share_this = publickey.exportkey()\n\\end{lstlisting}\n\nThe RSA encryption and decryption methods on these keys are textbook approaches.\nHowever, to increase security, we will want to pad the messages so every message encrypted with a particular will become exactly as large (in bits) as the key itself.\nA commonly used padding algorithm is implemented in PyCrypto in the \\li{Crypto.Cipher.PKCS1_OAEP} module.\n\\begin{lstlisting}\n>>> from Crypto.Cipher import PKCS1_OAEP as oaep\n\n# generate a new key from the original RSA key.\n# This key can encrypt and decrypt\n>>> paddedkey = oaep.new(keypair)\n>>> encrypted = paddedkey.encrypt('hello world')\n>>> paddedkey.decrypt(encrypted)\n'hello world'\n\\end{lstlisting}\n\nTo sign the message we use PyCrypto's \\li{Crypto.Signature.PKCS1_PSS} module.\nWe first need to hash the message using a cryptographically secure hash, such as SHA.\nJust as only private keys can decrypt, only private keys can sign.\nPublic keys can decrypt and verify.\n\\begin{lstlisting}\n>>> from Crypto.Signautre import PKCS1_PSS as pss\n>>> from Crypto.Hash import SHA\n>>> sigkey = pss.new(keypair)\n>>> mhash = SHA.new(\"Hello World\")\n>>> sigkey.sign\n\\end{lstlisting}\n\n\n\\begin{problem}[Group Project]\nSplit into several groups of at least three individuals.\nEach group member should generate a private and public keypair using PyCrypto.\nShare your public keys with everyone in the group.\n\nYou might find it useful to transmit your messages as strings.\nHere are two functions that will read and write specially formatted strings for your messages.\n\\begin{lstlisting}\ndef print_msg(m_encrypted):\n #print the encrypted message as a specially formatted string\n out = (\"----BEGIN MESSAGE----\",\n m_encrypted[0],\n \"----END MESSAGE----\",\n \"----BEGIN SIGNATURE----\",\n m_encrypted[1],\n \"----END SIGNATURE----\")\n return '\\n'.join(out)\n\ndef read_msg(m_string):\n d1 = m_string.find('----BEGIN MESSAGE----') + 21\n d2 = m_string.find('----END MESSAGE----', d1)\n \n d3 = m_string.find('----BEGIN SIGNATURE----', d2) + 23\n d4 = m_string.find('----END SIGNATURE----', d3)\n message = m_string[d1:d2]\n sign = m_string[d3:d4]\n return message.strip(), sign.strip()\n\\end{lstlisting}\n\n\\begin{enumerate}\n\\item Encrypt and sign a message for someone in the group and send it to the entire group.\nAttach the sender's name to the encrypted message (a claim that the message came from a particular sender).\nIn this exercise we will verify that the actual origin of the message is indeed the claimed origin.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message addressed for you.\n\\item Attempt to decrypt and verify message addressed for someone else in the group.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\n\\item Encrypt and sign a different message for someone in the group and send it, anonymously, to the entire group.\nFor example, if Bob encrypts a message and sends it to Alice, he should claim the message came from another individual.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message address to you.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\\end{enumerate}\n\\end{problem}\n\\end{comment}\n\n\n\\section*{Appendix: Helper Code}\nHere are some functions that you can use to make your implementation of RSA more user-friendly (see the ``Logistical considerations'' section).\nNote that you must import \\li{izip_longest} from \\li{itertools} before using some of these functions.\n \n \\begin{lstlisting}\n from itertools import izip_longest\n \n def partition(iterable, n, fillvalue=None):\n '''Partition data into blocks of length `n', padding with `fillvalue' if needed. Return a list of the partitions.\n \n EXAMPLE:\n >>> partition('ABCDEFG', 3, 'x')\n ['ABC', 'DEF', 'Gxx']\n '''\n args = [iter(iterable)] * n\n pieces = izip_longest(fillvalue=fillvalue, *args)\n return [''.join(block) for block in pieces]\n \ndef string_size(n):\n '''Return the maximum number of characters that can be encoded with the public key (e, n).\n \n In other words, find the largest integer L, such that if `string' has at most L characters, then a2i(`string') will be less than `n.'\n '''\n L=0\n max_int = 0\n while max_int < n:\n max_int += sum([2**i for i in range(8*L, 8*L+8)])\n L += 1\n return L-1\n \ndef string_to_int(msg):\n '''Convert the string `msg' to an integer.\n '''\n # bytearray will give us the ASCII values for each character\n if not isinstance(msg, bytearray):\n msg = bytearray(msg)\n binmsg = []\n # convert each character to binary\n for c in msg:\n binmsg.append(bin(c)[2:].zfill(8))\n return int(''.join(binmsg), 2)\n\ndef int_to_string(msg):\n '''Convert the integer `msg' to a string.\n \n This function is the inverse of string_to_int().\n '''\n # convert to binary first\n binmsg = bin(msg)[2:]\n # we need to pad the message so length is divisible by 8\n binmsg = \"0\"*(8-(len(binmsg)%8)) + binmsg\n msg = bytearray()\n for block in partition(binmsg, 8):\n # convert block of 8 bits back to ASCII\n msg.append(int(block, 2))\n return str(msg)\n \\end{lstlisting}", "meta": {"hexsha": "062a779299a474f144e4d41d8c0fded1fce8d451", "size": 20497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/RSA/PublicKey.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/RSA/PublicKey.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/RSA/PublicKey.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 40.5881188119, "max_line_length": 200, "alphanum_fraction": 0.7197638679, "num_tokens": 5344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191322715435, "lm_q2_score": 0.919642527874199, "lm_q1q2_score": 0.8785521017287885}} {"text": "In this section we will show the finite difference equations needed to solve\n\\begin{align*}\n\\frac{\\partial u}{\\partial t}=\\frac{1}{Re}\\left(\\frac{\\partial^2 u}{\\partial x^2}+\\frac{\\partial^2 u}{\\partial y^2}\\right),\n\\end{align*}\nusing ADI. Let $d_1=\\frac{\\Delta t}{2Re\\Delta x^2}$ and $d_2=\\frac{\\Delta t}{2Re\\Delta y^2}$.\n\\subsection{Step 1. Implicit in x-direction}\nThe differential equation discretized implicitly in the x-direction yields\n\\begin{align*}\n\\frac{u_{i+1/2,j}^{n+1/2}-u_{i+1/2,j}^n}{\\Delta t/2}=\\frac{1}{Re\\Delta x^2}\\left(u_{i+3/2,j}^{n+1/2}-2u_{i+1/2,j}^{n+1/2}+u_{i-1/2,j}^{n+1/2}\\right)+\\frac{1}{Re\\Delta y^2}\\left(u_{i+1/2,j+1}^{n}-2u_{i+1/2,j}^{n}+u_{i+1/2,j-1}^{n}\\right).\n\\end{align*}\nUsing the definitions of $d_1$, $d_2$ and reorganizing the terms we obtain\n\\begin{align*}\n-d_1u_{i-1/2,j}^{n+1/2}-(1+2d_1)u_{i+1/2,j}^{n+1/2}-d_1u_{i+3/2,j}^{n+1/2}=d_2u_{i+1/2,j-1}^n+(1-2d_2)u_{i+1/2,j}^n+d_2u_{i+1/2,j+1}^n,\n\\end{align*}\nwhich gives us\n\\begin{align*}\na_{i+1/2,j}=-d_1,~~~~~~b_{i+1/2,j}=1+2d_1,~~~~~~c_{i+1/2,j}=-d_1,\n\\end{align*}\nand\n\\begin{align*}\nd_{i+1/2,j}=d_2u_{i+1/2,j-1}^n+(1-2d_2)u_{i+1/2,j}^n+d_2u_{i+1/2,j+1}^n.\n\\end{align*}\n\\subsubsection{Boundary Conditions}\nTo account for the left boundary we have imposed $a_{3/2,j}=0$ and \n\\begin{align*}\nd_{3/2,j}=d_2u_{3/2,j-1}^n+(1-2d_2)u_{3/2,j}^n+d_2u_{3/2,j+1}^n+d_1u_{3/2,j},\n\\end{align*}\nwhere $u_{3/2,j}$ is given by the boundary conditions\n\n\\[ u_{3/2,j}=\\begin{cases} \n U_{in1}(y_j) & x\\leq 0 \\\\\n 0 & 100\\leq x \n \\end{cases}\n\\]\n\n\\subsection{Step 2. Implicit in y-direction}\n", "meta": {"hexsha": "310206e6cfe33bb029b716ef1efb75cb67100766", "size": 1572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework_7/Latex/u_dev.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/CFD/Homework_7/Latex/u_dev.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/CFD/Homework_7/Latex/u_dev.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4864864865, "max_line_length": 237, "alphanum_fraction": 0.6323155216, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731131913228, "lm_q2_score": 0.9124361622627654, "lm_q1q2_score": 0.8783777609138392}} {"text": "In this section, we will indicate several important logical equivalences between the logical operators that we have introduced thus far. \n\nRecall in the previous section that boolean expressions can be viewed as functions of each variable, so we deduced that two expressions are logically equivalent if they have the same truth table. In fact, in some cases we can compare boolean expressions with different number of variables. For example, the logical expression $(p \\land q) \\lor (r \\lor (\\shortsim r))$ is logically equivalent to the logical expression $p \\land q$. We can naturally view $p \\land q$ as a function of the boolean variables $p$ and $q$, but we can also view this as a function of $p$, $q$, and $r$, where the result is independent of the value of $r$. So in this way we can compare logical expressions with varying or different boolean variables.\n\nNow we will show a basic logical equivalence called the \\textbf{contrapositive law}. The contrapositive law asserts for any logical variables $p$ and $q$ we have the equivalence\n\\[p \\implies q \\equiv (\\shortsim p) \\implies (\\shortsim q).\\]\nTo demonstrate that this equivalence is true it suffices to show that each entry in their respective truth tables are equal, as demonstrated below:\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|l|l|l|l|l|l|}\n\\hline\n$p$ & $q$ & $p \\implies q$ & & $p$ & $q$ & $(\\shortsim q) \\implies (\\shortsim p)$ \\\\ \\hline\n$T$ & $T$ & $T$ & & $T$ & $T$ & $T$ \\\\ \\hline\n$T$ & $F$ & $T$ & & $T$ & $F$ & $T$ \\\\ \\hline\n$T$ & $F$ & $F$ & & $T$ & $F$ & $F$ \\\\ \\hline\n$F$ & $T$ & $T$ & & $F$ & $T$ & $T$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nThe same approach is used when demonstrating each logical equivalence in the table below. \n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\nLogical Equivalence & Description \\\\ \\hline\n$p \\land q \\equiv q \\land p$, $p \\lor q \\equiv q \\lor p$ & Commutativity of $\\land$ and $\\lor$\\\\ \\hline\n$(p \\land q) \\land r \\equiv p \\land (q \\land r)$ & Associativity of $\\land$\\\\ \\hline\n$(p \\lor q) \\lor r \\equiv p \\lor (q \\lor r)$ & Associativity of $\\lor$ \\\\ \\hline\n$(p \\lor q) \\land r \\equiv (p \\land r) \\lor (q \\land r) $ & Distributivity of $\\land$ over $\\lor$ \\\\ \\hline\n$(p \\land q) \\lor r \\equiv (p \\lor r) \\land (q \\lor r) $ & Distributivity of $\\lor$ over $\\land$ \\\\ \\hline\n$p \\land T \\equiv p$ & $\\land$ identity \\\\ \\hline\n$p \\lor F \\equiv p$ & $\\lor$ identity \\\\ \\hline\n$\\shortsim(\\shortsim p) \\equiv p$ & Double Negation \\\\ \\hline\n$p \\land p \\equiv p \\lor p \\equiv p$ & Idempotence of $\\land$ and $\\lor$ \\\\ \\hline\n$p \\lor (p \\land q) \\equiv p \\land (p \\lor q) \\equiv p$ & Absorption Property \\\\ \\hline\n$a \\implies b \\equiv (\\shortsim b) \\implies (\\shortsim a)$ & Contrapositive Property \\\\ \\hline\n$a \\implies b \\equiv (\\shortsim a) \\lor b$ & Implication as Disjunction \\\\ \\hline\n$a \\odot b \\equiv (a \\implies b) \\land (b \\implies a)$ & XNOR as Conjunction \\\\ \\hline\n$a \\land (\\shortsim a) \\equiv F$, $b \\lor (\\shortsim b) \\equiv T$ & Simplification Rules \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nUsing logical equivalences like the ones in the table above, it is now possible to show that certain expressions are logically equivalent without explicitly constructing their truth tables, as the examples below show.\n\n\\begin{example}\nIn this example we will show that the expression\n\\[\\left((q \\lor z) \\land (k \\lor (\\shortsim k))\\right) \\implies \\left(((\\shortsim q) \\land (\\shortsim z)) \\lor p\\right)\\]\nis logically equivalent to the simpler expression \n\\[(\\shortsim(q \\lor z)) \\lor p.\\]\n\nTo do this we will simplify the first expression using rules stated in the table.\n\n\\begin{align*}\n& \\left((q \\lor z) \\land (k \\lor (\\shortsim k))\\right) \\implies \\left(((\\shortsim q) \\land (\\shortsim z)) \\lor p\\right) \\\\\n\\equiv& \\left((q \\lor z) \\land T\\right) \\implies \\left(((\\shortsim q) \\land (\\shortsim z)) \\lor p\\right) \\\\\n\\equiv& (q \\lor z) \\implies \\left(((\\shortsim q) \\land (\\shortsim z)) \\lor p\\right) \\\\\n\\equiv& (q \\lor z) \\implies \\left(\\shortsim(q \\lor z) \\lor p\\right) \\\\\n\\equiv& (\\shortsim(q \\lor z) \\lor \\shortsim(q \\lor z)) \\lor p \\\\\n\\equiv& (\\shortsim(q \\lor z)) \\lor p\n\\end{align*}\n\nas desired.\n\\end{example}\n\n\\begin{example}\nIn this example we will simplify the expression \n\\[(k \\land l) \\lor ((k \\land m) \\land k \\land (l \\lor (\\shortsim m))).\\]\n\nBut not now because I am lazy.\n\\end{example}\n\nIn general, the rules above (and rules that can be derived from them) form the basis of a system where one can do calculations with logical variables. Now we will discuss some of these properties individually and make more comments about them.\n\n\\subsection{Commutativity and Associativity}\n\nIn general, a binary operator $\\otimes$ is said to be commutative if $p \\otimes q \\equiv q \\otimes p$, and associative if $(p \\otimes q) \\otimes r \\equiv p \\otimes (q \\otimes r)$. As noted in the table above, the operators $\\lor$ and $\\land$ are associative and commutative.\n\nCommutativity and Associativity are rather strong properties to have for any binary operator. This is because not all operators are associative or commutative. For example, the implies operator is not commutative, that is,\n\\[p \\implies q \\not\\equiv q \\implies p,\\]\nand the NAND operator is not associative, that is\n\\[p \\uparrow (q \\uparrow r) \\not\\equiv p \\uparrow (q \\uparrow r).\\]\nOne can see this by constructing the truth table for each expression respectively.\n\n\\subsection{The Absorption Property}\n\nThe proper way to interpret the absorption properties in the table above are that their values are independent of the variable $q$ when evaluated. To see this, consider the expression $p \\lor (p \\land q)$. Evaluating $q$ as $F$ we get\n\\[p \\lor (p \\land F) \\equiv p \\lor F \\equiv p\\]\nby other properties in the table. Similarly, evaluating $q$ as $T$ we get\n\\[p \\lor (p \\land T) \\equiv p \\lor p \\equiv p.\\]\n\n\\subsection{Implication as Disjunction}\n\nThe implication as disjunction property is the first example of the important idea of creating an expression given a truth table where all the variable assignments evaluate to true except for one. In this case, the implies operator evaluates $T$ unless $p \\equiv T$ and $q \\equiv F$. In this case, we can create an or expression $(\\shortsim p) \\lor q$ which we see has the same truth table as $p \\implies q$. This idea of creating such an indicator function given any truth table later will be important when we study the conjunctive and disjunctive normal forms in a following section.\n\n\\subsection{Exercises}\n\\input{Ch1/op_cons_ex}", "meta": {"hexsha": "ac4124bde5495da399a5ea1f3a7281e887e7ae0f", "size": 6490, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch1/op_cons.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch1/op_cons.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch1/op_cons.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.2244897959, "max_line_length": 727, "alphanum_fraction": 0.7009244992, "num_tokens": 1931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.9294404033240911, "lm_q1q2_score": 0.878316267427476}} {"text": "%\n% Chapter 3.9\n%\n\n\\section*{3.9 Antiderivatives}\n\nA function \\(F\\) is called an \\textbf{antiderivative} of \\(f\\) on an interval \\(I\\) if \\(F'(x)=f(x)\\) for all \\(x\\) in \\(I\\).\n\n\\subsubsection*{Theorem}\n\nIf \\(F\\) is an antiderivative of \\(f\\) on an interval \\(I\\), then the most general antiderivative of \\(f\\) on \\(I\\) is \n$$ F(x) + C $$\nwhere \\(C\\) is an arbitrary constant.\n\n\\subsection*{General Antiderivative Formulae}\n\n$$ \\text{The antiderivative of } \\quad cf(x) \\quad \\text{ is } \\quad cF(x) + C. $$\n$$ \\text{The antiderivative of } \\quad f(x)+g(x) \\quad \\text{ is } \\quad F(x) + G(x) + C. $$\n$$ \\text{The antiderivative of } \\quad x^{n} (n \\neq -1) \\quad \\text{ is } \\quad \\frac{x^{n+1}}{n+1} + C. $$\n$$ \\text{The antiderivative of } \\quad \\cos(x) \\quad \\text{ is } \\quad \\sin(x) + C. $$\n$$ \\text{The antiderivative of } \\quad \\sin(x) \\quad \\text{ is } \\quad -\\cos(x) + C. $$\n$$ \\text{The antiderivative of } \\quad \\sec^2(x) \\quad \\text{ is } \\quad \\tan(x) + C. $$\n$$ \\text{The antiderivative of } \\quad \\sec(x)\\tan(x) \\quad \\text{ is } \\quad \\sec(x) + C. $$\n\\\\\nAn equation that involves the derivatives of a function is called a \\textbf{differential equation}.\n", "meta": {"hexsha": "f4b78eda6ed1ba0d2ca3ab016156db546bc4d0f7", "size": 1171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-9.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/3-9.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/3-9.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0384615385, "max_line_length": 125, "alphanum_fraction": 0.609735269, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377249197138, "lm_q2_score": 0.9161096164524095, "lm_q1q2_score": 0.8781256275313643}} {"text": "\\subsection{Definition and Notation}\n\nMost roughly speaking, a set is a collection of objects. These objects can be numbers, people, or even other sets themselves. In general this collection need not be homogeneous (so for example, we can have a set which contains both a number and a person). For the purposes of this book, we will not even try to discuss a formal logical definition of a set (this gets very complicated). So for the rest of this book we can assume that a set is a collection of objects without any issues whatsoever.\n\nIn general, when we are describing sets as a collection of specific objects, we tend to use curly braces $\\{\\}$ to enclose these objects while delimiting them by commas.\n\n\\begin{example}\nIf we wanted to describe the set containing the numbers $1$, $2$, and $3$, we would do so as $\\{1, 2, 3\\}$. The set $\\{1, \\{1, 2\\}\\}$ is the set which contains the number $1$, and the set $\\{1, 2\\}$ containing $1$ and $2$.\n\nThe set $\\{1, 1\\}$ is the set containing the numbers $1$, \\ldots and $1$? Since $1$ and $1$ are in fact the same this set is the same as $\\{1\\}$. We will make this example more formally clear later in the chapter.\n\\end{example}\n\nIn general describing sets like this gets awkward when the number of elements that the set contains gets very large. For example, it is very awkward to write out \n\\[\\{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15\\}\\]\nto describe the set of positive integers between $1$ and $15$ inclusive. There are a couple of things we can do. For most purposes if we instead wrote this set as\n\\[\\{1, 2, 3, \\dots, 14, 15\\}\\]\nwhere most people would understand what the set was. Another thing we can do is use a variable, such as $A$, to denote the set of positive integers between $1$ and $15$ inclusive. The best convention is to combine these two notions. We can define\n\\[A = \\{1, 2, 3, \\dots, 14, 15\\}.\\]\nIn this formulation $A$ is defined as the set of positive integers between $1$ and $15$ inclusive. Once we have defined $A$ in this way we can freely use just the character ``$A$'' instead of $\\{1, 2, 3, \\dots, 14, 15\\}$, which is a good way to write concisely.\n\nIn general, we can refer to any abstract set using a variable such as $A$, $B$, etc. (In general most people will use capital letters to refer to sets). \n\n\\begin{example}\nThe set $\\mathbb{N}$, known as the set of \\textbf{natural numbers}, denotes the set of positive integers. That is,\n\\[\\mathbb{N} = \\{1, 2, 3, 4, \\dots\\}.\\]\nThe set $\\mathbb{Z}$ (german for \\textit{Zahlen}) denotes the set of all integers. That is,\n\\[\\mathbb{Z} = \\{\\dots, -2, 1, 0, 1, 2, \\dots\\}.\\]\nIn some texts people include $0$ in the natural numbers. This is entirely a matter of convention and not for any very deep reason. Sometimes it is convenient to include $0$. \n\nThe empty set, denoted $\\varnothing$ is the set which does not contain any elements.\n\\end{example}\n\n\\subsection{Set Inclusion and Set Equality}\n\nThe first thing we describe in this section is notation to describe whether an object (usually denoted by a lowercase letter) is in a certain set. We use the $\\in$ notation in order to do so. That is, we say that \n\\[x \\in A\\]\nif the object $x$ is in the set $A$. Alternatively if an object $x$ is not in $A$ we write $x \\not\\in A$ instead.\n\n\\begin{example}\nLet $A = \\{1, 2, 3, \\dots, 14, 15\\}$. Then $6 \\in A$. \n\nThe empty set $\\varnothing$ has the property that $x \\not\\in A$ for any conceivable object $x$.\n\\end{example}\n\nThe notion of set containment, which is an inquiry about whether any object is contained in a set, leads naturally to a general notion of inquiring whether some set is contained inside another. The definition for this is pretty natural. Roughly speaking, a set $A$ is contained in a set $B$ only if all the objects contained in $A$ are also contained in $B$. We make this notion more formal now.\n\n\\begin{definition}\nSuppose $A$ and $B$ are sets. Then we say that $A \\subset B$ if we have for every $x \\in A$ we have $x \\in B$ also.\n\\end{definition}\n\n\\begin{example}\nWe have \n\\[\\{1, 2\\} \\subset \\{1, 2, 3\\}.\\]\n\\end{example}\n\nA closely related concept to set inclusion is set equality. Below we define set equality. Roughly two sets are equal if they contain the same elements. We will define set equality then using the subset definition.\n\\begin{definition}\nSuppose $A$ and $B$ are sets. Then $A = B$ if $A \\subset B$ and $B \\subset A$.\n\\end{definition}\n\nThis definition roughly encodes the notion of set equality. Since in the definition of subset, $A \\subset B$ if all the elements of $A$ were in $B$. So two sets $A$ and $B$ are equal if all the elements of $A$ are in $B$, and all the elements of $B$ are in $A$. This raises some subtle, but not particularly deep observations.\n\n\\begin{example}\nWe claim that \n\\[\\{1, 2, 3, 3\\} = \\{1, 2, 3\\}.\\]\n\nThis can be easily verified using the definition of set equality. However it is true that both sets do not ``look'' the same. \n\\end{example}\n\nThis subtlety with multiple elements in a set shows that we only need to consider sets where each element of the set is unique in that set, since such a set will always be equal to one with the same elements but maybe some of them duplicated. %%probably a terrible explanation.\n\n\\subsection{Common Set Operations}\n\nIn this section we describe common set operations and notations used to manipulate sets and create new sets. First we will explain why this is useful. In practice, when one is using sets, in general one considers sets with certain properties. That is one would like to consider perhaps certain objects with a certain property. In practice one would define these sets using \\textbf{set builder notation}. The idea of defining such a set $S$ is encapsulated in the notation below.\n\n\\[S = \\{\\text{all the objects $x$ of some type} \\colon \\text{$x$ has some special property}\\}.\\]\nLet's break down this notation further. With this notation, it is accepted that $S$ is defined to be the set of all objects $x$ such that $x$ has a special property. For example, the set \n\\[S = \\{x \\in \\mathbb{Z} \\colon |x| \\leq 5\\}\\]\nis the set of integers with absolute value less than or equal to $5$. In other words,\n\\[S = \\{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5\\}.\\]\nIn general set builder notation is very useful to create sets of objects with certain properties.\n\nNot only do we want to describe objects with a certain property, but much of the time we would like to describe objects with more than one property or objects with at least one of the following few properties. These concepts are encapsulated by set intersection and set union, respectively.\n\n\\subsubsection{Set Intersection}\n\nSuppose $E$ is the set of even numbers and $T$ is the set of multiples of $3$. Then if a number $n$ is divisible by $6$, then it is both an even number and a multiple of $3$. So $n$ is in $E$ and $T$ at the same time. Using notation already presented, one might say that $n \\in E$ and $n \\in T$. However, this is not the most concise way to write this. In order to express that an object is in two sets and the same time we introduce the notion of \\textit{set intersection}.\n\n\\begin{definition}\nLet $A$ and $B$ be sets. We define $A \\cap B$ (read as ``$A$ intersect $B$'') to be the objects $n$ which are contained in both $A$ and $B$. A little more formally,\n\\[A \\cap B = \\{n \\colon (n \\in A) \\land (n \\in B)\\}.\\]\n\\end{definition}\n\nIn the example described above, the most concise way to write that $n$ is both even and a multiple of three would be $n \\in E \\cap T$.\n\n\\begin{definition}\nLet $A$ and $B$ be sets. We say that $A$ and $B$ are \\textbf{disjoint} if $A \\cap B = \\varnothing$. That is, $A$ and $B$ have no elements in common.\n\\end{definition}\n\n\\subsubsection{Set Union}\n%%the first example I thought up was that of boys and girls in a schoolyard. But this might be politically incorrect in more than one way. \nSimilarly to how we would like to describe objects with multiple properties at the same time, in many cases it is useful to describe objects which have one of many properties, but not necessarily all of them at the same time.\nConsider, for example, the set of all candy $C$ that some person has acquired one Halloween night. Any piece of candy satisfies the following condition. Either it contains chocolate or it does not. These are clearly mutually exclusive possibilities. Let $H$ denote the set of candies in the Halloween loot which contain chocolate, and let $J$ denote the set of candies in the Halloween loot that do not contain chocolate. Then we may observe the following.\n\\begin{itemize}\n\t\\item Every candy $c$ in the Halloween loot is either in $H$ or in $J$, since a piece of candy in the loot either does or does not contain chocolate.\n\t\\item $H \\cap J = \\varnothing$, because a piece of candy cannot both contain and not contain chocolate at the same time\\footnote{Here we are assuming something known as the \\textbf{law of the excluded middle}.}\n\\end{itemize}\n\nAs with set intersection, we would like some notation that would indicate that $c$, a piece of candy, is either in $H$ or in $J$. This is done using the set union notation, as defined below.\n\\begin{definition}\nLet $A$ and $B$ be sets. We define $A \\cup B$ (read as ``$A$ union $B$'') to be the objects $n$ which are contained in at least one of $A$ or $B$. A little more formally,\n\\[A \\cup B = \\{n \\colon (n \\in A) \\lor (n \\in B)\\}.\\]\n\\end{definition}\nFor instance, in the example above, we could write $c \\in H \\cup J$ to indicate that each piece of candy is in either $H$ or in $J$. This is not the most general use of set union because as we observed, the sets $H$ and $J$ were disjoint. As a simple example, one can verify that \n\\[\\{1, 2, 3\\} \\cup \\{2, 3, 4\\} = \\{1, 2, 3, 4\\}.\\]\n\n\\begin{definition}\nSuppose that $S$ is a set and $A$ and $B$ are subsets of $S$. We say that $A$ and $B$ cover $S$ if \n\\[A \\cup B = S.\\]\n\\end{definition}\n\n\\subsubsection{Union and Intersection of More Than Two Sets}\n\nIn the above two parts we have defined set intersection and set union for two sets $A$ and $B$. As stated before, these notations are useful for describing objects that have many properties or at least one out of many given properties respectively. However, with our definitions we can only do this when ``many'' equals $2$. So now we define union and intersection for more than two sets. First, we define set union and intersection for arbitrarily many finite sets, and then for an arbitrary index set (which we will define later).\n\n\\begin{definition}\nSuppose $n \\geq 2$, and $A_1, A_2, \\dots, A_n$ are sets. We define their intersection and union to be\n\\[A_1 \\cap A_2 \\cap \\cdots \\cap A_n = \\{x \\colon (x \\in A_1) \\land (x \\in A_2) \\land \\cdots \\land (x \\in A_n)\\}\\]\nand\n\\[A_1 \\cup A_2 \\cup \\cdots \\cup A_n = \\{x \\colon (x \\in A_1) \\lor (x \\in A_2) \\lor \\cdots \\lor (x \\in A_n)\\}\\]\n\nWe can also write these intersections and unions in big union and intersection notation, which looks like this:\n\\[\\bigcup_{i = 1}^nA_i = A_1 \\cup A_2 \\cup \\cdots \\cup A_n\\]\nand \n\\[\\bigcap_{i = 1}^nA_i = A_1 \\cap A_2 \\cap \\cdots \\cap A_n.\\]\n\\end{definition}\n\nOne might observe that in the case of chapter 1\\footnote{this is temporary to indicate that i have not mentioned this issue in chapter 1 at all} that the definition of a union (resp. intersection) of more than two sets involves a logical formula that is not fully well defined namely a large connection of logical ands (resp. logical ors). As we have stated then this will not be a problem due to the associativity of the logical operators $\\land$ and $\\lor$. We will resolve this problem fully in Chapter 4. %note please label the chapters later.\n\nNow we discuss the union of sets over an arbitrary index. Let $I$ be a set, possibly infinite. Suppose we have a collection of sets $A_i$ for each $i \\in I$. In many cases we would like to discuss the union (or perhaps intersection) of these sets, denoted by\n\\[\\bigcup_{i \\in I}A_i, \\bigcap_{i \\in I}A_i\\]\n\nWe will define these unions and intersections similarly to how we did it for finitely many sets.\n\\begin{definition}\nLet $I$ be any set, and suppose that $A_i$ are sets defined for each $i \\in I$. We will define the union and intersection of these sets as follows: We define\n\\[\\bigcup_{i \\in I}A_i = \\{x \\colon \\text{$x \\in A_i$ for some $i \\in I$}\\}\\]\nand\n\\[\\bigcap_{i \\in I}A_i = \\{x \\colon \\text{$x \\in A_i$ for all $i \\in I$}\\}.\\]\n\\end{definition}\n\n\\begin{example}\nConsider the set $I = \\mathbb{N}$. We will define the set $A_n$ for each $n \\in \\mathbb{N}$ to be the set of positive multiples of $n$. That is,\n\\[A_n = \\{n, 2n, 3n, 4n, \\dots\\}.\\]\nFirst we will determine \n\\[\\bigcup_{n \\in I}A_n.\\] We claim this is just $\\mathbb{N}$. Indeed, observe that since $A_n \\subset \\mathbb{N}$ for all $n \\in I$, their union is a subset of $\\mathbb{N}$ as well. For the other direction, we only need to observe that for each $n \\in \\mathbb{N}$, $n \\in A_n$. So clearly by the definition of subset we have the other inclusion. %maybe explain more.\n\nNow we will determine\n\\[\\bigcap_{n \\in I}A_n.\\] We claim that this set is empty. Indeed, again we observe since $A_n$ are subsets of $\\mathbb{N}$ we observe that their intersection is as well. Now we just need to show that no element of $\\mathbb{N}$ is in the intersection (hence the intersection is empty). To see this, we only need to observe that any $n \\in \\mathbb{N}$ is not contained in $A_{n + 1}$. Hence no $k \\in \\mathbb{N}$ can be contained in all of the $A_n$ at the same time (which is the requirement for $k$ to be in the intersection.\n\\end{example}\n\nAs a remark, the indexing set $I = \\mathbb{N}$ is so common that many people usually use the following notation for a union indexed by the natural numbers. In this case people usually write\n\\[\\bigcup_{i = 1}^\\infty A_i\\] instead of \n\\[\\bigcup_{i \\in \\mathbb{N}}A_i.\\]\n\n\n\\begin{example}\nConsider again the set $I = \\mathbb{N}$. We will define a collection of sets $A_n$ for $n \\in I$ which have the following properties:\n\\begin{itemize}\n\t\\item \\[\\bigcup_{i = 1}^{\\infty}A_n = \\mathbb{N}\\]\n\t\\item $A_i \\cap A_j = \\varnothing$ when $i \\neq j$,\n\t\\item $A_i$ are infinite sets for each $I$. \n\\end{itemize}\n\nI will work out this example later because I am lazy.\n\\end{example}", "meta": {"hexsha": "48163b55d37cffe4de23c8754cd5f3a9d6c88038", "size": 14204, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch3/sets1.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch3/sets1.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch3/sets1.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.1657142857, "max_line_length": 547, "alphanum_fraction": 0.7197972402, "num_tokens": 4077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.941654164300481, "lm_q2_score": 0.9324533088603708, "lm_q1q2_score": 0.8780485413041308}} {"text": "\n\\subsection{Expected value}\n\\subsubsection{Definition}\n\nFor a random variable (or vector of random variables), \\(x\\), we define the expected value of \\(f(x)\\) as :\n\n\\(E[f(x)]:=\\sum f(x_i) P(x_i)\\)\n\nThe expected value of random variable \\(x\\) is therefore this where \\(f(x)=x\\).\n\n\\(E(x)=\\sum_i x_i P(x_i)\\)\n\n\\subsubsection{Linearity of expectation}\n\nWe can show that \\(E(x+y)=E(x)+E(y)\\):\n\n\\(E[x+y]=\\sum_i \\sum_j (x_i+y_j) P(x_i \\land y_j)\\)\n\n\\(E[x+y]=\\sum_i \\sum_j x_i [P(x_i \\land y_j)]+\\sum_i \\sum_j [y_j P(x_i \\land y_j)]\\)\n\n\\(E[x+y]=\\sum_i x_i \\sum_j [P(x_i \\land y_j)]+\\sum_j y_j \\sum_i [P(x_i \\land y_j)]\\)\n\n\\(E[x+y]=\\sum_i x_i P(x_i)+\\sum_j y_j P(y_j)\\)\n\n\\(E[x+y]=E[x]+E[y]\\)\n\n\\subsubsection{Expectations of multiples}\n\nExpectations\n\n\\(E(cx)=\\sum_i cx P(x_i)\\)\n\n\\(E(cx)=c\\sum_i x P(x_i)\\)\n\n\\(E(cx)=cE(x)\\)\n\n\\subsubsection{Expectations of constants}\n\n\\(E(c)=\\sum_i c_i P(c_i)\\)\n\n\\(E(c)= cP(c)\\)\n\n\\(E(c)= c\\)\n\n\\subsubsection{Conditional expectation}\n\nIf \\(Y\\) is a variable we are interested in understanding, and \\(X\\) is a vector of other variables, we can create a model for \\(Y\\) given \\(X\\).\n\nThis is the conditional expectation.\n\n\\(E[Y|X]\\)\n\n\\(E[P(Y|X)Y]\\)\n\nIn the continuous case this is\n\n\\(E(Y|X)=\\int_{-\\infty }^{\\infty }yP(y|X)dy\\)\n\nWe can then identify an error vector.\n\n\\(\\epsilon :=Y-E(Y|X)\\)\n\nSo:\n\n\\(Y=E(Y|X)+\\epsilon \\)\n\nHere \\(Y\\) is called the dependent variable, and \\(X\\) is called the dependent variable.\n\n\\subsubsection{Iterated expectation}\n\n\\(E[E[Y]]=E[Y]\\)\n\n\\(E[E[Y|X]=E[Y]\\)\n\n", "meta": {"hexsha": "a00a24c6bcd81df51be279cba1eb15bd97fb5154", "size": 1507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMoments/01-02-singleExpected.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityMoments/01-02-singleExpected.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityMoments/01-02-singleExpected.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0933333333, "max_line_length": 145, "alphanum_fraction": 0.6297279363, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142221377825, "lm_q2_score": 0.9230391563648734, "lm_q1q2_score": 0.8779415136035993}} {"text": "% Random SVD\n\\subsection{Randomized SVD}\n\\label{sec:rsvd}\n\nRandomized SVD is a method to very efficient and effective way to perform approximate singular value decompositions using random matrix theory. The premise is a very large data matrix $\\mathbf{X} \\in \\mathbb{R}^{n \\times m}$ that has low \\textit{intrinsic rank} $r$, so that $\\mathbf{X} \\approx \\mathbf{U_r \\Sigma_r V_r}^T$ will be a good approximation.\n\n\\subsubsection{Step 1: Sample Column Space of $\\mathbf{X}$ with $\\mathbf{P}$}\nGiven a random projection matrix $\\mathbf{P}\\in\\mathbb{R}^{m \\times r}$, the matrix:\n\n\\begin{equation}\n\\mathbf{Z} = \\mathbf{XP}\n\\end{equation}\n\nwill, because of the properties of random matrices, likely have the same rank $r$ dominant column space as $\\mathbf{X}$. SVD is usually calculated via the QR-decomposition of a matrix. Performing the QR decomposition of $\\mathbf{Z}$ is much less laborious, because $\\mathbf{Z}\\in\\mathbb{R}^{m \\times r}$ is much smaller than $\\mathbf{X}$. We obtain:\n\n\\begin{equation}\n\\mathbf{X} = \\mathbf{QR}\n\\end{equation}\n\nWhere $\\mathbf{Q}\\in\\mathbb{R}^{m \\times r}$ and $\\mathbf{R}\\in\\mathbb{R}^{r \\times r}$.\n\n\n\\subsubsection{Step 2: Compute SVD on Projected $\\mathbf{Y = Q^T X}$}\nThe next step consists of projecting $\\mathbf{Z}$ into $\\mathbf{Q}$:\n\n\\begin{equation}\n\\mathbf{Y} = \\mathbf{Q}^T\\mathbf{X}\n\\end{equation}\n\nResulting in the matrix $\\mathbf{Y}\\in\\mathbb{R}^{r\\times n}$. Performing the SVD on $\\mathbf{Y}$ (which is, again, much smaller than $\\mathbf{X}$), gives:\n\n\\begin{equation}\n\\mathbf{Y} = \\mathbf{U}_Y\\mathbf{\\Sigma}_r\\mathbf{V}_r^T\n\\end{equation}\n\nWhere $\\mathbf{\\Sigma}_r$ and $\\mathbf{V}_r$ turn out to likely be the same as those that would be obtained from the SVD of $\\mathbf{X}$ itself. In the last step, $\\mathbf{U}_r$ is recovered using the mathrix $\\mathbf{Q}$, via $\\mathbf{U}_r = \\mathbf{QU}_Y$. \n\nGuaranteed error bounds for the low rank approximation obtained with this technique. There are two approaches to improve the accuracy of randomized SVD. The first is to oversample, by letting the projection matrix $\\mathbf{P}$ have a rank larger than $r$. The second is to \"sharpen\" the singular value spectrum by using the matrix $\\mathbf{(X X^T)^q X }$ instead of $\\mathbf{X}$. Calculating the power results in a matrix with a much faster drop off in the singular values, but is much more computationally expensive. This technique is useful when the singular values of $\\mathbf{X}$ decay only slowly. The column space of the power iteration $\\mathbf{...X X^T X X^T X X^T X}$ has the same column space, so that the trick with the projection operation works here too, only that the dominant subspace will be emphasized.\\\\\n\n\n\\begin{python}\ndef rSVD(X,r,q,p):\n \"\"\"\n Randomized SVD Code\n \"\"\"\n # Step 1: Sample column space of X with P matrix\n ny = X.shape[1]\n P = np.random.randn(ny,r+p)\n Z = X @ P\n for k in range(q):\n Z = X @ (X.T @ Z)\n\n Q, R = np.linalg.qr(Z,mode='reduced')\n\n # Step 2: Compute SVD on projected Y = Q.T @ X\n Y = Q.T @ X\n UY, S, VT = np.linalg.svd(Y,full_matrices=False)\n U = Q @ UY\n\n return U, S, VT\n\\end{python}\n\nEmpirically, randomized SVD outperforms SVD significantly the lower the rank of the TSVD.\n\n\n\\begin{figure}\n\\centering\n \\includegraphics[width=\\textwidth]{randomized_svd.png}\n \\caption{Left: Time taken to perform conventional SVD (black line) and randomized SVD (colored lines) on the photo of the two young aristocrats which had a data matrix with rank $r=1277$. The different colors correspond to different numbers of power iterations performed ($q$). Right: Average mean square error (AMSE) of truncated SVD using matrices derived with randomized SVD compared with conventional SVD. Especially for small $r$, rSVD is significantly faster even after a few power iterations. For very small $r$, power iterations easily reduce the error introduced by the randomized method by several orders of magnitude, but at some point the method seems to increase the error. Perhaps this is due to numerical stability. I'm not sure. To somewhat account for random fluctuations, the curves shown are averaged over 20 trials.}\n \\label{fig:svd_scree}\n\\end{figure}", "meta": {"hexsha": "1ec52f39c89f0030d618d8ff2689de3fad7e968c", "size": 4190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_randomsvd.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/unsup_randomsvd.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/unsup_randomsvd.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.014084507, "max_line_length": 840, "alphanum_fraction": 0.723627685, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464605, "lm_q2_score": 0.9207896704568165, "lm_q1q2_score": 0.8777658099790888}} {"text": "\\section{Linear dynamical systems}\n\\subsection{Linear dynamical systems}\n$x_{t+1} = A_tx_t$ , t = 1,2,. . .\\\\\n\\textbullet $A_t$ are n Ă— n dynamics matrices\n\\textbullet $(A_t)_{ij}(x_t)_j$\nis contribution to $(x_{t+1})_i$\nfrom $(x_t)_j$\\\\\n\\textbullet system is called time-invariant if $A_t = A$ doesn't depend on time\\\\\n\\textbullet can simulate evolution of xt using recursion $x_{t+1} = A_tx$\\\\\n\\textbullet linear dynamical system with input\\\\\n$x_{t+1} = A_tx_t + B_tu_t + c_t$, t = 1,2,...\\\\\n\\thickspace -- $u_t$ is an input m-vector\\\\\n\\thickspace -- $B_t$ is n Ă— m input matrix\\\\\n\\thickspace -- $c_t$ is offset\\\\\n\\textbf{K-Markov model}:\\\\\n$x_{t+1} = A_1x_t + ... + A_Kx_{t-K+1}$, t = K,K + 1,...\\\\\n\\thickspace -- next state depends on current state and K - 1 previous states\\\\\n\\thickspace – also known as auto-regresssive model\\\\\n\\thickspace – for K = 1, this is the standard linear dynamical system $x_{t+1} = Ax_t$\\\\\n\\subsection{Population dynamics}\n\\textbullet $x_t \\in R^{100}$ gives population distribution in year t = 1,...,T\\\\\n\\textbullet $(x_t)^i$ is the number of people with age i - 1 in year t (say, on January 1)\\\\\n\\textbullet birth rate $b \\in R^{100}$, death (or mortality) rate $d \\in R^{100}$\\\\\n\\textbullet $b_i$ is the number of births per person with age i - 1\\\\\n\\textbullet $d_i$ is the portion of those aged i - 1 who will die this year (we’ll take $d_{100} = 1$)\n\\textbullet let’s find next year’s population distribution $x_t+1$ (ignoring immigration)\\\\\n\\textbullet number of 0-year-olds next year is total births this year:\\\\\n$(x_{t+1})_1 = b^Tx_t$\\\\\n\\textbullet number of i-year-olds next year is number of (i - 1)-year-olds this year, minus those who die:\n$(x_{t+1})_{i+1} = (1 - d_i)(x_t)_i$ , i = 1,..,99\\\\\n\\textbullet $x_{t+1} = Ax_t$ , where\\\\\n$A =\n\\begin{bmatrix}\n b_1 & b_2 &...& b_{99} & {b_{100}} \\\\\n 1-d_1 & 0 &...& 0 & 0\\\\\n 0 & 1-d_2 &...& 0 & 0\\\\\n . & . &...& . &.\\\\\n . & . &...& . &.\\\\\n 0 & 0 &...& 1-d_{99} & 0\n\\end{bmatrix}\n$\n\\subsection{Epidemic dynamics}\n\\textbf{SIR Model}\\\\\n\\textbullet 4-vector $x_t$ gives proportion of population in 4 infection states\\\\\n-- \\textit{Susceptible}: can acquire the disease the next day\\\\\n-- \\textit{Infected}: have the disease\n-- \\textit{Recovered}: had the disease, recovered, now immune\\\\\n-- \\textit{Deceased}: had the disease, and unfortunately died\\\\\n\\textbullet sometimes called SIR model\\\\\n\\textbullet e.g., $x_t = (0.75,0.10,0.10,0.05)$\n\\textbf{over each day},\\\\\n\\textbullet among susceptible population,\\\\\n-- 5\\% acquires the disease\\\\\n-- 95\\% remain susceptible\n\\textbullet among infected population,\\\\\n-- 1\\% dies\\\\\n-- 10\\% recovers with immunity\\\\\n-- 4\\% recover without immunity (i.e., become susceptible)\\\\\n-- 85\\% remain infected\\\\\n\\textbullet 100\\% of immune and dead people remain in their state\\\\\n\\textbullet epidemic dynamics as linear dynamical system\\\\\n$\nx_{t+1} =\n\\begin{bmatrix}\n 0.95 & 0.04 & 0 & 0 \\\\\n 0.05 & 0.85 & 0 & 0\\\\\n 0 & 0.10 & 1 & 0\\\\\n . & . &...& . &\\\\\n . & . &...& . &\\\\\n 0 & 0.01 & 0 & 1\n\\end{bmatrix}x_t\n$\\\\\n\n", "meta": {"hexsha": "2cfddd13e933e23fedf52959582ec076c212b64f", "size": 3063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_stars_repo_name": "meanmachin3/COT5615", "max_stars_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_issues_repo_name": "meanmachin3/COT5615", "max_issues_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_forks_repo_name": "meanmachin3/COT5615", "max_forks_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 41.3918918919, "max_line_length": 106, "alphanum_fraction": 0.6389160953, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.964321452198369, "lm_q2_score": 0.9099070072595894, "lm_q1q2_score": 0.8774428466060391}} {"text": "\\chapter{Graph}\n\nA \\emph{graph} is \\(G = (V,E)\\) where\n\\(V\\) is the set of \\emph{vertices} and \\(E \\subseteq V \\times V\\) is the set of \\emph{edges}.\n\n\\(E\\) is a relation.\n\n\\(G\\) is a \\emph{function} iff \\(\\forall a, b, c : a E b \\wedge a E c \\implies b=c\\).\n\n\\(G\\) is \\emph{undirected} iff \\(E\\) is symmetric.\n\nA \\emph{path} is a sequence of edges.\n\nLet \\(P(a,b)\\) mean ``there is a path from \\(a\\) to \\(b\\)'' or ``\\(a\\) has a path to \\(b\\)''.\nThen \\(P(a,b) = E(a,b) \\vee \\exists c (P(a,c) \\wedge P(c,b))\\).\nWe say that \\(b\\) is \\emph{reachable} from \\(a\\) iff there is a path from \\(a\\) to \\(b\\).\n\n\\(G\\) is \\emph{cyclic} if it has a vertex that has a path to itself.\n\\(G\\) is \\emph{acyclic} iff it is not cyclic.\n\n\\(G\\) is \\emph{connected} iff \\(\\forall a,b \\in V, a\\neq b : P(a,b)\\).\n\\(G\\) is \\emph{disconnected} iff it is not connected.\n\n\\(G\\) is \\emph{complete} iff \\(\\forall a,b \\in V, a \\neq b : E(a,b)\\).\n\n\\(G_1 = (V_1,E_1)\\) is a \\emph{subgraph} of \\(G_2 = (V_2,E_2)\\)\niff \\(G_2\\) is a graph, \\(V_1 \\subseteq V_2\\), and \\(E_1 \\subseteq E_2\\).\n\nA \\emph{loop} is an edge of the form \\((a,a)\\).\n\nThe \\emph{length} of a path is the number of edges in that path.\n\n% https://en.wikipedia.org/wiki/Distance_(graph_theory)\n\nThe \\emph{geodesic distance} from \\(a\\) to \\(b\\) is \\(d(a,b)\\),\nthe length of the shortest path from \\(a\\) to \\(b\\).\n\nThe natural metric space of a connected undirected graph \\((V,E)\\) is \\((V,d)\\) where\n\\(d(a,b)\\) is the length of the shortest path from \\(a\\) to \\(b\\).\n\nThe \\emph{indegree} of \\(v\\) is \\(|\\{ (a,v) : a E v \\}|\\).\n\nThe \\emph{outdegree} of \\(v\\) is \\(|\\{ (v,a) : v E a \\}|\\).\n\nA vertex is \\emph{source} iff its indegree is zero.\n\nA vertex is \\emph{sink} iff its outdegree is zero.\n\nThe graph's \\emph{fringe} of \\(A\\) is \\(F(A) = \\{ b ~|~ a \\in A, ~ (a,b) \\in E \\}\\).\n\nLet \\(F^{n+1}(A) = F(F^n(A))\\).\nProperty: \\(F(\\emptyset) = \\emptyset\\).\nProperty: \\(F(A \\cup B) = F(A) \\cup F(B)\\).\n\nA \\emph{tree} is an undirected acyclic graph.\n", "meta": {"hexsha": "4a3ec20e0103a64f3946bd4b234209f6d397e288", "size": 1972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/graph.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/graph.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/graph.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 35.2142857143, "max_line_length": 94, "alphanum_fraction": 0.5851926978, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9669140244715405, "lm_q2_score": 0.9073122201074846, "lm_q1q2_score": 0.8772929101963362}} {"text": "\n\\subsection{\\(L_p\\) norms}\n\n\\(L_p\\) norms can be used to measure the distance between two metrics.\n\nIf we have data points \\(v\\) and \\(w\\) the distance is:\n\n\\(||v-w||=(\\sum_i |v_i-w_i|^p)^{\\dfrac{1}{p}}\\)\n\nIf \\(p=2\\) we have the Euclidian norm. If \\(p=1\\) we have the Manhatten norm.\n\n", "meta": {"hexsha": "cc561b7677ab5826289a887ac92d1266fe083323", "size": 286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/01-01-Lp.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/distance/01-01-Lp.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/distance/01-01-Lp.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8333333333, "max_line_length": 77, "alphanum_fraction": 0.6328671329, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9664104953173166, "lm_q2_score": 0.9073122232403329, "lm_q1q2_score": 0.8768360550691459}} {"text": "\\textbf{Solve the nonlinear boundary value problem}\n\\begin{align*}\ny''=y'+\\cos(y),~~y(0)=0,~~y(\\pi)=1.\n\\end{align*}\n\\textbf{Use finite differences to discretize the problem and Newton’s method to solve the resulting system of equations. Estimate (numerically) the number of discretized points needed to obtain a solution that is accurate to 4 digits at $x = \\pi/6$.}\n\nWe can express the previous differential equation as\n\\begin{align*}\ny''-y'-\\cos(y)=0,\n\\end{align*}\nso that its roots will give us the solution. To do so we need to discretize the derivatives using finite differences in order to be able to use Newton's method. Then, the differential equation takes the linear form\n\\begin{align*}\ny'' - y_x - cos(y) &= D_2y - D_1y - cos(y)\\\\\n&=My-\\cos(y) =0~,\n\\end{align*}\nwhere the matrix $M = D_2 - D_1$. The matrices $D_1$ and $D_2$ will give us the discrete values of the first and second derivative, respectively, and are obtained using second order centered finite differences. For $D_1$,\n\\begin{align*}\n&y' = \\frac{1}{2(\\Delta x)}\n\\begin{bmatrix}\n-1 & 0 & 1 & ~& \\dots & 0 \\\\\n0 & -1 & 0 & 1 & \\dots & 0 \\\\ \n\\vdots & ~& \\ddots & \\ddots & \\ddots & \\vdots \\\\\n0 & \\dots & ~ & -1 & 0 & 1 \\\\\n\\end{bmatrix}y +\n\\begin{bmatrix}\n0 \\\\\n\\vdots \\\\\n0 \\\\\n\\frac{1}{2 \\Delta x}\n\\end{bmatrix} = D_1y + g_1,\n\\end{align*}\nwhere the column vector $g_1$ contains is found by imposing the boundary conditions. Note that the matrices are calculated in such a way that they give us the derivatives for the interior nodes, since the boundary nodes we know their values thanks to the boundary conditions. For $D_2$,\n\\begin{align*}\n& y'' = \\frac{1}{(\\Delta x)^2} \\begin{bmatrix}\n1 & -2 & 1 & ~& \\dots & 0 \\\\\n0 & 1 & -2 & 1 & \\dots & 0 \\\\ \n\\vdots & ~& \\ddots & \\ddots & \\ddots & \\vdots \\\\\n0 & \\dots & ~ & 1 & -2 & 1 \\\\\n\\end{bmatrix}y + \\begin{bmatrix}\n0 \\\\\n\\vdots \\\\\n0 \\\\\n\\frac{1}{( \\Delta x)^2}\n\\end{bmatrix} = D_2y + g_2~,\n\\end{align*}\nwhere the column vector $g_2$ contains is found by imposing the boundary conditions. We now define\n\\begin{align*}\n\\vec{F}(\\vec{y}) = My - cos(y) + g_2 - g_1~,\n\\end{align*}\nwhere $\\vec{y}$ contains the interior nodes. The solution to our differential equations will be the vector $y$ that makes $\\vec{F}(\\vec{y})=0$. To calculate those roots we will use Newton's method. In order to be able to use it, we need to calculate the Jacobian,\n\\begin{align*}\nJ_{jk}=\\frac{\\partial}{y_j}F(y_k).\n\\end{align*}\nFirst note that\n\\begin{align*}\n\\frac{\\partial }{\\partial y_j} \\sum_{l=1}^{N}M_{kl}y_l = M_{kl}\n\\end{align*}\nand\n\\begin{align*}\n\\frac{\\partial }{\\partial y_j} \\cos(y_k) = \\begin{dcases}\n\t-\\sin(y_k) & \\text{for}~k = j\\\\\n\t\t0 & \\text{for}~j \\neq k \n\\end{dcases}\n\\end{align*}\nHence, the Jacobian can be coded as\n\\begin{align*}\nJ(\\vec{F}(\\vec{y})) = M + \\text{diag}(\\sin(y)).\n\\end{align*}\n\nWe will first run the code in a while loop to find out how many nodes we need to have an $L_1$ norm of $y^{new}(\\pi/6)-y^{old}(\\pi/6)$ less than a $tol=10^{-4}$. Using 31 nodes I obtained an $L_1$ norm of $7.269\\cdot 10^{-5}$. To be safe, since it is a low number of nodes and the code runs fast, we could run it for double number of elements $N$. Using then 61 nodes we obtain an $L_1$ norm of the error of $7.603\\cdot 10^{-6}$. Using 61 nodes we have obtained the solution showed in the next figure\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.75]{prob3sol.eps}}\n\\caption{Solution for 61 points}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\n\\begin{verbatim}\n%% Problem 3\nclose all\nclc\nformat long\n% Find an answer with sufficient level of convergence\ntol=1e-4;\ni=1;\nN=6;\nerr=1;\nyy=zeros(6+1,1);\nwhile err>tol\n i=i+1;\n y_old=yy(N/6);\n N = i*6;\n xi=linspace(0,pi,N+1)';\n [F,J,y0]=FandJ(N);\n [yy,niter] = newton(F,J,y0,1e-14);\n y_new=yy(N/6);\n % Check solution\n err=max(abs(y_new-y_old));\nend\n% Results\nnodes=N+1\nerr\n% Run it for N=60\nN=60;\nxi=linspace(0,pi,N+1)';\n[F,J,y0]=FandJ(N);\n[yy,niter] = newton(F,J,y0,1e-14);\ny_new=yy(N/6);\n% Plot the solution\nfigure\nplot(xi,[0; yy; 1],'linewidth',1.5)\nhold on\nplot(xi(N/6+1),y_new,'r.','markerSize',12)\ngrid on\nleg1= legend('Solution', 'Value at $\\pi/6$');\nset(leg1,'interpreter','latex','FontSize',17);\nset(gca,'fontsize',axisfontsize)\nxlabel('$x$','interpreter','latex','fontsize',labelfontsize)\nylabel('$y$','interpreter','latex','fontsize',labelfontsize)\nsaveas(gcf,'Latex/FIGURES/prob3sol','epsc')\n\\end{verbatim}\n\\subsubsection*{Function to calculate F and J}\n\\begin{verbatim}\nfunction [F,J,y0]=FandJ(N)\nx = linspace(0,pi,N+1)';\nh=pi/N;\nxi = x(2:N);\ny0 = xi/pi;\n\nD1 = (gallery('tridiag',N+1,-1,0,1))/(2*h);\nD1(1,:) = [];\nD1(end,:) = [];\nD1(:,1) = [];\nD1(:,end) = [];\n\nD2 = (gallery('tridiag',N+1,1,-2,1))/(h^2);\nD2(1,:) = [];\nD2(end,:) = [];\nD2(:,1) = [];\nD2(:,end) = [];\n\n% g1 = [zeros(N-2,1)];\n% g1(N-2) = (1/(2*h));\n% g2 = [zeros(N-2,1)];\n% g2(N-2) = (1/(h^2));\n% e1 = g2 - g1;\n\nM = D2 - D1;\ne1 = [zeros(N-1,1)];\ne1(N-1) = ((2-h)/(2*h^2));\n\nF = @(y) (M*y)-cos(y)+e1;\nJ = @(y) M + diag(sin(y));\nend\n\\end{verbatim}", "meta": {"hexsha": "7a9f8e103199a8a0a801b1ee038092f656f23d74", "size": 5012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1282051282, "max_line_length": 500, "alphanum_fraction": 0.6412609737, "num_tokens": 1838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025232, "lm_q2_score": 0.9230391674796139, "lm_q1q2_score": 0.8765820222681165}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS671: Machine Learning\n% Copyright 2015 Pejman Ghorbanzade \n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nLet $f: \\mathbb{R}^2 \\rightarrow \\mathbb{R}$ be the function defined by\n\n\\begin{equation}\nf(x) = x_1^2 + 2x_1 x_2 - 10x_1 + 5x_2\n\\label{eq31}\n\\end{equation}\n\nIs $f$ convex, concave or neither? Why?\n\n\\subsection*{Solution}\n\nWe use the fact that $f(x)$ is a twice-differentiable continuous function for any $x\\in \\mathbb{R}^2$.\nLet $H_f$ be defined as Hessian matrix of the function $f$.\nWe use the theorem that function $f$ is convex, if and only if, $H_f(x)$ is positive semidefinite for all $x\\in \\mathbb{R}^2$, and $f$ is concave if and only if $H_f$ is negative semidefinite for all $x\\in \\mathbb{R}^2$.\nTherefore, objective would be to obtain $H_f$ and verify whether it's positive semidefinite or negative semidefinite or neither.\n\nBy definition, $H_f$ can be obtained using second partial derivatives of $f(x)$ as shown in Eq. \\ref{eq32}.\n\n\\begin{equation}\nH_f(\\mathbf{x})\n= \\begin{pmatrix}\n\\frac{\\partial^2 f}{\\partial^2 x_1} & \\frac{\\partial^2 f}{\\partial x_1 \\partial x_2}\\\\[0.6em]\n\\frac{\\partial^2 f}{\\partial x_2 \\partial x_1} & \\frac{\\partial^2 f}{\\partial^2 x_2}\\\\\n\\end{pmatrix}\n\\label{eq32}\n\\end{equation}\n\nUsing Eq. \\ref{eq31}, partial derivatives of $H_f$ are obtained as given in Eq. \\ref{eq33} and Eq. \\ref{eq34}.\n\n\\begin{equation}\n\\frac{\\partial f}{\\partial x_1} = 2x_1 + 2x_2 - 10\n\\label{eq33}\n\\end{equation}\n\\begin{equation}\n\\frac{\\partial f}{\\partial x_2} = 2x_1 + 5\n\\label{eq34}\n\\end{equation}\n\nSubstituting Eq. \\ref{eq33} and Eq. \\ref{eq34} into Eq. \\ref{eq32},\n\n\\begin{equation}\nH_f(\\mathbf{x}) = \\begin{pmatrix}2 & 2\\\\2 & 0\\\\\\end{pmatrix}\n\\end{equation}\n\nFor $H_f(\\mathbf{x})$ to be positive semidefinite, eigenvalues of $H_f$ must be non-negative.\nSimilarly, for $H_f(\\mathbf{x})$ to be negative semidefinite, eigenvalues of $H_f$ must be non-positive.\nTo obtain Eigenvalues of $H_f$, characteristic polynomial of $H_f$ is constructed as shown in Eq. \\ref{eq35}.\n\n\\begin{equation}\nA-\\lambda I = \\begin{pmatrix}2-\\lambda & 2\\\\ 2 & -\\lambda\\\\\\end{pmatrix}\\Rightarrow \\text{det}(A-\\lambda I) = (\\lambda - 1)^2 -5\n\\label{eq35}\n\\end{equation}\n\nAs eigenvalues are solutions to Eq. \\ref{eq35}, $H_f$ will have two eigenvalues $1+\\sqrt{5} > 0$ and $1-\\sqrt{5} < 0$.\nTherefore, $H_f$ is neither positive semidefinite nor negative semidefinite.\nHence, function $f$ is neither convex nor concave.\n", "meta": {"hexsha": "f1e7ab41b1819c3e619456dea46a41fe2463860a", "size": 2685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/hw03/hw03q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 40.6818181818, "max_line_length": 220, "alphanum_fraction": 0.6752327747, "num_tokens": 912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632234212403, "lm_q2_score": 0.920789673173896, "lm_q1q2_score": 0.876465826400295}} {"text": "\\subsection{The optimisation problem}\n\nSuppose all training samples $\\z\\train_t$ are gathered and divided over two data matrices $\\Sm \\in \\reals^{C \\cross N_S}$ and $\\Nm \\in \\reals^{C \\cross N_N}$, where $\\Sm$ (for `signal') contains all $N_S$ samples of $\\z\\train_t$ where an SWR is present, and $\\Nm$ (for `noise') contains all $N_N$ other samples. (These matrices can be easily constructed by concatenating segments from $\\z\\train_t$).\n\n\\Cref{eq:linear} then becomes, in vector notation:\n%\n\\begin{align*}\n\\out_S &= \\w^T \\Sm \\\\\n\\out_N &= \\w^T \\Nm,\n\\end{align*}\nwhere each element of the row vectors $\\out_S$ and $\\out_N$ is a filtered sample of $\\Sm$ and $\\Nm$, respectively. \\Cref{fig:GEVec_principle} (right) shows the distribution of the values in two example data vectors $\\out_S$ and $\\out_N$.\n\nWe want to find the weight vector $\\what$ that maximises the variance of $\\out_S$ versus the variance of $\\out_N$, i.e.\n%\n\\begin{align}\n\\what &= \\argmax_{\\w} \\frac{\\Var(\\out_S)}\n {\\Var(\\out_N)} \\label{eq:argmax_SNR} \\\\[1em]\n &= \\argmax_{\\w} \n \\frac{\\frac{1}{N_S} \\out_S \\out_S^T}\n {\\frac{1}{N_N} \\out_N \\out_N^T} \\nonumber \\\\[1em]\n &= \\argmax_{\\w}\n \\frac{\\frac{1}{N_S} \\w^T \\Sm \\Sm^T \\w}\n {\\frac{1}{N_N} \\w^T \\Nm \\Nm^T \\w} \\nonumber\n\\end{align}\n\nIn this last equation, we recognize the empirical covariance matrices $\\Rss$ and $\\Rnn$, which are defined as:\n%\n\\begin{align}\n\\Rss &= \\frac{1}{N_S} \\Sm \\Sm^T \\label{eq:covariance_S}\\\\\n\\Rnn &= \\frac{1}{N_N} \\Nm \\Nm^T \\label{eq:covariance_N}\n\\end{align}\n%\n$\\Rss \\in \\reals^{C \\cross C}$ and $\\Rnn \\in \\reals^{C \\cross C}$ are symmetric matrices, where each diagonal element yields the variance of a channel, and each off-diagonal element yields the covariance between a pair of channels.\n\nThe condition for the optimal weight vector, \\cref{eq:argmax_SNR}, is thus equivalent to:\n%\n\\begin{equation}\n\\label{eq:argmax_R}\n\\what = \\argmax_{\\w} \\frac{\\w^T \\Rss \\w}\n {\\w^T \\Rnn \\w}\n\\end{equation}\n%\nIn \\cref{apx:GEvecs-maximise-SNR}, we show that the solution $\\what$ to this optimisation problem is the first so called ``generalized eigenvector'' of $(\\Rss, \\Rnn)$.\n", "meta": {"hexsha": "4d82011e47829bcf324b37b5246f2c716369fa5f", "size": 2214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/GEVec/The-optimisation-problem.tex", "max_stars_repo_name": "tfiers/master-thesis", "max_stars_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T01:39:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T01:39:24.000Z", "max_issues_repo_path": "modules/GEVec/The-optimisation-problem.tex", "max_issues_repo_name": "tfiers/master-thesis", "max_issues_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-10T22:37:35.000Z", "max_forks_repo_path": "modules/GEVec/The-optimisation-problem.tex", "max_forks_repo_name": "tfiers/master-thesis", "max_forks_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3181818182, "max_line_length": 399, "alphanum_fraction": 0.6549232159, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731126558705, "lm_q2_score": 0.909907001151883, "lm_q1q2_score": 0.875943005026252}} {"text": "\\section{Higher-Order Taylor Method}\n\\begin{defn}[Local Truncation Error]\nThe difference method\n\\begin{equation*}\n \\begin{cases}\n \\omega_0=\\alpha & \\\\\n \\omega_{i+1}=\\omega_i+h\\phi(t_i+\\omega_i) & \\text{for each $i=0,1,\\cdots,N-1$}\n \\end{cases}\n\\end{equation*}\nhas local truncation error\n\\begin{equation*}\n \\tau_{i+1}(x)=\\frac{y_{i+1}-\\left(y_i+h\\phi(t_i+y_i)\\right)}{h}=\\frac{y_{i+1}-y_i}{h}-\\phi(t_i,y_i)\n\\end{equation*}\nfor each $i=0,1,\\cdots,N-1$ where $y_i$ and $y_{i+1}$ denote the accuracy at a specific step, assuming that the method was exact at the previous step.\n\\end{defn}\nEuler's method has $\\tau_{i+1}=\\frac{h}{2}y''(\\xi_i)$, so the local truncation error in Euler's method is $O(h)$ .\n\\subsection{Taylor Method of Order $n$}\n\\begin{equation*}\n \\begin{cases}\n \\omega_0=\\alpha & \\\\\n \\omega_{i+1}=\\omega_i+h\\phi(t_i+\\omega_i) & \\text{for each $i=0,1,\\cdots,N-1$}\n \\end{cases}\n\\end{equation*}\nwhere $T^{(n)}(t_i,\\omega_i)=f(t_i,\\omega_i)+\\frac{h}{2}f'(t_i,\\omega_i)+\\cdots+\\frac{h^{n-1}}{n!}f^{(n-1)}(t_i,\\omega_i)$.\n\\begin{theo}\nIf Taylor's method of order $n$ is used to approximate the solution to\n\\[\n\\frac{\\D y}{\\D t}=f(t,y),\\quad a\\leq t\\leq b,\\quad y(a)=\\alpha\n\\]\nwith step size $h$ and if $y\\in C^{n+1}[a,b]$, then the local truncation error is $O(h^n)$.\n\\end{theo}\n\\begin{proof}\n\\begin{align*}\n y_{i+1} &= y_i+hf(t_i,y_i)+\\cdots+\\frac{h^n}{n!}f^{(n-1)}(t_i,y_i)+\\frac{h^{n+1}}{(n+1)!}f^{(n)}(\\xi_i,y(\\xi_i)) \\\\\n \\Rightarrow & \\tau_{i+1}(h) = \\frac{y_{i+1}-y_i}{h}-T^{(n)}(t_i,y_i)=\\frac{h^n}{(n+1)!}f^{(n)}(\\xi_i,y(\\xi_i))\n\\end{align*}\nfor each $i=0,1,\\cdots,N-1$. Since $y\\in C^{n+1}[a,b]$, we have $y^{(n+1)}(t)=f^{(n)}(t,y(t))$ bounded on $[a,b]$ and $\\tau_i(h)=O(h^n)$ for each $i=1,2,\\cdots,N$.\n\\end{proof}", "meta": {"hexsha": "9c1eb99134178514138167f72c6dd5dda60833ff", "size": 1748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/5.3_Higher-order_taylor_method.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/5.3_Higher-order_taylor_method.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/5.3_Higher-order_taylor_method.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.0, "max_line_length": 163, "alphanum_fraction": 0.6184210526, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.9230391706552538, "lm_q1q2_score": 0.8758878048330533}} {"text": "\n\\subsection{Green's theorem}\nGreen's theorem tells us that\n\n$$\\oint P\\,dx+Q\\,dy=\\int\\!\\!\\!\\int\n\\left({\\partial Q\\over\\partial x}-{\\partial P\\over\\partial y}\\right)\ndx\\,dy$$\n\nIn other words, a line integral and a surface integral can yield\nthe same result.\n\nExample 1.\nThe following exercise is from {\\it Advanced Calculus}\nby Wilfred Kaplan, p.~287.\nEvaluate $\\oint (2x^3-y^3)\\,dx+(x^3+y^3)\\,dy$ around the circle\n$x^2+y^2=1$ using Green's theorem.\n\nIt turns out that Eigenmath cannot solve the double integral over\n$x$ and $y$ directly.\nPolar coordinates are used instead.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nP = 2x^3-y^3\nQ = x^3+y^3\nf = d(Q,x)-d(P,y)\nx = r*cos(theta)\ny = r*sin(theta)\ndefint(f*r,r,0,1,theta,0,2pi)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{3}{2}\\pi$\n\nThe $defint$ integrand is $f{*}r$ because $r\\,dr\\,d\\theta=dx\\,dy$.\n\nNow let us try computing the line integral side of Green's theorem\nand see if we get the same result.\nWe need to use the trick of converting sine and cosine to exponentials\nso that Eigenmath can find a solution.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = cos(t)\ny = sin(t)\nP = 2x^3-y^3\nQ = x^3+y^3\nf = P*d(x,t)+Q*d(y,t)\nf = circexp(f)\ndefint(f,t,0,2pi)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{3}{2}\\pi$\n\nExample 2.\nCompute both sides of Green's theorem for\n$F=(1-y,x)$ over the disk $x^2+y^2\\le4$.\n\nFirst compute the line integral along the boundary of the disk.\nNote that the radius of the disk is 2.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Line integral\nP = 1-y\nQ = x\nx = 2*cos(t)\ny = 2*sin(t)\ndefint(P*d(x,t)+Q*d(y,t),t,0,2pi)\n\\end{Verbatim}\n\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Surface integral\nx = quote(x) --clear x\ny = quote(y) --clear y\nh = sqrt(4-x^2)\ndefint(d(Q,x)-d(P,y),y,-h,h,x,-2,2)\n\\end{Verbatim}\n\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Try computing the surface integral using polar coordinates.\nf = d(Q,x)-d(P,y) --do before change of coordinates\nx = r*cos(theta)\ny = r*sin(theta)\ndefint(f*r,r,0,2,theta,0,2pi)\n\\end{Verbatim}\n\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ndefint(f*r,theta,0,2pi,r,0,2) --try integrating over theta first\n\\end{Verbatim}\n\n$\\displaystyle 8\\pi$\n\nIn this case, Eigenmath solved both forms of the polar integral.\nHowever, in cases where Eigenmath fails to solve a double integral, try\nchanging the order of integration.\n", "meta": {"hexsha": "7ab51bd08036c510a7058439b82c35c7b4b7e26f", "size": 2468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/greens-theorem.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/greens-theorem.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/greens-theorem.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9292929293, "max_line_length": 71, "alphanum_fraction": 0.7005672609, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.9273632916317103, "lm_q1q2_score": 0.8755949611765843}} {"text": "\n\\subsection{Conditional probability}\n\nWe define conditional probability\n\n\\(P(E_i|E_j):=\\dfrac{P(E_i\\land E_j)}{P(E_j)}\\)\n\nWe can show this is between \\(0\\) and \\(1\\).\n\n\\(P(E_j)=P(E_i\\land E_j)+P(\\bar{E_i}\\land E_j)\\)\n\n\\(P(E_i|E_j):=\\dfrac{P(E_i\\land E_j)}{ P(E_i\\land E_j)+P(\\bar{E_i}\\land E_j)}\\)\n\nWe know:\n\n\\(P(x_i|y_j):=\\dfrac{P(x_i \\land y_j)}{P(y_j)}\\)\n\n\\(P(y_j|x_i):=\\dfrac{P(x_i \\land y_j)}{P(x_i)}\\)\n\nSo:\n\n\\(P(x_i|y_j)P(y_j)=P(y_j|x_i) P(x_i)\\)\n\n\\(P(x_i|y_j)=\\dfrac{P(y_j|x_i) P(x_i)}{P(y_j)}\\)\n\nNote that this is undefined when \\(P(y_j)=0\\)\n\nNote that for the same event, \n\n\\(P(x_i|x_j)=\\dfrac{P(x_i\\land x_j)}{P(x_j)}\\)\n\n\\(P(x_i|x_j)=0\\)\n\nFor the same outcome:\n\n\\(P(x_i|x_i)=\\dfrac{P(x_i\\land x_i)}{P(x_i)}\\)\n\n\\(P(x_i|x_i)=\\dfrac{P(x_i)}{P(x_i)}\\)\n\n\\(P(x_i|x_i)=1\\)\n\n\\subsection{Bayes' theorem}\n\nFrom the definition of conditional probability we know that:\n\n\\(P(E_i|E_j):=\\dfrac{P(E_i\\land E_j)}{P(E_j)}\\)\n\n\\(P(E_j|E_i):=\\dfrac{P(E_i\\land E_j)}{P(E_i)}\\)\n\nSo:\n\n\\(P(E_i\\land E_j)=P(E_i|E_j)P(E_j)\\)\n\n\\(P(E_i\\land E_j)=P(E_j|E_i)P(E_i)\\)\n\nSo:\n\n\\(P(E_i|E_j)P(E_j)=P(E_j|E_i)P(E_i)\\)\n\n\\subsection{Independent variables}\n\nEvents are independent if:\n\n\\(P(E_i|E_j)=P(E_i)\\)\n\nNote that:\n\n\\(P(E_i\\land E_j)=P(E_i|E_j)P(E_j)\\)\n\nAnd so for independent events:\n\n\\(P(E_i\\land E_j)=P(E_i)P(E_j)\\)\n\n\\subsection{Conjugate priors}\n\nIf the prior \\(P(\\theta)\\) and the posterior \\(P(\\theta | X)\\) are in the same family of distributions (eg both Gaussian), then the prior and posterior are conjugate distributions\n\n", "meta": {"hexsha": "8908755db17b949f55583b0bf433a664d44667a5", "size": 1507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityBayes/01-04-otherBayes.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityBayes/01-04-otherBayes.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityBayes/01-04-otherBayes.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3205128205, "max_line_length": 179, "alphanum_fraction": 0.6363636364, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9706877684006775, "lm_q2_score": 0.9019206824612296, "lm_q1q2_score": 0.875483374532707}} {"text": "\\chapter{Elements of Probability}\n\\label{Appendix_A}\n\\section{Basic Definitions}\n\t\\begin{definition}\n\t\tA probability measure $\\mathbb{P}$ on a measurable space $(\\Omega, \\mathcal{F})$ is a function from $\\mathcal{F}$ to $[0, 1]$ such that\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item\n\t\t\t\t$\\mathbb{P} (\\emptyset) = 0$, and $\\mathbb{P} (\\Omega) = 1$.\n\t\t\t\t\\item \n\t\t\t\tIf $\\{ A_n \\}_{n \\geq 1} \\in \\mathcal{F}$ and $A_i \\cap A_j \\neq \\emptyset$ if $i \\neq j$, then $\\mathbb{P} (\\cup^{\\infty}_{n=1} A_n) = \\sum^{\\infty}_{n = 1} \\mathbb{P} (A_n)$.\n\t\t\t\\end{itemize}\t\n\t\\end{definition}\n\t\n\t\\noindent A $\\sigma$-algebra on a set $X$ is a collection of subsets of $X$ that includes the empty subset and is closed under complement and under countable unions. Denote $\\sigma (D) = \\cap \\{ H : H \\text{ is a } \\sigma \\text{-algebra of } \\Omega, D \\subseteq H \\}$. We call $\\sigma (D)$ a $\\sigma$-algebra generated by $D$.\n\t\n\t\\begin{definition}\n\t\tA triple $(\\Omega, \\mathcal{F}, \\mathbb{P})$ is called a probability space if\n\t\t\\begin{itemize}\n\t\t\t\\item\n\t\t\t$\\Omega$ is a sample space which is a collection of all samples.\n\t\t\t\\item \n\t\t\t$\\mathcal{F}$ is a $\\sigma$-algebra on $\\Omega$.\n\t\t\t\\item\n\t\t\t$\\mathbb{P}$ is a probability measure on $(\\Omega, \\mathcal{F})$. \n\t\t\\end{itemize}\t\n\t\\end{definition}\n\n\t\\noindent On a given probability space $(\\Omega, \\mathcal{F}, \\mathbb{P}) (\\Omega = \\mathbb{R})$, if a cumulative distribution function of a random variable $X$ is normal, i.e.,\n\t\\begin{align}\n\t\t\\mathbb{P} (X < x) = \\displaystyle \\int_{-\\infty}^{x} \\frac{1}{ \\sigma \\sqrt{2 \\pi} } e^{-\\frac{(y - \\mu)^2}{2 \\sigma^2}} dy, \\hspace{2mm} \\sigma > 0,\n\t\\end{align}\n\tthen the random variable $X$ is called a Gaussian (normal) random variable on the probability space $(\\Omega, \\mathcal{F}, \\mathbb{P})$. Here $X$ is completely characterized by its mean $\\mu$ and its standard deviation $\\sigma$. We denote $X \\sim \\mathcal{N} (\\mu, \\sigma^2)$. The probability density function of $X$ is\n\t\\begin{align*}\n\t\tp(x) = \\frac{1}{\\sigma \\sqrt{2 \\pi}} e^{-\\frac{(x - \\mu)^2}{2 \\sigma^2}}.\n\t\\end{align*}\n\n\t\\noindent When $\\mu = 0$ and $\\sigma = 1$, we call $X$ a standard Gaussian (normal) random variable.\n\t\n\t\\begin{definition}\n\t\tA probability space $(\\Omega, \\mathcal{F}, \\mathbb{P})$ is said to be a complete probability space if for all $B ∈\\in \\mathcal{F}$ with $\\mathbb{P} (B) = 0$ and all $A \\subseteq B$ one has $A \\in \\mathcal{F}$.\n\t\\end{definition}\n\t\n\t\\begin{definition}\n\t\tIf $(\\Omega, \\mathcal{F}, \\mathbb{P})$ is a given probability space then a function $Y : \\Omega \\rightarrow \\mathbb{R}^n$ is called $\\mathcal{F}$-measurable if $Y^{-1} (U) = \\{ w \\in \\Omega : Y(w) \\in U \\} \\in \\mathcal{F}$ holds for all open sets $U \\in \\mathbb{R}^n$. If $X : \\Omega \\rightarrow \\mathbb{R}^n$ is a function, then $\\sigma (X)$ is the smallest $\\sigma$-algebra on $\\Omega$ containing all the sets $X^{-1} (U)$ for all open sets $U$ in $\\mathbb{R}^n$.\n\t\\end{definition}\n\t\n\t\\begin{definition}\n\t\tSuppose that $(\\Omega, \\mathcal{F}, \\mathbb{P})$ is a given complete probability space. A random variable $X$ is an $\\mathcal{F}$-measurable function $X : \\Omega \\rightarrow \\mathbb{R}^n$.\n\t\\end{definition}\n\t\n\t\\noindent Its well known that every random variable induces a probability measure $\\mu_X$ (distribution of $X$) on $\\mathbb{R}_n$ given by\n\t\\begin{align*}\n\t\t\\mu_X (B) = \\mathbb{P} (X^{-1} (B)).\n\t\\end{align*}\n\tIf $ \\int_{\\Omega} | X(w) | d \\mathbb{P} (w) < \\infty$, the expectation of $X$ w.r.t. $\\mathbb{P}$ is defined by\n\t\\begin{align*}\n\t\t\\mathbb{E} [X] = \\int_{\\Omega} X(w) d \\mathbb{P} (w) = \\int_{\\mathbb{R}^n} x d \\mu_X (x).\n\t\\end{align*} \n\tAlso the $p$-th moment of $X$ is defined as (if the integrals are well defined)\n\t\\begin{align*}\n\t\t\\mathbb{E} [X^p] = \\int_{\\Omega} X^p d \\mathbb{P} (w) = \\int_{\\mathbb{R}^n} x^p d \\mu_X (x).\n\t\\end{align*}\n\tThe centered moments are defined by $\\mathbb{E} \\left[ |X - \\mathbb{E}[X]| \\right]$, $p = 1, 2, \\dots, $. When\n\t$p = 2$, the centered moment is also called the variance. \\\\\n\t\n\t\\begin{definition}\n\t\tLet $(\\Omega, \\mathcal{F}, \\mathbb{P})$ be a probability space and let $T \\subseteq \\mathbb{R}$ be\n\t\ttime. A collection of random variables $X_t$ , $t \\in T$ with values in $\\mathbb{R}$ is called a\n\t\tstochastic process. If time is an interval, $\\mathbb{R}^+$ or $\\mathbb{R}$, it is called a stochastic process with continuous time. For any fixed $w \\in \\Omega$, one can regard $X_t (w)$ as a function of\n\t\t$t$ (called a sample function of the stochastic process).\n\t\\end{definition}\n\n\t\\noindent On a probability space $(\\Omega, \\mathcal{F}, \\mathbb{P})$, a filtration refers to an increasing sequence of $\\sigma$-algebras:\n\t\\begin{align*}\n\t\t\\mathcal{F}_0 \\subseteq \\mathcal{F}_1 \\subseteq \\mathcal{F}_2 \\subseteq \\cdots \\subseteq \\mathcal{F}_n \\subseteq \\cdots .\n\t\\end{align*}\n\t\n\t\\noindent A natural filtration (w.r.t. $X$) is the smallest $\\sigma$-algebra that contains\n\tinformation of $X$. It is generated by $X$ and $\\mathcal{F}^X_n = \\sigma(X_1, \\dots, X_n)$ with $\\mathcal{F}^X_0 = \\{\\emptyset, \\Omega \\}$. If $\\lim_{n \\rightarrow \\infty} \\mathcal{F}_n \\subseteq \\mathcal{F}$, then we call $(\\Omega, \\mathcal{F}, \\{ \\mathcal{F}_n \\}_{n \\geq 1}, \\mathbb{P})$ a filtered probability space. A stochastic process $\\{X_n \\}$ on a filtered probability space is an adapted process if $X_n$ is $\\mathcal{F}_n$-measurable for each $n$.\n\t\n\t\\begin{definition}\n\t\tA family of sub-$\\sigma$-algebras $\\mathcal{F}_t \\subseteq \\mathcal{F}$ indexed by $t \\in [0, \\infty)$ is called a filtration if it is increasing $\\mathcal{F}_s \\subseteq \\mathcal{F}_t$ when $0 \\leq s \\leq t < \\infty$.\n\t\\end{definition}\n\t\n\t\\begin{definition} \n\t\tA collection of random variables is called a Gaussian process, if the joint distribution of any finite number of its members is Gaussian. In other words, a Gaussian process is a $\\mathbb{R}^d$-valued stochastic process with continuous time (or with index) $t$ such that $\\left(X(t_0), X(t_1), \\dots, X(t_n) \\right)^T$ is a $(n+1)$-dimensional Gaussian random vector\n\t\tfor any $0 \\leq t_0 < t_1 < \\cdots < t_n$. The Gaussian process is denoted as $X = \\{X(t)\\}_{t \\in I}$ where $I$ is a set of indexes.\n\t\\end{definition}\n\t\n\t\\begin{definition}\n\t\t\\label{brownian_motion}\n\t\t A continuous time stochastic process $W(t)$ is called a standard Brownian motion if\n\t\t\\begin{itemize}\n\t\t\t\\item\n\t\t\t$W(t)$ is almost surely continuous in $t$, and $W(0) = 0$. \n\t\t\t\\item\n\t\t\t$W(t)$ has independent increments $W(t_{i+1}) - W(t_i)$ for all $t_n \\geq 0$, $i = 0, 1, \\dots, n$.\n\t\t\t\\item\n\t\t\t$W(t) - W(s) \\sim \\mathcal{N} (0, t-s)$, i.e., obeys the normal distribution with mean zero and variance $t - s$.\n\t\t\\end{itemize}\t\n\t\\end{definition}\n\n\t\\noindent Set $x \\in D \\subset \\mathbb{R}^d$, we define infinite dimensional Gaussian processes as follows\n\t\\begin{align*}\n\t\tW^Q (x, t) = \\displaystyle \\sum^{\\infty}_{j = 1} \\sqrt{q_j} e_j (x) W_j (t),\n\t\\end{align*}\n\twhere $W_j (t)$ are mutually independent Brownian motions. Here $q_j \\geq 0$, $j \\in \\mathbb{N}^d$ and $\\{ e_j (x) \\}$ is an orthonormal basis in $L^2 (D)$. The following expansion is usually considered in literature:\n\t\\begin{align*}\n\t\t\\dot{W}^Q (x, t) = \\displaystyle \\sum^{\\infty}_{j = 1} \\sqrt{q_j} e_j (x) \\dot{W}_j (t).\n\t\\end{align*}\n\twhere $\\dot{W}_j (t) =\\frac{d}{dt} W$, is formally the first-order derivative of $W_j (t)$ in time. When $q_j = 1$ for all $j$, we have a space-time white noise, and if $\\sum^{\\infty}_{j = 1} \\sqrt{q_j}$ is called a $Q$-Wiener process. \\\\\n\n\t\\noindent The Brownian motion and white noise can also be defined in terms of orthogonal expansions. Suppose that $\\{e_j (t)\\}_{j \\geq 1}$ is a complete orthonormal system in $L^2 ([0, T ])$, then the Brownian motion $W(t)$ can be defined by\n\t\\begin{align}\n\t W(t) = \\displaystyle \\sum_{j=1}^{\\infty} \\beta_j \\int_{0}^{t} e_j (s) ds, \\hspace{2mm} t \\in [0, T],\n\t\\end{align}\n\twhere $\\beta_j$ are mutually independent standard Gaussian random variables for each $j$, and it can be also checked that is indeed a standard Brownian motion. Correspondingly, the white noise is defined by\n\t\\begin{align}\n\t \\dot{W}(t) = \\displaystyle \\sum_{j=1}^{\\infty} \\beta_j e_j (t), \\hspace{2mm} t \\in [0, T].\n \\end{align}\n\n\t\\begin{definition}\n\t\t\\label{cylindrical}\n\t\tLet $\\{e_j\\}_{j \\geq 1}$ be a complete orthonormal system of a separable Hilbert space $\\mathcal{H}$, and $T \\in \\mathbb{R}^+$, and $\\{\\beta_j (t)\\}_{j \\geq 1}$ be an independent and identically distributed sequence of Brownian Motions. Then a cylindrical Wiener process $W$ in $\\mathcal{H}$ is given by\n\t\t\\begin{align*}\n\t\t\tW(t) = \\displaystyle \\sum_{j=1}^{\\infty} \\beta_j e_j (t)\n\t\t\\end{align*}\t\n\t\\end{definition}\n\t\n\t\\section{Some Important Results in Probability Spaces}\n\t\n\t\n\tIt is well known that the Hermite Polynomials $\\{P_k (\\dot) \\}_{k \\in \\mathbb{N}}$ with $P_0 = 1$ is a complete orthonormal system for $L_2 (\\mathbb{R}, \\mu_1 (dx))$ with $\\mu_1 (dx) = \\frac{1}{\\sqrt{2 \\ pi}} e^{- \\frac{x^2}{2}} dx$, which are defined by \n\t\\begin{align}\n\t\t\\label{hermite_polynomials}\n\t\tP_k(x) = \\frac{(-1)^k}{(k!)^{1/2}} e^{\\frac{x^2}{2}} \\frac{d^k}{dx^k} e^{-\\frac{x^2}{2}}, \\hspace{3mm} x \\in \\mathbb{R}\n\t\\end{align}\n\t\n\t\n\tA functional $\\Phi: \\mathcal{H} \\longrightarrow \\mathbb{R}$, is said to be a smooth simple functional (or a cylinder functional) if there exists a $C^{\\infty} $-function $\\varphi$ on $\\mathbb{R}^n$ and $n$-continuous linear functional $l_1 ,\\cdots ,l_n$ on $\\mathcal{H}$ such that for $h \\in \\mathcal{H}$\n\t\\begin{align*}\n\t\t\\Phi(h) = \\phi(h_1, \\cdots, h_n) \\hspace{2mm} \\text{where} \\hspace{2mm} h_i = l_i (h), \\hspace{2mm} i = 1, \\cdots, n.\n\t\\end{align*}\n\t\n\tLet $\\mathbb{H} = L_2 (\\mathcal{H}, \\mu)$ denote the Hilbert space of Borel measurable functionals on the probability space with inner product\n\t\\begin{align}\n\t\t\\label{Inner_Functionals}\t\n\t\t\\langle \\Phi, \\Psi \\rangle_{\\mathbb{H}} = \\displaystyle \\int_{\\mathcal{H}} \\Phi (v) \\Psi (v) \\mu (dx), \\hspace{2mm} \\Phi, \\Psi \\in \\mathbb{H},\n\t\\end{align}\n\tand the norm $\\| \\Phi \\|_{\\mathbb{H}} = \\langle \\Phi, \\Phi\\rangle_{\\mathbb{H}}^{1/2}$. In $\\mathcal{H}$ we choose a basis system $\\{\\varphi_k \\}$ such that $\\varphi_k \\in \\mathcal{H}$.\\\\\t\n\t\n\tLet $\\Lambda$ an operator such that $Tr < +\\infty$. We will denote as $\\mathcal{H}_0$ the Hilbert subspace of $\\mathcal{H}$ with inner product $\\langle g, h \\rangle_0 = \\langle \\Lambda^{1/2} g, \\Lambda^{1/2} h \\rangle_{\\mathcal{H}}$ for $g, h \\in \\Lambda^{1/2} \\mathcal{H}$, which is the completion of $\\Lambda^{1/2} \\mathcal{H}$ with respect to the norm $\\| g \\|_0 = \\langle g, g \\rangle^{1/2}$, and also is dense in $\\mathcal{H}$. Then, by using the above can be defined The Hermite functional as follows\n\t\\begin{align}\n\t\\label{hermite_funcionals}\n\t\tH_n(h) = \\prod_{i=1}^{\\infty} P_{n_i} (l_i (h)), h \\in \\mathcal{H}_0 , n \\in J\n\t\\end{align}\n\twith\n\t\\begin{equation*}\n\t\tl_i (h) = \\left\\langle h, \\Lambda^{-1/2} \\varphi_i \\right\\rangle_{\\mathcal{H}}, \\hspace{3mm} i = 1,2 \\cdots\n\t\\end{equation*}\n\tand the set $\\mathcal{J}$ is given by\n\t\\begin{align}\n\t\\label{Conjunto_J}\t\n\t\t\\mathcal{J} = \\{\\alpha = (\\alpha_i,i \\geq 1) | \\alpha_i \\in \\mathbb{N}\\cup {0}, |\\alpha|:= \\displaystyle \\sum _{i = 0}^{\\infty}\\alpha_i < \\infty\\}\n\t\\end{align}\n\t\n\n\t\\begin{lemma}\n\t\\label{dense}\t\n\t\tFor $h \\in \\mathcal{H}$ let $l_i (h) = (h, \\Lambda^{-1/2} \\varphi_i )_{\\mathcal{H}}$, $i=1, 2, \\cdots$. Then the set $\\{H_n \\}$ of all Hermite polynomials on $\\mathcal{H}$ forms a complete orthonormal system for $\\mathbb{H}$. Hence the set of all functionals are dense in $\\mathbb{H}$. Moreover, we have the direct sum decomposition:\n\t\t\\begin{align*}\n\t\t\\mathbb{H} = \\displaystyle \\bigoplus^{\\infty}_{j=0} K_j,\n\t\t\\end{align*}\n\t\twhere $K_j$ is the subspace of $\\mathbb{H}$ spanned by $\\{H_n : |n| = j \\}$. This result can be found in \\cite{DAPRATO1994}.\n\t\\end{lemma}\n\n\n\t\\begin{lemma}\n\t\t\\label{eigen}\n\t\tLet $H_n (h)$ be a Hermite polynomial functional given by (\\ref{hermite_funcionals}), and suppose that the operator $-A$ have eigenfunctions $e_k$ with eigenvalues $\\lambda_k$. Then the operator given in (\\ref{operator_L}) satisfies the following\n\t\t\\begin{align}\n\t\t\t\\label{eigen_lambda_kolmo}\n\t\t\t\\mathcal{L} H_n (h) = - \\lambda_n H_n (h)\n\t\t\\end{align}\n\t\tfor any $n \\in \\mathcal{J}$ and $H_n \\in \\mathcal{H}$, where\n\t\t\\begin{align*}\n\t\t\t\\lambda_n = \\displaystyle \\sum_{k=1}^{\\infty} n_k \\lambda_k\n\t\t\\end{align*}\n\t\\end{lemma}", "meta": {"hexsha": "fff1c9c12fc5352a86d61c7e7756e5cbb676d3f0", "size": 12299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/appendix/Appendix.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/appendix/Appendix.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/appendix/Appendix.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 65.0740740741, "max_line_length": 507, "alphanum_fraction": 0.653549069, "num_tokens": 4555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551556203814, "lm_q2_score": 0.907312213841788, "lm_q1q2_score": 0.8754248672825911}} {"text": "\n\\subsection{Surface area}\nLet $S$ be a surface parameterized by $x$ and $y$.\nThat is, let $S=(x,y,z)$ where $z=f(x,y)$.\nThe tangent lines at a point on $S$ form a tiny parallelogram.\nThe area $a$ of the parallelogram is given by the magnitude of the cross product.\n$$a=\\left|{\\partial S\\over\\partial x}\\times{\\partial S\\over\\partial y}\\right|$$\nBy summing over all the parallelograms we obtain the total surface area $A$.\nHence\n$$A=\\int\\!\\!\\!\\int dA=\\int\\!\\!\\!\\int a\\,dx\\,dy$$\nThe following example computes the surface area of a unit disk\nparallel to the $xy$ plane.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nz = 2\nS = (x,y,z)\na = abs(cross(d(S,x),d(S,y)))\ndefint(a,y,-sqrt(1-x^2),sqrt(1-x^2),x,-1,1)\n\\end{Verbatim}\n\n$\\displaystyle \\pi$\n\nThe result is $\\pi$, the area of a unit circle, which is what we expect.\nThe following example computes the surface area of $z=x^2+2y$ over\na unit square.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nz = x^2+2y\nS = (x,y,z)\na = abs(cross(d(S,x),d(S,y)))\ndefint(a,x,0,1,y,0,1)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{3}{2}+\\frac{5}{8}\\log(5)$\n\nThe following exercise is from\n{\\it Multivariable Mathematics} by Williamson and Trotter, p. 598.\nFind the area of the spiral ramp defined by\n$$S=\\begin{bmatrix}u\\cos v\\\\\\ u\\sin v\\\\ v\\end{bmatrix},\\qquad 0\\le u\\le1,\\qquad 0\\le v\\le3\\pi$$\n%The coordinates $x$, $y$ and $z$ are\n%functions of the parameter space $(u,v)$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = u*cos(v)\ny = u*sin(v)\nz = v\nS = (x,y,z)\na = abs(cross(d(S,u),d(S,v)))\ndefint(a,u,0,1,v,0,3pi)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{3}{2}\\pi\\log(1+2^{1/2})+\\frac{3\\pi}{2^{1/2}}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfloat\n\\end{Verbatim}\n\n$\\displaystyle 10.8177$\n", "meta": {"hexsha": "51d4bc722aa7a80d36dbe2a50115ab5eccc661df", "size": 1762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/surface-area.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/surface-area.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/surface-area.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8644067797, "max_line_length": 95, "alphanum_fraction": 0.6765039728, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611631680359, "lm_q2_score": 0.9111797106148062, "lm_q1q2_score": 0.8750616067411496}} {"text": "\n\\subsection{Matrix additon and multiplication}\n\n\\subsubsection{Matrix multiplication}\n\n\\(A=A^{mn}\\)\n\n\\(B=B^{no}\\)\n\n\\(C=C^{mo}=A.B\\)\n\n\\(c_{ij}=\\sum_{r=1}^na_{ir}b_{rj}\\)\n\nMatrix multiplication depends on the order. Unlike for real numbers, \n\n\\(AB\\ne BA\\)\n\nMatrix multiplication is not defined unless the condition above on dimensions is met.\n\nA matrix multiplied by the identity matrix returns the original matrix.\n\nFor matrix \\(M=M^{mn}\\)\n\n\\(M=MI^m=I^nM\\)\n\n\\subsubsection{Matrix addition}\n\n\\(2\\) matricies of the same size, that is with idental dimensions, can be added together.\n\nIf we have \\(2\\) matrices \\(A^{mn}\\) and \\(B^{mn}\\)\n\n\\(C=A+B\\)\n\n\\(c_{ij}=a_{ij}+b_{ij}\\)\n\nAn empty matrix with \\(0\\)s of the same size as the other matrix is the identity matrix for addition.\n\n\\subsubsection{Scalar multiplication}\n\nA matrix can be multiplied by a scalar. Every element in the matrix is multiplied by this.\n\n\\(B=cA\\)\n\n\\(b_{ij}=ca_{ij}\\)\n\nThe scalar \\(1\\) is the identity scalar.\n\n", "meta": {"hexsha": "4e263be28512876c0ef2c760627dc5bce49452a6", "size": 978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/04-03-linearOperations.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystems/04-03-linearOperations.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/04-03-linearOperations.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.375, "max_line_length": 101, "alphanum_fraction": 0.6963190184, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.964321450147636, "lm_q2_score": 0.9073122244934722, "lm_q1q2_score": 0.8749406400602225}} {"text": "\\subsection{Sampling from multi-variate normal distributions with arbitrary correlations}\n\nThe multi-variate distribution is given by:\n\n\\begin{equation}\np(\\bar{x}) = {1\\over{(2\\pi)^{k/2}{|\\tilde{C}|}^{1/2}}}\\,{\\exp{-{1\\over{2}}{(\\bar{x} - \\bar{\\mu})^T\\tilde{C}^{-1}{(\\bar{x} - \\bar{\\mu})}}}}\n\\end{equation}\n\nIf we write out the terms of the exponent $M \\equiv (\\bar{x} - \\bar{\\mu})^T\\tilde{C}^{-1}(\\bar{x} - \\bar{\\mu})$\nwe have:\n\n\\begin{equation}\nM = {x_k}^2 C_{kk} - 2x_k\\mu_kC_{kk} + 2\\sum_{i \\neq k}{x_k(x_i - \\mu_i)C_{ki}} + C_{kk}B_k\n\\end{equation}\n\nwhere $B_k/C_{kk}$ represents all terms that don't depend on $x_k$. If we rewrite this as:\n\n\\begin{eqnarray}\nM &=& C_{kk}{x_k}^2 + C_{kk}x_k\\left(2\\sum_{i \\neq k}{(x_i - \\mu_i)C_{ki}/C_{kk} - 2\\mu_k}\\right) + C_{kk}B_k\\\\\n &=& C_{kk}{x_k}^2 + C_{kk}x_kA_k + C_{kk}B_k\\\\\n &=& C_{kk}\\left({x_k}^2 + x_kA_k + A_k^2/4\\right) + C_{kk}\\left(B_k - A_k^2/4\\right) \\\\\n &=& C_{kk}\\left(x_k + A_k/2\\right)^2 + C_{kk}\\left(B_k - A_k^2/4\\right) \n\\end{eqnarray}\n\nwe see that if $\\mu_k^\\prime \\equiv -A_k/2$, the exponent can be written, up to a constant factor, as:\n\n\\begin{equation}\nM_k = C_{kk}\\left(x_k - \\mu_k^\\prime\\right)^2. \n\\end{equation}\n\nWe see then that up to a normalization, the conditional distribution for\n$x_k$, $p(x_k|\\{x_{i\\neq k}\\})$ is simply given by a univariate gaussian\nwith:\n\n\\begin{eqnarray}\n\\mu_k^\\prime &=& -A_k/2 \\\\\n\\sigma_k &=& 1/\\sqrt{C_{kk}}\n\\end{eqnarray}\n\nOur prescription for generating samples from the joint distribution is\nthen to Gibbs sample from the univariate conditional distributions,\nstarting from a random point, and iterating each time from the\nprevious point. The result is itself a Markov chain which\ncollectively represents an unbiased sample from the joint\ndistribution.\n\n", "meta": {"hexsha": "3912a0dfb37e04bed9de8d458684c467181b61f0", "size": 1770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/sampling.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/sampling.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/sampling.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 37.6595744681, "max_line_length": 138, "alphanum_fraction": 0.6672316384, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799462157138, "lm_q2_score": 0.9073122295060291, "lm_q1q2_score": 0.8744493317541802}} {"text": "\\subsection{Sets}\r\n\\begin{definition}\r\n\tA set $A$ is a collection of distinct elements. Those elements can be anything, like numbers, functions, and even other sets.\r\n\\end{definition}\r\nWe can define a set by giving its elements, like $A = \\{-2, 5, 3\\}$ or by describing its properties, like $A = \\{x \\mid x > 0\\}$ where the vertical bar means ``such that''.\r\nIf an object $x$ is a member of the set $A$, we write $x\\in A$.\\bigskip\r\n\r\n\r\n\\noindent\r\nA set $A$ is called a subset of a set $B$ if every element of $A$ is also an element of $B$. \r\nWe can write this as $A \\subseteq B$. \r\nFor example, $\\{7, 10, 16\\} \\subseteq \\{5, 6, 7, 9, 10, 11, 16\\}$. \r\nNote that this relation can be strict if there exists at least one element in $B$ that is not also an element of $A$. \r\nSome common sets and their informal definitions are given below:\r\n\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{c|c|c}\r\n\t\tSet Name & Symbol & Informal Definition \\\\ \\hline\r\n\t\tNatural numbers & $\\mathbb{N}$ & $\\{1, 2, 3, \\dots\\}$ \t\t\t\t\t\t \\\\\r\n\t\tIntegers & $\\mathbb{Z}$ & $\\{\\dots, -3, -2, -1, 0, 1, 2, 3, \\dots\\}$ \\\\\r\n\t\tRational numbers & $\\mathbb{Q}$ & $\\{\\frac{m}{n} \\mid m,n \\in\\mathbb{Z}$ and $n \\neq 0\\}$ \\\\\r\n\t\tReal numbers & $\\mathbb{R}$ & Any number on the number line\\footnote{Sadly, there is no way to give a stronger formal definition without higher mathematics.} \\\\\r\n\t\\end{tabular}\r\n\\end{table}\r\n\r\nThis means that $\\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q} \\subset \\mathbb{R}$.\\bigskip\r\n\r\n\r\n\\noindent\r\nThere are several common operations that can be performed on sets.\r\nThe union $A \\cup B$ of two sets $A$ and $B$ is the set of all elements that are elements of $A$ or of $B$. \r\nSimilarly, the intersection $A \\cap B$ of two sets $A$ and $B$ is the set of all elements that are also elements of both $A$ and $B$.\r\n\\begin{example}\r\n\tIf $A = \\{\\sqrt{2}, 2, 5, 8\\}$ and $B = \\{-9, 8, 2.3\\}$, what are $A \\cup B$ and $A \\cap B$?\t\t\r\n\\end{example}\r\n\\begin{answer}\r\n\tTo find the union, we combine the sets, making sure to include any repeated element only once:\r\n\t\\begin{equation*}\r\n\t\tA \\cup B = \\{-9, \\sqrt{2}, 2, 2.3, 5, 8\\}.\r\n\t\\end{equation*}\r\n\tThen, since the only element both sets share is 8, we also have\r\n\t\\begin{equation*}\r\n\t\tA \\cap B = \\{8\\}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Intervals}\r\n\\begin{definition}\r\n\tWe call a subset $I$ of $\\mathbb{R}$ an interval if, for any $a, b \\in I$ and $x \\in \\mathbb{R}$ such that $a \\leq x \\leq b$, then $x \\in I$. \r\n\\end{definition}\r\nWe can write an interval more simply using the notation $[a, b]$, which is equivalent to $\\{x \\in \\mathbb{R} \\mid a \\leq x \\leq b\\}$. \r\nThis is called a closed interval, and to make the inequalities strict, we can also define an open interval by using parantheses instead of square brackets.\\bigskip\r\n\r\nIn addition, we can mix the two to create half-open intervals, where one inequality is strict and the other isn't. \r\nFor instance, $(2, 5]$ refers to the set $\\{x \\in \\mathbb{R} \\mid x < 2 \\leq 5\\}$\r\nFinally, if the interval is unbounded in either direction, we use the notations $-\\infty$ and $\\infty$ to indicate that there is no minimum or maximum, respectively.\r\n\r\n\\begin{example}\r\n\tIs $8 \\in (-\\infty, 4) \\cup [8, 100)$?\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince $8 \\leq 8 < 100$ is a true statement, $8 \\in [8, 100)$. \r\n\tSince we are taking the union with another set, all of the members of the right interval will also be members of the union of intervals. \r\n\tTherefore, the statement is true.\r\n\\end{answer}", "meta": {"hexsha": "c373d5cbefb5fae323e65a35d44fc628c23f436e", "size": 3857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/sets.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/sets.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/sets.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 58.4393939394, "max_line_length": 173, "alphanum_fraction": 0.5989110708, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305360354471, "lm_q2_score": 0.9073122213606241, "lm_q1q2_score": 0.8739508373327061}} {"text": "\n\\subsection{Einstein summation convention}\n\nA vector can be written as a sum of its components.\n\n\\(v=\\sum_i e_i v^i\\)\n\nThe Einstein summation convention is to remove the \\(\\sum_i \\) symbols where they are implicit.\n\nFor example we would instead write the vector as:\n\n\\(v=e_iv^i\\)\n\n\\subsubsection{Adding vectors}\n\n\\(v+w=(\\sum_i e_i v^i)+(\\sum_i f_iw^i)\\)\n\n\\(v+w=\\sum_i (e_iv^i+f_iw^i)\\)\n\n\\(v+w=e_iv^i+f_iw^i\\)\n\nIf the bases are the same then:\n\n\\(v+w=e_i (v^i+w^i)\\)\n\n\\subsubsection{Scalar multiplication}\n\n\\(cv=c\\sum_ie_iv^i\\)\n\n\\(cv=\\sum_i ce_iv^i\\)\n\n\\(cv=ce_iv^i\\)\n\n\\subsubsection{Matrix multiplication}\n\n\\(AB_{ik}=\\sum_jA_{ij}B_{jk}\\)\n\n\\(AB_{ik}=A_{ij}B_{jk}\\)\n\n\\subsubsection{Inner products}\n\n\\(\\langle v, w\\rangle =\\langle \\sum_i e_iv^i, \\sum_j f_jw^j\\rangle \\)\n\n\\(\\langle v, w\\rangle =\\sum_iv^i\\langle e_i, \\sum_j f_iw^j\\rangle \\)\n\n\\(\\langle v, w\\rangle =\\sum_i \\sum_jv^i\\overline {w^j}\\langle e_i, f_j\\rangle\\)\n\nIf the two bases are the same then:\n\n\\(\\langle v, w\\rangle =\\sum_i \\sum_jv^i\\overline {w^j}\\langle e_i, e_j\\rangle\\)\n\nWe can define the metric as:\n\n\\(g_{ij}:=\\langle e_i,e_j\\rangle \\)\n\n\\(\\langle v, w\\rangle =v^i\\overline {w^j}g_{ij}\\)\n\n", "meta": {"hexsha": "e0c890ace1c47ec2d0b80d6534bbc0facdfba623", "size": 1155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/01-01-einstein.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/01-01-einstein.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/01-01-einstein.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.9137931034, "max_line_length": 95, "alphanum_fraction": 0.6727272727, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9719924818279465, "lm_q2_score": 0.8991213813246445, "lm_q1q2_score": 0.8739392228983126}} {"text": "\n\\subsection{Gamma function}\n\nThe gamma function expands the factorial function to the real (and complex) numbers\n\nWe want:\n\n\\(f(1)=1\\)\n\n\\(f(x+1)=xf(x)\\)\n\nThere are an infinite number of functions which fit this. The function could fluctuate between the natural numbers.\n\nThe function we use is:\n\n\\(\\Gamma (z)=\\int_0^\\infty x^{z-1}e^{-x}dx\\)\n\n", "meta": {"hexsha": "12cee6f5a2795006ed11db59651075e678b08eca", "size": 343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/importantFunctions/01-01-gamma.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/importantFunctions/01-01-gamma.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/importantFunctions/01-01-gamma.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.0555555556, "max_line_length": 115, "alphanum_fraction": 0.7113702624, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9688561667674652, "lm_q2_score": 0.901920685097536, "lm_q1q2_score": 0.8738314176918848}} {"text": "\\chapter{Matrices}\n\\section{Vector space}\nA vector space is a collection of objects called vectors, which may be added together and multiplied (``scaled'') by numbers, called scalars.\\par \nLet $F$ be the field\\footnote{a field is a set on which addition, subtraction, multiplication, and division are defined, and behave as when they are applied to rational and real numbers.} and $X$ be abelian group\\footnote{an abelian group, also called a commutative group, is a group in which the result of applying the group operation to two group elements does not depend on the order in which they are written.}. The pair $\\left(X,\\odot \\right)$ is a vector space if $\\odot \\, : F \\times X \\rightarrow X$ satisfies $\\forall s,t \\in F$ and $\\forall u,v \\in X$:\n\\begin{equation*}\n\\begin{cases}\n\ts \\odot \\left( t \\odot u \\right) &= \\left(s \\cdot t \\right) \\odot u \\\\\n\ts \\odot \\left( u+v \\right) &= \\left(s \\odot u \\right) + \\left(s \\odot v \\right) \\odot u \\\\\n\t\\left( s+t \\right) \\odot u &= \\left(s + u \\right) \\odot \\left(s + v \\right) \\\\\n\t1 \\odot u &= u\n\\end{cases}\n\\end{equation*}\nThe elements of $F$ (meaning $s,t$) are called ``scalars''. The elements of $X$ (meaning $u,v$) are called ``vectors''. The habit to denote vectors in this notebook, say $u \\in X$, by $\\vect{u}$.\\par \nIn this notebook, $F=\\mathbb{R}$, thus we only discuss vector spaces. Additionally, we omit the symbol $\\odot$, thus $s \\odot \\vect{u}$ is writing $s\\vect{u}$.\n\\begin{example}\n$\\mathbb{R}$ is a vector space.\n\\end{example}\n\n\\begin{example}\n$\\mathbb{R}^2$ is also a vector space, where for $\\vect{u}=\\left(u_1,u_2\\right)$ and $\\vect{v}=\\left(v_1,v_2\\right)$ and $s \\in \\mathbb{R}$:\n\t\\begin{equation*}\n\t\\begin{cases}\n\t\ts\\vect{u} &= \\left(su_1,su_2\\right) \\\\\n\t\t\\vect{u}+\\vect{v} &= \\left(u_1 + u_2 , u_2 + v_2 \\right) \\\\\n\t\t\\vect{0} &= (0,0)\n\t\\end{cases}\n\t\\end{equation*}\n\\end{example}\n\n\\begin{example}\nAny $\\mathbb{R}^n$ is a vector space, where for $\\vect{u}=\\left(u_1,u_2,\\ldots ,u_n\\right)$ and $\\vect{v}=\\left(v_1,v_2,\\ldots ,v_n\\right)$ and $s \\in \\mathbb{R}$ satisfies:\n \\begin{equation*}\n \t\\begin{cases}\n\t\ts\\vect{u} &= \\left(su_1,su_2,\\ldots ,su_n\\right) \\\\\n\t\t\\vect{u}+\\vect{v} &= \\left(u_1 + u_2 , u_2 + v_2 ,\\ldots ,u_n + v_n \\right) \\\\\n\t\t\\vect{0} &= (\\underbrace{0,0,\\ldots ,0}_\\text{n times})\n\t\\end{cases}\n \\end{equation*}\n\\end{example}\n\n\\note If $\\vect{u} \\in \\mathbb{R}^2$ and $\\vect{v} \\in \\mathbb{R}^3$ then $\\vect{u} + \\vect{v}$ is not defined because $\\vect{u}$ and $\\vect{v}$ do not belong to the same vector space.\n\n\\section{Definition}\nLet $\\mathbb{R}^{m \\times n}$ be the set of all tables with $m$ rows and $n$ columns such that they consist of real numbers. For example, $\\begin{mtrx} 2 & 3 & -1 \\\\ 2 & 1 & 4 \\end{mtrx}$ is a table of $2 \\times 3$\nLet define a table $\\vect{A}$ such that:\n\\begin{equation*}\n \\vect{A}=\n \\begin{mtrx}\n\t\ta_{11} & a_{12} & \\ldots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\ldots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\ldots & a_{mn}\n \\end{mtrx}\n\\end{equation*}\nNote that the element $a_{ij}$, called the ij-entry, appears in the \\emph{i}th row and the \\emph{j}th column. We simply denote $\\vect{A}=\\left[a_{ij}\\right]$, where $i \\in {1,2,\\ldots ,m}$ and $j \\in {1,2,\\ldots ,n}$.\\par \nNow, $\\mathbb{R}^{m \\times n}$ is a vector space if $\\vect{A}=\\left[a_{ij}\\right]$ and $\\vect{B}=\\left[b_{ij}\\right]$ and $s \\in \\mathbb{R}$ satisfies:\n\\begin{equation*}\n\\begin{cases}\n\\vect{A} + \\vect{B} &= \\left[ a_{ij} + a_{ij} \\right] \\\\\ns\\vect{A} &= \\left[sa_{ij}\\right] \\\\\n\\left[0\\right] & \\text{is the zero-element}\n\\end{cases}\n\\end{equation*}\nIn this case, $\\left[0\\right]$ is an $m\\times n$ table whose entries are all zero. $\\vect{A},\\vect{B},\\left[0\\right]$ are now called matrices. Notice that a vector can be regarded as a special type of matrix. A row vector is a $1\\times n$ matrix, and a column vector is a $m\\times 1$ matrix.\n\\begin{example}\nVector $\\vect{s}=(1,2)$ can be written as a matrix $\\rvect{1,2}$ (row vector) or $\\cvect{1,2}$ (column vector).\n\\end{example}\n\\section{Basic operations}\n\\subsection{Matrix addition}\nLet $\\vect{A}$ and $\\vect{B}$ are two matrices of the same vector space. The sum of $\\vect{A}$ and $\\vect{B}$, written $\\vect{A}+\\vect{B}$, is the matrix obtained by adding corresponding elements from $\\vect{A}$ and $\\vect{B}$:\n\\begin{equation*}\n \\begin{mtrx}\n\t\ta_{11} & a_{12} & \\ldots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\ldots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\ldots & a_{mn}\n \\end{mtrx}\n +\n \\begin{mtrx}\n\t\tb_{11} & b_{12} & \\ldots & b_{1n} \\\\\n\t\tb_{21} & b_{22} & \\ldots & b_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\tb_{m1} & b_{m2} & \\ldots & b_{mn}\n \\end{mtrx} \n =\n \\begin{mtrx}\n\t\ta_{11}+b_{11} & a_{12}+b_{12} & \\ldots & a_{1n}+b_{1n} \\\\\n\t\ta_{21}+b_{21} & a_{22}+b_{22} & \\ldots & a_{2n}+b_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1}+b_{m1} & a_{m2}+b_{m2} & \\ldots & a_{mn}+b_{mn}\n \\end{mtrx} \n\\end{equation*}\n\\subsection{Scalar multiplication}\nThe product of a scalar $k$ and a matrix $\\vect{A}$, written $k\\vect{A}$ or $\\vect{A} k$, is the matrix obtained by muliplying each element of $\\vect{A}$ by $k$:\n\\begin{equation*}\n k\n \\begin{mtrx}\n\t\ta_{11} & a_{12} & \\ldots & a_{1n} \\\\\n\t\ta_{21} & a_{22} & \\ldots & a_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\ta_{m1} & a_{m2} & \\ldots & a_{mn}\n \\end{mtrx}\n =\n \\begin{mtrx}\n\t\tka_{11} & ka_{12} & \\ldots & ka_{1n} \\\\\n\t\tka_{21} & ka_{22} & \\ldots & ka_{2n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\tka_{m1} & ka_{m2} & \\ldots & ka_{mn}\n \\end{mtrx} \n\\end{equation*}\nWe also define $-\\vect{A}=(-1)\\vect{A}$ and $\\vect{A}-\\vect{B}=\\vect{A}+(-\\vect{B})$. The matrix $-\\vect{A}$ is called the \\emph{negative} of the matrix $\\vect{A}$.\n\\subsection{Matrix multiplication}\nNow suppose $\\vect{A}$ and $\\vect{B}$ are two matrices such that the number of columns of $\\vect{A}$ is equal to the number of rows of $\\vect{B}$, say $\\vect{A}$ is an $m\\times p$ matrix and $\\vect{B}$ is an $p\\times n$. Then the product of $\\vect{A}$ and $\\vect{B}$, written $\\vect{A}\\vect{B}$, is the $m\\times n$ matrix whose ij-entry is obtained by muliplying the elements of \\emph{i}th row of $\\vect{A}$ by the corresponding elements of the \\emph{j}th column of $\\vect{B}$ and then adding:\n\\begin{equation*}\n \\begin{mtrx}\n\t\ta_{11} & a_{12} & \\ldots & a_{1p} \\\\\n\t\t . & . & \\ldots & . \\\\\n\t\ta_{i1} & a_{i2} & \\ldots & a_{ip} \\\\\n\t\t . & . & \\ldots & . \\\\\n\t\ta_{m1} & a_{m2} & \\ldots & a_{mp}\n \\end{mtrx}\n \\quad\n \\begin{mtrx}\n\t\tb_{11} & \\ldots & b_{1j} & b_{1n} \\\\\n\t\t\\vdots & \\vdots & \\vdots & \\vdots \\\\\n\t\tb_{m1} & b_{m2} & \\ldots & b_{mn}\n \\end{mtrx} \n =\n \\begin{mtrx}\n\t\tc_{11} & \\ldots & c_{1n} \\\\\n\t\t\\vdots & \\vdots & \\vdots \\\\\t\t\n\t\t\\vdots & c_{ij} & \\vdots \\\\\n\t\t\\vdots & \\vdots & \\vdots \\\\\t\t\n\t\tc_{m1} & \\ldots & c_{mn} \n \\end{mtrx} \n\\end{equation*}\nwhere \\[ c_{ij} = a_{i1}b_{1j} + a_{i1}b_{1j} + \\ldots + a_{ip}b_{pj} = \\sum_{k=1}^p a_{ik}b_{kj} \\]\nIf the number of columns of $\\vect{A}$ is not equal to the number of rows of $\\vect{B}$, then the product $\\vect{A}\\vect{B}$ is not defined.\n\n\\begin{example}\n Find $\\vect{A}\\vect{B}$, where \n \\begin{equation*}\n A=\n \\begin{mtrx}\n 1&3\\\\\n 2& -1\n \\end{mtrx}\n \\qquad\n B=\n \\begin{mtrx}\n 2&0& -4 \\\\\n 3& -2 &6\n \\end{mtrx}\n \\end{equation*}\n Since $\\vect{A}$ is a $2\\times 2$ matrix, $\\vect{B}$ is a $2\\times 3$, the product matrix $\\vect{A}\\vect{B}$ is defined and is a $2\\times 3$ matrix. To obtain the elements in the first row of the product matrix $\\vect{A}\\vect{B}$, multiply the first row $\\rvect{1,3}$ of $\\vect{A}$ by the columns:\n \\[ \\cvect{2,3} \\qquad \\cvect{0,-2} \\qquad \\text{and} \\cvect{-4,6} \\]\n of $\\vect{B}$ respectively:\n \\begin{meq*}\n \\smtrx{1,3\\\\2,-1} \\smtrx{2,0,-4\\\\3,-2,6} & = & \n\t \\smtrx{\n\t 1 \\cdot 2 + 3 \\cdot 3 ,\n\t 1 \\cdot 0 + 3(-2) ,\n\t 1(-4) + 3 \\cdot 6\\\\\n\t ,,\n }\\\\\n & = & \\smtrx{11,-6,14\\\\,,}\n \\end{meq*} \n To obtain the elements in the second row of the product matrix $\\vect{A}\\vect{B}$, multiply the second row $\\rvect{2,-1}$ of $\\vect{A}$ by the columns of $\\vect{B}$ respectively: \n \\begin{meq*}\n \\smtrx{1,3\\\\2,-1} \\smtrx{2,0,-4\\\\3,-2,6} & = & \n\t \\smtrx{\n 11,-6,14 \\\\\n 2 \\cdot 2 + (-1) \\cdot 3 ,\n 2 \\cdot 0 + (-1) \\cdot (-2),\n 2 \\cdot (-4) + (-1) \\cdot 6\n }\\\\\n & = & \\smtrx{11,-6,14\\\\1,2,-14}\n \\end{meq*} \n\\end{example}\n\n\\subsection{Transpose}\nThe transpose of a matrix is an operator which flips a matrix over its diagonal, that is, it switches the row and column indices of the matrix by producing another matrix.\\par \nLet $\\vect{A}\\in \\mathbb{R}^{m\\times n}$. The transpose of $\\vect{A}$, denote $\\trans{A}$, is a matrix $\\trans{A}\\in \\mathbb{R}^{n\\times m}$ such that for $\\vect{A}=\\smtrx{a_{ij}}$, we have $\\trans{A}=\\smtrx{a_{ji}}$.\\par \n\\begin{example}\n The transpose of $\\vect{A}=\\smtrx{2,3,1\\\\ 0,7,8}$ is $\\trans{A}=\\smtrx{2,0\\\\ 3,7\\\\ 1,8}$.\n\\end{example}\nFor matrices $\\vect{A}\\vect{B}$ and scalar $k$, we have the following properties of transpose:\n\\begin{itemize}\n\\item The operation of taking the transpose is an involution (self-inverse), meaning that $\\trans{\\left( \\trans{A} \\right)}=\\vect{A}$.\n\\item The transpose respects addition, $\\trans{\\left( \\vect{A}+\\vect{B} \\right)}=\\trans{A}+\\trans{B}$.\n\\item The order of the factors reverses when taking tranpose of a product matrix, $\\trans{ \\left(\\vect{A}\\vect{B}\\right) }=\\trans{B}\\trans{A}$. From this, one can deduce that a square matrix $\\vect{A}$ is invertible if and only if its transpose $\\trans{A}$ is invertible, and in this case, we have $\\trans{\\left( \\inverse{A} \\right)}=\\inverse{\\left( \\trans{A} \\right)}$.\n\\item $\\trans{\\left( c\\vect{A} \\right)}=c\\trans{A}$.\n\\end{itemize}\n\n\\section{Square matrices}\n\\subsection{Definition}\nA matrix with the same number of rows as columns is called a \\emph{square matrix}. A square matrix with \\emph{n} rows and \\emph{n} columns is said to be of \\emph{order n}, and is called \\emph{n-square matrix}. The diagonal of an n-square matrix $\\vect{A}=\\smtrx{a_{ij}}$ consists of elements $a_{11},a_{22},\\ldots , a_{mn}$.\n\\begin{example}\nThe matrix \\[ \\smtrx{1,-2,0 \\\\ 0,-4,-1 \\\\ 5,3,2} \\] is a square matrix of order 3. The numbers along the diagonal are 1, -4, and 2.\n\\end{example}\n\\subsection{Unit matrix}\nThe n-square matrix with 1s along the diagonal and 0s elsewhere, e.g., \\[ \\smtrx{1,0,0\\\\ 0,1,0\\\\ 0,0,1} \\] is called \\emph{unit matrix} and will be denoted by $\\vect{I}$. The unit matrix $\\vect{I}$ plays the same role in matrix multplication as the number 1 does in the usual multiplication of number. Specifically, \\[ \\vect{A}\\vect{I}=\\vect{I}\\vect{A}=\\vect{A} \\] for any square matrix $\\vect{A}$.\\par \nWe can form powers of a square matrix $\\vect{X}$ by defining:\\[ \\vect{X}^2=\\vect{X}\\vect{X}, \\quad \\vect{X}^3=\\vect{X}^2 \\vect{X} \\quad \\ldots \\vect{X}^0=\\vect{I} \\]\n\\subsection{Invertible matrix}\nAn n-square matrix $\\vect{A}$ is said to be invertible if there exists an n-square matrix $\\vect{B}$ with the property \\[ \\vect{A}\\vect{B}=\\vect{B}\\vect{A}=\\vect{I}_n \\] Such a matrix $\\vect{B}$ is unique, and is called the \\emph{inverse} of $\\vect{A}$, and is denoted by $\\inverse{A}$. Observe that $\\vect{B}$ is the inverse of $\\vect{A}$ if and only if $\\vect{A}$ is the inverse of $\\vect{B}$.\n\\begin{example}\nSuppose \\[ \\vect{A}=\\smtrx{2,5\\\\ 1,3} \\quad \\text{and} \\quad \\vect{B}=\\smtrx{3,-5\\\\ -1,2} \\] Then \\[ \\vect{A}\\vect{B}=\\smtrx{6-5,-10+10\\\\ 3-3,-5+6}=\\smtrx{1,0\\\\ 0,1}=\\vect{I}_2 \\]\n\\[ \\vect{B}\\vect{A}=\\smtrx{6-5,15-15\\\\ -2+2,-5+6}=\\smtrx{1,0\\\\ 0,1}=\\vect{I}_2 \\] Thus $\\vect{A}$ and $\\vect{B}$ are inverses.\n\\end{example}\n\\subsection{Determinants}\n \\label{sec:Determinants}\nTo each n-square matrix $\\vect{A}=\\smtrx{a_{ij}}$ we assign a specific number called the \\emph{determinant} of $\\vect{A}$, denoted $\\dt{A}$ or\n\\begin{equation*}\n\\dmtrx{\n a_{11},a_{12},\\ldots ,a_{1n}\\\\\n a_{21},a_{22},\\ldots ,a_{2n}\\\\\n \\vdots,\\vdots,\\ddots,\\vdots \\\\\n a_{n1},a_{n2},\\ldots ,a_{nn}\\\\\n}\n\\end{equation*}\nThe determinants of matrices of order one, two, three are defined as follows:\n\\begin{meq*}\n\\dmtrx{a_{11}} &=& a_{11} \\\\\n\\dmtrx{a_{11},a_{12}\\\\a_{21},a_{22}} &=& a_{11}a_{22}-a_{12}a_{21}\\\\\n\\dmtrx{a_{11},a_{12},a_{13}\\\\a_{21},a_{22},a_{23}\\\\a_{31},a_{32},a_{33}} &=& a_{11}a_{22}a_{33}+a_{21}a_{23}a_{31}+a_{13}a_{21}a_{32}-a_{13}a_{22}a_{31}-a_{12}a_{21}a_{33}-a_{11}a_{23}a_{32}\n\\end{meq*}\nBelow is another way to calculate determinant of a $3\\times 3$ matrix:\n\\begin{equation}\\label{det-3matrix}\n\\dmtrx{\n a_{11},a_{12},a_{13}\\\\\n a_{21},a_{22},a_{23}\\\\\n a_{31},a_{32},a_{33}\n}\n= \\dmtrx{a_{22},a_{23}\\\\a_{32},a_{33}} a_{11} - \\dmtrx{a_{21},a_{23}\\\\a_{31},a_{33}} a_{12} + \\dmtrx{a_{21},a_{22}\\\\a_{31},a_{32}} a_{13}\n\\end{equation}\nIn general, one can calculate determinant of an n-square matrix $\\vect{A}$ using the following formula: \\[ \\dt{A}=\\sum^n_{j=1} (-1)^{i+j}a_{ij} \\dt{A_{ij}} \\]\nUsing determinant, we can calculate the inverse of an invertible matrix. For example, the inverse of a $2\\times 2$ matrix with nonzero determinant can be calculated as follow: \\[ \\inverse{A}=\\smtrx{a,b\\\\c,d}^{-1}=\\frac{1}{\\dt{A}} \\smtrx{d,-b\\\\-c,a} \\]\nFor n-square matrix $\\vect{A}=\\smtrx{a_{ij}}$ with nonzero determinant, the inverse would be:\n\\[ \\inverse{A}= \\frac{1}{\\dt{A}} \n\\dmtrx{\n c_{11},c_{12},\\ldots ,c_{1n}\\\\\n c_{21},c_{22},\\ldots ,c_{2n}\\\\\n \\vdots,\\vdots,\\ddots,\\vdots \\\\\n c_{n1},c_{n2},\\ldots ,c_{nn}\\\\\n}\n\\]\nwhere $c_{ij}=(-1)^{i+j} \\dt{A_{ij}}$.\\par \nFor matrices $\\vect{A},\\vect{B}$ and scalar $k \\neq 0$, we have the following properties of determinants:\n\\begin{itemize}\n\\item $\\det (\\vect{A}\\vect{B})=\\dt{A} \\cdot \\dt{B}$\n\\item A \\emph{square} matrix is invertible if and only if it has a nonzero determinant.\n\\item Swapping two rows of a matrix produces the negative matrix. If $\\vect{B}$ is a matrix $\\vect{A}$ with any two rows interchanged, then $\\dt{B}=-\\dt{A}$.\n\\item If $\\vect{B}$ is a matrix $\\vect{A}$ but one row multiplied by $k$ then $\\dt{B}=k\\dt{A}$.\n\\item If $\\vect{B}$ is a matrix $\\vect{A}$ but row \\emph{i}th, say $R_i$, is replaced by $R_i + kR_t, \\forall t \\neq i$, then $\\dt{B}=\\dt{A}$.\n\\end{itemize}\n\\begin{example}\nGiven matrix $\\vect{A}$:\n\\[ \\vect{A}=\\smtrx{-2,-1,4\\\\ 6,-3,-2\\\\ 4,1,2} \\quad \\dt{A}=100 \\]\nInterchange any two rows of $\\vect{A}$, we have matrix $\\vect{B}$:\n\\[ \\vect{B}=\\smtrx{6,-3,-2\\\\ -2,-1,4\\\\ 4,1,2} \\quad \\dt{B}=-\\dt{A}=-100 \\]\nMultiply first row of $\\vect{A}$ with 4 , we have matrix $\\vect{B}$:\n\\[ \\vect{B}=\\smtrx{-8,-4,16\\\\ 6,-3,-2\\\\ 4,1,2} \\quad \\dt{B}=4\\dt{A}=400 \\]\nReplace the first row $R_1$ by $R_1+\\dfrac{1}{2}R_3$\n\\[ \\vect{B}=\\smtrx{1,-5/2,3\\\\ 6,-3,-2\\\\ 4,1,2} \\quad \\dt{B}=\\dt{A}=100 \\]\n\\end{example}\n\\subsection{Eigenvectors and eigenvalues}\nLet $\\vect{A}$ be an n-square matrix. The eigenvector of $\\vect{A}$ is a column vector $\\vect{x}$ that satisfies:\n\\begin{equation*}\n\\vect{A}\\vect{x}=\\lambda\\vect{x}\n\\end{equation*}\nLet us start to find $\\vect{x}$ such that\n\\begin{meq*}\n\\vect{A}\\vect{x} &=& \\lambda\\vect{x} \\\\\n\\Leftrightarrow \\vect{A}\\vect{x}-\\lambda\\vect{x} &=& \\vect{0} \\\\\n\\Leftrightarrow \\left( \\vect{A}-\\lambda\\vect{I} \\right)\\vect{x} &=& \\vect{0} \\\\\n\\end{meq*}\nwhere $\\vect{I}$ is the identity matrix living in the same vector space with $\\vect{A}$. There are infinite number of solutions for $\\vect{x}$ if there exists $\\lambda$ that makes $\\det \\left( \\vect{A}-\\lambda\\vect{I} \\right) =\\vect{0}$. In that case, $\\lambda$ is called eigenvalue associated with the eigenvector $\\vect{x}$.\\par \n\\note There are no more than $n$ distinct eigenvalues for an n-square matrix.\n\\begin{example}\nTo calculate the eigenvalues and eigenvectors of $\\vect{A}=\\smtrx{2,1\\\\1,4}$, we need to solve the following equation:\n\\begin{meq*}\n\\det \\left( \\vect{A}- \\lambda\\vect{I} \\right) =0 &\\Leftrightarrow & \\dmtrx{2-\\lambda,1\\\\1,4-\\lambda}=0 \\\\\n\\Leftrightarrow (2-\\lambda)(4-\\lambda)=0 &\\Leftrightarrow & {\\lambda}^2-6\\lambda +7=0 \\\\\n\\Leftrightarrow {\\lambda}_1=3+\\sqrt{2} &\\quad\\text{and}\\quad & {\\lambda}_2=3-\\sqrt{2}\n\\end{meq*}\nIf the eigenvalue is ${\\lambda}_1=3+\\sqrt{2}$, then \n\\begin{IEEEeqnarray*}{l}\n\\left( \\vect{A} - \\left(3+\\sqrt{2}\\right) \\vect{I} \\right)\\vect{x} = \\vect{0} \\\\\n\\smtrx{-1-\\sqrt{2},1\\\\1,1-\\sqrt{2}}\\cvect{x_1,x_2}=\\vect{0}\\\\\n\\Leftrightarrow \n\t\\begin{cases}\n\t \\left( -1-\\sqrt{2} \\right)x_1+x_2 &=0\\\\\n\t x_1+\\left( 1-\\sqrt{2} \\right)x_2 &=0\n\t\\end{cases}\\\\\n\\Leftrightarrow x_1 = \\left( 1+\\sqrt{2} \\right)x_2\t\n\\end{IEEEeqnarray*}\nEigenvectors corresponding to ${\\lambda}_1=3+\\sqrt{2}$ are\n\\[ \\vect{x}=\\cvect{1,1+\\sqrt{2}}k, \\quad k\\in\\mathbb{R}\\backslash\\lbrace 0 \\rbrace \\]\nLikewise, If the eigenvalue is ${\\lambda}_1=3-\\sqrt{2}$, then the corresponding eigenvectors are\n\\[ \\vect{x}=\\cvect{1,1-\\sqrt{2}}k, \\quad k\\in\\mathbb{R}\\backslash\\lbrace 0 \\rbrace \\]\n\\end{example}\n\\note The sum of diagonal members of the matrix equals to the sum of eigenvalues.\n\\section{Vector operations}\n\\subsection{Inner product}\nLet $X$ be a vector space. If one can define a binary operation $\\cdot \\, : X \\times X \\rightarrow \\mathbb{R}$ (take 2 vectors and produce a scalar) such that $\\forall \\vect{w},\\vect{u},\\vect{v}\\in X$ and $\\forall s\\in \\mathbb{R}$, we have:\n\\begin{equation*}\n\\begin{cases}\n \\vect{u} \\cdot \\vect{v} &= \\vect{v} \\cdot \\vect{u} \\\\\n \\vect{u} \\cdot \\left( \\vect{v}+\\vect{w} \\right) &= \\vect{u} \\cdot \\vect{v} + \\vect{u} \\cdot \\vect{w} \\\\\n s\\left( \\vect{u} \\cdot \\vect{v} \\right) &= \\left( s\\vect{u} \\right)\\cdot \\vect{v}=\\vect{u} \\cdot \\left( s\\vect{v} \\right) \\\\\n \\vect{u} \\cdot \\vect{u} & \\geqslant 0 \\\\\n \\vect{u} \\cdot \\vect{u} = 0 \\Leftrightarrow \\vect{u}=0\n\\end{cases}\n\\end{equation*}\nthen $X$ is called inner product space. The binary operation $\\cdot$ is called inner product.\\par \nInner product is used to calculate norm of vectors. For any vector $\\vect{u}\\in X$, one can define norm $\\norm{u}$ by \\[ \\norm{u}=\\sqrt{\\vect{u} \\cdot \\vect{u}} \\]\nFor any two vectors $\\vect{u},\\vect{v}\\in X$, we have \\[ \\vect{u} \\cdot \\vect{v} = \\norm{u}\\norm{v}\\cos \\alpha \\]\nA vector whose norm is 1, is called a unit vector. One can define a unit vector $\\uvect{x}$ by the following formula: \\[ \\uvect{x}=\\frac{1}{\\norm{x}}\\vect{x} \\]\n\\begin{example}\nVector $\\vect{x}=(-2,5,3,6)$ has inner product norm of $\\norm{x}=\\sqrt{(-2)^2+5^2+3^2+6^2}=\\sqrt{74}$. Thus, \\[ \\uvect{x}=\\frac{1}{\\norm{x}}\\vect{x}=\\frac{1}{\\sqrt{74}} (-2,5,3,6) \\]\n\\end{example}\n\\subsection{Cross product}\nLet $\\mathbb{R}^3$ be a vector space. If one can define a binary operation $\\times \\, : X \\times X \\rightarrow X$ (take 2 vectors and produce a vector) such that $\\forall \\vect{a},\\vect{b},\\vect{c}\\in \\mathbb{R}^3$, we have:\n\\begin{equation}\\label{cross-product}\n\\vect{c}=\\vect{a}\\times\\vect{b}=\\dmtrx{\\vect{i},\\vect{j},\\vect{k}\\\\a_1,a_2,a_3\\\\b_1,b_2,b_3}\n\\end{equation}\nwhere $\\vect{i},\\vect{j},\\vect{k}$ are the base vectors, and $\\vect{a}=(a_1,a_2,a_3), \\quad \\vect{b}=(b_1,b_2,b_3)$. Note that the determinant in \\eqref{cross-product} produces a vector instead of a scalar. It is also called \\emph{symbolic determinant}.\n\\begin{example}\nLet $\\vect{a}=(1,0,5),\\quad\\vect{b}=(-1,2,1)$. Applying the formula \\eqref{det-3matrix}, the cross product $\\vect{a}\\times\\vect{b}$ is\n\\begin{meq*}\n\\vect{c}=\\dmtrx{\\vect{i},\\vect{j},\\vect{k}\\\\1,0,5\\\\-1,2,1} &=& \\dmtrx{0,5\\\\2,1}\\vect{i}-\\dmtrx{1,5\\\\-1,1}\\vect{j}+\\dmtrx{1,0\\\\-1,2}\\vect{k} \\\\\n&=& (-10)\\vect{i}-6\\vect{j}+2\\vect{k}\n\\end{meq*}\nwhich means that $\\vect{c}=(-10,-6,2)$\n\\end{example}\nIf we draw $\\vect{a},\\vect{b}$ and $\\vect{c}=\\vect{a}\\times\\vect{b}$ in a right-handed three-dimensional coordinate system, then $\\vect{c}$ is perpendicular to both $\\vect{a}$ and $\\vect{b}$. Moreover, if vectors $\\vect{a}$ and $\\vect{b}$ are considered as edges of a parallelogram then $A=\\Vert\\vect{a}\\times\\vect{b}\\Vert$ is the area of that parallelogram.\\par \nFor vectors $\\vect{a},\\vect{b},\\vect{c}$ and scalar $k \\neq 0$, we have the following properties of cros products:\n\\begin{itemize}\n\\item $\\Vert\\vect{a}\\times\\vect{b}\\Vert = \\norm{a}\\norm{b}\\sin\\alpha$, where $\\alpha=\\angle (\\vect{a},\\vect{b})$.\n\\item $\\vect{a}\\times\\vect{b}=-\\left( \\vect{b}\\times\\vect{a} \\right)$ \n\\item $\\vect{a}\\times\\vect{a}=\\vect{0}$, where $\\vect{0}$ is zero-vector (not a scalar).\n\\item $\\left( k\\vect{a} \\right)\\times\\vect{b}=\\vect{a}\\times\\left( k\\vect{b} \\right)=k\\left( \\vect{a}\\times\\vect{b} \\right)$\n\\item $\\vect{c}\\times\\left( \\vect{a}+\\vect{b} \\right)=\\vect{c}\\times\\vect{a}+\\vect{c}\\times\\vect{b}$\n\\item Cross product is not associative, $\\vect{c}\\times\\left( \\vect{a}\\times\\vect{b} \\right)$ may not equal to $\\left( \\vect{c}\\times\\vect{a} \\right)\\times\\vect{b}$.\n\\item Given three vectors $\\vect{a}=(a_1,a_2,a_3),\\vect{b}=(b_1,b_2,b_3)$ and $\\vect{c}=(c_1,c_2,c_3)$. The combination of cross product and inner product as follow produces a scalar:\n\t\\begin{equation}\n\t\\left( \\vect{a}\\times\\vect{b} \\right)\\cdot\\vect{c}=\\dmtrx{c_1,c_2,c_3\\\\a_1,a_2,a_3\\\\b_1,b_2,b_3}\n\t\\end{equation}\n\\end{itemize}\n\n\\section{Matrix applications}\n\\subsection{Orthogonal projection}\nThe orthogonal projection of $\\vect{v}$ onto the line spanned by a nonzero $\\vect{s}$ (see figure \\ref{Linalg_projection}) is: \n\\[ \\vect{v}_{\\vect{s}}=\\frac{\\vect{v}\\cdot\\vect{s}}{\\norm{s}^2} \\, \\vect{s} \\]\n\n\\begin{figure}[hbtp]\n\\caption{Orthogonal projection}\n\\label{Linalg_projection}\n\\centering\n \\begin{tikzpicture}\n\t\\tkzInit[xmin=-1,xmax=6,ymin=-1,ymax=6]\n\t\\tkzDrawX[noticks] \\tkzDrawY[noticks]\n\t\\tkzDefPoint(0,0){O} \\tkzDefPoint(3,4){A} \\tkzDefPoint(2,0.5){B}\n\t\\tkzDefPoint(-0.5,-0.125){C} \\tkzDefPoint(4,1){D}\n\t\\tkzDefPointBy[projection=onto O--C](A) \\tkzGetPoint{P}\n\t\\tkzDrawVectors(O,A O,B O,P)\n\t\\tkzDrawLine(C,D)\n\t\\tkzDrawSegment(A,P)\n\t\\tkzLabelSegment[above=3pt](O,A){$\\vect{u}$}\n\t\\tkzLabelSegment[below=1pt](O,B){$\\vect{v}$}\n\t\\tkzLabelSegment[above=1pt](O,P){$\\vect{v}_{\\vect{s}}$}\n\t\\tkzLabelAngle[pos = 0.5](B,O,A){$\\alpha$}\n\t\\tkzMarkAngle[fill= yellow,size=0.75cm,opacity=.3](B,O,A)\n\t\\tkzMarkRightAngle(C,P,A)\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\subsection{Rotation}\nIn linear algebra, a rotation matrix is a matrix that is used to perform a rotation in Euclidean space.\n\\subsubsection{In two dimensions}\nIn two dimensions, every rotation matrix has the following form,\n\\[ \\vect{R}=\\smtrx{\\cos\\alpha,-\\sin\\alpha\\\\ \\sin\\alpha,\\cos\\alpha} \\]\nrotates points in the xy-plane counterclockwise through an angle $\\alpha$ about the origin of the Cartesian coordinate system. The column vectors are calculated by means of the following matrix multiplication,\n\\begin{equation*}\n\\cvect{x',y'}=\\smtrx{\\cos\\alpha,-\\sin\\alpha\\\\ \\sin\\alpha,\\cos\\alpha}\\cvect{x,y}\n\\end{equation*}\nSo the new coordinates $\\left( x',y' \\right)$ of the point $\\left( x,y \\right)$ after rotation are\n\\[\n x'=x\\cos \\alpha -y\\sin \\alpha \\, \\quad\n y'=x\\sin \\alpha +y\\cos \\alpha \\,.\n\\]\n\\subsubsection{In three dimensions}\nA basic rotation (also called elemental rotation) is a rotation about one of the axes of a Coordinate system. The following three basic rotation matrices rotate vectors by an angle $\\theta$ about the x-, y-, or z-axis, in three dimensions, using the right-hand rule:\n\\[ {\\begin{alignedat}{1}R_{x}(\\theta )&={\\begin{bmatrix}1&0&0\\\\0&\\cos \\theta &-\\sin \\theta \\\\[3pt]0&\\sin \\theta &\\cos \\theta \\\\[3pt]\\end{bmatrix}}\\\\[6pt]R_{y}(\\theta )&={\\begin{bmatrix}\\cos \\theta &0&\\sin \\theta \\\\[3pt]0&1&0\\\\[3pt]-\\sin \\theta &0&\\cos \\theta \\\\\\end{bmatrix}}\\\\[6pt]R_{z}(\\theta )&={\\begin{bmatrix}\\cos \\theta &-\\sin \\theta &0\\\\[3pt]\\sin \\theta &\\cos \\theta &0\\\\[3pt]0&0&1\\\\\\end{bmatrix}}\\end{alignedat}}\\]\n\n\n\\section{Exercises}\n\\begin{exercise}\nConsider an object living in 3D real place. Its current position is $P(2,5,3)$. The object is heading towards the point $Q(4,10,5)$, and moves to that direction exactly 3 length units. Calculate the position of this object after movement.\n\\end{exercise}\n\n\\begin{solution}\nLet $\\vect{y}$ be the vector of the movement and $\\vect{x}$ be the distance between P and Q. We have:\n\\begin{meq*}\n\\vect{x} &=& \\vect{Q}-\\vect{P}=(4,10,5)-(2,5,3)=(2,5,2) \\\\\n\\norm{x} &=& \\sqrt{2^2+5^2+2^2}=\\sqrt{33},\\quad \\uvect{x}=\\frac{1}{\\sqrt{33}}(2,5,2) \\\\\n\\vect{y} &=& \\vect{P}+3\\uvect{x}=(2,5,3)+\\frac{3}{\\sqrt{33}}(2,5,2) \\qedhere \n\\end{meq*}\n\\end{solution}\n\n\\begin{exercise}\nLet $\\vect{a}=(2,4)$ and $\\vect{b}=(1,-3)$ be vectors in $\\mathbb{R}^2$. If these vectors are considered as edges of a parallelogram then calculate its area A. \n\\end{exercise}\n\n\\begin{solution}\nLet $\\vect{A}$ be the matrix formed by $\\vect{a}$ and $\\vect{b}$\n\\[ \\vect{A}=\\smtrx{2,1\\\\4,-3} \\]\nThe area of the parallelogram is the absolute value of the determinant of $\\vect{A}$\n\\[ S=\\vert \\dt{A}\\vert = \\vert 2(-3)-4\\cdot 1 \\vert =10 \\qedhere \\]\n\\end{solution}\n\n\\begin{exercise}\\label{change-origin}\nLet $\\vect{p}_0 \\in \\mathbb{R}^2$ be such that $\\vect{p}_0 =(5,3)$ and the corresponding point in $\\mathbb{R}^2$ is $P(5,3)$. We define the function $f:\\mathbb{R}^2\\rightarrow\\mathbb{R}^2$ such that $f(\\vect{x})=\\vect{x}-\\vect{p}_0$. Calculate $f((0,0)),f((-5,9)),f((\\vect{p}_0))$. Define the meaning of this function.\n\\end{exercise}\n\n\\begin{solution}\nThis function moves the origin of the coordinate system from $O(0,0)$ to $P(5,3)$, and then calculates the new coordinate of vector $\\vect{x}$. For example, the coordinate of $O(0,0)$ in the new coordinate system is $f((0,0))=(-5,3)$. Point $(-5,9)$ now becomes $f((-5,9))=(-10,6)$. And, of course, because $P(5,3)$ becomes the origin of the coordinate system, its coordinate is $(0,0)$.\n\\end{solution}\n\n\\begin{exercise}\nSuppose we have a cube in $\\mathbb{R}^3$ such that the vertices are at the point (0,0,0), (0,0,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Determine a function $f:\\mathbb{R}^{3\\times8}\\rightarrow\\mathbb{R}^{3\\times8}$ such that cube is centered at the origin of the coordinate system O(0,0,0), thus the center of the cube is mapped to 0.\n\\end{exercise}\n\n\\begin{solution}\nWe write each point of the cube as a column in a single matrix $\\vect{C}$:\n\\[ \\vect{C}=\\smtrx{0,0,0,0,1,1,1,1\\\\0,0,1,1,0,0,1,1\\\\0,1,0,1,0,1,0,1} \\]\nThe center of the cube is $C_0=(1/2,1/2,1/2)$. The function $f$ moves the origin of the coordinate from point O(0,0,0) to $C_0$. According to exercise \\ref{change-origin}, that function is \n\\[ f(\\vect{C})=\\vect{C} - \\cvect{1/2,1/2,1/2}\\rvect{1,1,1,1,1,1,1,1}\\qedhere \\]\n\\end{solution}\n", "meta": {"hexsha": "04a41e8934c21ecb482c8c984f24b0846c6f5143", "size": 26513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Matrices.tex", "max_stars_repo_name": "buiquanghuy23103/Math", "max_stars_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrices.tex", "max_issues_repo_name": "buiquanghuy23103/Math", "max_issues_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matrices.tex", "max_forks_repo_name": "buiquanghuy23103/Math", "max_forks_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.2568181818, "max_line_length": 562, "alphanum_fraction": 0.6333119602, "num_tokens": 10257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.9207896845856297, "lm_q1q2_score": 0.8737532299955508}} {"text": "\\section{Geometrical Probability}\r\n\\subsection{Buffon's Needle}\r\nSuppose we have parallel horizontal lines, each with distance $L$ apart from each other and we have a needle with length $\\ell\\le L$.\r\nThrow the needle at random, then we want to know the probbaility that it intersects at least one line.\r\nSuppose we have dropped the needle, then let $\\Theta$ be its horizontal inclination and $X$ the distance between the distance between the left end to the line above.\r\nSo we take $X\\sim\\operatorname{Unif}[0,L]$ and $\\Theta\\sim\\operatorname{Unif}[0,\\pi]$ and they are independent.\r\nHence\r\n$$p=\\mathbb P(\\text{The needle intersects the lines})=\\mathbb P(X\\le\\ell\\sin\\Theta)$$\r\nSo we can now calculate this by\r\n\\begin{align*}\r\n p&=\\mathbb P(\\text{The needle intersects the lines})\\\\\r\n &=\\mathbb P(X\\le\\ell\\sin\\Theta)\\\\\r\n &=\\int_0^L\\int_0^\\pi 1_{x\\le l\\sin\\theta}f_{X,\\Theta}(x,\\theta)\\,\\mathrm d\\theta\\,\\mathrm dx\\\\\r\n &=\\int_0^L\\int_0^\\pi 1_{x\\le l\\sin\\theta}\\frac{1}{\\pi L}\\,\\mathrm d\\theta\\,\\mathrm dx\\\\\r\n &=\\frac{1}{\\pi L}\\int_0^\\pi\\ell\\sin\\theta\\,\\mathrm d\\theta\\\\\r\n &=\\frac{2\\ell}{\\pi L}\r\n\\end{align*}\r\nHence $\\pi=2\\ell/(pL)$.\r\nNow we want to approximate $\\pi$ by this experiment.\r\nThrow $n$ needles independently and let $\\hat{p}_n$ be the proportion of needles intersecting a line.\r\nWe want to approximate $p$ by $\\hat{p}_n$ thus approximate $\\pi$ by $\\hat\\pi_n=2\\ell/(\\hat{p}_nL)$.\r\nSuppose we want $\\mathbb P(|\\hat\\pi_n-\\pi|\\le 0.001)\\ge 0.99$, we want to know how large $n$ has to be.\\\\\r\nDefine $f(x)=2\\ell/(xL)$, then $f(p)=\\pi$ and $f^\\prime(p)=-\\pi/p$.\r\nAlso $f(\\hat{p}_n)=\\hat\\pi_n$.\r\nLet $S_n$ be the number of needles intersecting a line, then $S_n\\sim\\operatorname{Bin}(n,p)$, so $S_n\\approx np+\\sqrt{np(1-p)}Z$ where $Z\\sim\\mathcal N(0,1)$.\r\nSo $\\hat{p}_n\\approx p+\\sqrt{p(1-p)/n}Z$.\r\nBy Taylor's Theorem,\r\n$$\\hat\\pi_n=f(\\hat{p}_n)\\approx f(p)+(\\hat{p}_n-p)f^\\prime(p)=\\pi-(\\hat{p}_n-p)\\pi/p$$\r\nSo when we substitute back, we obtain\r\n$$\\hat\\pi_n-\\pi\\approx-\\pi\\sqrt{\\frac{1-p}{pn}}Z$$\r\nSo\r\n$$\\mathbb P(|\\hat\\pi_n-\\pi|\\le 0.001)=\\mathbb P\\left( \\pi\\sqrt{\\frac{1-p}{pn}}|Z|<0.001 \\right)$$\r\nNow $\\mathbb P(|z|\\ge 2.58)<0.01$.\r\nAlso the variance of $\\pi\\sqrt{(1-p)/(pn)}Z$ is $\\pi^2(1-p)/(pn)$ which is decreasing in $p$.\r\nWe can minimize the variance by taking $\\ell=L$, so $p=2/\\pi$ and the variance is $\\pi^2(\\pi/2-1)/n$, so in this case we need\r\n$$\\sqrt{\\frac{\\pi^2}{n}(\\frac{\\pi}{2}-1)}2.58=0.001\\implies n=3.75\\times 10^7$$\r\nwhich is quite large.\r\n\\subsection{Bertrand's Paradox}\r\nWe have a circle of radius $r$ and draw a chord at random.\r\nWe want to know the probability that it has length at most $r$.\r\nThere are two ways to do this.\r\nThe first approach is let $X\\sim\\operatorname{Unif}(0,r)$ to be the perpendicular distance between the chord and the center of the circle.\r\nLet $C$ be the length, then $C\\le r\\iff 4X^2\\ge 3r^2$, so the probability is $1-\\sqrt{3}/2\\approx 0.134$.\\\\\r\nThere is a second approach.\r\nFix one point of the chord and choose $\\Theta\\sim\\operatorname{Unif}(0,2\\pi)$ to be the angle between this point and the other point of the chord.\r\nSo $C\\le r\\iff \\Theta\\le\\pi/3\\lor\\Theta\\ge 2\\pi-\\pi/3$, hence the probability is $1/3$ which is far enough from $0.134$.\\\\\r\nBut this is not a paradox since we are using essentially different sample spaces.", "meta": {"hexsha": "a44bcb420e780215f4c9789bb4868dd3776a2311", "size": 3309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/geom.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14/geom.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14/geom.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.4042553191, "max_line_length": 166, "alphanum_fraction": 0.6775460864, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.9219218321735119, "lm_q1q2_score": 0.873411270296135}} {"text": "\\section*{Exercise 26.1-4}\n\\subsubsection*{Prove that the flows in a network form a convex set.}\nLet $f_1,f_2,\\alpha$ be as given in the exercise description.\n\nWe want to prove that $f_{\\alpha}\\equiv\\alpha f_1 + (1- \\alpha)f_2$ $\\forall \\alpha \\in (0,1)$ is a flow.\n\nWe start by showing the capacity constraint i.e. \n\\begin{align}\n\\forall u,v \\in V \\text{ it holds that } 0\\leq f_{\\alpha}(u,v)\\leq c(u,v)\\label{Ex.26.1.4:ScalarCapacityConstraint}.\n\\end{align}\n\nSince $f_1$ and $f_2$ are flows, the capacity constraint holds for both of them. Since the capacity function $c$ is a property of the network, and not the individual flows, the capacity constraint for $f_1$ and $f_2$ are identical to \\eqref{Ex.26.1.4:ScalarCapacityConstraint} i.e they are bounded by the same upper and lower bounds.\n\nHence $\\forall \\alpha \\in (0,1)$ and $\\forall u,v \\in V$ the following equations hold\n\\begin{align*}\nf_{\\alpha}(u,v) &= \\alpha f_1(u,v) + (1- \\alpha)f_2(u,v)\\\\\n &\\geq \\alpha 0 + (1- \\alpha)0 \\\\\n\t\t\t\t\t\t\t\t&\\geq 0\n\\end{align*}\nand\n\\begin{align*}\nf_{\\alpha}(u,v) &= \\alpha f_1(u,v) + (1- \\alpha)f_2(u,v)\\\\\n &\\leq \\alpha c(u,v) + (1- \\alpha)c(u,v) \\\\\n\t\t\t\t\t\t\t\t&= c(u,v)\n\\end{align*}\nCombining the two inequalities above yields that \\eqref{Ex.26.1.4:ScalarCapacityConstraint} holds.\n\nWe then want to show that the flow conservation property holds. i.e\n\\begin{align}\n\\forall u \\in V\\setminus\\{s,t\\} \\text{ it holds that } \\sum_{v\\in V}f_{\\alpha}(v,u) = \\sum_{v\\in V}f_{\\alpha}(u,v)\\label{Ex.26.1.4:FlowConservationConstraint}.\n\\end{align}\nFirst note that since $f_1$ and $f_2$ are flows, the flow conservation property holds for both of them individually.\n\nPick a vertex $u$ such that $u\\in V\\setminus\\{s,t\\}$ then \n\\begin{align*}\n \\sum_{v\\in V}f_{\\alpha}(v,u) &= \\sum_{v\\in V} \\left(\\alpha f_1(v,u) + (1- \\alpha)f_2(v,u) \\right)\\\\\n &= \\alpha \\sum_{v\\in V} f_1(v,u) + (1- \\alpha) \\sum_{v\\in V} f_2(v,u)\\\\\n &= \\alpha \\sum_{v\\in V} f_1(u,v) + (1- \\alpha) \\sum_{v\\in V} f_2(u,v)\\\\\n &= \\sum_{v\\in V} \\left(\\alpha f_1(u,v) + (1- \\alpha)f_2(u,v) \\right)\\\\\n &= \\sum_{v\\in V}f_{\\alpha}(u,v)\n\\end{align*}\nSince this holds for all $u\\in V\\setminus\\{s,t\\}$, we have now shown \\eqref{Ex.26.1.4:FlowConservationConstraint}.\n\nWe have now shown the capacity constraint and the flow conservation property for $f_{\\alpha}$, hence $f_{\\alpha}$ is a flow. So the flows in a network form a convex set.", "meta": {"hexsha": "f1c835216ce5cbb34e21503e9f6c608e14bfb11c", "size": 2411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/Ex.26.1.4.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge1/Ex.26.1.4.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge1/Ex.26.1.4.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7954545455, "max_line_length": 333, "alphanum_fraction": 0.6594773953, "num_tokens": 883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.9334308165850442, "lm_q1q2_score": 0.8730812581536226}} {"text": "\n\\section{Weierstrass Theorem} \nTo approximate any continuous function, a very simple idea is to approximate the function in a polynomial space. \nAn important property of this space is that polynomials can approximate any reasonable function!\n\\begin{itemize}\n\\item $P_n(\\mathbb{R}^d)$ is dense in $C(\\Omega)$ [Weierstrass theorem]\n\\item $P_n(\\mathbb{R}^d)$ is dense in all Sobolev spaces: $L^2(\\Omega), W^{m,p}(\\Omega), \\ldots$\n\\end{itemize}\n\n\\input{6DL/WTheoremProof}\n \n\\subsection{Curse of dimensionality}\nNumber of coefficients for polynomial space $P_n(\\mathbb{R}^d)$ is\n$$\n\tN = \\binom{d+n}{n} = \\frac{(n+d)!}{d!n!}.\n$$\nFor example $n = 100$:\n\t\t\\begin{table}\n\t\t\t\\centering\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$d = $& $2$ & $4$ & $8$\\\\\n\t\t\t\t\\hline\n\t\t\t\t$N=$ & $5\\times10^3$ & $4.6\\times10^6$ & $3.5\\times10^{11}$ \t\\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{table}\nAs the this table shows, the dimension of the polynomial space $P_n(\\mathbb{R}^d)$ increases rapidly as the degree $n$ increases. This leads to an extremely large space therefore very expensive to approximate functions in polynomial spaces in high dimensions.\n\\input{6DL/Runge}\n\\input{6DL/Fourier}\n\\input{6DL/DNN_Qualitative}\n", "meta": {"hexsha": "1d23b53ffd549061b716d4126ebc4749833d5e4e", "size": 1203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/5 Polynomials and Weierstrass theorem/5.1-PolyWeierstrass.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/5 Polynomials and Weierstrass theorem/5.1-PolyWeierstrass.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/5 Polynomials and Weierstrass theorem/5.1-PolyWeierstrass.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.59375, "max_line_length": 261, "alphanum_fraction": 0.6874480466, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542852576265, "lm_q2_score": 0.9099070115349837, "lm_q1q2_score": 0.8727412092997401}} {"text": "\n\\subsection{Green's theorem}\nGreen's theorem tells us that\n$$\\oint P\\,dx+Q\\,dy=\\int\\!\\!\\!\\int\n\\left(\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}\\right)\ndx\\,dy$$\n\n\\noindent\nIn other words, a line integral and a surface integral can yield\nthe same result.\n\n\\bigskip\n\\noindent\nExample 1.\nThe following exercise is from {\\it Advanced Calculus}\nby Wilfred Kaplan, p.~287.\nEvaluate $\\oint (2x^3-y^3)\\,dx+(x^3+y^3)\\,dy$ around the circle\n$x^2+y^2=1$ using Green's theorem.\n\n\\bigskip\n\\noindent\nIt turns out that Eigenmath cannot solve the double integral over\n$x$ and $y$ directly.\nPolar coordinates are used instead.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nP = 2x^3 - y^3\nQ = x^3 + y^3\nf = d(Q,x) - d(P,y)\nx = r cos(theta)\ny = r sin(theta)\ndefint(f r,r,0,1,theta,0,2pi)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{3}{2}\\pi$\n\n\\bigskip\n\\noindent\nThe $defint$ integrand is $f\\,r$ because $r\\,dr\\,d\\theta=dx\\,dy$.\n\n\\bigskip\n\\noindent\nNow let us try computing the line integral side of Green's theorem\nand see if we get the same result.\nWe need to use the trick of converting sine and cosine to exponentials\nso that Eigenmath can find a solution.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = cos(t)\ny = sin(t)\nP = 2x^3 - y^3\nQ = x^3 + y^3\nf = P d(x,t) + Q d(y,t)\nf = circexp(f)\ndefint(f,t,0,2pi)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{3}{2}\\pi$\n\n\\bigskip\n\\noindent\nExample 2.\nCompute both sides of Green's theorem for\n$F=(1-y,x)$ over the disk $x^2+y^2\\le4$.\n\n\\bigskip\n\\noindent\nFirst compute the line integral along the boundary of the disk.\nNote that the radius of the disk is 2.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Line integral\nP = 1 - y\nQ = x\nx = 2 cos(t)\ny = 2 sin(t)\ndefint(P d(x,t) + Q d(y,t),t,0,2pi)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Surface integral\nx = quote(x) --clear x\ny = quote(y) --clear y\nh = sqrt(4-x^2)\ndefint(d(Q,x)-d(P,y),y,-h,h,x,-2,2)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n-- Try computing the surface integral using polar coordinates.\nf = d(Q,x) - d(P,y) --do before change of coordinates\nx = r cos(theta)\ny = r sin(theta)\ndefint(f r,r,0,2,theta,0,2pi)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 8\\pi$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ndefint(f r,theta,0,2pi,r,0,2) --try integrating over theta first\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 8\\pi$\n\n\\bigskip\n\\noindent\nIn this case, Eigenmath solved both forms of the polar integral.\nHowever, in cases where Eigenmath fails to solve a double integral, try\nchanging the order of integration.\n", "meta": {"hexsha": "22a8be0b44ef553594d1c07493477683e869d3a9", "size": 2693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/greens-theorem.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/greens-theorem.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/greens-theorem.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 22.6302521008, "max_line_length": 72, "alphanum_fraction": 0.7025621983, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.939024820841433, "lm_q1q2_score": 0.8717989038890764}} {"text": "\\chapter{Integral Transforms }\n\\section{Integral Transforms}\nFrequently in mathematical physics we encounter pairs of functions related by an expression of the form\n\\begin{equation}\ng(x)=\\int_{a}^{b} f(t) K(x, t) d t\\label{FT-01}\n\\end{equation}\nwhere it is understood that $a, b$, and $K(x, t)$ (called the kernel) will be the same for all function pairs $f$ and $g$. We can write the relationship expressed in Eq. (\\ref{FT-01}) in the more symbolic form\n\\begin{equation}\ng(x)=\\mathcal{L}{ f(t)}\n\\end{equation}\nthereby emphasizing the fact that Eq. $(\\ref{FT-01})$ can be interpreted as an operator equation. The function $g(x)$ is called the integral transform of $f(t)$ by the operator $\\mathcal{L}$, with the specific transform determined by the choice of $a, b$, and $K(x, t)$. The operator defined by Eq. (\\ref{FT-01}) will be linear:\n\\begin{align}\n\\int_{a}^{b}\\left[f_{1}(t)+f_{2}(t)\\right] K(x, t) d t&=\\int_{a}^{b} f_{1}(t) K(x, t) d t+\\int_{a}^{b} f_{2}(t) K(t) d t \\\\\n\\int_{a}^{b} c f(t) K(\\alpha, t) d t&=c \\int_{a}^{b} f(t) K(\\alpha, t) d t\n\\end{align}\nIn order for transforms to be useful, we will shortly see that we need to be able to \"undo\" their effect. From a practical viewpoint, this means that not only must there exist an operator $\\mathcal{L}^{-1}$, but also that we have a reasonably convenient and powerful method of evaluating\n\\begin{equation}\n\\mathcal{L}^{-1} g(x)=f(t)\n\\end{equation}\nfor an acceptably broad range of $g(x)$. The procedure for inverting a transform takes a wide variety of forms that depend on the specific properties of $K(x, t)$, so we cannot write a formula that is as general as that for $\\mathcal{L}$ in Eq. (\\ref{FT-01}).\\\\\nNot all superficially reasonable choices for the kernel $K(x, t)$ will lead to operators $\\mathcal{L}$ that have inverses, and even for strategically chosen kernels it may be the case that $\\mathcal{L}$ and $\\mathcal{L}^{-1}$ will only exist for substantially restricted classes of functions. Thus, the entire development of the present chapter is restricted (for any given integral transform) to functions for which the indicated operations can be carried out.\\\\\nOne of the frequent uses of integral transforms is to use one, together with its inverse, to form an \\textbf{integral representation} of a function that we originally had in an explicit form. This move (which appears to be in the direction of generating greater complexity) has value that arises from the relatively simple behavior of the transforms of differentiation and integration operators. Procedures involving integral representations are also presented in later sections of this chapter.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=9cm]{FT-01}\n\\end{figure}\n\\newpage\n\\begin{abox}\n\tFourier Transform\n\t\\end{abox}\n\nThe integral transform that has seen the widest use is the Fourier transform, defined as\n\\begin{equation}\ng(\\omega)=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} f(t) e^{i \\omega t} d t\n\\end{equation}\nThe notation for this transform is not entirely universal; some writers omit the prefactor $1 / \\sqrt{2 \\pi}$; we keep it because it causes the transform and its inverse to have formulas that are more symmetrical. In applications involving periodic systems, one occasionally encounters a definition with kernel $\\exp \\left(2 \\pi i \\omega t / a_{0}\\right)$, where $a_{0}$ is a lattice constant. These differences in notation do not change the mathematics, but cause formulas to differ by powers of $2 \\pi$ or $a_{0}$. Caution is therefore advised when combining material from different sources.\\\\\n\\section{Infinite Fourier Transform}\n\\begin{align*}\n\\text{The fourier transform of }f(x)[-\\infty0)$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tF\\left[e^{-a|x|}\\right] &=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{a x} e^{i s x} d x+\\int_{0}^{\\infty} e^{-a x} e^{i s x} d x\\right]=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left(\\frac{e^{(a+i s) x}}{(a+i s)}\\right)_{-\\infty}^{0}+\\left(\\frac{e^{-(a-i s) x}}{(i s-a)}\\right)_{0}^{\\infty}\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{1}{a+i s}+\\frac{1}{a-i s}\\right]=\\frac{2 a}{\\sqrt{2 \\pi}\\left(s^{2}+a^{2}\\right)} \\because\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\n\\section{Properties of Fourier Transform}\n(i) \\textbf{Linearity theorem:} \n\\begin{align*}\n\\text{If }F(x)&=a_{1} f_{1}(x)+a_{2} f_{2}(x)+\\ldots\\text{ then, }\\\\f(s)&=F[f(x)]=a_{1} f_{1}(s)+a_{2} f_{2}(s)+\\ldots\n\\end{align*}\n(ii) \\textbf{Change of scale property: }\n\\begin{align*}\n\\text{If }F[f(x)]&=f(s),\\text{ then }F\\{f(a x)\\}\\\\&=\\frac{1}{a} f(\\mathrm{~s} / a)\n\\end{align*}\n(iii) $\\text{If }F\\{f(x)\\}=f(s),\\text{ then }F\\left\\{f^{*}(x)\\right\\}=f^{*}(-s)$\\\\\\\\\n(iv) \\textbf{Shifting property:}\n \\begin{align*}\n\\text{ If $f(s)$ is the Fourier transform of }\\mathrm{f}(\\mathrm{x}), \\text{ then }F\\{f(x \\pm a)\\}=e^{\\mp i s a} f(s)\n \\end{align*}\n(v) \\textbf{Modulation theorem:} \\\\\\\\\nIf $F\\{f(x)\\}=f(s)$, then $F\\{f(x) \\cos a x\\}=\\frac{1}{2} f(s-a)+\\frac{1}{2} f(s+a)$\n\\section{Parseval Identity for Fourier Transform}\nIf the Fourier transform of $f(x)$ and $g(x)$ be $f(s) \\& g(s)$ respectively, then\\\\\\\\\n(i) $\\int_{-\\infty}^{\\infty} f(s) g^{*}(s) d s=\\int_{-\\infty}^{\\infty} f(x) g^{*}(x) d x$\\\\\\\\\nwhere $g^{*}(s)$ is complex conjugate of $g(s)$ and $g^{*}(x)$ is the complex conjugate of $g(x)$.\\\\\\\\\n(ii) $\\left.\\int_{-\\infty}^{\\infty}|f(s)|\\right.^{2} d s=\\int_{-\\infty}^{\\infty}|f(x)|^{2} d x$\n\\begin{exercise}Using parseval's identity show that $\\int_{b}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x=\\pi / 2$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\{f(x)\\}&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} f(x) e^{i x x} d x=\\sqrt{\\frac{2}{\\pi}} \\frac{\\sin a s}{s}\\\\\n\t\\text{Using parseval identity, }\\int_{-\\infty}^{\\infty}|f(x)|^{2} d x&=\\int_{-\\infty}^{\\infty}|f(s)|^{2} d s\\\\\n\t\\int_{-a}^{\\infty} l^{2} d x&=\\int_{-\\infty}^{\\infty} \\frac{2}{\\pi} \\frac{\\sin ^{2} a s}{s^{2}} d s \\\\ 2 a&=\\frac{2}{\\pi} \\int_{-\\infty}^{\\infty}\\left(\\frac{\\sin a s}{s}\\right)^{2} d s\\\\\n\t\\text{Putting }a s&=x \\Rightarrow a d s=d x\\\\\n\t\\Rightarrow \\pi&=\\int_{-\\infty}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x \\\\ \\int_{0}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x&=\\frac{\\pi}{2}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tIf the fourier transform of $f(x)$ is $f(s)$, then find the fourier transform of $\\frac{d f}{d x}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\left[\\frac{d f}{d x}\\right]&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} \\frac{d f}{d x} e^{i s x} d x\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[e^{i s x} f(x)\\right]_{-\\infty}^{\\infty}-\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} i s e^{i s x} f(x) d x\\\\\n\t\\intertext{Since $f(x)$ should be a well behave function for the fourier tranform to exist, therefore, the first term of the above equation should be equal to zero.}\n\t\\text{Then }F\\left[\\frac{d f}{d x}\\right]&=-i s \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{i s x} f(x) d x=-is f( {s})\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind Fourier transform of $f(x)= \\begin{cases}x^{2}, & |x|a\\end{cases}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\{f(x)\\} &=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{i s x} f(x) d x=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-a}^{a} e^{i s x} x^{2} d x \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left(\\frac{e^{i s x}}{i s} \\cdot x^{2}\\right)_{x=-a}^{a}-\\frac{2}{i s} \\int_{-a}^{a} x e^{i s x} d x\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{a^{2}}{i s}\\left(e^{i s a}-e^{-i s a}\\right)-\\frac{2}{i s}\\left[\\left(\\frac{x e^{i s x}}{i s}\\right)_{x=-a}^{a}-\\frac{1}{i s} \\int_{-a}^{a} e^{i s x} d x\\right]\\right]\\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{2 a^{2}}{s} \\sin (s a)+\\frac{2 a}{s^{2}} \\cos (s a)-\\frac{4}{s^{3}} \\sin (s a)\\right]\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the complex fourier transform $e^{-|x|}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\left\\{e^{-|x|}\\right\\}&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{-|x|} e^{i s x} d x\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{-|x|} e^{i s x} d x+\\int_{0}^{\\infty} e^{-|x|} \\cdot e^{i s x} d x\\right]\\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{x} \\cdot e^{i s x} d x+\\int_{0}^{\\infty} e^{-x(1-i s)} d x\\right]\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left[\\frac{e^{x(1+i s)}}{1+i s}\\right]_{x=-\\infty}^{0}+\\left[\\frac{e^{-x(1-i s)}}{-(1-i s)}\\right]_{x=0}^{\\infty}\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{1}{1-i s}+\\frac{1}{1+i s}\\right]\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left(\\frac{2}{1+s^{2}}\\right)\n\t\\end{align*}\n\\end{answer}\n\n\n\\begin{exercise}\n\tThe graph of a real periodic function $f(x)$ for the range $[-\\infty, \\infty]$ is shown below\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{FT01}\n\t\\end{figure}\n\tWhich of the following graphs represents the real part of its Fourier transform?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-06}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{b.}]\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-05}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{c.}]\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-03}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{d.}] \t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT02}\n\t\t\\end{figure}\n\t\\end{tasks}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { The given graph in the question is of } f(x)&=\\cos \\omega x\\\\\n\tF(\\cos \\omega x)=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{+\\infty} \\cos \\omega x e^{i k x} d x&=\\frac{1}{\\sqrt{2 \\pi}}\\left(\\int_{-\\infty}^{+\\infty} \\frac{e^{i(k+\\omega) x}}{2} d x+\\int_{-\\infty}^{+\\infty} \\frac{e^{i(k-\\omega) x}}{2} d x\\right)\\\\\n\t&\\Rightarrow F(\\cos \\omega x) \\frac{1}{\\sqrt{2 \\pi}}\\left(\\frac{1}{2} \\delta(k+\\omega)+\\frac{1}{2} \\delta(k-\\omega)\\right)\n\t\\intertext{Therefore, the fourier transform of $f(x)=\\cos x \\omega x$ consist of two delta functions of same height at $k=\\omega$ and $k=-\\omega$.}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{option (b)}\n\\end{answer}\n\\newpage\n\\begin{abox}\n\tLaplace Transforms\n\\end{abox}\nThe Laplace transform $f(s)$ of a function $F(t)$ is defined by \n\\begin{equation}\nf(s)=\\mathcal{L}\\{F(t)\\}=\\int_{0}^{\\infty} e^{-s t} F(t) d t .\n\\end{equation}\nA few comments on the existence of the integral are in order. The infinite integral of $F(t)$,\n\\begin{equation*}\n\\int_{0}^{\\infty} F(t) d t,\n\\end{equation*}\nneed not exist. For instance, $F(t)$ may diverge exponentially for large $t$. However, if there are some constants $s_{0}, M$, and $t_{0} \\geq 0$ such that for all $t>t_{0}$\n\\begin{equation}\n\\left|e^{-s_{0} t} F(t)\\right| \\leq M,\\label{LT-01}\n\\end{equation}\nthe Laplace transform will exist for $s>s_{0} $. $F(t)$ is then said to be of exponential order. As a counter example, $F(t)=e^{t^{2}}$ does not satisfy the condition given by Eq. (\\ref{LT-01}) and is not of exponential order. Thus, $\\mathcal{L}\\left\\{e^{t^{2}}\\right\\}$ does not exist.\nThe Laplace transform may also fail to exist because of a sufficiently strong singularity in the function $F(t)$ as $t \\rightarrow 0$. For example,\n\\begin{equation*}\n\\int_{0}^{\\infty} e^{-s t} t^{n} d t\n\\end{equation*}\ndiverges at the origin for $n \\leq-1$. The Laplace transform $\\mathcal{L}\\left\\{t^{n}\\right\\}$ does not exist for $n \\leq-1$. \n\n\\section{Important Laplace Transforms:}\n\\begin{enumerate}\n\t\\item $\\mathcal{L}(1)=\\frac{1}{s}$\n\t\\begin{exercise}\n\t\t$$\n\t\t\\mathcal{L}(1)=\\frac{1}{s}\n\t\t$$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(1)&=\\int_{0}^{\\infty} 1 \\cdot e^{-s t} d t=\\left[\\frac{e^{-s t}}{-s}\\right]_{0}^{\\infty}\\\\&=-\\frac{1}{s}\\left[\\frac{1}{e^{s t}}\\right]_{0}^{\\infty}=-\\frac{1}{s}[0-1]\\\\&=\\frac{1}{s}\\\\\n\t\t\\text{ Hence }\\mathcal{L}(1)&=\\frac{1}{s}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}(n=0,1,2, \\ldots \\ldots . .)$\n\t\\begin{exercise}\n\t\t$\\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}$ where $n$ and $s$ are positive.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}\\left(t^{n}\\right)&=\\int_{0}^{\\infty} e^{-s t} t^{n} d t\\\\\n\t\t\\text{Putting }s t=&x \\quad\\text{ or }\\quad t=\\frac{x}{s} \\quad\\text{ or } \\quad d t=\\frac{d x}{s}\\\\\n\t\t\\text{Thus we have}\\mathcal{L}\\left(t^{n}\\right)&=\\int_{0}^{\\infty} e^{-x}\\left(\\frac{x}{s}\\right)^{n} \\frac{d x}{s_{r}} \\quad \\Rightarrow \\quad \\mathcal{L}\\left(t^{n}\\right)=\\frac{1}{s^{n+1}} \\int_{0}^{\\infty} e^{-x} \\cdot x^{n} d x\\\\\n\t\t\\Rightarrow \\mathcal{L}\\left(t^{n}\\right)&=\\frac{\\sqrt{n+1}}{s^{n+1}} \\Rightarrow \\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}\\hspace{2cm}\\left[\\begin{array}{c}\n\t\t{\\left[n+1=\\int_{0}^{\\infty} e^{-x} \\cdot x^{n} d x\\right] } \\\\\n\t\t\\text { and } \\quad \\mid \\overline{n+1}=n !\n\t\t\\end{array}\\right]\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}(s>a)$\n\t\\begin{exercise}\n\t\t$\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}, \\quad$ where $s>a$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}\\left(e^{a t}\\right) &=\\int_{0}^{\\infty} e^{-s t} \\cdot e^{a t} d t=\\int_{0}^{\\infty} e^{-s t+a t} \\cdot d t \\\\\n\t\t&=\\int_{0}^{\\infty} e^{(-s+a) t} \\cdot d t=\\int_{0}^{\\infty} e^{-(s-a) t} \\cdot d t=\\left[\\frac{e^{-(s-a) t}}{-(s-a)}\\right]_{0}^{\\infty}=-\\frac{1}{s-a}\\left[\\frac{1}{e^{(s-a) t}}\\right]_{0}^{\\infty}\\\\\n\t\t&=\\frac{-1}{(s-a)}(0-1)=\\frac{1}{s-a}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\cos a t)=\\frac{s}{s^{2}+a^{2}}$\n\t$(s>0)$\n\t\\begin{exercise}\n\t\t$L(\\cos a t)=\\frac{s}{s^{2}+a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\cos a t)&=\\mathcal{L}\\left(\\frac{e^{t a t}+e^{-i a t}}{2}\\right) \\quad\\left[\\because \\cos a t=\\frac{e^{i a t}+e^{-i a t}}{2}\\right]\\\\\n\t\t&=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{i a t}+e^{-i a t}\\right)\\right]=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{i a t}\\right)+\\mathcal{L}\\left(e^{i a t}\\right)\\right]=\\frac{1}{2}\\left[\\frac{1}{s-i a}+\\frac{1}{s+i a}\\right]=\\frac{1}{2} \\frac{s+i a+s-i a}{s^{2}+a^{2}}\\\\\n\t\t&=\\frac{s}{s^{2}+a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\sin a t)=\\frac{a}{s^{2}+a^{2}} \\quad(s>0)$\n\t\t\\begin{exercise}\n\t\t$\\mathcal{L}(\\sin a t)=\\frac{a}{s^{2}+a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\sin a t)&=\\mathcal{L}\\left[\\frac{e^{i a t}-e^{-i a t}}{2 i}\\right]\\hspace{3cm} \\left[\\because \\sin a t=\\frac{e^{i a t}-e^{-i a t}}{2 i}\\right]\\\\\n\t\t&=\\frac{1}{2 i}\\left[L\\left(e^{i a t}-e^{-i a t}\\right)\\right]=\\frac{1}{2 i}\\left[L\\left(e^{i a t}\\right)-\\mathcal{L}\\left(e^{-i a t}\\right)\\right] \\\\\n\t\t&=\\frac{1}{2 i}\\left[\\frac{1}{s-i a}-\\frac{1}{s+i a}\\right]=\\frac{1}{2 i} \\frac{s+i a-s+i a}{s^{2}+a^{2}}=\\frac{1}{2 i} \\frac{2 i a}{s^{2}+a^{2}}=\\frac{a}{s^{2}+2^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\\item $\\mathcal{L}(\\cosh a t)=\\frac{s}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\t\t\\begin{exercise}\n\t\t$\\mathcal{L}(\\cosh a t)=\\frac{s}{s^{2}-a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\cosh a t) &=L\\left[\\frac{e^{a t}+e^{-a t}}{2}\\right] \\hspace{4cm}\\left(\\therefore \\cosh a t=\\frac{e^{a t}+e^{-a t}}{2}\\right)\\\\\n\t\t&=\\frac{1}{2} \\mathcal{L}\\left(e^{a t}\\right)+\\frac{1}{2} L\\left(e^{-a t}\\right)=\\frac{1}{2}\\left[\\frac{1}{s-a}+\\frac{1}{s+a}\\right] \\hspace{2cm}\\left[\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}\\right]\\\\\n\t\t&=\\frac{1}{2}\\left[\\frac{s+a+s-a}{s^{2}-a^{2}}\\right]=\\frac{s}{s^{2}-a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\sinh a t)=\\frac{a}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\t\\begin{exercise}\n\t\t$L(\\sinh a t)=\\frac{a}{s^{2}-a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\sinh a t) &=\\mathcal{L}\\left[\\frac{1}{2}\\left(e^{a t}-e^{-a t}\\right)\\right] \\\\\n\t\t&=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{a t}\\right)-L\\left(e^{-a t}\\right)\\right]=\\frac{1}{2}\\left[\\frac{1}{s-a}-\\frac{1}{s+a}\\right]=\\frac{1}{2}\\left[\\frac{s+a-s+a}{s^{2}-a^{2}}\\right] \\\\\n\t\t&=\\frac{a}{s^{2}-a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\n\\subsubsection{Important properties:}\n\\begin{enumerate}\n\t\\item Linear Property: $\\mathcal{L}\\left[a_{1} f_{1}(t)+a_{2} f_{2}(t)\\right]=a_{1} \\mathcal{L}\\left[f_{1}(t)\\right]+a_{2} \\mathcal{L}\\left[f_{2}(t)\\right]$\n\t\\item Shifting Property: $\\mathcal{L}\\left[e^{a t} f(t)\\right]=f(s-a)$\n\t\\item Scaling Property: $\\mathcal{L}[f(a t)]=\\frac{1}{a} f\\left(\\frac{s}{a}\\right)$\n\t\\item $\\mathcal{L}\\left[t^{n} f(t)\\right]=(-1)^{n} \\frac{d^{n}}{d s^{n}}(f(s))$\n\t\\item $\\mathcal{L}\\left[\\frac{f(t)}{t}\\right]=\\int_{-\\infty}^{\\infty} f(s) d s$\n\t\\item $\\mathcal{L}\\left[\\int_{0}^{t} f(t) d t\\right]=\\frac{1}{s} f(s)$\n\t\\item $\\mathcal{L}\\left[f^{\\prime}(t)\\right]=s L[f(t)]-f(0)$\n\t\\item $\\mathcal{L}\\left[f^{\\prime \\prime}(t)\\right]=s^{2} L[f(t)]-f^{\\prime}(0)-s f(0)$\n\t\\item Laplace transform of a periodic function $f(t)$ having period ' $T$ ' is $$\\mathcal{L}[f({t})]=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s t} f({t}) d {t}$$\n\t\\item Laplace transform of the unit step function $u(t-a)=u_{a}(t)=\\left\\{\\begin{array}{lll}0 & \\text { for } & t0 \\\\ -1, & \\text { for } t<0\\end{array}\\right.$ and its Fourier transform is given by $-2 i / \\omega$. The Fourier transform of $\\frac{1}{2}[H(t+1 / 2)-H(t-1 / 2)]$ is\n{\\exyear{GATE 2015}}\n\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $\\frac{\\sin \\left(\\frac{\\omega}{2}\\right)}{\\frac{\\omega}{2}}$\n\\task[\\textbf{B.}] $\\frac{\\cos \\left(\\frac{\\omega}{2}\\right)}{\\frac{\\omega}{2}}$\n\\task[\\textbf{C.}] $\\sin \\left(\\frac{\\omega}{2}\\right)$\n\\task[\\textbf{D.}] 0\n\\end{tasks}\n\\item The Fourier transform of the function $\\frac{1}{x^{4}+3 x^{2}+2}$ up to proportionality constant is\n{\\exyear{JEST 2017}}\n\n\\begin{tasks}(2)\n\\task[\\textbf{A.}] $\\sqrt{2} \\exp \\left(-k^{2}\\right)-\\exp \\left(-2 k^{2}\\right)$\n\\task[\\textbf{B.}]$\\sqrt{2} \\exp (-|k|)-\\exp (-\\sqrt{2}|k|)$\n\\task[\\textbf{C.}] $\\sqrt{2} \\exp (-\\sqrt{|k|})-\\exp (-\\sqrt{2|k|})$\n\\task[\\textbf{D.}]$\\sqrt{2} \\exp \\left(-\\sqrt{2} k^{2}\\right)-\\exp \\left(-2 k^{2}\\right)$\n\\end{tasks}\n\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{D} &2&\\textbf{B}\\\\\\hline \n\t\t3&\\textbf{C} &4&\\textbf{B} \\\\\\hline\n\t\t5&\\textbf{D} &6&\\textbf{C} \\\\\\hline\n\t\t7&\\textbf{A}&8&\\textbf{B}\\\\\\hline\n\t\t9&\\textbf{D}&10&\\textbf{}\\\\\\hline\n\t\t11&\\textbf{} &12&\\textbf{}\\\\\\hline\n\t\t13&\\textbf{}&14&\\textbf{}\\\\\\hline\n\t\t15&\\textbf{}& &\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-2\n\\end{abox}\n\\begin{enumerate}\n\t\\item The graph of the function $f(x)=\\left\\{\\begin{array}{ll}1 & \\text { for } 2 n \\leq x \\leq 2 n+1 \\\\ 0 & \\text { for } 2 n+1 \\leq x \\leq 2 n+2\\end{array}\\right.$ where $n=(0,1,2, \\ldots \\ldots)$ is shown below. Its Laplace transform $\\tilde{f}(s)$ is\n{\t\\exyear{NET/JRF(DEC-2011)}}\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=2.7cm,width=7.5cm]{diagram-20211005(9)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1+e^{-s}}{s}$\n\t\t\\task[\\textbf{B.}] $\\frac{1-e^{-s}}{s}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{s\\left(1+e^{-s}\\right)}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{s\\left(1-e^{-s}\\right)}$\n\t\\end{tasks}\n\t\n\t\\item The inverse Laplace transforms of $\\frac{1}{s^{2}(s+1)}$ is\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2} t^{2} e^{-t}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2} t^{2}+1-e^{-t}$\n\t\t\\task[\\textbf{C.}] $t-1+e^{-t}$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{2} t^{2}\\left(1-e^{-t}\\right)$\n\t\\end{tasks}\n\t\n\t\\item The Laplace transform of\n\t$$\n\tf(t)=\\left\\{\\begin{array}{cc}\n\t\\frac{t}{T}, & 0T\n\t\\end{array}\\right.\n\t$$\n\tis\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{-\\left(1-e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\left(1-e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{C.}] $\\frac{\\left(1+e^{-s T}\\right)}{s^{2} T}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\left(1-e^{s T}\\right)}{s^{2} T}$\n\t\\end{tasks}\n\t\n\t\\item Consider the differential equation $\\frac{d y}{d t}+a y=e^{-b t}$ with the initial condition $y(0)=0$. Then the Laplace transform $Y(s)$ of the solution $y(t)$ is\n\t{\\exyear{NET/JRF(DEC-2017)}}\n\t\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{(s+a)(s+b)}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{b(s+a)}$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{a(s+b)}$\n\t\t\\task[\\textbf{D.}] $\\frac{e^{-a}-e^{-b}}{b-a}$\n\t\\end{tasks}\n\t\n\t\\item If $f(x)=\\left\\{\\begin{array}{ll}0 & \\text { for } x<3, \\\\ x-3 & \\text { for } x \\geq 3\\end{array}\\right.$ then the Laplace transform of $f(x)$ is\n\t{\\exyear{GATE 2010}}\n\t\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $s^{-2} e^{3 s}$\n\t\t\\task[\\textbf{B.}] $s^{2} e^{3 s}$\n\t\t\\task[\\textbf{C.}] $s^{-2}$\n\t\t\\task[\\textbf{D.}] $s^{-2} e^{-3 s}$\n\t\\end{tasks}\n\t\n\t\\item The Laplace transform of $\\frac{(\\sin (a t)-a t \\cos (a t))}{\\left(2 a^{3}\\right)}$ is \n\t{\\exyear{JEST 2018}}\n\t\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{2 a s}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\t\t\\task[\\textbf{B.}]$\\frac{s^{2}-a^{2}}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\t\t\\task[\\textbf{C.}]$\\frac{1}{(s+a)^{2}}$\n\t\t\\task[\\textbf{D.}]$\\frac{1}{\\left(s^{2}+a^{2}\\right)^{2}}$\n\t\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{C} &2&\\textbf{C}\\\\\\hline \n\t\t3&\\textbf{B} &4&\\textbf{A} \\\\\\hline\n\t\t5&\\textbf{D} &6 &\\textbf{D} \\\\\\hline\n\t\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}\n\n\t\\item The Fourier transform of $f(x)=\\left\\{\\begin{array}{cl}-1 & -1a\\end{cases}$\n\n\\begin{answer}\n\t\\begin{align*}\n\tF_{C}\\{f(x)\\} &=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} f(x) \\cos (p x) d x \\\\\n\t&=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{a} \\cos x \\cos (p x) d x+\\int_{a}^{\\infty} 0 \\cdot \\cos p x d x \\\\\n\t&=\\sqrt{\\frac{2}{\\pi}} \\frac{1}{2} \\int_{0}^{a}[\\cos (p+1) x \\cos (p-1) x] d x\\\\\n\t&=\\sqrt{\\frac{2}{\\pi}} \\frac{1}{2}\\left[\\frac{\\sin (p+1) x}{p+1}+\\frac{\\sin (p-1) x}{p-1}\\right]_{x=0}^{a} \\\\\n\t&=\\sqrt{\\frac{2}{\\pi}} \\frac{1}{2}\\left[\\frac{\\sin (p+1) a}{p+1}+\\frac{\\sin (p-1) a}{p-1}\\right]\n\t\\end{align*}\n\\end{answer}\n\n\\item\tFourier transform of the derivative of the Dirac $\\delta$-function, namely, $\\delta^{\\prime}(x)$, is proportional to\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]1\n\t\t\\task[\\textbf{c.}] $\\sin k$\n\t\t\\task[\\textbf{d.}] $\\mathrm{i} k$\n\t\\end{tasks}\n\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Fourier transform of } \\delta^{\\prime}(x)&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} \\delta^{\\prime}(x) e^{i k x} d x\\\\\n\t\\intertext { Using the property of Dirac delta function, } \\int_{-\\infty}^{\\infty} f(x) \\delta^{\\prime}(x-a) d x&=-f^{\\prime}(a)\\\\\n\t\\text { So, } \\quad F\\left[\\delta^{\\prime}(x)\\right]&=-\\frac{1}{\\sqrt{2 \\pi}}(i k) \\\\ F\\left[\\delta^{\\prime}(x)\\right] &\\propto i k\n\t\\end{align*}\n\tSo the correct answer is \\textbf{option (d)}\n\\end{answer}\n\\item Find the fourier transform of \n$f(x)=\\left\\{\\begin{array}{lll}1 & \\text { for } & |x|a\\end{array}\\right.$\n\\begin{answer}\n\t\\begin{align}\n\t\\intertext{The fourier transform of a function $f(x)$ is given by}\n\tF[f(x)]&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} f(x) \\cdot e^{i s x} d x\\label{FT15}\n\t\\intertext{Substituting the value of $f(x)$ in (\\ref{FT15}), we get}\n\tF[f(x)] &=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-a}^{a} 1 \\cdot e^{i s x} d x=\\left[\\frac{e^{i s x}}{i s}\\right]_{-a}^{a}=\\frac{1}{\\sqrt{2 \\pi}} \\frac{1}{(i s)}\\left[e^{i a s}-e^{-i a s}\\right] \\notag\\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}} \\frac{2}{s} \\cdot \\frac{e^{i a s}-e^{-i a s}}{2 i}=\\frac{1}{\\sqrt{2 \\pi}} \\frac{2 \\sin s a}{s}=\\sqrt{\\frac{2}{\\pi}} \\frac{\\sin s a}{s}\\notag\n\t\\end{align}\n\\end{answer}\n\n\\item Find Fourier Sine transform of $\\frac{1}{x}$\n\\begin{answer}\n\t\\begin{align}\n\t\\text{Here, }f(x)&=\\frac{1}{x}\\notag\\\\\n\tF_{s}[f(x)]&=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} f(x) \\sin s x d x\\label{FT18}\\\\\n\t\\text { Putting the value of } &f(x) \\text { in }(\\ref{FT18}) \\text {, we get }\\notag\\\\\n\tF_{s}\\left(\\frac{1}{x}\\right) &=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} \\frac{\\sin s x}{x} d x=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} \\frac{\\sin \\theta}{\\frac{\\theta}{s}} \\frac{d \\theta}{s} \\quad \\text { Putting } s x=\\theta \\text { so that } s d x=d \\theta \\notag\\\\\n\t&=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} \\frac{\\sin \\theta}{\\theta} d \\theta=\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{\\pi}{2}\\right) \\quad \\text { [Some useful result I on page 1208] Ans. } \\notag\\\\\n\t&=\\sqrt{\\frac{\\pi}{2}}\\notag\n\t\\end{align}\n\\end{answer}\n\\item Find the Fourier Sine Transform of $e^{-a x}$\n\\begin{answer}\n\t\\begin{align}\n\t\\text{Here, }f(x)&=e^{-a x}\\notag\n\\intertext{\tThe Fourier sine transform of $f(x)$ :}\n\tF_{s}[f(x)]&=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} f(x) \\sin s x d x\\label{FT19}\n\\intertext{\tOn putting the value of $f(x)$ in (\\ref{FT19}), we get}\n\tF_{s}\\left[e^{-a x}\\right]&=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} e^{-a x} \\sin s x d x\\notag\n\t\\intertext{On integrating by parts, we get}\n\tF_{s}\\left[e^{-a x}\\right] &=\\sqrt{\\frac{2}{\\pi}}\\left[\\frac{e^{-a x}}{a^{2}+s^{2}}[-a \\sin s x-s \\cos s x]\\right]_{0}^{\\infty}\\left[\\int e^{a x} \\sin b x d x=\\frac{e^{a x}}{a^{2}+b^{2}}(a \\sin b x-b \\cos b x)\\right] \\notag\\\\\n\t&=\\sqrt{\\frac{2}{\\pi}}\\left[0-\\frac{1}{a^{2}+s^{2}}(-s)\\right]=\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{s}{a^{2}+s^{2}}\\right)\\notag\n\\end{align}\n\\end{answer}\n\\item Find the laplace transform of $f(t)=\\frac{1-e^{t}}{t}$\n\n\\begin{answer}\n\t\\begin{align*}\n\t\\mathcal{L}\\left(\\frac{1-e^{t}}{t}\\right)&=\\int_{s}^{\\infty}\\left(\\frac{1}{s}-\\frac{1}{s-1}\\right) d s=[\\ln s-\\ln (s-1)]_{s}^{\\infty}=\\left[\\ln \\frac{s}{s-1}\\right]_{s}^{\\infty}:\\text{ (Using 5th property)}\\\\\n\t&=[\\ln s-\\ln (s-1)]_{s}^{\\infty}=\\left[\\ln \\frac{s}{s-1}\\right]_{s}^{\\infty}=\\ln \\left(\\frac{1}{\\left.1-\\frac{1}{s}\\right)_{s}}\\right)^{\\infty} \\\\\n\t&=0-\\ln \\frac{s}{s-1}=\\ln \\frac{(s-1)}{s}\n\t\\end{align*}\n\\end{answer}\n\n\\item\tFind the inverse laplace transform of\n\t$$\\mathrm{f}(\\mathrm{s}) =\\frac{\\mathrm{s}-2}{(\\mathrm{~s}-2)^{2}+25}+\\frac{\\mathrm{s}+4}{(\\mathrm{~s}+4)^{2}+81}+\\frac{1}{(\\mathrm{~s}+2)^{2}+9} $$\n\n\\begin{answer}\n\t\\begin{align*}\n\t\\mathcal{L}^{-1}[\\mathrm{f}(\\mathrm{s})] &=\\mathcal{L}^{-1}\\left[\\frac{\\mathrm{s}-2}{(\\mathrm{~s}-2)^{2}+25}\\right]+\\mathrm{L}^{-1}\\left[\\frac{\\mathrm{s}+4}{(\\mathrm{~s}+4)^{2}+81}\\right]+\\mathrm{L}^{-1}\\left[\\frac{1}{(\\mathrm{~s}+2)^{2}+9}\\right] \\\\\n\t&=\\mathrm{e}^{2 \\mathrm{t}} \\cos 5 \\mathrm{t}+\\mathrm{e}^{-4 \\mathrm{t}} \\cos 9 \\mathrm{t}+\\frac{\\mathrm{e}^{-2 \\mathrm{t}}}{3} \\sin 3 \\mathrm{t}\n\t\\end{align*}\n\\end{answer}\n\n\\item\tThe graph of the function\n\t$$f(t)= \\begin{cases}1 & \\text { for } 2 n \\leq t \\leq 2 n+1 \\\\ 0 & \\text { for } 2 n+1 \\leq t \\leq 2 n+2\\end{cases}$$\n\t(Where $n=0,1,2,........$)is shown below.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=2.5cm,width=6cm]{LT-01}\n\t\\end{figure}\n\tIts Laplace transform $\\tilde{f}(\\mathrm{s})$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1+e^{-s}}{s}$\n\t\t\\task[\\textbf{b.}]$\\frac{1-e^{-s}}{s}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{s\\left(1+e^{-s}\\right)}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{s\\left(1-e^{-s}\\right)}$\n\t\\end{tasks}\n\n\\begin{answer}\n\tGiven function is a periodic function of period $T=2$\n\t\\begin{align*}\n\t\\mathcal{L}[f(t)] &=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s t} f(t) d t=\\frac{1}{1-e^{-2 s}} \\int_{0}^{2} e^{-s t} d t \\\\\n\t&=\\frac{1}{1-e^{-2 s}}\\left[\\int_{0}^{1} e^{-s t} d t\\right]=\\frac{1}{1-e^{-2 s}}\\left(\\frac{1-e^{-s}}{s}\\right) \\\\\n\t&=\\frac{\\left(1-e^{-s}\\right)}{s\\left(1+e^{-s}\\right)\\left(1-e^{-s}\\right)}=\\frac{1}{s\\left(1+e^{-s}\\right)}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{option (c)}\n\\end{answer}\n\n\\item\tThe inverse transform of $\\frac{1}{s^2(s+1)}$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2} t^{2} e^{-t}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2} t^{2}+1-e^{-t}$\n\t\t\\task[\\textbf{c.}]$t-1+e^{-t}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{2} t^{2}\\left(1-e^{-t}\\right)$ \n\t\\end{tasks}\n\n\\begin{answer}\n\t\\begin{align*}\n\t&f(s)=\\frac{1}{s^{2}(s+1)}=\\frac{(s+1)-s(s+1)+s^{2}}{s^{2}(s+1)}=\\frac{1}{s^{2}}-\\frac{1}{s}+\\frac{1}{s+1} \\\\\n\t&\\Rightarrow \\mathcal{L}^{-1}[f(s)]=t-1+e^{-t}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{option (c)}\n\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "b4fbc1b25aed8713cff242868ef7533005fa1f33", "size": 41626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Fourier Transform.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Fourier Transform.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Fourier Transform.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5811648079, "max_line_length": 595, "alphanum_fraction": 0.586388315, "num_tokens": 18429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.9207896786080552, "lm_q1q2_score": 0.8716164451122903}} {"text": "\\section{Matrices}\n\\subsection{Matrices}\nThe set of real m Ă— n matrices is denoted $R^{m \\times n}$\n\\subsection{Zero and identity matrices}\n\\textbullet \\textit{Zero}: All elements equals 0.\\\\\n\\textbullet \\textit{Identity}: All elements equals 0 and diagonal element equals 1.\\\\\n\\textbullet \\textit{Sparse}: If many entries are 0\\\\\n\\textbullet \\textit{Diagonal}: off-diagonal entries are zero\\\\\n\\textbullet \\textit{Triangular}: \\textit{upper triangular} if $A_{ij} = 0 \\text{ for } i>j$, and it is \\textit{lower triangular} if $A_{ij} =0 \\text{ for } i>> u = Matrix([4,5,6])\n>>> n = Matrix([1,1,1])\n>>> (u.dot(n) / n.norm()**2)*n\n[5, 5, 5] # projection of v in the n dir\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIn the case where the direction vector $\\hat{n}$ is of unit length $\\|\\hat{n}\\| = 1$,\nthe projection formula simplifies to $\\Pi_{\\hat{n}}( \\vec{u} ) \\equiv (\\vec{u}\\cdot\\hat{n})\\hat{n}$.\n\n\nConsider now the plane $P$ defined by $(1,1,1)\\cdot[(x,y,z)-(0,0,0)]=0$.\nA plane is a two dimensional subspace of $\\mathbb{R}^3$.\nWe can decompose any vector $\\vec{u} \\in \\mathbb{R}^3$ into two parts $\\vec{u}=\\vec{v} + \\vec{w}$\nsuch that $\\vec{v}$ lies inside the plane and $\\vec{w}$ is perpendicular to the plane (parallel to $\\vec{n}=(1,1,1)$).\n\nTo obtain the perpendicular-to-$P$ component of $\\vec{u}$,\ncompute the projection of $\\vec{u}$ in the direction $\\vec{n}$:\n\\small\n\\begin{verbatimtab}\n>>> w = (u.dot(n) / n.norm()**2)*n\n[5, 5, 5]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nTo obtain the in-the-plane-$P$ component of $\\vec{u}$,\nstart with $\\vec{u}$ and subtract the perpendicular-to-$P$ part:\n\\small\n\\begin{verbatimtab}\n>>> v = u - (u.dot(n)/n.norm()**2)*n # same as u - w\n[ -1, 0, 1]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nYou should check on your own that $\\vec{v}+\\vec{w}=\\vec{u}$ as claimed.\n\n\\vspace{-5mm}\n", "meta": {"hexsha": "ae4bb8950bb8b0da57b00324634d14faac92fdd8", "size": 1865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "99.vectors_projectsions_FORLA.tex", "max_stars_repo_name": "ivanistheone/sympy_tutorial", "max_stars_repo_head_hexsha": "fa13b4d82c9bdbf4d2fc6083e603dace36a00fc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-11-24T02:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-01T16:23:20.000Z", "max_issues_repo_path": "tex/99.vectors_projectsions_FORLA.tex", "max_issues_repo_name": "minireference/sympytut_notebooks", "max_issues_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/99.vectors_projectsions_FORLA.tex", "max_forks_repo_name": "minireference/sympytut_notebooks", "max_forks_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-05-02T13:07:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T01:16:18.000Z", "avg_line_length": 28.6923076923, "max_line_length": 118, "alphanum_fraction": 0.6380697051, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214511730025, "lm_q2_score": 0.9032942106088968, "lm_q1q2_score": 0.8710659840105431}} {"text": "\\subsection{Cardinality}\n\n\\subsubsection{Cardinality of cartesian product}\n\nWhat about the cardinality of Cartesian products? So if we have sets:\n\n\\(\\{1,2,3\\}\\)\n\n\\(\\{a,b\\}\\)\n\nWe can have the Cartesian product set:\n\n\\(\\{(1,a),(2,a),(3,a),(1,b),(2,b),(3,b)\\}\\)\n\nWe can see that:\n\n\\(|A.B|=|A|.|B|\\)\n\\subsubsection{Cardinality of union and intersection}\n\n\\(|A\\lor B| = |A|+|B|-|A\\land B|\\)\n\\subsubsection{Cardinality of powerset}\n\n\\(|P(s)|=2^{|s|}\\)\n\n\\subsubsection{Cardinality of complement}\n\n\\(|a \\setminus b|=|a|-|a\\land b|\\)\n\n\\subsubsection{Cardinality of even/odd natural numbers}\n\nWhat about the cardinality of even numbers? Well, we can define a bijective function between each:\n\n\\(f(n)=2n\\)\n\nSimilarly for odd numbers:\n\n\\(f(n)=2n+1\\)\n\nSo these both have cardinality \\(\\aleph_0\\).\n\n", "meta": {"hexsha": "25e8904035380ca7a94aabb786f1ce3e269cd235", "size": 785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/algebraCardinality/01-01-cardinality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/algebraCardinality/01-01-cardinality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/algebraCardinality/01-01-cardinality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1463414634, "max_line_length": 98, "alphanum_fraction": 0.6675159236, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517061554854, "lm_q2_score": 0.905989829267587, "lm_q1q2_score": 0.8706124721942047}} {"text": "\\subsection{Hyperbolic trigonometric functions}\n\\label{basics:hyperbolic_trigonometric_functions}\n\nThe hyperbolic sine and cosine in \\texttt{SymPy} are denoted \\texttt{sinh} and \\texttt{cosh} respectively\nand \\texttt{SymPy} is smart enough to recognize them when simplifying expressions:\n\n\\small\n\\begin{verbatimtab}\n>>> simplify( (exp(x)+exp(-x))/2 )\ncosh(x)\n>>> simplify( (exp(x)-exp(-x))/2 )\nsinh(x)\n\\end{verbatimtab}\n\\normalsize\nRecall that $x=\\cosh(\\mu)$ and $y=\\sinh(\\mu)$ are defined as $x$ and $y$ coordinates of a point on the \nthe hyperbola with equation $x^2 - y^2 = 1$ and therefore satisfy the identity $\\cosh^2 x - \\sinh^2 x =1$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> simplify( cosh(x)**2 - sinh(x)**2 )\n1\n\\end{verbatimtab}\n\\normalsize", "meta": {"hexsha": "dc8924ad32087efbab031455e7f6f3ef32b2690e", "size": 744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "99.hyperbolic_functions_sympy_tutorial.tex", "max_stars_repo_name": "ivanistheone/sympy_tutorial", "max_stars_repo_head_hexsha": "fa13b4d82c9bdbf4d2fc6083e603dace36a00fc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-11-24T02:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-01T16:23:20.000Z", "max_issues_repo_path": "tex/99.hyperbolic_functions_sympy_tutorial.tex", "max_issues_repo_name": "minireference/sympytut_notebooks", "max_issues_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/99.hyperbolic_functions_sympy_tutorial.tex", "max_forks_repo_name": "minireference/sympytut_notebooks", "max_forks_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-05-02T13:07:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T01:16:18.000Z", "avg_line_length": 29.76, "max_line_length": 106, "alphanum_fraction": 0.7177419355, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9697854164256366, "lm_q2_score": 0.897695283896349, "lm_q1q2_score": 0.870571794716751}} {"text": "\\section{Matrix examples}\n\\subsection{Geometric transformations}\n\\textbullet \\textit{Scaling}: $y = Ax$ with $A = aI$ stretches a vector by the factor $|a|$ (or shrinks it when $|a| < 1$), and it flips the vector (reverses its direction) if $a < 0$\\\\\n\\textbullet \\textit{Dilation}: $y = Dx$, where D is a diagonal matrix, $D = diag(d1,d2)$. Stretches the vector x by different factors along the two different axes. (Or shrinks, if $|d_i| < 1$, and flips, if $di < 0$.)\\\\\n\\textbullet \\textit{Rotation Matrix (counter clockwise)}: \n$\ny = \n\\begin{bmatrix}\n cos \\theta & -sin \\theta \\\\\n sin \\theta & cos \\theta\n\\end{bmatrix}x\n$\\\\\n\\textbullet \\textit{Reflection}\nSuppose that y is the vector obtained by reflecting x through the line that passes through the origin, inclined $\\theta$ radians with respect to horizontal.\\\\\n$\ny = \n\\begin{bmatrix}\n cos (2\\theta) & sin(2\\theta) \\\\\n sin (2\\theta) & -cos (2\\theta)\n\\end{bmatrix}x\n$\\\\\n\\textbullet \\textit{Projection into a line}\nProjection of point x onto a set is the point in the set that is closest to x.\\\\\n$\ny = \n\\begin{bmatrix}\n (1/2)(1 + cos (2\\theta)) & (1/2)sin(2\\theta) \\\\\n (1/2)sin (2\\theta) & (1/2)(1 - cos (2\\theta))\n\\end{bmatrix}x\n$\n\\subsection{Selectors}\nAn $m \\times n$ selector matrix A is one in which each row is a unit vector (transposed):\n\\[\n\\begin{bmatrix}\n e^T_{k_1}\\\\\n .\\\\\n .\\\\\n e^T_{k_m}\\\\\n\\end{bmatrix}\n\\]\nWhen it multiplies a vector, it simply copies the $k_i$th entry of x into the $i$th entry of $y = Ax$:\\\\\n$y = (x_{k_1},x_{k_2},...,x_{k_m})$\\\\\n\\textbf{r:s matrix slicing}\\\\\n$A=[0_{m\\times(r-1)} I_{m\\times m} 0_{m \\times (n-s)}]$\\\\\nwhere $m=s-r+1$\n\\subsection{Incidence matrix}\n\\textbf{Directed graph}: A \\textit{directed graph} consists of a set of \\textit{vertices} (or nodes), labeled 1,...,n, and a set of \\textit{directed edges} (or branches), labeled 1,...,m. \\\\\n$\nA_{ij} = \\left\\{\n \\begin{array}{@{}ll@{}}\n 1, & \\text{edge j points to node i} \\\\\n -1, & \\text{edge j points from node i}\\\\\n 0, & \\text{otherwise}\n \\end{array}\\right.\n$\\\\\n\\subsection{Convolution}\nThe convolution of an n-vector a and an m-vector b is the (n + m - 1)-vector denoted c = a * b\\\\\n$c_k = \\sum_{i+j=k+1} a_ib_j, k=1,..,n+m-1$\\\\\n\\textbf{Properties of convolution}\\\\\n\\textbullet symmetric: $a * b = b * a$\\\\\n\\textbullet associative: $(a*b)*c = a*(b*c)$\\\\\n\\textbullet $a*b = 0$ implies that either $a = 0$ or $b = 0$\\\\\n\\textbullet A basic property is that for fixed a, the convolution a * b is a linear function of b; and for fixed b, it is a linear function of a, $a * b = T (b)a = T (a)b$ where where T(b) is the (n + m - 1) Ă— n matrix with entries\\\\\n$\nT(b)_{ij} = \\left\\{\n \\begin{array}{@{}ll@{}}\n b_{i-j+1}, & 1\\leq i-j+1 \\leq m\\\\\n 0, & \\text{otherwise}\n \\end{array}\\right.\n$\\\\\n\\textbf{Complexity of convolution}\\\\\n\\textbullet $c= a * b$: 2mn flops\\\\\n\\textbullet $T(a)b or T(b)a$: 2mn flops\\\\\n\\textbullet Convolution could be calculated faster using \\textit{fast Fourier transform (FFT)} : $5(m + n) log_2(m + n) flops$\\\\\n", "meta": {"hexsha": "5c7f31bdd792c7947f2ae6b12b283a2cf2e1d384", "size": 3023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 40.3066666667, "max_line_length": 233, "alphanum_fraction": 0.6394310288, "num_tokens": 1098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.971129093889291, "lm_q2_score": 0.8962513648201267, "lm_q1q2_score": 0.8703757758148101}} {"text": "\\section{Method of Moments}\n\nLet $X_1, \\ldots , X_ n \\stackrel{iid}{\\sim } \\mathbf{P}_{\\theta ^*}$ associated with model $(\\mathbb {E}, \\{ \\mathbf{P}_{\\theta }\\} _{\\theta \\in \\Theta })$, with $\\mathbb {E} \\subseteq \\mathbb {R}$ and $\\Theta \\subseteq \\mathbb {R^d}$, for some d $\\geq 1$\n\nPopulation moments:\\\\\n\n$m_k(\\theta) = \\mathbb{E}_{\\theta}[X^k_1], 1 \\leq k \\leq d$\\\\\n\nEmpirical moments:\\\\\n\n$\\widehat{m_k}(\\theta) = \\bar{X_n^k} = \\frac{1}{n} \\sum _{i=1}^{n}X_i^k$\n\nConvergence of empirical moments:\\\\\n\n$\\widehat{m_k} \\xrightarrow[n \\rightarrow \\infty]{P, a.s.} m_k$\\\\\n\n$(\\widehat{m_1}, \\ldots, \\widehat{m_d}) \\xrightarrow[n \\rightarrow \\infty]{P, a.s.} (m_1, \\ldots, m_d)$\n\nMOM Estimator $M$ is a map from the parameters of a model to the moments of its distribution. This map is invertible, (ie. it results into a system of equations that can be solved for the true parameter vector $\\theta^{*}$). Find the moments (as many as parameters), set up system of equations, solve for parameters, use empirical moments to estimate.\n\n$\\displaystyle \\psi : \\Theta \\displaystyle \\to \\mathbb {R}^ d$\\\\\n\n$\\displaystyle \\theta \\displaystyle \\mapsto (m_1(\\theta ), m_2(\\theta ), \\ldots , m_ d(\\theta ))$\\\\\n\n$M ^{-1}(m_1(\\theta ^*), m_2(\\theta ^*), \\ldots , m_ d(\\theta ^*))$\n\nThe MOM estimator uses the empirical moments:\\\\\n\n$M ^{-1}\\left( \\frac{1}{n} \\sum _{i = 1}^ n X_ i, \\frac{1}{n} \\sum _{i = 1}^ n X_ i^2, \\ldots , \\frac{1}{n} \\sum _{i = 1}^ n X_ i^ d \\right)$\\\\\n\n\n\nAssuming $M^{-1}$ is continuously differentiable at $M(0)$, the asymptotical variance of the MOM estimator is:\\\\\\\\\n\n$\\sqrt(n)(\\widehat{\\theta_n^{MM}} - \\theta) \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\Gamma)$\\\\\n\nwhere,\n\n$\\Gamma (\\theta )=\\left[\\frac{\\partial M^{-1}}{\\partial \\theta } (M(\\theta ))\\right]^{T} \\Sigma (\\theta )\\left[\\frac{\\partial M^{-1}}{\\partial \\theta } (M(\\theta ))\\right]$\n\n$\\Gamma(\\theta) = \\nabla_{\\theta}(M^{-1})^{T} \\Sigma \\nabla_{\\theta}(M^{-1}) $\n\n$\\Sigma_{\\theta}$ is the covariance matrix of the random vector of the moments $(X_1^1,X_1^2 \\ldots, X_1^d)$.", "meta": {"hexsha": "84c2942a521a954080ea49b96b7365d008e9bfd0", "size": 2052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Moments.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/Moments.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/Moments.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 47.7209302326, "max_line_length": 351, "alphanum_fraction": 0.6354775828, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.9124361515478209, "lm_q1q2_score": 0.8698026089065871}} {"text": "\\chapter{The Cartesian Product}\nThe \\emph{Cartesian product} $\\times$ is a binary operation on sets which produces a new set containing all ordered pairs where the first element comes from the left-hand set and the second element comes from the right-hand set. If $A = \\{a,b,c,\\dots\\}$ and $\\Gamma = \\{\\alpha,\\beta,\\gamma,\\dots\\}$, then $A \\times \\Gamma = \\{(a,\\alpha), (a,\\beta), \\dots, (b,\\alpha), \\dots\\}$.\nSpecifically, the Cartesian product is defined as\n\\[ A \\times B = \\{(a,b) : a \\in A, b \\in B\\}. \\]\nWhile we call it a binary operation, we can have an arbitrary number of sets upon which it can act; consider the generalization to $n$ sets\n\\[ A \\times B \\times C \\times \\cdots = \\{(a,b,c,\\dots) : a \\in A, b \\in B, c \\in C, \\dots\\}, \\]\nwhich produces an $n$-tuple. \nWe use the Cartesian product to describe the domain and range of new binary functions that we create. If we imagine a new binary operation $\\odot$ which acts upon sets $A$ and $B$ and maps to $C$, we could define it as\n\\[ \\odot : A \\times B \\to C. \\]\nFor the same of brevity, we often use an exponent to represent the number of times a Cartesian product has been taken over the same vector space, so\n\\[ A \\times A \\times A = A^3 \\]\nand\n\\[A \\times A \\times B \\times B \\times B = A^2 \\times B^3. \\]\n", "meta": {"hexsha": "9ef19da3184fa2f42ed72361495c433ac595c6b9", "size": 1273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/cartesian_product.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/cartesian_product.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/cartesian_product.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.9285714286, "max_line_length": 377, "alphanum_fraction": 0.6849960723, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.980280869588304, "lm_q2_score": 0.8872045855155176, "lm_q1q2_score": 0.8697096825918824}} {"text": "\\section{Decision Tree Learning (20 points)}\n \nIn this problem, we want to construct a decision tree to find out if a person will enjoy beer.\n\n\\paragraph{Definitions.} Let there be $k$ binary-valued attributes in the data. \n\nWe pick an attribute that maximizes the gain at each node:\n\\begin{equation}\\label{G}\n%\tG = \\max [I(D) - (I(D_L) + I(D_R))];\n\tG = I(D) - (I(D_L) + I(D_R));\n\\end{equation}\nwhere $D$ is the given dataset, and $D_L$ and $D_R$ are the sets on left and right hand-side branches after division. Ties may be broken arbitrarily. \n\nThere are three commonly used impurity measures used in binary decision trees: Entropy, Gini index, and Classification Error. In this problem, we use Gini index and define $I(D)$ as follows\\footnote{As an example, if $D$ has 10 items, with 4 positive items (\\emph{i.e.} 4 people who enjoy beer), and 6 negative items (\\emph{i.e.} 6 who do not), we have $I(D) = 10 \\times (1 - (0.16 + 0.36))$.}:\n\\[\n\tI(D) = |D| \\times \\left(1-\\sum_i p_i^2\\right),\n\\]\nwhere:\n\\begin{itemize}\n\t\\item $|D|$ is the number of items in $D$;\n\t\\item $1 - \\sum_i p_i^2$ is the gini index;\n\t\\item $p_i$ is the probability distribution of the items in $D$, or in other words, $p_i$ is the fraction of items that take value $i\\in\\{+,-\\}$. Put differently, $p_+$ is the fraction of positive items and $p_-$ is the fraction of negative items in $D$.\n\\end{itemize}\n\nNote that this intuitively has the feel that the more evenly-distributed the numbers are, the lower the $\\sum_i p_i^2$, and the larger the impurity.\n\n\\subquestion{(a) [10 Points]}\nLet $k = 3$. We have three binary attributes that we could use: ``likes wine'', ``likes running'' and ``likes pizza''. Suppose the following:\n\\begin{itemize}\n\t\\item There are 100 people in sample set, 40 of whom like beer and 60 who don't.\n\t\\item Out of the 100 people, 50 like wine; out of those 50 people who like wine, 20 like beer.\n\t\\item Out of the 100 people, 30 like running; out of those 30 people who like running, 20 like beer.\n\t\\item Out of the 100 people, 80 like pizza; out of those 80 people who like pizza, 30 like beer.\n\t\\end{itemize}\n\\task{What are the values of $G$ (defined in Equation~\\ref{G}) for wine, running and pizza attributes? Which attribute would you use to split the data at the root if you were to maximize the gain $G$ using the gini index metric defined above?}\n\n\n\\subquestion{(b) [10 Points]}\nLet's consider the following example:\n\\begin{itemize}\n\\item There are $100$ attributes with binary values $a_1, a_2, a_3, \\ldots, a_{100}$.\n\\item Let there be one example corresponding to each possible assignment of 0's and 1's to the values $a_1, a_2, a_3 \\ldots, a_{100}$. (Note that this gives us $2^{100}$ training examples.)\n\\item Let the values taken by the target variable $y$ depend on the values of $a_1$ for $99 \\%$ of the datapoints. More specifically, of all the datapoints where $a_1=1$, let $99 \\%$ of them are labeled $+$. Similarly, of all the datapoints where $a_1 = 0$, let $99 \\%$ of them are labeled with $-$. (Assume that the values taken by $y$ depend on $a_2, a_3, \\dots, a_{100}$ for fewer than $99\\%$ of the datapoints.)\n\\item Assume that we build a complete binary decision tree (\\emph{i.e.}, we use values of all attributes).\n\\end{itemize}\n\n\\task{Explain what the decision tree will look like. (A one line explanation will suffice.) Also, in 2-3 sentences, identify what the desired decision tree for this situation should look like to avoid overfitting, and why.(The desired decision tree isn't necessarily a complete binary decision tree)}\n\n\n\\subsection*{What to submit}\n\\begin{enumerate}[(i)]\n\t\\item Values of $G$ for wine, running and pizza attributes. [part (a)]\n\t\\item The attribute you would use for splitting the data at the root. [part (a)]\n\t\\item Explain what the decision tree looks like in the described setting. Explain how a decision tree should look like to avoid overfitting. (1-2 lines each) [part (b)]\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "fb915cf46c379c39e9e70850286dc4d889d83078", "size": 3953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_dtree.tex", "max_stars_repo_name": "x3pi/mining-massive-datasets", "max_stars_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-24T01:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:54:57.000Z", "max_issues_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_dtree.tex", "max_issues_repo_name": "x3pi/mining-massive-datasets", "max_issues_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_dtree.tex", "max_forks_repo_name": "x3pi/mining-massive-datasets", "max_forks_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-09-11T17:31:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T20:33:33.000Z", "avg_line_length": 68.1551724138, "max_line_length": 416, "alphanum_fraction": 0.7204654693, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.9324533144915912, "lm_q1q2_score": 0.869469181956071}} {"text": "\n\\section{ Linear regression }\n\\subsection{Stochastic gradient descendent}\n\n\nStochastic gradient descendent (SGD) is a sequential version of the gradient descent. Instead of considering the full batch gradient on all $N$\ntraining data points, we consider a stochastic version of the gradient. First, pick a training data point $(x_n, y_n)$ uniformly random\n(hence the name 'stochastic') and consider only the error on that data point. \\cite{LFD}\n\nThe gradient of this single data point's error is used for the weight update in exactly the same that the gradient was used in batch gradient descent.\n\nAnother variants are the \\textbf{mini-batch gradient descent} and the \\textbf{batch gradient descendent}, the differences among them are the size of the batch: one for the pure stochastic gradient descendent, between 32 or 64 for the mini-batch variation and more than that for the batch gradient descendent.\n\n\n\\subsection{Pseudo - inverse algorithm}\nPseudo inverse algorithm also known as \\textbf{linear regression algorithm} or \\textbf{ordinary least squares}(OLS) is based on minimizing the squared error between the \nprojection matrix $h(x) = w^T x$ and $y$, the target vector, where $x \\in \\mathbb R^{N \\times (d+1)}$ is the feature matrix and\n$N \\in \\mathbb N$ the training data size. \n\n\\begin{equation*}\n E_{in}(w) = \\frac{1}{N} \\sum_{n=1}{N} (w^T x_n - y)^2 \n = \\frac{1}{N} \\| Xw -y \\|^2 \n\\end{equation*}\n\nWhere $\\|.\\|$ is the Euclidean norm of a vector.\n\nSince $E_{in}(w)$ is differentiable we can use standard matrix calculus to find the $w$ that minimizes $E_{in}$ with respect to w:\n\n$$\\nabla E_{in}(w) = \\frac{2}{N}(X^TXw - X^T y) =0$$\nFinally to get $\\nabla E_{in}(w)$ to be $0$, we should find a $w$ that satisfies\n\n$$X^TXw = X y$$\n\nIf $X^TX$ is invertible, $w = X^\\dagger y$ where $X^\\dagger = (X^T X)^{-1}$ is the \\texttt{pseudo-inverse} of $X$. The resulted $w$ is the unique optimal solution that minimizes $E_{in}$. Otherwise a pseudo-inverse can still be defined, but the solution will not be unique.\n\nIn practice, $X^TX$ is invertible in most of the cases since $N$ is often much more bigger than $d+1$, so there will likely be $d+1$ linearly independent vector $x_n$.\n\n\n\n\\subsection{Exercise 1}\n\nEstimate a linear regression model from the data provided by the\nfeature vectors (Average intensity, Symmetry)\nusing both the pseudo-inverse algorithm and the Stochastic Gradient Descent (SGD).\nThe labels will be $\\{-1,1\\}$,\none for each feature vector of each number.\nDraw the solutions obtained together with the data used in the fitting.\nAssess the goodness of the result using $E_{in}$ and $E_{out}$\n(for Eout calculate the predictions using the data from the test file).\n\n\n\n\\subsubsection{Error}\n\n\nAs we have said the error is the mean squared error:\n$$E_{out}(h) = \\mathbb E [(h(x) -y)^2]$$\n $$E_{in}(w) = \\frac{1}{N} \\| Xw -y \\|^2$$\n\nA direct implementation is\n\n\\begin{minted}{python}\n def Error(x,y,w):\n '''quadratic error \n INPUT\n x: input data matrix\n y: target vector\n w: vector to \n\n OUTPUT\n quadratic error >= 0\n '''\n error_times_n = np.linalg.norm(x.dot(w) - y.reshape(-1,1))**2\n \n return error_times_n/len(x)\n\n \\end{minted}\n\n \n\n For the euclidean norm we have used \\texttt{np.linalg.norm} \\cite{norm} numpy function.\n\n The gradient computation is direct too:\n\n $$\\nabla E_{in}(w) = \\frac{2}{N}(X^TXw - X^T y)= \\frac{2}{N}(X^T(Xw - y))$$\n \n\\begin{minted}{python}\n def dError(x,y,w):\n ''' gradient\n OUTPUT\n column vector\n '''\n\n return (2/len(x)*(x.T.dot(x.dot(w) - y.reshape(-1,1))))\n \\end{minted}\n\n \\subsubsection{Interpretation of the mean squared error, E}\n The mean squared error function $E: \\mathbb R ^d \\longrightarrow \\mathbb R^+_0$ measures the average of the squared difference between the estimated values and the actual value\\cite{MSE}. Hence, the nearer to zero, the better.\n\n \n \n\n\\subsubsection{Pseudo-inverse algorithm}\n\nAs we have described in pseudo inverse introduction, firstly we need to compute the pseudo-inverse. For that we have use \\texttt{np.linalg.pinv} \\cite{pseudo-inverse}function from numpy library.\n\n\\begin{minted}{python}\n def pseudoInverseMatrix ( X ):\n '''\n INPUT \n X: is a matrix (must be a np.array) to use transpose and dot method\n OUTPUT\n hat matrix \n '''\n\n '''\n #S =( X^TX ) ^{-1}\n simetric_inverse = np.linalg.inv( X.T.dot(X) )\n\n # S X^T = ( X^TX ) ^{-1} X^T\n return simetric_inverse.dot(X.T)\n '''\n return np.linalg.pinv(X)\n\\end{minted}\n\nFinally we have to compute $w = X^\\dagger y$\n\n\n\\begin{minted}{python}\n def pseudoInverse(X, Y):\n ''' \n INPUT\n X is the feature matrix \n Y is the target vector (y_1, ..., y_m)\n \n OUTPUT: \n w: weight vector\n '''\n X_pseudo_inverse = pseudoInverseMatrix ( X )\n Y_transposed = Y.reshape(-1, 1)\n \n w = X_pseudo_inverse.dot( Y_transposed)\n \n return w\n\n \\end{minted}\n\n \\subsubsection{Pseudo-inverse linear regression model}\n\n After computing the algorithm we obtain:\n\n\\begin{verbatim}\n___ Goodness of the Pseudo-inverse fit ___\n\n Ein: 0.07918658628900395\n Eout: 0.1309538372005258\n\nEvaluating output training data set\nInput size: 1561\nBad negatives : 7\nBad positives : 3\nAccuracy rate : 99.35938500960923 %\n\nEvaluating output test data set\nInput size: 424\nBad negatives : 1\nBad positives : 7\nAccuracy rate : 98.11320754716981 %\n\n\\end{verbatim}\n\n Which means that the $w$ computed by our pseudo-inverse algorithm by the training data set has a $E_{in}(w) = 0.079$ and by the test data $E_{out}(w) = 0.131$, for our experiment it is a good fit, because it is closed enough to zero. In addition, if we evaluate the data classification,\n from $1561$ training data it only misclassify $10$ points, whereof 7 was truly positives. The accuracy rate $(\\frac{\\text{good classified data}}{\\text{data set size}})$\n is $99.358 \\%$, which continues being really good.\n\n Initially, we could think that it classifies the positives values better, but if we analyse the output from test data set, there are more negatives values misclassified, so we cannot establish any relation. Moreover here the accuracy rate is $98.113 \\%$\n\n Finally, a graphic representation for the solutions is\n\n \n \\includegraphics[width=\\linewidth]{2_1_pseudo_inverse.png}\n\n\n Something really import about this method is that it is equal or better than the gradient descent, therefore in the next experiments\n we are going to compare the results which it. \n\n \\subsubsection{How have we plotted the regression line.}\n\n Firstable, to draw a line we need two points.\n\n Therefore we use the sign um to classify the numbers, we are going to find two points in $\\mathbb R^2$ that their estimation is zero, which means that they are in the middle of classification (the regression line).\n\n The obtained weight vector $w^T = (w_1,w_2,w_3)$, means that for a point $(x,y) \\in \\mathbb R^2$\n its estimation is $h(x,y) = (1,x,y) w = w_1 + w_2x + w_3y$.\n\n To calculate the two points we are going to equalize $h(x,y)=0$ and from the infinity solutions we would compute two:\n\n if $x=0$ then $y = \\frac{- w_1}{w_3}$, and if $x=1$ then $y = \\frac{- w_1 - w_2}{w_3}.$\n \n\n The related code is\n\n\n \\begin{minted}{python}\n # regression line\n # x= 0\n symmetry_for_cero_intensity = -w[0]/w[2]\n\n # x = 1, 0 = w0 + w1 * w2 * x2\n # then y = (-w0 - w1) /w2\n symmetry_for_one_intensity= (-w[0] - w[1])/w[2]\n\n # plotting order\n plt.plot([0, 1],\n [symmetry_for_cero_intensity,symmetry_for_one_intensity],\n 'k-',\n label=(title+ ' regression'))\n \n \\end{minted}\n\n \n \\subsubsection{Stochastic gradient descendent}\n\n Based on the description of the algorithm, we have done two implementations:\n\n This one is strictly based on the classroom's slides, however depending on the \\texttt{batch\\_size} the exact number of iterations will be\n$$\\texttt{max\\_iter} \\times \\lfloor \\frac{ \\texttt{(len(y))}}{\\texttt{ batch\\_size}} \\rfloor$$ \n\n \n \\begin{minted}{python}\ndef sgd(x,y, eta = 0.01, max_iter = 1000, batch_size = 32, error=10**(-10)):\n '''\n Stochastic gradient descent\n INPUT \n x: data set\n y: target vector\n eta: learning rate\n max_iter \n\n OUTPUT \n w: weight vector\n '''\n \n #initialize data\n w = np.zeros((x.shape[1], 1), np.float64)\n n_iterations = 0\n\n len_x = len(x)\n x_index = np.arange( len_x )\n batch_start = 0\n w_error = Error(x,y,w)\n\n while n_iterations < max_iter and w_error > error :\n \n #shuffle and split the same into a sequence of mini-batches\n np.random.shuffle(x_index)\n for batch_start in range(0, len_x, batch_size):\n iter_index = x_index[ batch_start : batch_start + batch_size]\n\n \n w = w - eta* dError(x[iter_index, :], y[iter_index], w)\n \n n_iterations += 1\n w_error = Error(x,y,w)\n\n \n return w\n \\end{minted}\n\n In order to control exactly the numbers of iterations we are going to use this function: \n\n \\begin{minted}{python}\n def sgd_exact_number_iter(x,y, eta = 0.01,\n max_iter = 1000, batch_size = 32, error = 10**(-10)):\n '''\n Stochastic gradient descent\n INPUT \n x: data set\n y: target vector\n eta: learning rate\n max_iter \n OUTPUT \n w: weight vector\n '''\n #initialize data\n w = np.zeros((x.shape[1], 1), np.float64)\n \n n_iterations = 0\n batch_start = 0\n len_x = len(x)\n \n x_index = np.arange( len_x )\n w_error = Error(x,y,w)\n \n while n_iterations < max_iter and w_error > error:\n #shuffle and split the same into a sequence of mini-batches\n if batch_start == 0:\n x_index = np.random.permutation(x_index)\n iter_index = x_index[ batch_start : batch_start + batch_size]\n\n w = w - eta* dError(x[iter_index, :], y[iter_index], w)\n \n n_iterations += 1\n\n batch_start += batch_size\n if batch_start >= len_x: # if end, restart\n batch_start = 0\n \n w_error = Error(x,y,w)\n\n\n return w\n\n \\end{minted}\n\n\n Due to the fact that this is a stochastic method and the gradient's descent does not reduce the error in every step, there are other variations, for example we can save and return only the $w$ found which has the less error.\n\n\n \\begin{minted}{python}\n def sgd_save_w(x,y, eta = 0.01, max_iter = 1000,\n batch_size = 32, error = 10**(-10)):\n '''\n Stochastic gradient descent\n INPUT \n x: data set\n y: target vector\n eta: learning rate\n max_iter \n OUTPUT \n w: weight vector\n '''\n #initialize data\n w = np.zeros((x.shape[1], 1), np.float64)\n \n n_iterations = 0\n batch_start = 0\n len_x = len(x)\n \n x_index = np.arange( len_x )\n w_error = Error(x,y,w)\n\n #IMPROVEMENT\n best_error = w_error\n best_w = w \n \n while n_iterations < max_iter and w_error > error:\n #shuffle and split the same into a sequence of mini-batches\n if batch_start == 0:\n x_index = np.random.permutation(x_index)\n iter_index = x_index[ batch_start : batch_start + batch_size]\n\n w = w - eta* dError(x[iter_index, :], y[iter_index], w)\n \n n_iterations += 1\n\n batch_start += batch_size\n if batch_start >= len_x: # if end, restart\n batch_start = 0\n \n w_error = Error(x,y,w)\n\n # IMPROVEMENT \n if w_error < best_error:\n best_w = w\n best_error = w_error\n\n\n return best_w\n\n \\end{minted}\n\n This algorithm is interesting because it returns the best $w$ found and has (in order) the same computational cost. \n\n\n \\paragraph{Initial point}\n\n Another consideration is that as we know, it is really important the chosen of the initial point in gradient descendent. However, due to the fact that we are working with the mean quadratic error, we know that only exists one global minimum, so here the relevance of the initial point is to reduce iterations. Therefore we theoretically do not have more information, we have chosen the $w_0 = 0 \\in \\mathbb R^d.$\n\n\n \\paragraph{The experiment result} We are going to execute the \\texttt{sgd} algorithm (our version) with $\\eta = 0.01$ batch sizes $1,32, 200 \\text{ and } \\texttt{len(y)}$ and the numbers of steps $50 \\text{ and } 300$.\n\n\n \n\n\n\\begin{table}[H]\n\\begin{tabular}{|c|c|c|c|c|c|}\n\\hline\n Batch size & Iterations & $E_{in}$ & $E_{out}$ & Training accuracy rate $(\\%)$ & Test accuracy rate $(\\%)$ \\\\ \\hline\n 1 & 50 & 0.0798 & 0.131 & 99.423 & 98.349 \\\\ \\hline\n 32 & 50 & 0.081 & 0.133 & 99.295 & 98.113 \\\\ \\hline\n200 & 50 & 0.082 & 0.135 & 99.424 & 98.113 \\\\ \\hline\n 1561 & 50 & 0.404 & 0.428 & 99.167 & 95.28 \\\\ \\hline \n\\end{tabular}\n\\end{table}\n\n\nAs we can see, as bigger is the batch size the worse is the error.\nSomething really interesting is that we are minimizing based on the quadratic error, but it does not mean we are minimizing the accuracy error ( there is a correlation but not a coincidence. A good example of that is if we compare bath's size 200 with bath's size 32. \nAs we increase the numbers of iterations the general error decrease (see 300 steps). \n\n\nAnother interesting observation is that for batch's size one, 200 iterations is worse than 50, this is because we are oscillating over the solution. The algorithm we have described which saves the best $w$, \\texttt{sgd\\_save\\_w} would solve this problem. \n\n\\includegraphics[angle=90,width=\\linewidth]{2_1_comparatives_50.png}\n\n\\includegraphics[angle=90,origin=c,width=\\linewidth]{2_1_comparatives_300.png}\n\n\n \\paragraph{50 steps} \n \\begin{verbatim}\n\n___ Goodness of the Stochastic Gradient Descendt (SGD) fit ___\n\n\n\tSGD, batch size 1\nEin: 0.07981803904587495\nEout: 0.13188855705205335\n\nEvaluating output training data set\nFor w^T = [[-1.15690746 -1.20909308 -0.50379833]]\nInput size: 1561\nBad negatives : 6\nBad positives : 3\nAccuracy rate : 99.4234465086483 %\n\nEvaluating output test data set\nFor w^T = [[-1.15690746 -1.20909308 -0.50379833]]\nInput size: 424\nBad negatives : 0\nBad positives : 7\nAccuracy rate : 98.34905660377359 %\n\n--- End of a section, press any enter to continue ---\n\n\n\tSGD, batch size 32\nEin: 0.08183880846320654\nEout: 0.13300563169544255\n\nEvaluating output training data set\nFor w^T = [[-1.23840622 -0.24445313 -0.45432575]]\nInput size: 1561\nBad negatives : 8\nBad positives : 3\nAccuracy rate : 99.29532351057014 %\n\nEvaluating output test data set\nFor w^T = [[-1.23840622 -0.24445313 -0.45432575]]\nInput size: 424\nBad negatives : 1\nBad positives : 7\nAccuracy rate : 98.11320754716981 %\n\n--- End of a section, press any enter to continue ---\n\n\n\tSGD, batch size 200\nEin: 0.0824097083428238\nEout: 0.13514678139988967\n\nEvaluating output training data set\nFor w^T = [[-1.21138905 -0.14846307 -0.44806566]]\nInput size: 1561\nBad negatives : 6\nBad positives : 3\nAccuracy rate : 99.4234465086483 %\n\nEvaluating output test data set\nFor w^T = [[-1.21138905 -0.14846307 -0.44806566]]\nInput size: 424\nBad negatives : 1\nBad positives : 7\nAccuracy rate : 98.11320754716981 %\n\n--- End of a section, press any enter to continue ---\n\n\n\tSGD, batch size 1561\nEin: 0.40484272492435486\nEout: 0.42805781278130317\n\nEvaluating output training data set\nFor w^T = [[-0.42953442 -0.04548081 -0.23773542]]\nInput size: 1561\nBad negatives : 1\nBad positives : 12\nAccuracy rate : 99.16720051249199 %\n\nEvaluating output test data set\nFor w^T = [[-0.42953442 -0.04548081 -0.23773542]]\nInput size: 424\nBad negatives : 0\nBad positives : 20\nAccuracy rate : 95.28301886792453 %\n\n--- End of a section, press any enter to continue ---\n\n\\end{verbatim}\n\n \n \\paragraph{300 steps} \n\\begin{verbatim}\n\n\tSGD, batch size 1\nEin: 0.07991429824341009\nEout: 0.13043428762931666\n\nEvaluating output training data set\nFor w^T = [[-1.14204678 -1.25437994 -0.4976879 ]]\nInput size: 1561\nBad negatives : 7\nBad positives : 3\nAccuracy rate : 99.35938500960923 %\n\nEvaluating output test data set\nFor w^T = [[-1.14204678 -1.25437994 -0.4976879 ]]\nInput size: 424\nBad negatives : 0\nBad positives : 7\nAccuracy rate : 98.34905660377359 %\n\n--- End of a section, press any enter to continue ---\n\n\tSGD, batch size 32\nEin: 0.08063407701065878\nEout: 0.13581316178349648\n\nEvaluating output training data set\nFor w^T = [[-1.18587205 -0.6497891 -0.48419008]]\nInput size: 1561\nBad negatives : 5\nBad positives : 3\nAccuracy rate : 99.48750800768738 %\n\nEvaluating output test data set\nFor w^T = [[-1.18587205 -0.6497891 -0.48419008]]\nInput size: 424\nBad negatives : 0\nBad positives : 7\nAccuracy rate : 98.34905660377359 %\n\n--- End of a section, press any enter to continue ---\n\n\n\tSGD, batch size 200\nEin: 0.08138110980377243\nEout: 0.1344240103546277\n\nEvaluating output training data set\nFor w^T = [[-1.23721465 -0.24176584 -0.46011533]]\nInput size: 1561\nBad negatives : 7\nBad positives : 3\nAccuracy rate : 99.35938500960923 %\n\nEvaluating output test data set\nFor w^T = [[-1.23721465 -0.24176584 -0.46011533]]\nInput size: 424\nBad negatives : 1\nBad positives : 7\nAccuracy rate : 98.11320754716981 %\n\n--- End of a section, press any enter to continue ---\n\n\n\tSGD, batch size 1561\nEin: 0.085568968925448\nEout: 0.13713701679830562\n\nEvaluating output training data set\nFor w^T = [[-1.15962485 -0.13812568 -0.43405538]]\nInput size: 1561\nBad negatives : 5\nBad positives : 3\nAccuracy rate : 99.48750800768738 %\n\nEvaluating output test data set\nFor w^T = [[-1.15962485 -0.13812568 -0.43405538]]\nInput size: 424\nBad negatives : 0\nBad positives : 7\nAccuracy rate : 98.34905660377359 %\n\n--- End of a section, press any enter to continue ---\n\n\\end{verbatim}\n\n\n\n\\section{Experiment }\n\n\\subsection{a) Generate a training sample}\n\nWe are going to use a uniform generation:\n\n\\begin{minted}{python}\ndef simula_unif(N, d, size):\n ''' generate a trining sample of N points\nin the square [-size,size]x[-size,size]\n'''\n return np.random.uniform(-size,size,(N,d))\n \n\\end{minted}\n\nAfter fixed random seed to $1$.\n\nThe final 2D map is\n\n\\includegraphics[width=\\linewidth]{2_2_a_training_sample.png}\n\n\\subsection{b) Labels, noise and map}\n\nb) Let's consider the function $f(x_1, x_2) = sign((x_1 - 0.2)^2 + x_2^2 - 0.6)$ that we will use to assign a label to each point of the previous sample. We introduce noise on the labels, randomly changing the sign of 10 \\% of them.\nDraw the obtained labels map.\n\n\nBefore plotting, it is important to have in mind that a circumference with radius $r$ and center $(c_1, c_2) \\in \\mathbb R^2$ are the points $(x_1, x_2) \\in \\mathbb R^2$ that verify \n\n\\[ (x_1 - c_1)^2 + (x_2 - c_2)^2 = r^2\\]\n\nTherefore looking at $f$ it is easy to think that we are going to see a circle of radius $\\sqrt{0.6}$ and center $(0.2, 0)$.\n\nThe plotting is\n\n\\includegraphics[width=\\linewidth]{/2_2_b_labelled_before_noise.png}\n\nIn order to introduce noise on the label we are going to change randomly the sign of the $10\\%$ of the labels obtained by $b$.\n\n\n\n\\begin{minted}{python}\n#labels \ny = np.array( [f(x[0],x[1]) for x in training_sample ])\n\nindex = list(range(size_training_example))\nnp.random.shuffle(index)\n\npercent_noisy_data = 10.0\nsize_noisy_data = int((size_training_example *percent_noisy_data)/ 100 )\n\n\nnoisy_y = np.copy(y)\nfor i in index[:size_noisy_data]:\n noisy_y[i] *= -1\n\n \\end{minted}\n\n As we can see the idea behind the snippet is simple: The noised labels would be a copy of the original ones and $10\\%$ of the data would change their sign.\n\n The final map is :\n\n\n \\includegraphics[width=\\linewidth]{2_2_b_labelled_after_noise.png}\n \n\n \\subsection{ Estimate the fitting error of $E_{in}$ using SGD}\n\n \\subsubsection{Experiment c}\n Using $(1, x_1, x_2)$ as feature vector, fit a linear regression model to the generated datasets and estimate the weights w. Estimate the fitting error of Ein using Stochastic Gradient Descent (SGD).\n\n Having in mind the observation in the last subsection that the labels follow a circumference's equation with a bit of noise, a linear regression model it is not going to be the best approach.\n\n The experiment results are:\n\\begin{verbatim}\nEXPERIMENT (c) \n\n\tSGD, batch size 5\nEin: 0.9038395322567018\n\nEvaluating output training data set\nFor w^T = [[ 0.05824863 -0.51637342 0.06313758]]\nInput size: 1000\nBad negatives : 163\nBad positives : 212\nAccuracy rate : 62.5 %\n\\end{verbatim}\n\n\nRemember that the bad negatives are the points that the regression classify in negative but they are positives and the bad positives are the negative ones that are classify as a positives.\n\nFinally the accuracy rate was the corrected classify data divided by the input size, so it is not a good model due to the fact that the accuracy rate is so close to a random one, that it would theoretically have a $50\\%$ of accuracy rate.\n\nA visual representation of the projection is\n\n\n\\includegraphics[width=\\linewidth]{2_2_c_linear_regression.png}\n\n\\subsubsection{d) Repetition of the experiment}\n\nIn order to see that the last result was not hazaour we are going to repeat the experiment 1000 times, the result is:\n\n\\begin{verbatim}\n\n EXPERIMENT (d), lineal regression\n\nThe mean value of E_in in all 1000 experiments is: 0.9270571984798377\nThe mean value of E_out in all 1000 experiments is: 0.9330084274789892\n\n\\end{verbatim}\n\n\nSo as we can se the mean error is even worse hence, our linear regression is not a good one.\n\n\\subsubsection{e) Quadratic adjustment}\n\ne) Assess how good you consider the fit with this linear model is according to the mean values obtained for Ein and Eout. Repeat the same previous experiment but using non-linear characteristics. Now, we will use the following feature vector: $\\phi_2(x) =(1,x_1,x_2,x_1 x_2, x_1^2, x_2^2)$. Fit the new linear regression model and calculate the new vector of weights w. Calculate the average errors of Ein and Eout. Which model do you consider the most appropriate according to the average errors for Ein and Eout?\n\n\n\nNow, instead of using a linear features vector, we are going to use a quadratic one\n\n\\begin{minted}{python}\n def quadraticFeatureVector(x_n):\n '''\n INPUT \n xn = (x1,x2) vector of coordinates \n \n '''\n return np.array([ 1,\n x_n[0],\n x_n[1],\n x_n[0]*x_n[1],\n x_n[0]* x_n[0],\n x_n[1]* x_n[1] ])\n\n \\end{minted}\n\n We know that the function is a circumference with a 10\\% of noise, so apriori we now that our target function is going to be\n\n \n $$h(x,y) = (x-0.2)^2 + y^2 -0.6 = x^2 - 0.4x + 0.04 + y^2 - 0.6 = x^2 + y^2 - 0.4x - 0.56$$\n\n What means that our target weight vector is goint to be\n\n $$w_t = (-0.56, -0.4, 0,0,1,1)$$\n\n Moreover due to the fact that we are introducing 10\\% of noisy our accuracy level must be around $90\\%$\n\n After $1000$ iterations we obtain:\n\n \\begin{verbatim}\n SGD, batch size 5, number iterations 1000\nEin: 0.5724680127717665\n\nEvaluating output training data set\nFor w^T = \n[[-0.67345368 -0.45209455 -0.0521589 0.07569398 0.92011803 1.23673771]]\nInput size: 1000\nBad negatives : 94\nBad positives : 55\nAccuracy rate : 85.1 %\n\n\\end{verbatim}\n\n \\includegraphics[width=\\linewidth]{2_3_parabolle.png}\n\n \n \n The results are close to our first approach,\n \n but apriori, for $1000$ iterations they seen a bit bad.\n\n However if we analyse how the error, accuracy rate and $w$ are evoluting over $10, 50, 100, 200, 500, 700, 1000$ we clearly see that the error is improving, so the iterations were not enought.\n\n Something interesting is that the $700$ iterations have better accuracy rate than 1000, this is for the same reason we explained at exercise 1; we are minimazing the error, not the accuracy rate. \n \n\n \\begin{verbatim}\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 10\nEin: 0.96683465968506\n\nEvaluating output training data set\nFor w^T =\n[[ 0.02353559 -0.04212481 -0.00067979 0.00785992 0.02654321 0.03756063]]\nInput size: 1000\nBad negatives : 0\nBad positives : 474\nAccuracy rate : 52.6 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 50\nEin: 0.8964601273439083\n\nEvaluating output training data set\nFor w^T =\n [[-0.00103819 -0.136871 -0.01033269 0.00363211 0.1056979 0.14178948]]\nInput size: 1000\nBad negatives : 34\nBad positives : 266\nAccuracy rate : 70.0 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 100\nEin: 0.8337613668693657\n\nEvaluating output training data set\nFor w^T = [[-0.04576936 -0.244725 -0.00396614 0.015827 0.19350407 0.24068118]]\nInput size: 1000\nBad negatives : 64\nBad positives : 198\nAccuracy rate : 73.8 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 200\nEin: 0.751970586436338\n\nEvaluating output training data set\nFor w^T = [[-0.16858105 -0.3725849 -0.01499836 0.02664101 0.30993404 0.4367047 ]]\nInput size: 1000\nBad negatives : 93\nBad positives : 121\nAccuracy rate : 78.6 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 500\nEin: 0.6352766784644138\n\nEvaluating output training data set\nFor w^T = \n[[-0.41975341 -0.46092311 -0.02902233 0.06514428 0.6286317 0.84761192]]\nInput size: 1000\nBad negatives : 80\nBad positives : 72\nAccuracy rate : 84.8 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 700\nEin: 0.5997408279310205\n\nEvaluating output training data set\nFor w^T = \n[[-0.53430804 -0.46110075 -0.0464511 0.06892706 0.76915291 1.04094009]]\nInput size: 1000\nBad negatives : 78\nBad positives : 63\nAccuracy rate : 85.9 %\n\nFor one experiment:\n\n SGD, batch size 5, number iterations 1000\nEin: 0.5724680127717665\n\nEvaluating output training data set\nFor w^T = \n[[-0.67345368 -0.45209455 -0.0521589 0.07569398 0.92011803 1.23673771]]\nInput size: 1000\nBad negatives : 94\nBad positives : 55\nAccuracy rate : 85.1 %\n\n\\end{verbatim}\n\n\n\\subsubsection{Mean error and conclusion}\n\n\nIn order to see the last result was not hazaour we are going to repeat the experiment 1000 times, the result is:\n\n\n\\begin{verbatim}\nThe mean value of E_in in all 1000 experiments is: 0.600107053636983\nThe mean value of E_out in all 1000 experiments is: 0.6058641910896161\n\\end{verbatim}\n\nMore or less the error is the same, so we can trust that a good adjustment is a quadratic one.\n\nSomething which we have known a priori, because we knew our target vector (something that in real life does not happen).\n\n", "meta": {"hexsha": "3ed103d0a9b8a898918aeea6d79ca7eb13cbc1ca", "size": 27492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "practica1/memory/linear_regression.tex", "max_stars_repo_name": "BlancaCC/aprendizaje-automatico", "max_stars_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practica1/memory/linear_regression.tex", "max_issues_repo_name": "BlancaCC/aprendizaje-automatico", "max_issues_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-04T14:03:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:03:37.000Z", "max_forks_repo_path": "practica1/memory/linear_regression.tex", "max_forks_repo_name": "BlancaCC/aprendizaje-automatico", "max_forks_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2764505119, "max_line_length": 514, "alphanum_fraction": 0.6668485378, "num_tokens": 8079, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.9294403979493139, "lm_q1q2_score": 0.8693488373528583}} {"text": "\n\\subsection{Taylor series}\n\n\n\\(f(x)\\) can be estimated at point \\(c\\) by identifying its repeated differentials at point \\(c\\).\n\nThe coefficients of an infinate number of polynomials at point \\(c\\) allow this.\n\n\\(f(x)=\\sum_{i=0}^{\\infty }a_i(x-c)^i\\)\n\n\\(f'(x)=\\sum_{i=1}^{\\infty }a_i(x-c)^{i-1}i\\)\n\n\\(f''(x)=\\sum_{i=2}^{\\infty }a_i(x-c)^{i-2}i(i-1)\\)\n\n\\(f^j(x)=\\sum_{i=j}^{\\infty }a_i(x-c)^{i-j}\\dfrac{i!}{(i-j)!}\\)\n\nFor \\(x=c\\) only the first term in the series is non-zero.\n\n\\(f^j(c)=\\sum_{i=j}^{\\infty }a_i(c-c)^{i-j}\\dfrac{i!}{(i-j)!}\\)\n\n\\(f^j(c)=a_ij!\\)\n\nSo:\n\n\\(a_j=\\dfrac{f^j(c)}{j!}\\)\n\nSo:\n\n\\(f(x)=\\sum_{i=0}^\\infty (x-c)^i \\dfrac{f^i(c)}{i!}\\)\n\n", "meta": {"hexsha": "f4898db40d2e0d0e130596813764fd4e8f1b2c3c", "size": 654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/02-01-diffTaylor.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/transformations/02-01-diffTaylor.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/transformations/02-01-diffTaylor.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0967741935, "max_line_length": 98, "alphanum_fraction": 0.5565749235, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104924150547, "lm_q2_score": 0.8991213860551286, "lm_q1q2_score": 0.8689203414384433}} {"text": "\n\\subsection{Diagonalisable matrices and eigendecomposition}\n\nIf matrix \\(M\\) is diagonalisable if there exists matrix \\(P\\) and diagonal matrix \\(A\\) such that:\n\n\\(M=P^{-1}AP\\)\n\n\\subsubsection{Diagonalisiable matrices and powers}\n\nIf these exist then we can more easily work out matrix powers.\n\n\\(M^n=(P^{-1}AP)^n=P^{-1}A^nP\\)\n\n\\(A^n\\) is easy to calculate, as each entry in the diagonal taken to the power of \\(n\\).\n\n\\subsubsection{Defective matrices}\n\nDefective matrices are those which cannot be diagonalised.\n\nNon-singular matries can be defective or not defective, for example the identiy matrix.\n\nSingular matrices can also be defective or not defective, for example the empty matrix.\n\n\\subsubsection{Eigen-decomposition}\n\nConsider an eigenvector \\(v\\) and eigenvalue \\(\\lambda \\) of matrix \\(M\\).\n\nWe known that \\(Mv=\\lambda v\\).\n\nIf \\(M\\) is full rank then we can generalise for all eigenvectors and eigenvalues:\n\n\\(MQ=Q\\Lambda\\)\n\nWhere \\(Q\\) is the eigenvectors as columns, and \\(\\Lambda \\) is a diagonal matrix with the corresponding eigenvalues. We can then show that:\n\n\\(M=Q\\Lambda Q^{-1}\\)\n\nThis is only possible to calculate if the matrix of eigenvectors is non-singular. Otherwise the matrix is defective.\n\nIf there are linearly dependent eigenvectors then we cannot use eigen-decomposition.\n\n\\subsection{Using the eigen-decomposition to invert a matrix}\n\nThis can be used to invert \\(M\\).\n\nWe know that:\n\n\\(M^{-1}=(Q\\Lambda Q^{-1})^{-1}\\)\n\n\\(M^{-1}=Q^{-1}\\Lambda^{-1}Q\\)\n\nWe know \\(\\Lambda \\) can be easily inverted by taking the reciprocal of each diagonal element. We already know both \\(Q\\) and its inverse from the decomposition.\n\nIf any eigenvalues are \\(0\\) then \\(\\Lambda \\) cannot be inverted. These are singular matrices.\n\n", "meta": {"hexsha": "54a96daa5bb6308f870812635e2f68c4a452addf", "size": 1749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/03-03-diagonal.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/03-03-diagonal.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/03-03-diagonal.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2321428571, "max_line_length": 161, "alphanum_fraction": 0.7318467696, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.9207896786080552, "lm_q1q2_score": 0.8686247057166692}} {"text": "Let's modify the permutation problem, so that we do not care in which order the $s$ objects are chosen from the $n$ objects. This amounts to the following problem: How many ways are there to choose a size $s$ subset of objects from a size $n$ set of objects? (Remember that order does not matter when listing a subset.)\n\nIn order to indicate the general solution we will solve a more specific example.\n\\begin{example}\n Suppose I have $6$ different colors of paint, and I must choose $4$ of them to mix together (so that the order in which I choose the paint does not matter). How many ways are there for me to make such a choice?\n\\end{example}\n\\begin{proof}[solution]\n From the permutation problem, we have seen that there are $P(6, 4) = 6!/2! = 360$ ways to choose $4$ colors in order. However, this is not the answer to the problem, because we count certain combinations as different when they are really the same. For example, the ordered selection (red, blue, green, yellow) will be counted differently from the ordered selection (blue, green, red, yellow). This means for each distinct combination, we count it $4! = 24$ times (since this is the number of ways to arrange $n!$ in a line.\n \n This means that the number of permutations is the number of combinations times $4!$. So there are $\\frac{1}{4!}P(6,4) = 15$ ways to choose $4$ colors without regard to order.\n\\end{proof}\n\nWe can directly generalize this problem to solve the general combination problem. We call a collection of $r$ objects chosen from a collection of $n$ objects, where the order does not matter, a \\textit{combination} of $r$ objects from $n$. From the permutation problem there are $P(n, r) = n!/(n-r)!$ ways to choose $r$ objects in a certain order. For each \\textit{combination} of $r$ objects there are $r!$ different orderings associated with it. Since each distinct combination gives rise to $r!$ different permutations, and each permutation can be realized as a combination, we conclude that there must \n\\[\\frac{1}{r!}P(n, r) = \\frac{n!}{r!(n-r)!}\\]\ndistinct combinations of $r$ objects from $n$ objects. This number is important enough that we give it a special notation. We define the ``binomial coefficient'' $\\binom{n}{r}$ (read ``$n$ choose $r$'') to be the value $\\frac{n!}{r!(n-r)!}$.\n\nThe method of solving the combination problem from the permutation problem is an important (often only implicitly discussed!) technique, which we call \\textbf{the principle of division}.\n\n\\begin{tcolorbox}\n Suppose I want to count the number a certain collection of objects $S$, and that I know the number of objects to a certain other collection of objects $T$ with the following properties:\n \\begin{itemize}\n \\item For each element $s \\in S$ we can associate it with exactly $r$ objects in $T$.\n \\item Each object in $T$ can only be associated with a unique object in $S$.\n \\end{itemize}\n\nThen it follows that the number of objects in the collection $S$ is $|T|/r$, or the number of objects in $T$ divided by $r$.\n\\end{tcolorbox}\n\n\\section{Probability in terms of Combinatorics}\n\nWith knowledge of combinatorics, it is possible to give the answer to some basic questions about probability. Here is the basic idea:\n\n\\begin{tcolorbox}\n Suppose that I have a \\textit{finite} (this is important!) collection $S$ of objects, and I want to know the probability that I choose some object with a certain property from $S$. Let $T$ denote the subcollection of objects with this property. Then the desired probability is $|T|/|S|$, or the size of $T$ divided by the size of $S$.\n\\end{tcolorbox}\nRemark that this collection is finite is important, because implicitly this probability was attained under the uniform distribution, which does not make sense for infinite collections.", "meta": {"hexsha": "d88e7f30bbea4e3521ea8961146468d69fd7595e", "size": 3760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch7/combination.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch7/combination.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch7/combination.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 104.4444444444, "max_line_length": 606, "alphanum_fraction": 0.7497340426, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.9399133447766225, "lm_q1q2_score": 0.8686132329916227}} {"text": "\\subsection{Eigenspace}\n\nKernel of a matrix always forms subspace of domain. If $\\lambda$ is an eigenvalue for $A$,\nkernel of $A-\\lambda I$ is the \\textbf{eigenspace} associated with $\\lambda$ and \nthis is denotes as $E_\\lambda=\\mathrm{ker}(A-\\lambda I)$.\n\nIf $A-\\lambda I$ has column vectors $\\tb{v}_1$ and $\\tb{v}_2$, then \n$E_\\lambda=\\mathrm{span}\\left\\{\\begin{bmatrix}c_1\\\\c_2\\end{bmatrix}\\right\\}$ where $c_1\\tb{v}_1+c_2\\tb{v}_2=\\tb{0}$.\n\n\\subsection{Multiplicity}\n\nDimension of eigenspace $E_\\lambda$ is \\textbf{geometric multiplicity} of $\\lambda$.\nMultiplicity of root $\\lambda$ is \\textbf{algebraic multiplicity} in characteristic polynomial $p_A(\\lambda)$.\nTherefore, geometric multiplicity $\\leq$ algebraic multiplicity, considering the case of $p_A(\\lambda)=(\\lambda-\\lambda_0)^2$.\n\nThus, this represents a $2\\times 2$ matrix which fixes one line and moves every other line, known as a shear. All lines but $x$-axis move.\nHas characteristic polynomial $p_A(\\lambda)=(\\lambda-1)^2$, so $E_1=\\mathrm{ker}\\begin{bmatrix}0&k\\\\0&0\\end{bmatrix}=\\mathrm{span}\\left\\{\\begin{bmatrix}1\\\\0\\end{bmatrix}\\right\\}$.\n\n\\subsection{Eigenbasis}\n\nConsists of the eigenvectors of the coefficient matrix. \\textbf{An $n\\times n$ matrix needs $n$ linearly independent\neigenvectors to have an eigenbasis}. This means that if $A$ has eigenvectors $\\lambda_1\\neq\\lambda_2$, then $E_{\\lambda_1}\\cap E_{\\lambda_2}=\\left\\{\\tb{0}\\right\\}$.\nThis is because if some $\\tb{v}\\in E_{\\lambda_1}$, then $A\\tb{v}=\\lambda_1\\tb{v}$ and $A\\tb{v}=\\lambda_2\\tb{v}$.\nThus, $(\\lambda_1-\\lambda_2)\\tb{v}=\\tb{0}$, so $\\tb{v}=\\tb{0}$.\n\n\\noindent\nFurthermore, if $E_{\\lambda_1}$ has basis $\\mathfrak{E}_{\\lambda_1}$ and $E_{\\lambda_2}$ with $\\mathfrak{E}_{\\lambda_2}$, $\\mathfrak{E}_{\\lambda_1}\\cup \\mathfrak{E}_{\\lambda_2}$ is linearly independent as well \nwith the total elements being the sum of the number of elements in each individual basis.\nCan then be concluded that:\n\n$$\n\\boxed{\\text{An $n\\times n$ matrix has eigenbasis iff sum of geometric multiplicities of eigenvalues is $n$.}}\n$$", "meta": {"hexsha": "c1552feb0cb1bb6715d4523a5d8373d027eca35b", "size": 2056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/19_matrix-eigenvector.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/19_matrix-eigenvector.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/19_matrix-eigenvector.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.303030303, "max_line_length": 210, "alphanum_fraction": 0.7242217899, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.9241418178895029, "lm_q1q2_score": 0.8686132317668049}} {"text": "\\textbf{Based on the theorems of chapter 8 of Approximation Theory and Approximation Practice by Trefethen, what can you say about the convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolants to the following functions? Which is the case that converges much faster than the theorems predict? Can you speculate why?}\n\\newline\n\nThe convergence, predicted by \\textsc{Theorem 8.2}, is \n\\begin{align*}\n\\|f-p_n\\|\\leq\\frac{4M\\rho^{-n}}{\\rho-1},\n\\end{align*}\nwith \n\\begin{align*}\n\\rho = \\alpha+\\sqrt{\\alpha^2-1}~~~~\\text{(real singularity at $x=\\pm\\alpha$)},\n\\end{align*}\nor\n\\begin{align*}\n\\rho = \\beta+\\sqrt{\\beta^2+1}~~~~\\text{(imaginary singularity at $x=\\pm i\\beta$)}.\n\\end{align*}\n\nApplying this to the following functions we obtain:\n\\begin{enumerate}[label=\\alph*)]\n\\item $f(x) = \\tan(x)$. This function has a real singularity at $x=\\pm \\pi/2$. Hence, \n\\begin{align*}\n\\rho = \\frac{\\pi}{2}+\\sqrt{\\frac{\\pi^2}{4}-1},\n\\end{align*}\nand we have obtained the rate of convergence showed in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{tan(x).png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)=\\tan(x)$.}\n\\end{figure}\n\n\n\\item $f(x) = \\tanh(x)$. This function has a imaginary singularity at $x=\\pm i\\pi/2$. Hence, \n\\begin{align*}\n\\rho = \\frac{\\pi}{2}+\\sqrt{\\frac{\\pi^2}{4}+1},\n\\end{align*}\nand we have obtained the rate of convergence showed in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{tanh(x).png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)=\\tanh(x)$.}\n\\end{figure}\n\n\n\\item $f(x) = \\frac{\\log(\\frac{x+3}{4})}{x-1}$. This function has a real singularity at $x=-3$. Hence, \n\\begin{align*}\n\\rho = 3+\\sqrt{8},\n\\end{align*}\nand we have obtained the rate of convergence showed in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{log1.png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)= \\frac{\\log(\\frac{x+3}{4})}{x-1}$.}\n\\end{figure}\n\n\\item $f(x) = \\int_{-1}^{x}\\cos(t^2)dt$. This function is entire, analytic at all finite points of the complex plane. Hence its convergence is much faster as is shown in the following figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{integral.png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)= \\frac{\\log(\\frac{x+3}{4})}{x-1}$.}\n\\end{figure}\n\n\n\n\\item $f(x) = \\tan(\\tan(x))$. This function has a real singularity at $x=\\pm \\arctan(\\pi/2)=\\pm k$. Hence, \n\\begin{align*}\n\\rho = k+\\sqrt{k^2-1},\n\\end{align*}\nand we have obtained the rate of convergence showed in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{tan(tan(x)).png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)= \\tan(\\tan(x))$.}\n\\end{figure}\n\n\\item $f(x) = (1+x)\\log(1+x)$. This function has a real singularity at $x=-1$. Hence, \n\\begin{align*}\n\\rho = -1,\n\\end{align*}\nand we have obtained the rate of convergence showed in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{(1+x)log(1+x)wrong.png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)= (1+x)\\log(1+x)$.}\n\\end{figure}\nThis figure is not right since the function does not satisfies the assumptions of \\newline \\textsc{Theorem 8.1}, it is not analytic in $[-1,1]$. The rate of convergence found is algebraic (much worse than the previous cases), as shown in the following figure.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{(1+x)log(1+x)right.png}\\caption{Algebraic convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to \\newline $f(x)= (1+x)\\log(1+x)$.}\n\\end{figure}\n\\end{enumerate}\n\nOverall, it has been tested that the larger the ellipse with foci $\\{-1,1\\}$ within which the function is analytic, the faster the convergence.\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\nrho = 0.5*pi+sqrt(0.25*pi^2-1);\norderAcuracy('tan(x)',50,2,rho)\n\nrho = (0.5*pi+sqrt(0.25*pi^2+1));\norderAcuracy('tanh(x)',40,2,rho)\n\nrho = (3+sqrt(8));\norderAcuracy('log((x+3)/4)/(x-1)',30,2,rho,'log1')\n\nk = atan(pi/2);\nrho = k+sqrt(k^2-1);\norderAcuracy('tan(tan(x))',460,20,rho)\n\nrho = -1;\norderAcuracy('(1+x)*log(1+x)',460,20,rho,'(1+x)log(1+x)wrong')\norderAcuracy('(1+x)*log(1+x)',460,20,rho,'(1+x)log(1+x)right')\n\nfunction orderAcuracy(func,Nmax,Nstep,rho,namefig)\n labelfontsize = 14;\n figformat = 'png';\n if nargin < 5\n namefig = func;\n end\n f = chebfun(func);\n nn = 0:Nstep:Nmax; ee = 0*nn;\n for j=1:length(nn)\n n = nn(j);\n fn = chebfun(f,n+1);\n ee(j) = norm(f-fn);\n end\n figure\n if strcmp(namefig,'(1+x)log(1+x)right')\n semilogy(nn,2000*nn.^(-3.8),'-b')\n else \n semilogy(nn,rho.^(-nn),'-b')\n end\n hold on\n semilogy(nn,ee,'r*')\n grid on\n xlabel('$N$','interpreter','latex')\n ylabel('$\\|f-p_N\\|$','interpreter','latex')\n set(gca,'fontsize',labelfontsize)\n txt=['Latex/FIGURES\\' namefig];\n saveas(gcf,txt,figformat)\nend\n\n% For the integral function\nnn = 2:2:20;\nerr = 0*nn;\nfor k = 1:length(nn)\n N = nn(k);\n x = -.98:0.02:1;\n F = 0*x;\n FN = F;\n for j = 1:length(x) \n f = chebfun('cos(t^2)', [-1 x(j)]);\n fN = chebfun('cos(t^2)', [-1 x(j)],N);\n F(j) = sum(f);\n FN(j) = sum(fN);\n F = [0 F]; FN = [0 FN]; x = [-1 x];\n end\n err(k) = norm(F-FN);\nend\nfigure\nsemilogy(nn,err,'r*')\ngrid on\nxlabel('$N$','interpreter','latex')\nylabel('$\\|f-p_N\\|$','interpreter','latex')\nset(gca,'fontsize',labelfontsize)\ntxt='Latex/FIGURES\\integral';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}", "meta": {"hexsha": "dca5a7d04d8b9bf433b61656467a368de442bc10", "size": 5667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework3/Latex/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework3/Latex/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.41875, "max_line_length": 324, "alphanum_fraction": 0.6596082583, "num_tokens": 1968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.9572777984923251, "lm_q1q2_score": 0.868549848208484}} {"text": "\\section{Generative Learning: Gaussian Discriminant Analysis}\nA generative model learns who the data is generated by estimating $P(x|y)$\nwhich is then used to estimate $P(y|x)$ via Bayes rule.\n\\subsection{Assumptions}\nGaussian Discriminant Analysis assumes the following:\n\\begin{enumerate}\n \\item $y\\sim\\textrm{Bernoulli}(\\phi)$\n \\item $x|y=0\\sim\\mathcal{N}(\\mu_0,\\Sigma)$\n \\item $x|y=1\\sim\\mathcal{N}(\\mu_1,\\Sigma)$\n\\end{enumerate}\nWriting out the distributions be have:\n\\begin{equation}\n P(y) = \\phi^y \\cdot (1-\\phi)^{1-y}\n\\end{equation}\n\\begin{equation}\n P(x|y=k) = \\frac{1}{(2\\pi)^{n/2}|\\Sigma|^{1/2}} \\exp \\left(-\\frac{1}{2} (x-\\mu_k)^T \\Sigma^{-1} (x - \\mu_k)\\right)\n\\end{equation}\n\\subsection{Estimation}\nThe log-likelihood of the data is given by:\n\\begin{equation}\n \\begin{aligned}\n \\ell(\\phi, \\mu_0, \\mu_1, \\Sigma) \\quad =& \\quad \\log \\prod_{i=1}^{m}P(x^{(i)}, y^{(i)}; \\phi, \\mu_0, \\mu_1, \\Sigma) \\\\\n =& \\quad \\log \\prod_{i=1}^m P(x^{(i)}| y^{(i)}; \\phi, \\mu_0, \\mu_1, \\Sigma) \\cdot P(y^{(i)}; \\phi)\n \\end{aligned}\n\\end{equation}\nBy maximizing $\\ell$ with respect to the parameters, we get the following MLE\nof the parameters:\n\\begin{equation}\n \\phi = \\displaystyle\\frac{1}{m}\\sum_{i=1}^m1_{\\{y^{(i)}=1\\}}\n\\end{equation}\n\\begin{equation}\n \\mu_k = \\displaystyle\\frac{\\sum_{i=1}^m1_{\\{y^{(i)}=k\\}}x^{(i)}}{\\sum_{i=1}^m1_{\\{y^{(i)}=k\\}}}\n\\end{equation}\n\\begin{equation}\n \\Sigma = \\displaystyle\\frac{1}{m}\\sum_{i=1}^m(x^{(i)}-\\mu_{y^{(i)}})(x^{(i)}-\\mu_{y^{(i)}})^T\n\\end{equation}\n\\subsection{Prediction}\nTo classify a point $x$, we find the class $y=k$ which maximizes the probability:\n\\begin{equation}\n \\hat{y} = \\underset{k}{\\textrm{arg max}} \\,\\, P(y=k) \\cdot\\prod_j P(x_j | y=k)\n\\end{equation}\n", "meta": {"hexsha": "0f3125cfca2a1e4d564bc006eb754086358af858", "size": 1722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/guassian_disc.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/guassian_disc.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/guassian_disc.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0, "max_line_length": 122, "alphanum_fraction": 0.6405342625, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9719924810166349, "lm_q2_score": 0.8933094117351309, "lm_q1q2_score": 0.8682900314279406}} {"text": "\\textbf{Consider the predictor-corrector time-stepping scheme:}\n\\begin{align*}\n& y_{n+1}^p = y_n + \\frac{\\Delta t}{12}(23f_n - 16f_{n-1}+5f_{n-2}), \\\\\n&y_{n+1} = y_n + \\frac{\\Delta t}{12}(5f(t_{n+1},y_{n+1}^p) + 8f)n - f_{n-1})~.\n\\end{align*}\n\\textbf{where $f_n = f(t_n,y_n)$ and $y'(t) = f(t,y)$, $y(0) = y_0$. Plot the stability region for this scheme.}\n\nLet $f_n = \\lambda y^{n}$ and $a = \\frac{\\Delta t \\lambda}{12}$. We start by simply substituting $y_{n+1}^p$ from the first equation into the second,\n\\begin{align*}\ny^{n+1} = y^n + a \\left[ 5(y^n + a(23y^n- 16y^{n-1}+5y^{n-1})) + 8y^n - y^{n-1} \\right]~.\n\\end{align*} \nFurther let $y^{n+1} = gy^n$,\n\\begin{align*}\ngy^n = y^n +a\\left[ 5y^n + 115ay^n - 80\\frac{a}{g}y^n + 25\\frac{a}{g^2}y^n\\right] + 8ay^n - \\frac{a}{g}y^n.\n\\end{align*}\nReorganizing the terms, we obtain a second degree polynomial for $a$,\n\\begin{align*}\n(115g^2 - 80g +25)a^2 + (13g^2-g)a + (g^2-g^3) = 0,\n\\end{align*}\nwhich gives us the solution\n\\begin{align*}\na = \\frac{-(13g^2 - g) \\pm \\sqrt{(13g^2-g)^2 - 4(115g^2 - 80g+25)(g^2-g^3)}}{2(115g^2 - 80g +25)}.\n\\end{align*}\nNote that $z =\\Delta t\\lambda= 12a$, \n\\begin{align*}\nz =12 \\frac{-(13g^2 - g) \\pm \\sqrt{(13g^2-g)^2 - 4(115g^2 - 80g+25)(g^2-g^3)}}{2(115g^2 - 80g +25)}.\n\\end{align*}\nWe plot the previos in \\textsl{Matlab} and obatin stability region shown in the next figure.\n\n\\begin{figure}[H]\n\\centering %%% not \\center\n{\\includegraphics[scale=0.75]{P3.eps}}\n\\caption{Stability region.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 3\nclear variables\nclose all\nclc\nN=300;\ntheta = linspace(0,2*pi,N);\ng=exp(1i*theta);\na=115*g.^2-80*g+25;\nb=13*g.^2-g;\nc=g.^2-g.^3;\nsq=sqrt(b.^2-4*a.*c);\nzp=12*(-b+sq)./(2*a);\nzn=12*(-b-sq)./(2*a);\nfigure\nplot(real(zp),imag(zp),'b.')\nhold on\nplot(real(zn),imag(zn),'b.')\ngrid on\naxis('image', [-2.5 0.5 -1.5 1.5])\nxlabel('$\\Re(z)$','interpreter','latex'...\n ,'fontsize',16)\nylabel('$\\Im(z)$','interpreter','latex'...\n ,'fontsize',16)\ntxt='Latex/FIGURES/P3';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}", "meta": {"hexsha": "d1a1cf53e88e8aac363ec22559169167a1121df3", "size": 2058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6666666667, "max_line_length": 149, "alphanum_fraction": 0.6064139942, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342049451595, "lm_q2_score": 0.9073122201074847, "lm_q1q2_score": 0.8679659043195511}} {"text": "\\begin{solution}\nWe start by expanding $f(x+h)$ and $f(x-h)$ up to eigth order,\n\\begin{align*}\nf(x\\pm h)=&f(x)\\pm hf'(x)+\\frac{h^2}{2}f''(x)\\pm\\frac{h^3}{3!}f'''(x)+\\frac{h^4}{4!}f^{(IV)}(x)\\pm\\frac{h^5}{5!}f^{(V))}(x)+\\frac{h^6}{6!}f^{(VI)}(x)\\\\\n&\\pm\\frac{h^7}{7!}f^{(VII))}(x)+\\frac{h^8}{8!}f^{(VIII)}(x)+\\mathcal{O}(h^9).\n\\end{align*}\nBy adding both $f(x+h)$ and $f(x-h)$ together, crossing out many terms, \n\\begin{align*}\nf(x+h)+f(x-h)=2f(x)+h^2f''(x)+\\frac{2h^4}{4!}f^{(IV)}+\\frac{2h^6}{6!}f^{(VI)}+\\frac{2h^8}{8!}f^{(VIII)}+\\mathcal{O}(h^9),\n\\end{align*}\nwe can now isolate the second derivative\n\\begin{align*}\nf''(x)=\\frac{f(x-h)-2f(x)+f(x+h)}{h^2}-\\frac{h^2}{12}f^{(IV)}-\\frac{2h^4}{6!}f^{(VI)}-\\frac{2h^6}{8!}f^{(VIII)}+\\mathcal{O}(h^9).\n\\end{align*}\nIf we want sixth order precision we need to get rid of the firs two leading terms of the error. In order to do so we use more stencil points. We can express the second derivative as\n\\begin{align*}\nf''(x)=\\frac{f(x-2h)-2f(x)+f(x+2h)}{4h^2}-\\frac{h^2}{3}f^{(IV)}-\\frac{2h^4}{45}f^{(VI)}-\\frac{h^6}{315}f^{(VIII)}+\\mathcal{O}(h^9),\n\\end{align*}\nand\n\\begin{align*}\nf''(x)=\\frac{f(x-3h)-2f(x)+f(x+3h)}{9h^2}-\\frac{3h^2}{4}f^{(IV)}-\\frac{9h^4}{40}f^{(VI)}-\\frac{81h^6}{2240}f^{(VIII)}+\\mathcal{O}(h^9).\n\\end{align*}\nMultiplying the three equations by $a,b,c$, respectively, and adding them together we can impose the condition that the coefficients of the second and fourth order error terms must be zero, obtaining a sixth order approximation. The system of equations to solve is then\n\\begin{align*}\n&\\frac{a}{12}+\\frac{b}{3}+\\frac{3c}{4}=0,\\\\\n&\\frac{0}{360}+\\frac{2b}{45}+\\frac{9c}{40}=0.\n\\end{align*}\nThe solutions are $a=15c$, $b=-6c$, and $c$ will vanish from the system. Once we put this values in the equations and add them together we get the final result\n\\begin{align*}\nf''(x)=&\\frac{15\\left[f(x-h)+f(x+h)\\right]-\\frac{3}{2}\\left[f(x-2h)+f(x+2h)\\right]+\\frac{1}{9}\\left[f(x-3h)+f(x+3h)\\right]-\\frac{245}{9}f(x)}{10h^2}\\\\&-\\frac{h^6}{560}f^{(VIII)}(x)+\\mathcal{O}(h^7),\n\\end{align*}\na sixth order approximation to the second derivative.\nIn the figure 1 we can see the funtion and its derivatives\n\\begin{align*}\nf(x)=e^x\\sin{(3x)},~~~~~~f'(x)=e^x\\left(\\sin{(3x)}+3\\cos{(3x)}\\right),~~~~~~f''(x)=e^x\\left(6\\cos{(3x)}-8\\sin{(3x)}\\right),\n\\end{align*}\nas well as the value of the second derivative at the point $x_0=0.4$.\n\\begin{figure}[H]\n\\centering %%% not \\center\n\\includegraphics[scale=0.7]{IMAGES/problem2_1.eps}\\caption{The function $f(x)$ and its two first derivatives. It is also included the value of the second derivative at $x_0=0.4$ (asterisk) and the approximated value (square) using the approximation derived above.}\n\\end{figure}\nWe can see that the approximated value for the three values of $h$ is very accurate as we cannot distinguish any square from the astersik. However, in the following figure we can see the error and, in logarithmic scale, seems to have a linear dependency on $h$. \n\\begin{figure}[H]\n\\centering %%% not \\center\n{\\includegraphics[scale=0.7]{IMAGES/problem2_2.eps}}\n\\caption{Error of the approximation.}\n\\end{figure}\nWe made a linear fitting and found out that the slope was $m=5.990378959014029$. This proves that the approximation is, indeed, of sixth order.\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\nx=-1:0.005:1;\nx_0=0.4;\nf = chebfun(@(x) exp(x)*sin(3*x));\ndf = chebfun(@(x) exp(x)*(sin(3*x)+3*cos(3*x)));\nddf = chebfun(@(x) exp(x)*(6*cos(3*x)-8*sin(3*x)));\n\nH=[0.1;0.05;0.025];\nddf_approx=zeros(3,1);\nfor k=1:3\n h=H(k);\n ddf_approx(k)=(15*(f(x_0-h)+f(x_0+h))-1.5*(f(x_0-2*h)+f(x_0+2*h))\n +(1/9)*(f(x_0-3*h)+f(x_0+3*h))-(245/9)*f(x_0))/(10*h^2);\nend\n\nfigure(1)\nplot(x,f(x),x,df(x),x,ddf(x),x_0,ddf(x_0),'*',x_0,ddf_approx(1),'s',\nx_0,ddf_approx(2),'s',x_0,ddf_approx(3),'s')\ngrid on\nlegend({'$f(x)$','$f''(x)$','$f''''(x)$'},'Interpreter','latex')\nxlabel('$x$','Interpreter','latex')\nset(gca,'fontsize',18)\nsaveas(gcf,'IMAGES/problem2_1','epsc')\n\nP=polyfit(log(H),log(abs(ddf(x_0)-ddf_approx)),1);\nh=0.01:1e-3:0.15;\nfigure(2)\nloglog(H,abs(ddf(x_0)-ddf_approx),'*')\ngrid on\nxlabel('$h$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nset(gca,'fontsize',14)\nhold on\nloglog(h,exp(P(1)*log(h)+P(2)))\ngrid on\naxis([2e-2 1.2e-1 1e-12 1e-2])\nsaveas(gcf,'IMAGES/problem2_2','epsc')\nP =\n\n 5.990378959014029 3.227778361027343\n\n\\end{verbatim}\n\\end{solution}", "meta": {"hexsha": "bc8c91203628d26eb67cdcd0a454d4186287dcc4", "size": 4453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 1/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 1/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 1/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.402173913, "max_line_length": 269, "alphanum_fraction": 0.6476532675, "num_tokens": 1809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.9241418168448761, "lm_q1q2_score": 0.8677921024178826}} {"text": "\\textit{CLRS section 3.2 p. 53}\n\\subsection{Monotonicity}\nA function $ f(n) $ is\n\\begin{description}\n \\item[monotonically increasing] if $ m \\leq n $ implies $ f(m) \\leq f(n) $.\n \\item[monotonically decreasing] if $ m \\leq n $ implies $ f(m) \\geq f(n) $.\n \\item[strictly increasing] if $ m < n $ implies $ f(m) < f(n) $.\n \\item[strictly decreasing] if $ m < n $ implies $ f(m) > f(n) $.\n\\end{description}\n\n\\subsection{Exponentials}\nFor all real $ a > 0$, $ b > 0 $, $ m $, and $ n $, we have the following identities:\\\\\n\\begin{align*}\na^0 &= 1\\\\\na^1 &= a\\\\\na^{-1} &= \\frac{1}{a}\\\\\n\\left( a^m\\right) ^n &= a^{nm}\\\\\n\\left( a^m\\right) ^n &= \\left( a^n\\right) ^m\\\\\na^ma^n &= a^{n+m}\\\\\n0^0&=1\\\\\na^mb^m&=(ab)^m\\\\\na^\\frac{m}{n} &= \\left( \\sqrt[n]{a}\\right) ^m\\\\\na^{-m}&=\\dfrac{1}{a^m}\\\\\na^{m-n}&=\\dfrac{a^m}{a^n}\n\\end{align*}\n\\subsection{Logarithms}\n\\emph{Logarithm functions apply only to the next term in the formula}, so that $ \\lg n + k $ will mean $ \\left( \\lg n\\right) +k $ and not $ \\lg(n+k) $.\nCLRS uses the following notations:\n\\begin{align*}\n\\lg n &= \\log_2 n &\\text{(binary logarithm)}\\\\\n\\ln n &= \\log_e n &\\text{(natural logarithm)}\\\\\n\\lg^kn &= (\\lg n)^k &\\text{(exponentiation)}\\\\\n\\lg\\lg n &= \\lg (\\lg n) &\\text{(composition)}\n\\end{align*}\nFor all real $ a > 0 $, $ b > 0 $, $ c > 0 $, and $ n $,\n\\begin{align*}\na &= b^{\\log_ba}\\\\\n\\log_c(ab) &= \\log_ca+\\log_cb\\\\\n\\log_ba^n &= n\\log_ba\\\\\n\\log_ba &= \\dfrac{\\log_ca}{\\log_cb}\\\\\n\\log_b\\left( \\frac{1}{a}\\right) &= -\\log_ba\\\\\n\\log_ba &= \\dfrac{1}{\\log_ab}\\\\\na^{\\log_bc}&=c^{\\log_ba}\\\\\n\\log_b 1 &= 0\\\\\n\\log_bb &= 1\\\\\n\\log_b\\left( \\frac{a}{c}\\right) &= \\log_b a - \\log_b c\n\\end{align*}\nwhere, in each equation above, logarithm bases are not 1.\\\\\n\nThere is a simple series expansion for $ \\ln (1+x) $ when $ |x| < 1 $:\n$$ \\ln(1+x) = x - \\dfrac{x^2}{2} + \\dfrac{x^3}{3} - \\dfrac{x^4}{4} + \\dfrac{x^5}{5} - \\cdots $$\n\nWe also have the following inequalities for $ x > -1 $:\n$$ \\dfrac{x}{1+x} \\leq \\ln(1+x) \\leq x $$\nwhere equality holds only for $ x = 0 $.", "meta": {"hexsha": "4e0dac2352f37e48acc4b217e21b7cab45c09816", "size": 2014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/notation.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Algorithms and Data Structures - Reference/notation.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms and Data Structures - Reference/notation.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 36.6181818182, "max_line_length": 151, "alphanum_fraction": 0.5714995035, "num_tokens": 852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025387, "lm_q2_score": 0.9032941995446778, "lm_q1q2_score": 0.8674886691824565}} {"text": "\n\\subsection{Definition}\n\nA series is the summation of a sequence. For a series \\(a_n\\) there is a corresponding series:\n\n\\(s_n=\\sum_{i=0}^na_n\\)\n\nWhere:\n\n\\(\\sum_{i=0}^na_i=a_0+a_1+a_2+...+a_n\\)\n\n\\subsection{Multiplication of summations}\n\nIf all members of a sequence are multiplied by a constant, so is each member of the series.\n\nWe can take constants out of the series:\n\n\\(s_n=\\sum_{i=0}^na_i\\)\n\n\\(s_n=\\sum_{i=0}^ncb_i\\)\n\n\\(s_n=a\\sum_{i=0}^nb_i\\)\n\n\\subsection{Summation of constants}\n\nIf all elements of a sequence are the same, then the series is a multiple of that constant.\n\n\\(s_n=\\sum_{i=0}^na_i\\)\n\n\\(s_n=\\sum_{i=0}^nc\\)\n\n\\(s_n=nc\\)\n\n\\subsection{Addition of summations}\n\nConsider a sequence \\(a_i=b_i+c_i\\).\n\n\\(s_n=\\sum_{i=0}^na_i\\)\n\n\\(s_n=\\sum_{i=0}^n(b_i+c_i)\\)\n\nWe can then split this out.\n\n\\(s_n=\\sum_{i=0}^nb_i+\\sum_{i=0}^nc_i\\)\n\n\\subsection{Summation from a different start point}\n\n\\(\\sum_{i=0}^na_i=a_0+\\sum_{i=1}^na_i\\)\n\n\\subsection{Multiple summations}\n\n\\(\\sum^n_{i=0} \\sum^m_{j=0} a_i=n\\sum^m_{j=0} a_i\\)\n\n\\(\\sum^n_{i=0} \\sum^m_{j=0} a_i b_j=\\sum^n_{i=0}a_i\\sum^m_{j=0}b_i\\)\n\n", "meta": {"hexsha": "a96f41b723dfb56ad94e0f1781ee5292143b51f5", "size": 1093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sequences/02-01-sum.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sequences/02-01-sum.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sequences/02-01-sum.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5178571429, "max_line_length": 94, "alphanum_fraction": 0.6724611162, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338090839607, "lm_q2_score": 0.9019206857566126, "lm_q1q2_score": 0.8672272324671736}} {"text": "\\subsubsection{Repeated Eigenvalues}\r\n\\noindent\r\nIf $A$ has an eigenvalue with multiplicity $k$, that eigenvalue needs to generate $k$ fundamental solutions.\r\nIf this eigenvalue generates $k$ linearly independent eigenvectors, then the process is much like with distinct eigenvalues.\r\nOtherwise, the matrix $A$ is defective.\r\n\\begin{theorem}\r\n\tIf $\\lambda$ is an eigenvalue with multiplicity $k$, and $\\left\\{\\vec{v_1}, \\ldots, \\vec{v_k}\\right\\}$ are corresponding linearly independent eigenvectors, the the set of fundamental solutions generated by $\\lambda$ is $\\left\\{e^{\\lambda t}\\vec{v_1}, \\ldots, e^{\\lambda t}\\vec{v_k}\\right\\}$.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the system\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t0 & 1 & 1 \\\\\r\n\t\t\t1 & 0 & 1 \\\\\r\n\t\t\t1 & 1 & 0\r\n\t\t\\end{bmatrix} \\vec{x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFinding the eigenvalues by finding the roots of the characteristic polynomial of $A$,\r\n\\begin{equation*}\r\n\tp(\\lambda) = \\det{(A - \\lambda I)} = -\\lambda^3 + 3\\lambda + 2 \\implies \\lambda = 2, -1, -1.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = 2$,\r\n\\begin{equation*}\r\n\t(A - 2I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_1\\begin{bmatrix}\r\n\t\t1 \\\\\r\n\t\t1 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nFinding the eigenvectors for $\\lambda = -1$,\r\n\\begin{equation*}\r\n\t(A + I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_2\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + C_3\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nSo, our solution is\r\n\\begin{equation*}\r\n\t\\vec{x} = C_1e^{2t}\\begin{bmatrix}\r\n\t\t1 \\\\\r\n\t\t1 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_2e^{-t}\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + C_3e^{-t}\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}", "meta": {"hexsha": "2d0132b5f78303c4ae166beffd7163d4a522150b", "size": 1788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/repeatedEigenvalues.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/repeatedEigenvalues.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/repeatedEigenvalues.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 29.8, "max_line_length": 293, "alphanum_fraction": 0.6314317673, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653855, "lm_q2_score": 0.918480244583138, "lm_q1q2_score": 0.8672077922604182}} {"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[utopia]{mathdesign}\n\\usepackage[headings]{fullpage}\n\\usepackage{color}\n\\usepackage{enumerate}\n\n\\pagestyle{myheadings}\n\\markboth{}{Blur}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n \\bf Blurred lines\n\\end{center}\n\nIn a computer, an image is ultimately a table of numbers representing pixel intensity values. We can regard these values as a matrix and model some common image operations using linear\nalgebra. A prominent example of such operations is blurring due to poor focus. \n\nConsider first an $m\\times 1$ vector $\\bfx$ of pixel intensities, mapped to a\nvector $\\bfz$ of intensities after blurring. We model each pixel\nin the new vector as a weighted average,\n\\[\nz_i = \\frac{1}{4}x_{i-1} + \\frac{1}{2}x_i + \\frac{1}{4} x_{i+1}.\n\\]\nPixel values that are beyond the boundaries, namely $x_0$ and $x_{m+1}$, are taken to be zero. We can express the relationship between original and blurred image as a matrix-vector product:\n\\begin{equation}\n\\label{eq:blurmatrix}\n\\bfz = \n\\begin{bmatrix}\n \\frac{1}{2} & \\frac{1}{4} & 0 & \\cdots & 0 \\\\[2mm]\n \\frac{1}{4} & \\frac{1}{2} & \\frac{1}{4} & \\cdots & 0 \\\\[2mm]\n & \\ddots & \\ddots & \\ddots & \\\\\n 0 & \\cdots & \\frac{1}{4} & \\frac{1}{2} & \\frac{1}{4} \\\\[2mm]\n 0 & 0 & \\cdots & \\frac{1}{4} & \\frac{1}{2} \n\\end{bmatrix}\n\\bfx = \\mB_m \\bfx,\n\\end{equation}\nwhere the $m$ subscript indicates an $m\\times m$ matrix. \n\nThings are not much more complicated for actual 2D images. Let $\\mX$\nbe an $m\\times n$ image and $\\mZ$ be a blurred version of\nit. We can first blur in the vertical direction by recalling the columnwise multiplication identity,\n\\[\n\\mB_m \\mX = \n\\begin{bmatrix}\n \\mB_m \\mX_1 & \\mB_m \\mX_2 & \\cdots & \\mB_m \\mX_n\n\\end{bmatrix}.\n\\]\nThus, $\\mB_m\\mX$ applies vertical blur to each column of the image. \n\nTo blur rows, we go in three steps. First, transpose the image to turn rows into columns. Second, apply blurring to each column as shown above. Finally, transpose the result back to restore the original orientation. Hence the fully blurred image is given by\n\\begin{equation}\n\\label{eq:blurop}\n \\mZ = \\Bigl[ \\mB_n(\\mB_m\\mX)^T \\Bigr]^T = \\mB_m \\mX \\, \\mB_n^T = \\mB_m \\mX \\, \\mB_n, \n\\end{equation}\nwhere the last step uses the symmetry apparent in~\\eqref{eq:blurmatrix}. \n\nFinally, we can simulate a larger amount of blur by applying our simple blur multiple times, as in $ (\\mB_m)^k \\mX \\, (\\mB_n)^k$ for some integer $k>1$. \n\n\\subsection*{Preparation}\n\nRead Section 2.2. Then read the online documentation for \\texttt{diag}, paying particular attention to the examples. \n\n\n\\subsection*{Goals}\n\nYou will write a function that produces a blur matrix of requested size. This will be used to blur an image that you import as a matrix.\n\n%\\end{document}\n\n\\subsection*{Procedure}\n\nDownload the template script \\texttt{Blur} and the template file \\texttt{blurmatrix.m}.\n\n\\begin{enumerate}\n\\item The file \\texttt{blurmatrix.m} has the first line\n\\begin{verbatim}\nfunction B = blurmatrix(n)\n\\end{verbatim}\nWithin the function, \\texttt{n} is an input parameter describing the size of the matrix, and \\texttt{B} is the result that is returned to the caller. Using the functions \\texttt{ones} and \\texttt{diag}, complete the definition of the function so that it returns $\\mB_n$ as in~\\eqref{eq:blurmatrix}.\n\\item In the script, construct the matrix $\\mB_7$ using a call to \\texttt{blurmatrix} and have it printed out (no semicolon) to show that it's correct.\n\\item Save an image to your working folder. (It should have between 400 and 1000 pixels in each dimension.) The template script has code for importing it, converting it to a floating-point matrix $\\mX$, and displaying it. \n\\item Apply blurring to your image 60 times in the vertical direction only, and display the result as in step~3. \n\\item Blur the image 60 times in each direction and display it. \n\\end{enumerate}\n\n\\subsection*{Extras}\n\\begin{enumerate}\n\\item[E1.] Look at the output of the final step. What creates the ``black lines'' around the edges? What happens to them as the number of blur applications increases? \n\\end{enumerate}\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "2ee43c1100d2a4ebb48da1c2947e157c24020412", "size": 4309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter02/Blur/Blur.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter02/Blur/Blur.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter02/Blur/Blur.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 42.6633663366, "max_line_length": 298, "alphanum_fraction": 0.7041076816, "num_tokens": 1287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566341987633822, "lm_q2_score": 0.9059898114992677, "lm_q1q2_score": 0.8667008374113896}} {"text": "% section6\r\n\\chapter{Linear Transformations}\r\n\r\n\\section{Matrices as Transformations}\r\n\r\n\\begin{exer} (\\textit{Linear Transformation: Rotation})\\\\\r\nMake a function file with a function name \\textit{reflect\\_pt} to find the reflection of the point $(a,b)$ about the line through the origin of the $xy$-plane that makes an angle of $\\theta\\,^{\\circ}$ with the positive $x$-axis. Make $a$, $b$, and $\\theta$ the inputs to the function and the reflection point $(x,y)$ the output. Using this function, find the result of this function for $(a,b)=(1,3)$ and $\\theta=12$ by the following commands:\r\n\r\n\\vspace{2mm}\r\n\r\n\\begin{verbatim}\r\n>> [x, y]=reflect_pt(1, 3, 12)\r\n\\end{verbatim}\r\n\r\n\\end{exer}\r\n\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n%--- The following is the function file 'reflect_pt.m'. ---%\r\nfunction [x, y]=reflect_pt(a, b, ang)\r\n theta=ang*(pi/180);\r\n T = [cos(2*theta) sin(2*theta); sin(2*theta) -cos(2*theta)];\r\n \r\n result=T*[a b]';\r\n x=result(1); y=result(2);\r\nend\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nx =\r\n 2.1338\r\n \r\ny =\r\n -2.3339\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\\begin{exer} (\\textit{Linear Transformation: Projection})\\\\ \r\nConsider successive rotations of $\\mathbb{R}^{3}$ by an angle $\\theta_{1}$ degree about the $x$-axis, then by an angle $\\theta_{2}$ degree about the $y$-axis, and then by an angle $\\theta_{3}$ degree about the $z$-axis. Make a function file named \\textit{comp\\_Rot} to find an appropriate axis and angle of rotation that achieves the same result in one rotation. Make $\\theta_{1}, \\theta_{2},$ and $\\theta_{3}$ degrees the inputs to the function and the axis and angle of rotation the outputs. Give the output axis as a unit vector. You may make the standard matrix for the composition of the rotations by multiplication of the standard matrices for the rotations about the position $x$-, $y$-, and $z$-axes, respectively. Using the function \\textit{comp\\_Rot}, check the result of the following commands:\r\n\r\n\\vspace{2mm}\r\n\r\n\\begin{verbatim}\r\n>> [L ang]=comp_Rot(45, 45, 45)\r\n\\end{verbatim}\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n%--- The following is the function file 'comp_Rot.m'. ---%\r\nfunction [L, ang] = comp_Rot(ang1, ang2, ang3)\r\n\r\n % Angle as a degree.\r\n angle=[ang1 ang2 ang3];\r\n\r\n % Convert angles from degrees to radians.\r\n theta=angle*(pi/180); \r\n\r\n % Rotation about x-axis, y-axis, and z-axis.\r\n Rx = [1 0 0; \r\n 0 cos(theta(1)) -sin(theta(1)); \r\n 0 sin(theta(1)) cos(theta(1))];\r\n Ry = [cos(theta(2)) 0 sin(theta(2)); \r\n 0 1 0; \r\n -sin(theta(2)) 0 cos(theta(2))];\r\n Rz = [cos(theta(3)) -sin(theta(3)) 0; \r\n sin(theta(3)) cos(theta(3)) 0; \r\n 0 0 1];\r\n\r\n % Composition of the three rotation matrices R = Ry*Rx*Rz.\r\n R = Rz*Ry*Rx; \r\n\r\n % Find the axis of rotation of R,\r\n % by finding the eigenvector of R \r\n % corresponding to the eigenvalue lambda=1.\r\n\r\n % Find a nonzero vector satisfying Rx = x.\r\n L = null(eye(3) - R);\r\n\r\n % Make the axis of rotation unit vector. \r\n L = L/norm(L); \r\n\r\n % Find the angle of rotation of R.\r\n % Note that w=(-x2,x1,0) is \r\n % orthogonal to the axis of rotation x=(x1,x2,x3).\r\n w = [-L(2) L(1) 0]';\r\n rot_theta = acos((dot(w, R*w))/((norm(w)*norm(R*w))));\r\n ang = ((rot_theta)*(180/pi));\r\nend\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nL =\r\n -0.3574\r\n -0.8629\r\n -0.3574\r\n\r\nang =\r\n 64.7368\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\\newpage\r\n\r\n\\section{Geometry of Linear Operators}\r\n\r\n\\begin{exer} (\\textit{Rotation as an Orthogonal Transformation})\\\\\r\nLet\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} \\displaystyle -\\frac{3}{7}&\\quad \\displaystyle -\\frac{2}{7}&\\quad \\displaystyle -\\frac{6}{7} \\vspace{3mm} \\\\ \\vspace{3mm} \\displaystyle \\frac{6}{7} & \\displaystyle -\\frac{3}{7} & \\displaystyle -\\frac{2}{7}\\\\ \\displaystyle -\\frac{2}{7} & \\displaystyle -\\frac{6}{7} & \\displaystyle \\frac{3}{7} \\end{array} \\right].\r\n\\end{displaymath}\r\n\r\n\\vspace{2mm}\r\n\\noindent Show that $A$ represents a rotation, and use Formulas $(16)$ and $(17)$ in Section $6.2$ to find the axis and angle of rotation.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nA = [-3/7 -2/7 -6/7; 6/7 -3/7 -2/7; -2/7 -6/7 3/7]; format short;\r\n\r\n% Check that A*A' is the identity matrix.\r\nA*A' \r\n\r\n% Although the off diagonal entries are not exactly all zeros,\r\n% the scaling factor suggests that roundoff error prevents\r\n% the computed matrix from being the identity matrix.\r\n% You can see that the product is exactly the identity matrix,\r\n% when the symbolic computation is used.\r\n\r\n% Check that det(A)=1 to conclude that A is orthogonal.\r\ndet(A) \r\n\r\n% Since A*A'=I and det(A) = 1, A represents a rotation.\r\n\r\n% By (16) of Section 6.2,\r\n% find the angle of rotation \r\n% and convert the angle from radians to degrees.\r\ntheta = acos((trace(A)-1)/2); ang = ((theta)*(180/pi));\r\ndisp('The angle of rotation in degrees is'); disp(ang);\r\n\r\n% By (17) of Section 6.2, find the axis of rotation.\r\n% The initial point at the origin.\r\ne1 = [1 0 0]'; \r\n\r\n% v is along the axis of rotation.\r\nv = (A+A'+((1-trace(A))*eye(3))) * e1; \r\ndisp('The axis of rotation passes through the point'); disp(v');\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe angle of rotation in degrees is\r\n 135.5847\r\nThe axis of rotation passes through the point\r\n 0.5714 0.5714 -1.1429\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\r\n\r\n\\section{Kernel and Range}\r\n\r\n\r\n\\begin{exer}\r\n(\\textit{Invertible Matrix as a Bijective Linear Transformation})\\\\\r\nConsider the matrix\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} 3& \\hspace{1mm} -5& \\hspace{1mm} -2&\\hspace{3mm} 2\\\\ -4 & 7 & 4 & 4 \\\\ 4 & -9 & -3 & 7 \\\\ 2 & -6 & -3 & 2 \\end{array} \\right].\r\n\\end{displaymath}\r\n\r\n\\vspace{2mm}\r\nReferring to the Theorem $6.3.15$ in Section $6.3$, show that $T_{A} : \\mathbb{R}^{4} \\rightarrow \\mathbb{R}^{4}$ is onto in at least four different ways. You may use several related MATLAB commands.\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nA = [3 -5 -2 2; -4 7 4 4; 4 -9 -3 7; 2 -6 -3 2];\r\nformat short;\r\n\r\n% By (a) in Theorem 6.3.15, use the command rref of A.\r\nrref(A)\r\n\r\n% Since the reduced row echelon form of A is the identity matrix,\r\n% the linear transformation T is onto.\r\n\r\n% By (d) in Theorem 6.3.15, use the command null of A.\r\n\r\n% Find a basis for the null space of A.\r\nnull(A, 'r') \r\n\r\n% Since the null space contains only the zero vector,\r\n% the linear transformation T is onto.\r\n\r\n% By (g) in Theorem 6.3.15, use the command rank of A.\r\n\r\n% Find the number of linearly independent columns of A.\r\nrank(A) \r\n\r\n% Since the column vectors of A are linearly independent,\r\n% the linear transformation T is onto.\r\n\r\n% By (i) in Theorem 6.3.15, use the command det of A.\r\n\r\n% Find the determinant of A.\r\ndet(A) \r\n\r\n% Since det(A) is nonzero,\r\n% the linear transformation T is onto.\r\n\r\n% By (j) in Theorem 6.3.15, use the command eig of A.\r\n\r\n% Find the eigenvalues A.\r\neig(A) \r\n\r\n% Since 0 is not an eigenvalue of A,\r\n% the linear transformation T is onto.\r\n\\end{verbatim}\r\n\\end{sol}\r\n\r\n\r\n\r\n\\section{Composition and Invertibility of Linear Transformations}\r\n\r\n\r\n\r\n\\begin{exer}(\\textit{Compositions of Linear Transformations})\\\\\r\nConsider successive rotations of $\\mathbb{R}^{3}$ by $30\\,^{\\circ}$ about the $z$-axis, then by $60\\,^{\\circ}$ about the $x$-axis, and then by $45\\,^{\\circ}$ about the $y$-axis. If it is desired to execute the three rotations by a single rotation about an appropriate axis, what axis and angle should be used?\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n% Angle as a degree.\r\nang1=30; ang2=60; ang3=45; \r\n\r\n% Convert angles from degrees to radians.\r\ntheta1=((ang1)*(pi/180)); \r\ntheta2=((ang2)*(pi/180));\r\ntheta3=((ang3)*(pi/180)); \r\n\r\nformat short;\r\n\r\n% Rotation about z-axis with the angle 30.\r\nRz = [cos(theta1) -sin(theta1) 0; sin(theta1) cos(theta1) 0; 0 0 1];\r\n% Rotation about x-axis with the angle 60.\r\nRx = [1 0 0; 0 cos(theta2) -sin(theta2); 0 sin(theta2) cos(theta2)];\r\n% Rotation about y-axis with the angle 45.\r\nRy = [cos(theta3) 0 sin(theta3); 0 1 0; -sin(theta3) 0 cos(theta3)];\r\n\r\n% Composition of the three rotation matrices R = Ry*Rx*Rz.\r\nR = Ry*Rx*Rz; \r\n\r\n% Find the axis of rotation of R,\r\n% by finding the eigenvector of R corresponding to the eigenvalue lambda=1.\r\n\r\n% Find a nonzero vector satisfying Rx = x.\r\nx = null(eye(3) - R); \r\n\r\n% Find the angle of rotation of R.\r\n% Note that w=(-x2,x1,0) is orthogonal to the axis of rotation x=(x1,x2,x3).\r\nw = [-x(2) x(1) 0]';\r\ntheta = acos((dot(w, R*w))/((norm(w)*norm(R*w))));\r\n\r\n% Convert the angle from radians to degrees.\r\nang = ((theta)*(180/pi));\r\n\r\ndisp('The angle of rotation in degrees is'); disp(ang);\r\ndisp('The axis of rotation is'); disp(x');\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe angle of rotation in degrees is\r\n 69.3559\r\n\r\nThe axis of rotation is\r\n -0.9350 -0.3525 -0.0391\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\\end{sol}", "meta": {"hexsha": "c53bd961671a461d6ddae517e32ce49abdf9d6f8", "size": 8982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section6.tex", "max_stars_repo_name": "mireiffe/mas109_matlab_2021_2", "max_stars_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section6.tex", "max_issues_repo_name": "mireiffe/mas109_matlab_2021_2", "max_issues_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-19T08:29:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T08:29:55.000Z", "max_forks_repo_path": "files/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section6.tex", "max_forks_repo_name": "mireiffe/mas109_matlab_2021_2", "max_forks_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7884615385, "max_line_length": 806, "alphanum_fraction": 0.6475172567, "num_tokens": 2829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.9124361634533147, "lm_q1q2_score": 0.8665126754416372}} {"text": "\\subsection{FEM ans ${\\rm DNN}_1$ in 1D}\nThanks to following connection between $\\varphi(x)$ in \\eqref{def_g} and ${\\rm ReLU}(x) = \\max(0,x )=x_+$\n\\begin{equation}\\label{key}\n\\varphi(x) = 2{\\rm ReLU}(x) - 4{\\rm ReLu}({x-\\frac{1}{2}}) + 2{\\rm ReLU}(x-1),\n\\end{equation}\nit suffices to show that each basis\nfunction $\\varphi_{\\ell,i}$ can be represented by a ReLU DNN. \nWe first note that the basis\nfunction $\\varphi_{\\ell,i}$ has the support in $[x_{\\ell,i-1},\nx_{\\ell,i+1} ]$ can be easily written as\n\\begin{equation}\n\\label{1d-basisu}\n\\varphi_{\\ell,i}(x) = \\frac{1}{h_{\\ell}}{\\rm ReLU}(x-x_{\\ell,i-1}) -\\frac{2}{h_{\\ell}}{\\rm ReLU}(x-x_{\\ell,i}) +\\frac{1}{h_\\ell}{\\rm ReLU}(x-x_{\\ell,i+1}).\n\\end{equation}\nMore generally, consider a general grid with vertex $\\{x_i\\}$, which is not necessarily uniform. The basis function $\\varphi_i$ of the linear element with support $[x_{i-1},\nx_{i+1} ]$ can be easily written as\n\\begin{equation}\n\\label{1d-basis}\n\\varphi_i(x) = \\frac{1}{h_{i-1}}{\\rm ReLU}(x-x_{i-1}) -(\\frac{1}{h_{i-1}}+\\frac{1}{h_i}){\\rm ReLU}(x-x_i) +\\frac{1}{h_i}{\\rm ReLU}(x-x_{i+1}),\n\\end{equation}\nwhere $h_i = x_{i+1} - x_i$.\n\nThus is to say, we have the next theorem.\n\\begin{theorem}\\label{thm:1dLFEMDNN}\n\tFor $d=1$, and $\\Omega\\subset \\mathbb R^d$ is \n\ta bounded interval, then ${\\rm DNN}_1$ can be used to cover all linear finite element \n\tfunction in on $\\Omega$.\n\\end{theorem}", "meta": {"hexsha": "cd03118bbd0c486cd59ab9795c86a699353f00e1", "size": 1396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNN1FEM-1D.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DNN1FEM-1D.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DNN1FEM-1D.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8571428571, "max_line_length": 174, "alphanum_fraction": 0.6547277937, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.9184802356574272, "lm_q1q2_score": 0.8664460997842246}} {"text": "\\subsection{Properties of matrix multiplication}\n\nWe have already seen that matrix multiplication is not in general\ncommutative, i.e., $AB$ and $BA$ may be different, even if they are\nboth defined. Sometimes it can happen that $AB=BA$ for specific\nmatrices $A$ and $B$. In this case, we say that $A$ and $B$\n\\textbf{commute}%\n\\index{matrix!commuting matrices}%\n\\index{commuting matrices}.\n\nThe following are some properties of matrix multiplication. Notice\nthat these properties hold only when the size of matrices are such\nthat the products are defined.\n\n\\begin{proposition}{Properties of matrix multiplication}{properties-of-matrix-multiplication}\n The following properties hold%\n \\index{matrix!properties of multiplication}%\n \\index{matrix!multiplication!properties}%\n \\index{properties of multiplication!matrices} for matrices $A,B,C$\n of appropriate dimensions and for scalars $r$.\n \\begin{itemize}\n \\item The associative law of multiplication\n \\begin{equation*}\n (AB)C ~=~ A(BC).\n \\end{equation*}\n \\item The existence of multiplicative units\n \\begin{equation*}\n I_mA ~=~ A ~=~ AI_n,\n \\end{equation*}\n where $A$ is an $m\\times n$-matrix.\n \\item Compatibility with scalar multiplication\n \\begin{equation*}\n (rA)B ~=~ r(AB) ~=~ A(rB).\n \\end{equation*}\n \\item The distributive laws of multiplication over addition\n \\begin{eqnarray*}\n A(B+C) &=& AB + AC, \\\\\n (B+C)A &=& BA + CA.\n \\end{eqnarray*}\n \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n First, we will prove the associative law. In the proof, it will be\n useful to use {\\em summation notation}%\n \\index{summation notation}. We write\n \\begin{equation*}\n \\sum_{i=1}^n x_i ~=~ x_1 + x_2 + \\ldots + x_n\n \\end{equation*}\n for the sum of the $n$ numbers $x_1,\\ldots,x_n$. Assume $A$ is an\n $m\\times n$-matrix, $B$ is an $n\\times p$-matrix, and $C$ is a\n $p\\times q$-matrix. Then both $(AB)C$ and $A(BC)$ are\n $n\\times q$-matrices. We must show that they have the same\n entries. The $(i,\\ell)$-entry of the matrix $(AB)C$ is\n \\begin{equation*}\n ((AB)C)_{i\\ell} = \\sum_{k=1}^p (AB)_{ik}c_{k\\ell}\n = \\sum_{k=1}^p (\\sum_{j=1}^n a_{ij}b_{jk})c_{k\\ell}\n = \\sum_{k=1}^p\\sum_{j=1}^n a_{ij}b_{jk}c_{k\\ell}.\n \\end{equation*}\n On the other hand, the $(i,\\ell)$-entry of the matrix $A(BC)$ is\n \\begin{equation*}\n (A(BC))_{i\\ell} = \\sum_{j=1}^n a_{ij}(BC)_{j\\ell}\n = \\sum_{j=1}^n a_{ij} (\\sum_{k=1}^p b_{jk} c_{k\\ell})\n = \\sum_{j=1}^n\\sum_{k=1}^p a_{ij} b_{jk} c_{k\\ell}.\n \\end{equation*}\n Both sums are equal, since they are both summing over all the terms\n where $j=1,\\ldots,n$ and $k=1,\\ldots,p$. Therefore, $(AB)C=A(BC)$.\n The fact that identity matrices act as multiplicative units was\n already mentioned in Proposition~\\ref{prop:identity-matrix}. We\n leave compatibility with scalar multiplication as an exercise.\n To prove the first distributive law, assume $A$ is an\n $m\\times n$-matrix, and $B$ and $C$ are $n\\times p$-matrices. Then\n both $A(B+C)$ and $AB+AC$ are $m\\times p$-matrices. We have\n \\begin{equation*}\n (A(B+C))_{ik} = \\sum_{j=1}^n a_{ij}(B+C)_{jk}\n = \\sum_{j=1}^n a_{ij}(b_{jk}+c_{jk})\n = \\sum_{j=1}^n a_{ij}b_{jk} + \\sum_{j=1}^n a_{ij}c_{jk}\n = (AB+AC)_{ik}.\n \\end{equation*}\n Thus $A(B+C) =AB+AC$ as claimed. The proof of the other distributive\n law is similar.\n\\end{proof}\n", "meta": {"hexsha": "ff2c52178e3039b3a9c36cee1b5651433ad2eef5", "size": 3364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Multiplication-Properties.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Multiplication-Properties.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Multiplication-Properties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.5301204819, "max_line_length": 93, "alphanum_fraction": 0.6602259215, "num_tokens": 1207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.9353465184022065, "lm_q1q2_score": 0.866414972919273}} {"text": "%\n% Chapter 1.7\n%\n\n\\section*{1.7 Definition of a Limit}\n\n\\subsection*{Formal Definition of a Limit}\n\nLet \\(f\\) be a function defined on some open interval that contains the number \\(a\\), except possibly \\(a\\) itself. Then we say that the limit of \\(f(x)\\) as \\(x\\) approaches \\(a\\) is \\(L\\) and we write\n$$\\lim_{x \\to a}f(x)=L$$\nif for every number \\(\\epsilon > 0\\) there is a number \\(\\delta > 0\\) such that\n$$\\text{if} \\quad 0< \\left| x-a \\right| <\\delta \\quad \\text{then} \\quad \\left| f(x)-L \\right| <\\epsilon$$\n\n\\subsection*{Formal Definition of a Left-Hand Limit}\n\n$$\\lim_{x \\to a^-}f(x)=L$$\nif for every number \\(\\epsilon > 0\\) there is a number \\(\\delta > 0\\) such that \n$$\\text{if} \\quad a-\\delta 0\\) there is a number \\(\\delta > 0\\) such that \n$$\\text{if} \\quad aM$$\n\n\n\\subsection*{Formal Definition of a Negative Infinite Limit}\n\nLet \\(f\\) be a function defined on some open interval that contains the number \\(a\\), except \\(a\\) itself. Then\n$$\\lim_{x \\to a}f(x)=-\\infty$$\nmeans that for every negative number \\(N\\) there is a positive number \\(\\delta\\) such that \n$$\\text{if} \\quad 0< \\left| x-a \\right| <\\delta \\quad \\text{then} \\quad f(x)>N$$\n\n\\subsection*{Famous Trigonometric Limits}\n\nSee Chapter 2.4\n", "meta": {"hexsha": "70c6e1e9764711daa6024e47587e9da04216812c", "size": 1833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-7.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-7.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-7.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.7333333333, "max_line_length": 202, "alphanum_fraction": 0.6552100382, "num_tokens": 608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.9136765145991261, "lm_q1q2_score": 0.8663065266557031}} {"text": "%!TEX root = ../main.tex\n\n\\subsection{Restrained Growth}\n\n\\objective{Create and use logistic curves}\n\n\nExponential growth can rarely be carried on for long. Bacteria fill the petri dish, \nbunnies eat all the grass, and the shower-water has a maximum heat it can \nreach. In every case, the is a constraint, a ceiling value that the population \ncannot grow beyond. Typically, it is approached asymptotically. This means there are\ntwo horizontal asymptotes. The left half of the graph is concave up (exponential\ngrowth) and the right half is concave down (logarithmic growth). \n\nHow can these graphical quantities be achieved algebraically? What can \nbe done to $y=e^x$ to make it have a horizontal asymptote? As we saw last\nchapter, rational functions have horizontal asymptotes at the level of the ratio\nof the numerator to the denominator ``at infinity''. So we need to create a \ndenominator. But we don't want the denominator to ever equal 0, lest we\ncreate a vertical asymptote. Dividing by $e^x$ is almost right. Let's make it\n$e^x+1$.\n\n$$\nf(x) = \\frac{e^x}{e^x+1}\n$$\n\n\\begin{figure}[h]\n\\begin{centering}\n\\includegraphics[scale=0.5]{\\chapdir/pics/basicalogistic}\n\\caption{A basic logistic curve}\n\\end{centering}\n\\end{figure}\n\nThat worked out nicely, but it made our equation slightly more complicated\nthan we might otherwise like. If we want to do any inside transformation (e.g.\nshift left/right, widen/narrow) then we will need to modify $x$ in two places. Can\nwe consolidate the $x$ to be in only one place? What could we do to the\nnumerator and denominator ?\n\nDividing top and bottom by $e^x$ will cancel the two terms with $x$ in them.\nFurthermore, we can eliminate the need for complex fraction by changing\na denominator under 1 to be a negative exponent.\n\n$$\nf(x) = \\frac{1}{1+e^{-x}}\n$$\n\nNotice which numbers control the behavior of the graph. The 1 in the numerator\nis the maximum height of the graph, which typically called $c$ for ceiling. If we\ninsert a multiplying constant next to $x$ in the exponent, it will contract the\ngraph in the $x$-direction, making the curve of the S steeper. If we insert\na multiplying constant next to x, it will shift the turning point to the right. No\nmatter what we do, the inflection point will occur half-way up.\n\n$$\nf(x) = \\frac{c}{1+ae^{-bx}}\n$$\n\n\\subsection{Regression}\nThe TI-8* has a LOGISTICREG function which is excellent for computing\nregressions of this kind, and outputs functions of the kind already discussed.\nHowever, if we need to make an equation ourselves by hand, $e$ is slightly\nawkward number to use. Algebra manipulation is much easier with this\nequation:\n\n$$\nf(x) = \\frac{c}{1+ab^{-x}}\n$$\n", "meta": {"hexsha": "9602ab3bd65f65959e2fc425384f1cbf376d4828", "size": 2680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0705.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch07/0705.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch07/0705.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8405797101, "max_line_length": 86, "alphanum_fraction": 0.751119403, "num_tokens": 715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.9173026618464795, "lm_q1q2_score": 0.866095945891066}} {"text": "\\section{Function Reference}\n\n\\subsection*{abs($x$)}\n\nReturns the absolute value or vector length of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nX = (x,y,z)\nabs(X)\n\\end{verbatim}\n}\n\n\\noindent\n$\\left(x^2+y^2+z^2\\right)^{1/2}$\n\n\\subsection*{adj($m$)}\n\nReturns the adjunct of matrix $m$.\nAdjunct is equal to determinant times inverse.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nadj(A) == det(A) inv(A)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{and($a,b,\\ldots$)}\n\nReturns 1 if all arguments are true (nonzero).\nReturns 0 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nand(1=1,2=2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{arccos($x$)}\n\nReturns the arc cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\narccos(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{3}\\pi$\n\n\\subsection*{arccosh($x$)}\n\nReturns the arc hyperbolic cosine of $x$.\n\n\\subsection*{arcsin($x$)}\n\nReturns the arc sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\narcsin(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{6}\\pi$\n\n\\subsection*{arcsinh($x$)}\n\nReturns the arc hyperbolic sine of $x$.\n\n\\subsection*{arctan($y,x$)}\n\nReturns the arc tangent of $y$ over $x$.\nIf $x$ is omitted then $x=1$ is used.\n\n{\\color{blue}\n\\begin{verbatim}\narctan(1,0)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{2}\\pi$\n\n\\subsection*{arctanh($x$)}\n\nReturns the arc hyperbolic tangent of $x$.\n\n\\subsection*{arg($z$)}\n\nReturns the angle of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\narg(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$\\arctan(-3,2)$\n\n\\subsection*{besselj($x,n$)}\n\nReturns a solution to the Bessel differential equation.\n\n{\\color{blue}\n\\begin{verbatim}\nbesselj(x,1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2^{1/2}\\sin(x)}{\\pi^{1/2}\\,x^{1/2}}$\n\n\\subsection*{binding($s$)}\n\nThe result of evaluating a symbol can differ from the symbol's binding.\nFor example, the result may be expanded.\nThe {\\tt binding} function returns the actual binding of a symbol.\n\n{\\color{blue}\n\\begin{verbatim}\np = quote((x + 1)^2)\np\n\\end{verbatim}\n}\n\n\\noindent\n$p=x^2+2x+1$\n\n{\\color{blue}\n\\begin{verbatim}\nbinding(p)\n\\end{verbatim}\n}\n\n\\noindent\n$(x+1)^2$\n\n\\subsection*{binomial($n,k$)}\n\nReturns the coefficient of $x^ky^{n-k}$ in $(x+y)^n$.\n\n{\\color{blue}\n\\begin{verbatim}\nbinomial(52,5)\n\\end{verbatim}\n}\n\n\\noindent\n$2598960$\n\n\\bigskip\n\\noindent\nNote:\n\\verb$binomial$\nand\n\\verb$choose$\nare the same function.\n\n\\subsection*{ceiling($x$)}\n\nReturns the smallest integer greater than or equal to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nceiling(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{check($x$)}\n\nIf $x$ is true (nonzero) then continue, else stop.\nExpression $x$ can include the relational operators\n\\verb$=$,\n\\verb$==$,\n\\verb$<$,\n\\verb$<=$,\n\\verb$>$,\n\\verb$>=$.\nUse the\n\\verb$not$\nfunction to test for inequality.\n\n{\\color{blue}\n\\begin{verbatim}\nA = 1\nB = 1\ncheck(A=B) -- stop here if A not equal to B\n\\end{verbatim}\n}\n\n\\subsection*{choose($n,k$)}\n\nReturns the number of combinations of $n$ items taken $k$ at a time.\nThe following example computes the number of poker hands.\n\n{\\color{blue}\n\\begin{verbatim}\nchoose(52,5)\n\\end{verbatim}\n}\n\n\\noindent\n$2598960$\n\n\\subsection*{circexp($x$)}\n\nReturns expression $x$ with circular and hyperbolic functions\nconverted to exponentials.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(cos(x) + i sin(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\exp(ix)$\n\n\\subsection*{clear}\n\nClears all symbol definitions.\n\n\\subsection*{clock($z$)}\n\nReturns complex $z$ in polar form with base of negative 1 instead of $e$.\n\n{\\color{blue}\n\\begin{verbatim}\nclock(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$13^{1/2}\\,(-1)^{\\arctan(-3,2)/\\pi}$\n\n\\subsection*{coeff($p,x,n$)}\n\nReturns the coefficient of $x^n$ in polynomial $p$.\n\n{\\color{blue}\n\\begin{verbatim}\np = x^3 + 6x^2 + 12x + 8\ncoeff(p,x,2)\n\\end{verbatim}\n}\n\n\\noindent\n$6$\n\n\\subsection*{cofactor($m,i,j$)}\n\nReturns a cofactor of matrix $m$.\nThe cofactor matrix is the transpose of the adjunct of $m$.\nThis function returns the cofactor component at row $i$ and column $j$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ncofactor(A,1,2) == transpose(adj(A))[1,2]\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{conj($z$)}\n\nReturns the complex conjugate of $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nconj(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$2 + 3 i$\n\n\\subsection*{contract($a,i,j$)}\n\nReturns tensor $a$ summed over indices $i$ and $j$.\nIf $i$ and $j$ are omitted then 1 and 2 are used.\nThe expression {\\tt contract(m)} computes the trace of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ncontract(A)\n\\end{verbatim}\n}\n\n\\noindent\n$a + d$\n\n\\subsection*{cos($x$)}\n\nReturns the cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncos(pi/4)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{2^{1/2}}$\n\n\\subsection*{cosh($x$)}\n\nReturns the hyperbolic cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(cosh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{2}\\exp(-x)+\\tfrac{1}{2}\\exp(x)$\n\n\n\\subsection*{cross($u,v$)}\n\nReturns the cross product of vectors $u$ and $v$.\nIt is OK to redefine {\\tt cross}.\nThis is the default definition.\n\n{\\color{blue}\n\\begin{verbatim}\ncross(u,v) = (u[2] v[3] - u[3] v[2],\n u[3] v[1] - u[1] v[3],\n u[1] v[2] - u[2] v[1])\n\\end{verbatim}\n}\n\n\\subsection*{curl($u$)}\n\nReturns the curl of vector $u$.\nIt is OK to redefine {\\tt curl}.\nThis is the default definition.\n\n{\\color{blue}\n\\begin{verbatim}\ncurl(u) = (d(u[3],y) - d(u[2],z),\n d(u[1],z) - d(u[3],x),\n d(u[2],x) - d(u[1],y))\n\\end{verbatim}\n}\n\n\\subsection*{d($f,x$)}\n\nReturns the partial derivative of $f$ with respect to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nd(x^2,x)\n\\end{verbatim}\n}\n\n\\noindent\n$2x$\n\n\\bigskip\n\\noindent\nArgument $f$ can be a tensor of any rank.\nArgument $x$ can be a vector.\nWhen $x$ is a vector the result is the gradient of $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nF = (f(),g(),h())\nX = (x,y,z)\nd(F,X)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}\n\\operatorname{d}(f(),x) & \\operatorname{d}(f(),y) & \\operatorname{d}(f(),z)\\\\\n\\operatorname{d}(g(),x) & \\operatorname{d}(g(),y) & \\operatorname{d}(g(),z)\\\\\n\\operatorname{d}(h(),x) & \\operatorname{d}(h(),y) & \\operatorname{d}(h(),z)\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nIt is OK to use {\\tt d} as a variable name.\nIt will not conflict with function {\\tt d}.\n\n\\bigskip\n\\noindent\nIt is OK to redefine {\\tt d} as a different function.\nThe function {\\tt derivative}, a synonym for {\\tt d},\ncan still be used to obtain a partial derivative.\n\n\\subsection*{defint($f,x,a,b$)}\n\nReturns the definite integral of $f$ with respect to $x$\nevaluated from $a$ to $b$.\nThe argument list can be extended for multiple integrals\nas shown in the following example.\n\n{\\color{blue}\n\\begin{verbatim}\nf = (1 + cos(theta)^2) sin(theta)\ndefint(f, theta, 0, pi, phi, 0, 2pi) -- integrate over theta then over phi\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{16}{3}\\pi$\n\n\\subsection*{deg($p,x$)}\n\nReturns the degree of polynomial $p(x)$.\n\n{\\color{blue}\n\\begin{verbatim}\np = (2x + 1)^3\ndeg(p,x)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{denominator($x$)}\n\nReturns the denominator of expression $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ndenominator(a/b)\n\\end{verbatim}\n}\n\n\\noindent\n$b$\n\n\\subsection*{det($m$)}\n\nReturns the determinant of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ndet(A)\n\\end{verbatim}\n}\n\n\\noindent\n$a d - b c$\n\n\\subsection*{dim($a,n$)}\n\nReturns the dimension of the $n$th index of tensor $a$.\nIndex numbering starts with 1.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(3,4),(5,6))\ndim(A,1)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{div($u$)}\n\nReturns the divergence of vector $u$.\nIt is OK to redefine {\\tt div}.\nThis is the default definition.\n\n{\\color{blue}\n\\begin{verbatim}\ndiv(u) = d(u[1],x) + d(u[2],y) + d(u[3],z)\n\\end{verbatim}\n}\n\n\\subsection*{do($a,b,\\ldots$)}\n\nEvaluates each argument from left to right.\nReturns the result of the final argument.\n\n{\\color{blue}\n\\begin{verbatim}\ndo(A=1,B=2,A+B)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{dot($a,b,\\ldots$)}\n\nReturns the dot product of vectors, matrices, and tensors.\nAlso known as the matrix product.\n\n{\\color{blue}\n\\begin{verbatim}\n-- solve for X in AX=B\nA = ((1,2),(3,4))\nB = (5,6)\nX = dot(inv(A),B)\nX\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}-4\\\\ \\tfrac{9}{2}\\end{bmatrix}$\n\n\\subsection*{draw($f,x$)}\n\nDraws a graph of $f(x)$.\nDrawing ranges can be set with {\\tt xrange} and {\\tt yrange}.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (0,1)\nyrange = (0,1)\ndraw(x^2,x)\n\\end{verbatim}\n}\n\n\\subsection*{e}\n\nSymbol {\\tt e} is initialized to the natural number $e=\\exp(1)$.\n\n{\\color{blue}\n\\begin{verbatim}\ne^x\n\\end{verbatim}\n}\n\n\\noindent\n$\\exp(x)$\n\n\\bigskip\n\\noindent\nNote: It is OK to clear or redefine {\\tt e} and use the symbol for something else.\n\n\\subsection*{eigen($m$)}\n\nComputes eigenvalues and eigenvectors numerically.\nMatrix $m$ is required to be both numerical and symmetric.\nEigenvectors are returned in Q and eigenvalues are returned in D.\nEach row of Q is an eigenvector.\nEach diagonal element of D is an eigenvalue.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(2,1))\neigen(A)\ndot(transpose(Q),D,Q)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}\n1.0 & 2.0\\\\\n2.0 & 1.0\n\\end{bmatrix}\n$\n\n\\subsection*{erf($x$)}\n\nError function of $x$.\n\n\\subsection*{erfc($x$)}\n\nComplementary error function of $x$.\n\n\\subsection*{eval($f,x,a$)}\n\nReturns expression $f$ evaluated at $x$ equals $a$.\nThe argument list can be extended for multivariate expressions.\nFor example,\n\\verb$eval(f,x,a,y,b)$\nis equivalent to\n\\verb$eval(eval(f,x,a),y,b)$.\n\n{\\color{blue}\n\\begin{verbatim}\neval(x + y,x,a,y,b)\n\\end{verbatim}\n}\n\n\\noindent\n$a+b$\n\n\\subsection*{exp($x$)}\n\nReturns the exponential of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\subsection*{expand($r,x$)}\n\nReturns the partial fraction expansion of the ratio of polynomials $r$ in $x$.\n\n{\\color{blue}\n\\begin{verbatim}\np = (x + 1)^2\nq = (x + 2)^2\nexpand(p/q,x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\frac{2}{x+2}+\\frac{1}{x^2+4x+4}+1$\n\n\\subsection*{expcos($z$)}\n\nReturns the cosine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpcos(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}\\exp(iz)+\\tfrac{1}{2}\\exp(-iz)$\n\n\\subsection*{expcosh($z$)}\n\nReturns the hyperbolic cosine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpcosh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}\\exp(-z)+\\tfrac{1}{2}\\exp(z)$\n\n\\subsection*{expsin($z$)}\n\nReturns the sine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpsin(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}i\\exp(iz)+\\tfrac{1}{2}i\\exp(-iz)$\n\n\\subsection*{expsinh($z$)}\n\nReturns the hyperbolic sine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpsinh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}\\exp(-z)+\\tfrac{1}{2}\\exp(z)$\n\n\\subsection*{exptan($z$)}\n\nReturns the tangent of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexptan(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{i}{\\exp(2iz)+1}-\\frac{i\\exp(2iz)}{\\exp(2iz)+1}$\n\n\\subsection*{exptanh($z$)}\n\nReturns the hyperbolic tangent of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexptanh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\frac{1}{\\exp(2z)+1}+\\frac{\\exp(2z)}{\\exp(2z)+1}$\n\n\\subsection*{factor($n$)}\n\nFactors numerical value $n$ and returns the result.\n\n{\\color{blue}\n\\begin{verbatim}\nfactor(12/35)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2^2\\times 3}{5\\times 7}$\n\n\\bigskip\n\\noindent\nIf $n$ is a floating point value then a rational approximation of $n$ is factored and returned.\n\n{\\color{blue}\n\\begin{verbatim}\nfactor(float(pi))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{5\\times 71}{113}$\n\n\\subsection*{factor($p,x$)}\n\nFactors polynomial $p$ of $x$ and returns the result.\nThe argument list can be extended for multivariate polynomials.\n\n{\\color{blue}\n\\begin{verbatim}\np = 2x + x y + y + 2\nfactor(p,x,y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x+1)(y+2)$\n\n\\bigskip\n\\noindent\nNote:\n\\verb$factor$\nreturns an unexpanded expression.\nIf the result is assigned to a symbol, evaluating the symbol will expand the result.\nUse\n\\verb$binding$\nto retrieve the unexpanded expression.\n\n{\\color{blue}\n\\begin{verbatim}\nq = factor(p,x,y)\nbinding(q)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x+1)(y+2)$\n\n\\subsection*{factorial($n$)}\n\nReturns the factorial of $n$.\nThe expression {\\tt n!} can also be used.\n\n{\\color{blue}\n\\begin{verbatim}\n20!\n\\end{verbatim}\n}\n\n\\noindent\n$2432902008176640000$\n\n\\subsection*{filter($f,a,b,\\ldots$)}\n\nReturns $f$ excluding any terms containing $a$, $b$, etc.\n\n{\\color{blue}\n\\begin{verbatim}\np = x^2 + 3x + 2\nfilter(p,x^2)\n\\end{verbatim}\n}\n\n\\noindent\n$3x+2$\n\n\\subsection*{float($x$)}\n\nReturns expression $x$ with rational numbers and integers converted to\nfloating point values.\nThe symbol {\\tt pi} and the natural number are also converted.\n\n{\\color{blue}\n\\begin{verbatim}\nfloat(212^17)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 3.52947\\times 10^{39}$\n\n\\subsection*{floor($x$)}\n\nReturns the largest integer less than or equal to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nfloor(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n\\subsection*{for($i,j,k,a,b,\\ldots$)}\n\nFor $i$ equals $j$ through $k$ evaluate $a$, $b$, etc.\n\n{\\color{blue}\n\\begin{verbatim}\nfor(k,1,3,A=k,print(A))\n\\end{verbatim}\n}\n\n\\noindent\n$A=1$\\\\\n$A=2$\\\\\n$A=3$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt for} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt for}.\n\n\\subsection*{gcd($a,b,\\ldots$)}\n\nReturns the greatest common divisor of expressions.\n\n{\\color{blue}\n\\begin{verbatim}\ngcd(x,x y)\n\\end{verbatim}\n}\n\n\\noindent\n$x$\n\n\\subsection*{hermite($x,n$)}\n\nReturns the $n$th Hermite polynomial in $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nhermite(x,3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 8x^3-12x$\n\n\n\\subsection*{hilbert($n$)}\n\nReturns an $n$ by $n$ Hilbert matrix.\n\n{\\color{blue}\n\\begin{verbatim}\nhilbert(3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n1 & \\tfrac{1}{2} & \\tfrac{1}{3}\\\\ \\\\\n\\tfrac{1}{2} & \\tfrac{1}{3} & \\tfrac{1}{4}\\\\ \\\\\n\\tfrac{1}{3} & \\tfrac{1}{4} & \\tfrac{1}{5}\n\\end{bmatrix}\n$\n\n\\subsection*{i}\n\nSymbol {\\tt i} is initialized to the imaginary unit $\\sqrt{-1}$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\bigskip\n\\noindent\nNote: It is OK to clear or redefine {\\tt i} and use the symbol for something else.\n\n\\subsection*{imag($z$)}\n\nReturns the imaginary part of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nimag(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$-3$\n\n\\subsection*{inner($a,b,\\ldots$)}\n\nReturns the inner product of vectors, matrices, and tensors.\nAlso known as the matrix product.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nB = (x,y)\ninner(A,B)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\nax+by\\\\\ncx+dy\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nNote: {\\tt inner} and {\\tt dot} are the same function.\n\n\\subsection*{integral($f,x$)}\n\nReturns the integral of $f$ with respect to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nintegral(x^2,x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{3}x^3$\n\n\\subsection*{inv($m$)}\n\nReturns the inverse of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(3,4))\ninv(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n-2 & 1\\\\\n\\tfrac{3}{2} & -\\tfrac{1}{2}\n\\end{bmatrix}\n$\n\n\\subsection*{isprime($n$)}\n\nReturns 1 if $n$ is a prime number. Returns zero otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nisprime(2^31 - 1)\n\\end{verbatim}\n}\n\n\\noindent\n1\n\n\\subsection*{j}\n\nSet {\\tt j=sqrt(-1)} to use {\\tt j} for the imaginary unit instead of {\\tt i}.\n\n{\\color{blue}\n\\begin{verbatim}\nj = sqrt(-1)\n1/sqrt(-1)\n\\end{verbatim}\n}\n\n\\noindent\n$-j$\n\n\\subsection*{laguerre($x,n,a$)}\n\nReturns the $n$th Laguerre polynomial in $x$.\nIf argument $a$ is omitted then $a=0$ is used.\n\n{\\color{blue}\n\\begin{verbatim}\nlaguerre(x,3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{6}x^3+\\tfrac{3}{2}x^2-3x+1$\n\n\\subsection*{last}\n\nThe result of the previous calculation is stored in {\\tt last}.\n\n{\\color{blue}\n\\begin{verbatim}\n212^17\n\\end{verbatim}\n}\n\n\\noindent\n$3529471145760275132301897342055866171392$\n\n{\\color{blue}\n\\begin{verbatim}\nlast\n\\end{verbatim}\n}\n\n\\noindent\n$last=3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nSymbol {\\tt last} is an implied argument when a function has no argument list.\n\n{\\color{blue}\n\\begin{verbatim}\nfloat\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 3.52947\\times10^{39}$\n\n\\subsection*{lcm($a,b,\\ldots$)}\n\nReturns the least common multiple of expressions.\n\n{\\color{blue}\n\\begin{verbatim}\nlcm(x,x y)\n\\end{verbatim}\n}\n\n\\noindent\n$xy$\n\n\\subsection*{leading($p,x$)}\n\nReturns the leading coefficient of polynomial $p(x)$.\n\n{\\color{blue}\n\\begin{verbatim}\nleading(3x^2 + 1,x)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{legendre($x,n,m$)}\n\nReturns the $n$th Legendre polynomial in $x$.\nIf $m$ is omitted then $m=0$ is used.\n\n{\\color{blue}\n\\begin{verbatim}\nlegendre(x,3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{5}{2}x^3-\\tfrac{3}{2}x$\n\n\\subsection*{lisp($x$)}\n\nEvaluates expression $x$ and returns the result as a\nstring in prefix notation.\nUseful for debugging scripts.\n\n{\\color{blue}\n\\begin{verbatim}\nlisp(x^2 + 1)\n\\end{verbatim}\n}\n\n\\noindent\n\\verb$(+ (^ x 2) 1)$\n\n\\subsection*{log($x$)}\n\nReturns the natural logarithm of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nlog(x^y)\n\\end{verbatim}\n}\n\n\\noindent\n$y\\log(x)$\n\n\\subsection*{mag($z$)}\n\nReturns the magnitude of complex $z$.\nFunction {\\tt mag} treats undefined symbols as real while {\\tt abs} does not.\n\n{\\color{blue}\n\\begin{verbatim}\nmag(x + i y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x^2+y^2)^{1/2}$\n\n\\subsection*{mod($a,b$)}\n\nReturns the remainder of $a$ divided by $b$.\n\n{\\color{blue}\n\\begin{verbatim}\nmod(10,7)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{not($x$)}\n\nReturns 0 if $x$ is true (nonzero).\nReturns 1 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nnot(1=1)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n\\subsection*{nroots($p,x$)}\n\nReturns all roots, both real and complex,\nof polynomial $p(x)$.\nThe roots are computed numerically.\n\n\\subsection*{number($x$)}\n\nReturns 1 if $x$ is a rational or floating point number.\nReturns 0 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nnumber(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{numerator($x$)}\n\nReturns the numerator of expression $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nnumerator(a/b)\n\\end{verbatim}\n}\n\n\\noindent\n$a$\n\n\\subsection*{or($a,b,\\ldots$)}\n\nReturns 1 if at least one argument is true (nonzero).\nReturns 0 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nor(1=1,2=2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{outer($a,b,\\ldots$)}\n\nReturns the outer product of vectors, matrices, and tensors.\nAlso known as the tensor product.\n\n{\\color{blue}\n\\begin{verbatim}\nA = (a,b,c)\nB = (x,y,z)\nouter(A,B)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\na x & a y & a z\\\\\nb x & b y & b z\\\\\nc x & c y & c z\n\\end{bmatrix}\n$\n\n\\subsection*{pi}\n\nSymbol for $\\pi$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\subsection*{polar($z$)}\n\nReturns complex $z$ in polar form.\n\n{\\color{blue}\n\\begin{verbatim}\npolar(x - i y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x^2+y^2)^{1/2}\\exp(i\\arctan(-y,x))$\n\n\\subsection*{power}\n\nUse \\verb$^$ to raise something to a power.\nUse parentheses for negative powers.\n\n{\\color{blue}\n\\begin{verbatim}\nx^(-2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{x^2}$\n\n\\subsection*{prime($n$)}\n\nReturns the $n$th prime number.\nThe domain of $n$ is 1 to 10000.\n{\\color{blue}\n\\begin{verbatim}\nprime(100)\n\\end{verbatim}\n}\n\n\\noindent\n$541$\n\n\\subsection*{print($a,b,\\ldots$)}\n\nEvaluate expressions and print the results.\nUseful for printing from inside a {\\tt for} loop.\n\n{\\color{blue}\n\\begin{verbatim}\nfor(j,1,3,print(j))\n\\end{verbatim}\n}\n\n\\noindent\n$j=1$\\newline\n$j=2$\\newline\n$j=3$\n\n\\section*{product($i,j,k,f$)}\n\nFor $i$ equals $j$ through $k$ evaluate $f$.\nReturns the product of all $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nproduct(j,1,3,x + j)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^3+6x^2+11x+6$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt product} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt product}.\n\n\\subsection*{quote($x$)}\n\nReturns expression $x$ without evaluating it first.\n\n{\\color{blue}\n\\begin{verbatim}\nquote((x + 1)^2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x+1)^2$\n\n\\subsection*{quotient($p,q,x$)}\n\nReturns the quotient of polynomial $p(x)$ over $q(x)$.\n\n{\\color{blue}\n\\begin{verbatim}\np = x^2 + 1\nq = x + 3\nquotient(p,q,x)\n\\end{verbatim}\n}\n\n\\noindent\n$x-3$\n\n\\subsection*{rank($a$)}\n\nReturns the number of indices that tensor $a$ has.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nrank(A)\n\\end{verbatim}\n}\n\n\\noindent\n2\n\n\\subsection*{rationalize($x$)}\n\nReturns expression $x$ with everything over a common denominator.\n\n{\\color{blue}\n\\begin{verbatim}\nrationalize(1/a + 1/b + 1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2a+ab+2b}{2ab}$\n\n\\bigskip\n\\noindent\nNote:\n\\verb$rationalize$\nreturns an unexpanded expression.\nIf the result is assigned to a symbol, evaluating the symbol will expand the result.\nUse\n\\verb$binding$\nto retrieve the unexpanded expression.\n\n{\\color{blue}\n\\begin{verbatim}\nf = rationalize(1/a + 1/b + 1/2)\nbinding(f)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2a+ab+2b}{2ab}$\n\n\\subsection*{real($z$)}\n\nReturns the real part of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nreal(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n2\n\n\\subsection*{rect($z$)}\n\nReturns complex $z$ in rectangular form.\n\n{\\color{blue}\n\\begin{verbatim}\nrect(exp(i x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\cos(x)+i\\sin(x)$\n\n\\subsection*{roots($p,x$)}\n\nReturns the $x$ such that $p(x)=0$.\nPolynomial $p(x)$ should be factorable over integers.\nReturns a vector for multiple roots.\n\n{\\color{blue}\n\\begin{verbatim}\nroots(x^2 + 3x + 2,x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n-2\\\\\n-1\n\\end{bmatrix}\n$\n\n\\subsection*{run({\\it file})}\n\nRun script {\\it file}.\nUseful for importing function libraries.\n\n{\\color{blue}\n\\begin{verbatim}\nrun(\"Downloads/EVA.txt\")\n\\end{verbatim}\n}\n\n\\noindent\nNote: {\\it file} must be in the Downloads folder due to security requirements for apps distributed on the Mac App Store.\n\n\\subsection*{simplify($x$)}\n\nReturns expression $x$ in a simpler form.\n\n{\\color{blue}\n\\begin{verbatim}\nsimplify(sin(x)^2 + cos(x)^2)\n\\end{verbatim}\n}\n\n\\noindent\n1\n\n\\subsection*{sin($x$)}\n\nReturns the sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsin(pi/4)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{2^{1/2}}$\n\n\\subsection*{sinh($x$)}\n\nReturns the hyperbolic sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(sinh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}\\exp(-x)+\\tfrac{1}{2}\\exp(x)$\n\n\\subsection*{sqrt($x$)}\n\nReturns the square root of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsqrt(10!)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 720\\; 7^{1/2}$\n\n\\subsection*{status}\n\nPrints memory statistics.\n\n\\bigskip\n\\noindent\n{\\color{blue}\n\\verb$status$\n}\n\n\\bigskip\n\\noindent\n\\verb$block_count 1$\\\\\n\\verb$free_count 99258$\\\\\n\\verb$gc_count 1$\\\\\n\\verb$bignum_count 370$\\\\\n\\verb$string_count 0$\\\\\n\\verb$tensor_count 5$\n\n\\subsection*{stop}\n\nIn a script, it does what it says.\n\n\\subsection*{string($x$)}\n\nEvaluates expression $x$ and returns the result as a string.\nUseful for testing scripts.\n\n{\\color{blue}\n\\begin{verbatim}\nstring((x + 1)^2) == \"x^2 + 2 x + 1\"\n\\end{verbatim}\n}\n\n\\noindent\n1\n\n\\subsection*{subst($a,b,c$)}\n\nSubstitutes $a$ for $b$ in $c$ and returns the result.\n\n{\\color{blue}\n\\begin{verbatim}\nsubst(x,y,y^2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^2$\n\n\\subsection*{sum($i,j,k,f$)}\n\nFor $i$ equals $j$ through $k$ evaluate $f$.\nReturns the sum of all $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nsum(j,1,5,x^j)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^5+x^4+x^3+x^2+x$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt sum} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt sum}.\n\n\\subsection*{tan($x$)}\n\nReturns the tangent of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsimplify(tan(x) - sin(x)/cos(x))\n\\end{verbatim}\n}\n\n\\noindent\n0\n\n\\subsection*{tanh($x$)}\n\nReturns the hyperbolic tangent of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(tanh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\frac{1}{\\exp(2x)+1}+\\frac{\\exp(2x)}{\\exp(2x)+1}$\n\n\\subsection*{taylor($f,x,n,a$)}\n\nReturns the Taylor expansion of $f(x)$ near $x=a$.\nIf argument $a$ is omitted then $a=0$ is used.\nArgument $n$ is the degree of the expansion.\n\n{\\color{blue}\n\\begin{verbatim}\ntaylor(sin(x),x,5)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{120}x^5-\\tfrac{1}{6}x^3+x$\n\n\\subsection*{test($a,b,c,d,\\ldots$)}\n\nIf argument $a$ is true (nonzero) then $b$ is returned, else if $c$ is true then $d$ is returned, etc.\nIf the number of arguments is odd then the final argument is returned if all else fails.\nExpressions can include the relational operators\n\\verb$=$,\n\\verb$==$,\n\\verb$<$,\n\\verb$<=$,\n\\verb$>$,\n\\verb$>=$.\nUse the\n\\verb$not$\nfunction to test for inequality.\n(The equality operator\n\\verb$==$\nis available for contexts in which\n\\verb$=$\nis the assignment operator.)\n\n{\\color{blue}\n\\begin{verbatim}\nA = 1\nB = 1\ntest(A=B,\"yes\",\"no\")\n\\end{verbatim}\n}\n\n\\noindent\nyes\n\n\\subsection*{trace}\n\nSet {\\tt trace=1} in a script to print the script as it is evaluated.\nUseful for debugging.\n\n{\\color{blue}\n\\begin{verbatim}\ntrace = 1\n\\end{verbatim}\n}\n\n\\noindent\nNote:\nThe\n\\verb$contract$\nfunction is used to obtain the trace of a matrix.\n\n\\subsection*{transpose($a,i,j$)}\n\nReturns the transpose of tensor $a$ with respect to indices $i$ and $j$.\nIf $i$ and $j$ are omitted then 1 and 2 are used.\nHence a matrix can be transposed with a single argument.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ntranspose(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\na & c\\\\\nb & d\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nNote:\nThe argument list can be extended for multiple transpose operations.\nThe arguments are evaluated from left to right.\nFor example,\n\\verb$transpose(A,1,2,2,3)$\nis equivalent to\n\\verb$transpose(transpose(A,1,2),2,3)$.\n\n\\subsection*{tty}\n\nSet {\\tt tty=1} to print results in text format.\n\n{\\color{blue}\n\\begin{verbatim}\ntty = 1\n(x + 1/2)^2\n\\end{verbatim}\n}\n\n\\noindent\n\\verb$x^2 + x + 1/4$\n\n\\subsection*{unit($n$)}\n\nReturns an $n$ by $n$ identity matrix.\n\n{\\color{blue}\n\\begin{verbatim}\nunit(3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n1 & 0 & 0\\\\\n0 & 1 & 0\\\\\n0 & 0 & 1\n\\end{bmatrix}\n$\n\n\\subsection*{zero($i,j,\\ldots$)}\n\nReturns a null tensor with dimensions $i$, $j$, etc.\nUseful for creating a tensor and then setting component values.\n\n{\\color{blue}\n\\begin{verbatim}\nA = zero(3,3)\nfor(k,1,3,A[k,k]=k)\nA\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\nA=\n\\begin{bmatrix}\n1 & 0 & 0\\\\\n0 & 2 & 0\\\\\n0 & 0 & 3\n\\end{bmatrix}\n$\n", "meta": {"hexsha": "cbb0cf52a9f5219f826f7a17be877370ae00e6b2", "size": 26986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/help.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/help.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/help.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3503981797, "max_line_length": 120, "alphanum_fraction": 0.672904469, "num_tokens": 9237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.9173026494123034, "lm_q1q2_score": 0.8660959370327816}} {"text": "\\section{Hashing}\nTo make Maths people feel better about this exam, with the courtesy of Harald Räcke.\n\nThe purpose of hashing is having a data structure that tries to directly compute the memory location from the given key, obtaining constant search time. \n\nHash functions and their associated hash tables are used in data storage and retrieval applications to access and store information thanks to their efficiency.\n\nGiven an universe $U$ of keys and a set $S \\leq U$ of used keys to be distributed over an array $T[0, \\dots, n-1]$, an optimal hash function $H : U \\rightarrow [0, \\dots, n-1]$ should be fast to evaluate, have small storage requirements and a good distribution of elements over the whole table.\n\nIdeally, the hash function would map all keys to different memory locations (direct addressing), yet this is unrealistic since the size of the table would be much larger than available memory.\n\nKnowing previously the set $S$ of actual keys, it could be possible to design a simple function that maps all of them to different memory locations (perfect hashing); but this is not often the case.\n\nThe best expectation would be a function which distributes keys evenly across the table, yet this leads to the problem of collision: usually the universe $U$ is much larger than the table size $n$, hence there may be two elements $k_1, k_2$ from the same set $S$ so that $h(k_1) = h(k_2)$, and therefore getting mapped to the same memory location.\n\nTypically, collisions do not appear once the size of the set $S$ of actual keys get close to $n$, but otherwise the probability of having a collision when hashing $m$ elements under uniform hashing is at least:\n$$1 - e^{-\\frac{m(m-1)}{2n}} \\approx 1 - e^{-\\frac{m^2}{2n}}$$\n\nPractically, hash tables should be larger than the amount of keys to store, for instance the next power of two. There also are scaling coefficients such as 1.5 or 1.5, to avoid resizing too much and wasting space. Precomputing prime numbers is an useful option, but requires a range of about 10\\% more than the number of keys.\n\nThere are methods to deal with collisions: open addressing, hashing with chaining, or just not resolving them at all.\n\nHashing with chaining arranges elements that map to the same position in a linear list, inserting at the front of the list. The average time required for an unsuccessful search is $A^- = 1 + \\frac{m}{n}$, while for a successful search it is $A^+ \\leq 1 + \\frac{\\nicefrac{m}{n}}{2}$.\n\nOpen addressing, in particular, stores all objects in the table defining a function that determines the position through a permutation of all possible $n - 1$ values. If an insertion fails, a new position is searched (either through a different function or looking for the first free slot).\n\nA good choice for $h(i, j)$ to have an uniform distribution over the possible values is a modulo with a prime number.\n\nIntroducing prime numbers is relevant because the size of hash table should not have factors in common with the linear component of the function, otherwise keys would be mapped to the same position. Increasing has also to be done by odd numbers, to reduce the possibility of remainder zero.\n\nPrime numbers can be generated through algorithms, of which the most basic is the prime sieve: a list of integers up to a desired number is created, and composite numbers are progressively removed until only primes are left. \n\nFor large primes used in cryptography, a random chosen range of odd numbers of the desired size is sieved against a number of relatively small primes, and the remaining are subject to primality testing (Miller-Rabin).\n\nTo keep uniformity of the distribution even allowing new elements to be added, rehashing might be necessary, or incremental of the prime.\n\n\\subsection{Fibonacci hashing}\nFibonacci hashing is a variation of classic hashing using instead of a modulo operation, a multiplication by the golden ratio:\n$$\\frac{x}{y} = \\frac{x + y}{x} \\implies \\phi = \\frac{1 + \\sqrt{5}}{2}$$\n\nThe golden ratio has a close relationship with Fibonacci numbers: the previous equality, in fact, holds between every Fibonacci number and its successor.\n\nThe $n^{th}$ Fibonacci number is obtained calculating $F_n = \\frac{1}{\\sqrt{5}}(\\phi^n - \\varphi^n)$, where $\\phi = \\frac{(1 + \\sqrt{5})}{2}$ and $\\varphi = \\frac{(1 - \\sqrt{5})}{2}$.\n\nIn the context of Fibonacci hashing, it is taken the reciprocal of $\\phi$, and hashing is performed multiplying the value $k$ by the integer relatively prime to $k$ which is closer to $\\phi^{-1}k$. \n\nConsecutive keys have an uniform spread distribution, therefore it is an efficient method.\n\n\\subsection{Neojoin}\nHashing is relevant in a distributed systems architecture because it can help determining how to locate relations on nodes.\n\nWhile performing a distributed join, tuples may join with tuples on remote nodes: relations can be repartitioned and redistributed for local joins, so that tuples will only join with the corresponding partition.\n\nThe partitioning scheme defines how to assign partitions to nodes, using for instance a hash function. There are several options to implement a scheme:\n\\begin{enumerate}\n\t\\item Minimizing network traffic, assigning a partition to the node which owns its largest part. This way, only the small fragments of a partition are sent over the network, but a schedule with minimal network traffic may have high duration;\n\t\\item Minimizing response time, i. e. the time from request to result. This is dominated by network duration, which depends on maximum straggler;\n\t\\item Minimizing maximum straggler, formulated as a NP-hard linear programming problem where nodes have the most similar possible amount of workload.\n\\end{enumerate}\n\nSatisfying those constraints may lead to unused resources, for instance nodes not doing any work.\n\n\\subsection{Chord hashing}\nChord is a protocol for a peer-to-peer distributed hash table. it stores key-values assigning a node the values for which it is responsible, using a chord to assign and discover values.\n\nNodes and keys are given an hashed identifier of $m$ bits, and using the Chord lookup protocol nodes are put in a circle that has as most $2^m$ nodes. \n\nEach node has a successor and a predecessor, going in clockwise direction, but normally there are holes in the sequence. In general, the successor of a node $k$ has the first identifier equal or greater than $k$.\n\nLookup is performed passing the query through the successors of a node, if the key cannot be found locally. This leads to linear worst-case performance, but can be avoided implementing a finger table in each node. \n\nA finger table contains up to $m$ entries, and entry $i$ of node $n$ contains the successor of key $(n + 2^{i-1}) \\mod 2^m$. At every lookup, the query is passed to closest successor or predecessor of $k$ in the finger table, narrowing worst-case performance to logarithmic.\n\nEach peer is responsible for all keys larger than the predecessor number until its own. Introducing a factor of $2^k$, the distance always increases by 2, halving the number of hops each time.\n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.45]{chord.png}\n\t\\centering\n\\end{figure}\n\n\\section{Distributed data processing}\nDistributed databases are a great solution to optimize memory and speed, yet not every operation is supported by them. Machine learning or graph algorithms, for instance, are hard to compute on a sharded relational schema.\n\nAnalysis can be implemented in several different ways, but certain tasks need to be handled in every implementation:\n\\begin{itemize}\n\t\\item Parallelization/synchronization;\n\t\\item Distribution of computation and data;\n\t\\item Communication between nodes;\n\t\\item Node failures.\n\\end{itemize}\n\nCreating a custom solution takes time and is error prone; functional abstractions can be used to specify computation in parallel. The runtime system, this way, manages program execution, data distribution and persistence, node failures and communication.\n\nWhen a cluster is necessary, it is possible to use pre-configured structures:\n\\begin{enumerate}\n\t\\item Infrastructure as a Service, externalizing resources and storage;\n\t\\item Platform as a Service, renting databases and web servers;\n\t\\item Software as a Service, using developer tools and additional packages.\n\\end{enumerate}\n\n\\subsection{MapReduce}\nMapReduce is a programming model with associated implementation for processing and generating big data sets with a parallel distributed algorithm on a cluster.\n\nIt is composed of:\n\\begin{enumerate}\n\t\\item A Map procedure, which performs filtering and sorting, applied by each worker to the local data and collecting output to a temporary storage;\n\t\\item A Shuffle phase, where workers redistribute data based on the same output keys, so that all data with the same key is located on the same node;\n\t\\item A Reduce method, which executes a summary operation (such as counting) on local data in parallel.\n\\end{enumerate}\n\nThe model is inspired by functional programming, but its key contributions are the scalability and fault tolerance achieved by optimizing the execution engine, especially on multi-threaded implementations. \n\nMaps can be performed in parallel, and a set of reducers can perform the reduction phase. Parallelism offers possibility of recovering from partial failure of servers or storage: the work can be rescheduled without recomputing all of it.\n\nLogically, Map takes one pair of data with a type in one data domain, and returns a list of pairs in a different domain:\n$$Map(k_1, v_1) \\rightarrow list(k_2, v_2)$$\n\nThe Reduce function is then applied in parallel to each group, which in turn produces a collection of values in the same domain:\n$$Reduce(k_2, list(v_2)) \\rightarrow list((k_3, v_3))$$\n\nEach Reduce call typically produces either one key-value par or an empty return.\n\nExample (from Wikipedia):\n\\begin{lstlisting}\nfunction map(String name, String document):\n\t// name: document name\n\t// document: document contents\n\tfor each word w in document:\n\t\temit (w, 1)\n\nfunction reduce(String word, Iterator partialCounts):\n\t// word: a word\n\t// partialCounts: a list of aggregated partial counts\n\tsum = 0\n\tfor each pc in partialCounts:\n\t\tsum += pc\n\temit (word, sum)\n\\end{lstlisting}\nThis MapReduce performs a word count on a document. Each document is split into words, and every word is counted by Map; then all pairs with the same key are put together and sent to Reduce, which sums the relative counts.\n\nMapReduce implementaton can be applied to many algorithms, such as joining of two relations or PageRank.\n\n\\subsubsection{PageRank}\nPageRank is an algorithm used by Google Search to rank web pages in their search engine results, measuring the relevance of them.\n\nIt works assigning a numerical weight to each element of an hyperlinked set of documents, with the purpose of obtaining its relative importance within the set.\n\nIt outputs a probability distribution used to represent the likelihood that a person randomly clicking on links will arrive at any particular page. Links from a page to itself are ignored.\n\nThe PageRank transferred from a given page to the targets of its outbound links upon the next iteration is divided equally among all outbound links. \n\nThe value for a page $v$ is dependent on the values for each page in the set containing all pages linking to $v$, divided by the number of links from $v$.\n\nPseudo-code PageRank:\n\\begin{enumerate}\n\t\\item Retrieve total number of nodes $n$;\n\t\\item Write initial values in each node, computed as $\\frac{1}{n}$;\n\t\\item Find next node as $\\frac{1-d}{n}$, where $d$ is the correction factor;\n\t\\item For each iteration of the algorithm:\n\t\\begin{enumerate}\n\t\t\\item Compute outgoing page rank fraction;\n\t\t\\item Add fraction to all neighbors;\n\t\\end{enumerate}\n\t\\item Swap next node and current;\n\t\\item Reset next reassigning it the value of $\\frac{1-d}{n}$.\n\\end{enumerate}\n\nThis algorithm looks at each node in the graph, computes the fraction of rank it has to pass on to neighbors, and writes it.\n\nFor better performance, the value can be computed in reverse, collecting all fractions from reverse neighbors.\n\nThe sequential reads are optimized for modern computers, but the random access to next node exhibits performance problems. Caches help alleviating this, since they can store most visited nodes.\n\nIf the memory requirements exceed the available main memory, the system will allocate too much memory, running into several page faults. Sorting by degree will make often-accessed nodes all in the same page.\n\nThe distributed version sends computed values to other nodes, but can cause overhead and network congestion. MapReduce assigns the Shuffle phase the duty of message passing.\n\nComputing PageRank using MapReduce is also performed using the function to repeatedly multiply a vector by the matrix representing how the distribution changes after every single step.\n\n\\subsection{Hadoop}\nHadoop is an open-source implementation of the MapReduce framework, written in Java (opposed to the proprietary of Google in C++). It is now an Apache project used for very large clusters to handle big data sets.\n\n\\subsubsection{MapReduce}\nHadoop MapReduce is an application on the cluster that negotiates resources with YARN: a JobTracker globally manages jobs, and every node has its own TaskTracker.\n\n\\begin{enumerate}\n\t\\item An user submits job configuration to JobTracker;\n\t\\item JobTracker submits mapper tasks to TaskTrackers, scheduling computation on all available cluster nodes;\n\t\\item Each task works on the data local to its node;\n\t\\item The Shuffler moves output produced my Map among the nodes in the cluster;\n\t\\item Once shuffling is complete, JobTracker schedules Reduce to all nodes.\n\\end{enumerate}\n\nSince the datasets are much larger than the main memory and processing happens on very big clusters, intermediate results must be written to disk and shuffled results should be ordered.\n\nMapReduce is however a framework not suitable for all uses: not everything can be expressed through the functions it offers, plus it is not a good fit for workloads with a lot of computation and smaller datasets.\n\n\\subsubsection{HDFS}\nHadoop relies on a distributed file system (HDFS), the primary data storage set used by its applications. It supports the rapid transfer of data between compute nodes, breaking information down into separate blocks and distributing it.\n\nThe file system ensures durability and data distribution, storing data read by Map, and pre-sorting and saving its output. \n\nShuffling moves data between nodes and merges pre-sorted data, and results of Reduce are again written to HDFS.\n\nHDFS is highly fault tolerant: the system replicates data multiple times, placing at least one copy on a different server rack than the others.\n\nFiles are split into blocks of 64MB, and by default each block has 3 replicas, so that missing data can be reconstructed. \n\nIt follows a master-slave architecture: Name node manages file system and regulates access, while data nodes manage attached storage.\n\nI/O is boosted by striping blocks of data over multiple disks, writing in parallel. HDFS exposes append-only files to users.\n\nJobTracker is responsible to cope with failing nodes: it notices that one TaskTracker is not responsive, and its task gets reassigned to another node.\n\nIf its job is in Reduce phase, the correspondent function is restarted on other TaskTrackers.\n\n\\subsubsection{YARN}\nYARN stands for Yet Another Resource Negotiator, and is a redesigned resource manager and large-scale distributed operating system for Hadoop.\n\nYARN splits up the functionalities of resource management and job scheduling into separate daemons, to obtain a global resouce manager and a master for every application.\n\nThe ResourceManager and the NodeManager form the data computation framework. A NodeManager is the agent in every machine which is responsible for containers, monitoring their resource usage and reporting results to the ResourceManager.\n\nThe Scheduler is responsible for allocating resources to the various running applications subject to constraints such as capacity, performing no tracking of application status.\n\n\\subsection{Optimizations}\nTo optimize MapReduce it is possible to add a combiner, an optional class that operated by accepting input from Map and passing it to Reduce after summarizing records with the same key.\n\nIt operates on each Map output key, having the same key-value output as the Reducer, and it helps segregating data into multiple groups.\n\nFolding is a function to save disk space: it analyzes a recursive data structure, and returns recombined results by recursively processing its constituent parts.\n\nPrograms working well on large clusters require a deep understanding of warehouse-sized computers: different settings need different techniques. In general, HDFS should be portable.\n\nOverall, Hadoop considers hardware failure to be the norm, with applications needing streaming access on large datasets. Its model, therefore, uses a model aiming to minimize writes and keeps computation local with the data.\n\n\\subsection{Scale up vs. out}\nA data center is usually made of computers piled in racks, and racks are connected via a switch to form a cluster.\n\nAccessing data on remote machines comes with a price: the faster is a local DRAM (20GB/S), but cluster DRAMs and disks are relatively slow. \n\nIn case no single machine is large enough to store all the data, it is necessary to choose between scaling up and out: a cluster of large expensive machines or a large cluster of cheap commodity machines.\n\nA simple execution model calculates the total cost summing the expense of computation with all global data access. The data kept locally is inversely proportional to the size of cluster.\n$$ TotalCost = \\frac{1ms}{n} + f \\times \\Big[100ns \\times \\frac{1}{n} + 100\\mu s \\times \\Big(1 - \\frac{1}{n}\\Big) \\Big]$$\n\n\\begin{itemize}\n\t\\item Light communication: $f = 1$;\n\t\\item Medium communication: $f = 10$;\n\t\\item Heavy communication: $f = 100$.\n\\end{itemize}\n\nWorkloads with light communication benefit from large clusters, while large amounts of random communication impede performance. Random reads must be avoided!\n\n\\subsection{Spark}\nSpark is an alternative to Hadoop which provides more expressive fault-tolerant runtime for distributed batched data analytics. It can handle more complex analysis with interactive queries processing real time streams.\n\nThe purpose of a new programming model is extending the existing naive algorithms implementation:\n\\begin{itemize}\n\t\\item Data can be outputted by sorted key;\n\t\\item Locality can be increased using different kinds of partitioning;\n\t\\item Window queries can be answered sorting by group.\n\\end{itemize}\n\nThe MapReduce model is extended too with complex data pipelines, but recovery mechanisms are lightweight and require less additional computation.\n\nSparks offers additional API for more functionalities, such as Spark SQL, GraphX and MLIB.\n\n\\subsubsection{RDDs}\nSpark revolves around the concept of a resilient distributed dataset (RDD), which is a fault-tolerant collection of elements that can be operated on in parallel.\n\nRDD is considered the evolution of the general Spark model, offering datasets that can be efficiently cached and manipulated. \n\nRDDs support two types of operations: transformations, which create a new dataset from an existing one, and actions, which return a value to the driver program after running a computation on the dataset.\n\nAll transformations in Spark are lazy, in that they do not compute their results right away. Instead, they just remember the transformations applied to some base dataset (e.g. a file). \n\nThey are only computed when an action requires a result to be returned to the driver program, and the dataset gets only loaded when operations are performed on it. This design enables Spark to run more efficiently.\n\nPipelines allow to chain transformations and intermediate steps do not need to be materialized since they can just be recomputed on node failure.\n\n\\subsubsection{DataFrames}\nDatFrames are dynamically strongly typed distributed collections of data organized into columns, conceptually equivalent to a table in a relational database.\n\nThey can be interacted with using SQL functions, allowing query optimization and avoiding interpretation overhead, although with a limited set of functions.\n\n\\subsubsection{Datasets}\nA Dataset is a combination between DataFrame and RDD, optionally weakly typed, to retain code compilation. It is still mapped as a RDD.\n\nDatasets can be created, analyzed (limited, filtered) and be subject of exploration, management or aggregation just like tables.\n\n\\subsubsection{Optimization}\nRDDs track lineage information to rebuild lost data, logging everything in a graph to recompute missing or damaged partitions. Spark offers support for DAGs.\n\nSnapshots are automatically created after repartitioning transformations and managed using a LRU cache to speed up recovery.\n\nThe optimizer builds a logical plan and applies transformation rules, to then generate the physical plan and select the cheapest cost model. \n\nSpark's runtime focuses on three main points:\n\\begin{itemize}\n\t\\item Memory Management and Binary Processing, leveraging semantics to eliminate the overhead of deserialization and garbage collection;\n\t\\item Cache-aware computation, using columnar storage and compression to exploit memory hierarchy;\n\t\\item Code generation to optimize usage of modern compilers and CPU.\n\\end{itemize}\n\nOperations to take care of reading, managing ETL pipelines, training and query are performed within the same framework.\n", "meta": {"hexsha": "11cd5ba878b2dbaee9fa166dd29906141c0698f7", "size": 21618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Foundations of Data Engineering/lectures/lecture5.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Foundations of Data Engineering/lectures/lecture5.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Foundations of Data Engineering/lectures/lecture5.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 70.4169381107, "max_line_length": 347, "alphanum_fraction": 0.7943843094, "num_tokens": 4587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778048911612, "lm_q2_score": 0.9046505293168444, "lm_q1q2_score": 0.8660018728980559}} {"text": "\n\\subsection{The Moore-Penrose pseudoinverse}\n\nFor a matrix \\(X\\), the pseudoinverse is \\((X^*X)^{-1}X^*\\).\n\nFor real matrices, this is: \\((X^TX)^{-1}X^T\\)\n\nThe pseudoinverse can be written as \\(X^+\\)\n\nTherefore \\(\\theta \\) is the pseudoinverse of the inputs, multiplied by the outputs. Or:\n\n\\(\\theta = X^+y\\)\n\nThe pseudoinverse satisfies:\n\n\\(XX^+X=X\\)\n\n\\(X^+XX^+=X^+\\)\n\n\n", "meta": {"hexsha": "cd5a86d8a797fcb52a381f106c92512aab22054b", "size": 372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/02-03-pseudo.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/02-03-pseudo.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/02-03-pseudo.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7142857143, "max_line_length": 88, "alphanum_fraction": 0.6344086022, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.970687770944576, "lm_q2_score": 0.8918110490322426, "lm_q1q2_score": 0.8656700792888515}} {"text": "\\subsection{Derivative of a Laplace Transform}\r\n\\noindent\r\nConsider the $n^{th}$ derivative of the Laplace transform of $f$,\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}^n}{\\mathrm{d}s^n}\\left(\\Laplace{f(t)}\\right) = \\frac{\\mathrm{d}^n}{\\mathrm{d}s^n}\\left(\\int_{0}^{\\infty}{f(t)e^{-st} \\mathrm{d}t}\\right).\r\n\\end{equation*}\r\nWe're able to change the order of differentiation and integration here without affecting the result.\r\n\\begin{align*}\r\n\t&= \\int_{0}^{\\infty}{f(t)\\frac{\\mathrm{d}^n}{\\mathrm{d}s^n}\\left(e^{-st}\\right) \\mathrm{d}t} \\\\\r\n\t&= \\int_{0}^{\\infty}{f(t)(-t)^ne^{-st} \\mathrm{d}t} \\\\\r\n\t&= (-1)^n\\Laplace{t^nf(t)}.\r\n\\end{align*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}^n}{\\mathrm{d}s^n}\\left(\\Laplace{f(t)}\\right) = (-1)^n\\Laplace{t^nf(t)}.\r\n\\end{equation*}\r\nThis formula is useful in both directions: finding the derivatives of Laplace transforms, and finding the Laplace transforms of functions multiplied by $t^n$.", "meta": {"hexsha": "adef44498b8e451bb6b67199040846b297f4b882", "size": 926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/derivativeOfLaplace.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/laplaceTransforms/derivations/derivativeOfLaplace.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/laplaceTransforms/derivations/derivativeOfLaplace.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 54.4705882353, "max_line_length": 158, "alphanum_fraction": 0.6609071274, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214532237354, "lm_q2_score": 0.8976953023710936, "lm_q1q2_score": 0.8656668385346136}} {"text": "\\section{Proof Methods}\n\n\\frame{{Part 2: Proof Methods}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]}\n\n\\subsection{Inference Rules}\n\n\\begin{frame}{Inference Rules}{}\n Inference (or logic deductions) are used to prove new propositions by using propositions that have been proposed before.\n \\bigskip\n\n We normally write an inference as follows:\n\n \\[\n \\frac{P, Q, R}{X}\n \\]\n\n This means \"propositions P, Q, R are true, meaning that proposition X is true\".\\bigskip\n\n \\structure{Inference Rules} are inferences that are particularly useful to build proofs. Let's see a few:\n\\end{frame}\n\n\\begin{frame}{Inference Rules}{Modus Ponens}\n The \\emph{Modus Ponens} inference rule is:\n \\[\n \\frac{P, P\\implies Q}{Q}\n \\]\n If P is true, and P implies Q is true, then Q is true.\\bigskip\n\n A few other related inference rules:\n \\[\n \\frac{P \\implies Q, Q \\implies R}{P \\implies R},\n \\frac{not(P) \\implies not(Q)}{Q \\implies P}\n \\]\n\n So one way to prove a proposition is to {\\bf start with propositions that you know are true} and {\\bf use inference rules to reach the proposition you want to prove}.\n\\end{frame}\n\n\\subsection{Proving Implications}\n\n\\begin{frame}{Proving an Implication}{Direct Proof}\n The \\emph{Modus Ponens} rule says that:\n \\[\n \\frac{P, P\\implies Q}{Q}\n \\]\n To prove $Q$, we have to prove that $P$, and that {\\bf $P$ implies $Q$}.\\bigskip\n\n We can prove an implication directly, by assuming $P$ is true, and showing that $Q$ must be true, step by step.\\bigskip\n\\end{frame}\n\n\\begin{frame}{Proving an Implication}{Direct Proof}\n{\\bf Theorem:} If $0 \\leq x \\leq 2$, then $-x^3 + 4x + 1 > 0$\\bigskip\n\n\\begin{proof}\n\\begin{itemize}\n \\item Let's assume $0 \\leq x \\leq 2$\n \\item We can rewrite $-x^3 + 4x$ as $x(2-x)(2+x)$\n \\item If $0 \\leq x \\leq 2$, then $x$, $(2-x)$, $(2+x)$ are all non-negative.\n \\item $x(2-x)(2+x) \\geq 0$\n \\item $x(2-x)(2+x) + 1 > 0$\n \\item $-x^3 + 4x + 1 > 0$\n\\end{itemize}\n\\end{proof}\n\n\\end{frame}\n\n\\begin{frame}{Proving an Implication}{Contrapositive}\n Another way to prove an implication is to \"prove the contrapositive\". This means using the following inference rule:\n\n \\[\n \\frac{\\text{NOT}(Q) \\implies \\text{NOT}(P)}{P \\implies Q}\n \\]\n\n So if we show that when Q is false, then P is always false, it is equivalent to show that when P is true, then Q is always true.\n\\end{frame}\n\n\\begin{frame}{Proving an Implication}{Contrapositive}\n {\\bf Theorem:} if $r$ is irrational, then $\\sqrt{r}$ is also irrational.\n\n \\begin{proof}\n We prove the contrapositive: If $\\sqrt{r}$ is rational, then $r$ is also rational.\n \\begin{itemize}\n \\item If $\\sqrt{r}$ is rational, then $\\sqrt{r}=\\frac{m}{n}$.\n \\item $m$ and $n$ are integers (definition of rational numbers)\n \\item Square both sides: $r = \\frac{m^2}{n^2}$.\n \\item $m^2$ and $n^2$ are also integers, so $r$ is rational.\n \\end{itemize}\n \\end{proof}\n\\end{frame}\n\n\n\n\\begin{frame}{Proving \"If and only If\"}\n Remember that \"If and only If\" can be defined as:\n \\[\n \\frac{P\\implies Q, Q \\implies P}{P\\iff Q}\n \\]\n\n So to prove $P\\iff Q$, we can first prove the implication from $P$ to $Q$, and then prove the implication from $Q$ to $P$.\\bigskip\n\n This is useful to show equivalence between two mathematical statements.\n\\end{frame}\n\n\n\\subsection{Proof by Cases}\n\n\\begin{frame}[fragile]{Proof By Cases}{Example}\n\n Let's say you are refactoring code, and you want to profe that the two code samples below are equivalent. How would you do it?\n \\vfill\n\n \\begin{block}{Code 1}\n\\begin{verbatim}\nIf (X > 0 OR (X <= 0 AND Y > 100))\n print(\"Hello!\")\n\\end{verbatim}\n \\end{block}\n \\begin{block}{Code 2}\n\\begin{verbatim}\nIf (X > 0 OR Y > 100)\n print(\"Hello!\")\n\\end{verbatim}\n \\end{block}\n\\end{frame}\n\n\\begin{frame}{Proof By Cases}{Definition}\n \\structure{Proof By Cases}, is a proof technique that uses the idea of \"divide and conquer\".\\vfill\n\n You break one complicated problem into easier, smaller sub-problems.\n \\vfill\n\n \\alert{Important!} When you create the cases, make sure that all possible cases are covered!\n\\end{frame}\n\n\\begin{frame}{Example: Friends and Strangers}\n\n {\\bf Theorem:} In a group of 6 people, where {\\bf every pair} is either a friend or a stranger, then we {\\bf always} have at least a set of \\structure{3 mutual friends} or a set of \\alert{3 mutual strangers}.\n\n \\begin{center}\n \\includegraphics[width=0.6\\textwidth]{../img/friends_and_strangers}\n \\end{center}\n \\pagenote{Friends or Strangers Image from \"Math for Computer Science\" MIT-OCW slides}\n\\end{frame}\n\n\\begin{frame}{Example: Friends and Strangers}\n \\begin{proof}\n The proof is by case analysis. Let \"A\" be one of the six people. There are two cases:\n \\begin{enumerate}\n \\item Among the 5 other people, at least 3 are friends with A;\n \\item Among the 5 other people, at least 3 are strangers with A;\n \\end{enumerate}\\medskip\n\n Let's assume case (1). Let's call the three friends B, C, D. There are two subcases:\n \\begin{enumerate}[A]\n \\item B-C, C-D, or B-D are friends. We have now \\structure{3 mutual friends} with A and the pair here.\n \\item B-C, C-D and B-D are strangers. This makes a \\structure{3 mutual strangers} set with the three pairs.\n \\end{enumerate}\\medskip\n\n This means that in case 1, the theorem holds. It is easy to see that case 2 is symmetrical to case 1.\n \\end{proof}\n\\end{frame}\n\n\n\\begin{frame}{A WRONG Proof By Cases}\n\n {\\bf Theorem:} $2a^2 > a$, for all $a\\in \\mathbb{Z}$.\n\n \\begin{proof}\n The proof is by case analysis.\n \\begin{enumerate}\n \\item Case 1: $a > 0$;\n \\begin{itemize}\n \\item $2a^2$ is equal to $2a\\times a$\n \\item Since $a > 0$ and $a \\in \\mathbb{Z}$, then $a \\geq 1$\n \\item $2\\times 1\\times 1 > 1$\n \\end{itemize}\n \\item Case 2: $a < 0$\n \\begin{itemize}\n \\item Since $a < 0$ and $a \\in \\mathbb{Z}$, then $a \\leq 1$\n \\item For any negative $a$, $a^2$ is positive, so $a^2 > a$.\n \\end{itemize}\n \\end{enumerate}\n Because the theorem holds for case (1) and case (2), it holds for all possible cases.\n \\end{proof}\n \\bigskip\n\n What is wrong with this proof?\n\\end{frame}\n\n\\subsection{Proof by Contradiction}\n\\begin{frame}{Proof By Contradiction}{Definition}\n\n \"Proof by Contradiction\" is a technique where you show that {\\bf the negative of the theorem implies a false fact to be true}.\\bigskip\n\n For a simple example: \"If gravity did not exist, then we would all be flying. Since we are not flying, then gravity must exist.\"\\bigskip\n\n Sometimes, it can be easy to create a proof by contradiction by finding a good counter-example. Other times, we have to find an absurd consequence of the negative.\\bigskip\n\n Use \"Proof by Contradiction\" to prove the following theorem:\\\\\n {\\bf Theorem:} $\\sqrt{2}$ is an irrational number.\n\\end{frame}\n\n\n\\begin{frame}{Proof by Contradiction}{Example}\n\n \\begin{proof}\n We use proof by contradiction, and assume $\\sqrt{2}$ is rational.\n \\begin{enumerate}\n \\item $\\sqrt{2} = \\frac{m}{n}$; $m,n \\in \\mathbb{Z}$; $n\\neq 0$, and $m,n$ have no common factors.\n \\item $n\\sqrt{2} = m$ and squaring both sides give $2n^2 = m^2$.\n \\item $m^2$ is even (because $n^2 = \\frac{m^2}{2}$)\n \\item If $m^2$ is even, then $m$ is even too. So $m = 2k$ for some integer $k$.\n \\item So, $2n^2 = (2k)^2$, which leads to $n^2 = 2k^2$.\n \\item Following the logic of (3) and (4), $n^2$ is even, and $n$ is even too.\n \\item However, if $m$ and $n$ are even, it is a contradiction with (1).\n \\end{enumerate}\n \\end{proof}\n\\end{frame}\n\n\n\n\\subsection{The Well Ordering Outline}\n\n\\begin{frame}{Well Ordering Principle}{Definition}\n\n The Well Ordering Principle (WOP) is a very useful principle in mathematics, that can also look a little bit \"obvious\":\\bigskip\n\n {\\Large\n \\begin{center}\n Every \\structure{non-empty} set of\\\\\n \\structure{Non-negative Integer Numbers} ($\\mathbb{Z}^+$)\\\\\n has \\alert{one smallest element}\n \\end{center}}\n\\end{frame}\n\n\\begin{frame}{Well Ordering Principle}\n \\frametitle{Well Ordering Examples}\n \\begin{itemize}\n \\item What is the smallest age among students in Tsukuba?\n \\bigskip\n\n \\item What is the smallest number of coins that adds to 876 yens?\n \\bigskip\n\n \\item What are the smallest integers $m$ and $n$ so that $x = \\frac{m}{n}$?\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Well Ordering Principle Proof Example}{}\n We can re-write the proof that $\\sqrt{2}$ is irrational using WOP.\n\n \\begin{proof}\n \\begin{enumerate}\n \\item $\\sqrt{2} = \\frac{m}{n}$; $m,n \\in \\mathbb{Z}$; $n\\neq 0$;\n \\item \\alert{By WOP, there is a {\\bf smallest} $m$ and $n$ so that $\\sqrt{2} = \\frac{m}{n}$}\n \\item $n\\sqrt{2} = m$ and squaring both sides give $2n^2 = m^2$.\n \\item $m^2$ is even (because $n^2 = \\frac{m^2}{2}$)\n \\item If $m^2$ is even, then $m$ is even too. So $m = 2k$ for some integer $k$.\n \\item So, $2n^2 = (2k)^2$, which leads to $n^2 = 2k^2$.\n \\item Following the logic of (4) and (5), $n^2$ is even, and $n$ is even too.\n \\item If $m$ and $n$ are even, then $\\sqrt{2} = \\frac{m/2}{n/2}$, and \\alert{$m/2$, $n/2$ are smaller than $m,n$, contradicting the WOP}.\n \\end{enumerate}\n \\end{proof}\n\\end{frame}\n\n\\begin{frame}{Why is the WOP useful?}{General form for a WOP proof}\n\n The WOP gives us a general framework to produce proofs by contradiction:\n\n \\begin{itemize}\n \\item Structure your theorem around predicate $P(n)$, where $n \\in \\mathbb{N}$.\n \\item Define a set $C$ of counter examples, so that $C ::=\\{n \\in \\mathbb{N}| P(n) \\text{ is false}\\}$.\n \\item By WOP, consider the minimum element $m \\in C$.\n \\item Find a contradiction, for example:\n \\begin{itemize}\n \\item if $m$ exists, then it implies in the existence of a smaller element $m' < m, m' \\in C$.\n \\item if $m$ exists, then actually $P(m)$ is true, and $m$ is not actually in $C$.\n \\end{itemize}\n \\item Therefore, the minimum element $m$ does not exist, the counter example set $C$ does not exist, and $P(n)$ is true for all $n$.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{WOP Proof examples:}\n Let's see two quick examples of proofs using WOP. Try doing these two proofs by yourself first:\n \\vfill\n\n \\begin{itemize}\n \\item {\\bf Theorem:} Every $n > 1, n\\in\\mathbb{N}$ is a product of prime numbers.\\bigskip\n\n \\item {\\bf Theorem:} For every $n\\in\\mathbb{N}$, $P(n): n+8 = 5a+3b; a,b \\in\\mathbb{N}$.\\\\(for every $n$, $n+8$ is composed of a sum of 3s and 5s)\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{WOP Proof example I: Prime factors}\n\n {\\bf Theorem:} Every integers bigger than 1 is a product of prime numbers.\n \\begin{proof}\n Proof by contradiction using the WOP.\n \\begin{itemize}\n \\item Assume, by WOP, that $m$ is the smallest $\\mathbb{N}$ that is not a product of prime numbers.\n \\item Obviously $m$ is not a prime, so $m = a_1a_2\\ldots a_n$, where $a_i$ is not prime.\n \\item Is $a_i$ a product of prime numbers?\n \\begin{itemize}\n \\item If $a_i$ is a product of prime numbers, then $a_i$ = $p_1p_2\\ldots p_n$, and $m$ is now a product of prime numbers (\\alert{contradiction})\n \\item If $a_i$ is not a product of prime numbers, then $m$ is not the {\\bf smallest} product of prime numbers. (\\alert{contradiction})\n \\end{itemize}\n \\end{itemize}\n \\end{proof}\n\\end{frame}\n\n\\begin{frame}{WOP Proof example II: Postal Numbers}\n {\\bf Theorem:} For every $n$, $n+8$ is composed of 3s and 5s.\n\n \\begin{proof}\n Proof by contradiction using the WOP\n \\begin{itemize}\n \\item First, we quickly verify that $P(n)$ is true for 0..8\n \\item By WOP, we assume that there is some minimum $m > 8$ where $P(m)$ is false.\n \\item If $P(m)$ is false, then $m+8$ cannot be composed of 3s and 5s.\n \\item If $m$ is minimum, then $P(m-8)$ is true, and $m$ is composed of 3s and 5s.\n \\item If $m$ is composed of 3s and 5s, then $m+8$ is $m+3+5$, and $P(m)$ is true! (\\alert{Contradiction})\n \\end{itemize}\n \\end{proof}\n\\end{frame}\n", "meta": {"hexsha": "3676a01a67f6bdbed6fec9fff3e8f992eab7f507", "size": 11998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week01/02_ProofMethods.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week01/02_ProofMethods.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week01/02_ProofMethods.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8036809816, "max_line_length": 210, "alphanum_fraction": 0.6631938656, "num_tokens": 3940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.9334308087146874, "lm_q1q2_score": 0.8656294729016966}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade \n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nShow that for any integer $n \\geq 0$,\n\\begin{equation}\n\\sum_{k=0}^{n} {n \\choose k}k = n2^{n-1}\n\\end{equation}\n\n\\subsection*{Solution}\n\nProof is given by differentiating over binomial formula, given in Equation \\ref{eq2}.\n\n\\begin{equation}\n(x + y)^n = \\sum_{k=0}^{n}{n \\choose k}x^ky^{n-k}\n\\label{eq2}\n\\end{equation}\n\nSubstituting $1$ for $y$ leads to\n\n\\begin{equation}\n(1 + x)^n = \\sum_{k=0}^{n}{n \\choose k}x^k\n\\label{eq3}\n\\end{equation}\n\nwhere $(1 + x)^n$ is simply the ordinary generating function for a finite sequence of binomial coefficients.\nBy differentiating Equation \\ref{eq3} over $x$, we will achieve\n\n\\begin{equation}\nn(1+x)^{n-1} = \\sum_{k=0}^{n} {n \\choose k}kx^{k-1}\n\\end{equation}\n\nNow substituting $1$ for $x$ will give us\n\n\\begin{equation}\n\\sum_{k=0}^{n}{n \\choose k}k = n2^{n-1}\n\\end{equation}\n\nand all equations are valid for any integer $n \\geq 0$.\n", "meta": {"hexsha": "ccc10908290208164b495837def3a84c2910cb66", "size": 1250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 27.7777777778, "max_line_length": 108, "alphanum_fraction": 0.6184, "num_tokens": 415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079104, "lm_q2_score": 0.9086178876533446, "lm_q1q2_score": 0.8655258958399694}} {"text": "\n\\subsection{Symmetric and antisymmetric tensors}\n\nConsider a tensor, e g \\(T_{abc}\\).\n\nIn general, this is not symmetric, that is:\n\n\\(T_{abc}\\ne T_{bac}\\)\n\n\\subsubsection{Symmetric part of a tensor}\n\nWe can write the symmetric part of this with regard to \\(a\\) and \\(b\\).\n\n\\(T_{(ab)c}=\\dfrac{1}{2}(T_{abc}+T_{bac})\\)\n\nClearly, \\(T_{(ab)c}=T_{(ba)c}\\)\n\n\\subsubsection{Antisymmetric part of a tensor}\n\nWe can also have an an antisymmetric part with regard to \\(a\\) and \\(b\\).\n\n\\(T_{[ab]c}=\\dfrac{1}{2}(T_{abc}-T_{bac})\\)\n\nClearly, \\(T_{[ab]c}=-T_{[ba]c}\\)\n\n\\subsubsection{Tensors as sums of their symmetric and antisymmetric parts}\n\n\\(T_{(ab)c}+T_{[ab]c}=\\dfrac{1}{2}(T_{abc}+T_{bac})+\\dfrac{1}{2}(T_{abc}-T_{bac})\\)\n\n\\(T_{(ab)c}+T_{[ab]c}=T_{abc}\\)\n\n", "meta": {"hexsha": "e21f05ab526b68d4b26fd170a5519e260b83fbd3", "size": 750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/03-04-symmetry.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/03-04-symmetry.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/03-04-symmetry.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4375, "max_line_length": 83, "alphanum_fraction": 0.644, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.9059898134030163, "lm_q1q2_score": 0.865509403539534}} {"text": "\\lab{The Finite Difference Method}{The Finite Difference Method}\n\\label{lab:finitedifference2}\n\nSuppose we have a function $u(x)$, defined on an interval $[a,b]$.\nLet $a = x_{-1}, x_0, x_1, \\ldots x_{n-1}$ be a grid of evenly spaced points, with $x_i = a + (i+1)h$, $h = (b-a)/n$.\nFrom a Taylor expansion of $u(x)$, we obtain the approximation\n\\[u''(x) = \\frac{u(x+h) - 2u(x) + u(x-h)}{h^2}, \\]\nwith error $E(h) = \\mathcal{O}(h^2)$.\nThus\n\\[u''(x) = \\frac{u(x_{i+1}) - 2u(x_i) + u(x_{i-1})}{h^2}, \\quad i = 0, \\ldots, n-2.\\]\nThis can be written in matrix form as\n\\begin{align}\n\\frac{1}{h^2}\n\\begin{bmatrix}\n-2 & 1 & \\\\\n1 & -2 & 1 \\\\\n& &\\ddots & \\\\\n & 1 & -2 & 1 \\\\\n & & 1 & -2\n\\end{bmatrix}\n\\begin{bmatrix}\nu(x_0) \\\\ u(x_1)\\\\ \\vdots \\\\ u(x_{n-3}) \\\\ u(x_{n-2})\n\\end{bmatrix} +\n\\begin{bmatrix}\nu(x_{-1})/h^2 \\\\ 0 \\\\ \\vdots \\\\ 0 \\\\ u(x_{n-1})/h^2\n\\end{bmatrix} =\n\\begin{bmatrix}\nu''(x_0) \\\\ u''(x_1)\\\\ \\vdots \\\\ u''(x_{n-3}) \\\\ u''(x_{n-2})\n\\end{bmatrix}\\label{finitedifference2:upp}\n\\end{align}\n\nSimilarly, since $u'(x) = (u(x+h) - u(x-h))/(2h)$ with error $E(h) = \\mathcal{O}(h^2)$, we have the approximation\n\\begin{align}\n\\frac{1}{2h}\n\\begin{bmatrix}\n0 & 1 & \\\\\n-1 & 0 & 1 \\\\\n& &\\ddots & \\\\\n & -1 & 0 & 1 \\\\\n & & -1 & 0\n\\end{bmatrix}\n\\begin{bmatrix}\nu(x_0) \\\\ u(x_1)\\\\ \\vdots \\\\ u(x_{n-3}) \\\\ u(x_{n-2})\n\\end{bmatrix} +\n\\begin{bmatrix}\n-u(x_{-1})/(2h) \\\\ 0 \\\\ \\vdots \\\\ 0 \\\\ u(x_{n-1})/(2h)\n\\end{bmatrix} =\n\\begin{bmatrix}\nu'(x_0) \\\\ u'(x_1)\\\\ \\vdots \\\\ u'(x_{n-3}) \\\\ u'(x_{n-2})\n\\end{bmatrix}\\label{finitedifference2:up}\n\\end{align}\n\n\\begin{problem}\n\tLet $u(x) = \\sin((x+\\pi)^2-1)$. Use \\eqref{finitedifference2:upp} and \\eqref{finitedifference2:up} to approximate $\\frac{1}{2}u'' - u'$ at the grid points. \\label{prob:finitedifference2:prob1}\n\\end{problem}\n\nSuppose that instead of knowing the function $u(x)$, we know that $\\frac{1}{2}u'' - u = f$, where the function $f(x)$ is given.\nHow do we solve for $u$ at the grid points?\n\n\\section*{Finite Difference Methods}\n\nNumerical methods for differential equations seek to approximate the exact solution $u(x)$ at some finite collection of points in the domain of the problem.\nInstead of analytically solving the original differential equation, defined over an infinite-dimensional function space, they use a simpler finite system of algebraic equations to approximate the original problem.\n\nConsider the following differential equation:\n\\begin{align}\n\t\\begin{split}\n\t&{ } \\epsilon u''(x)-u(x)'= f(x), \\quad x \\in (0,1), \\\\\n\t&{ } u(0) = 1, \\quad u(1) = 3.\n\t\\end{split} \\label{eqn:singular_perturbed_BVP}\n\\end{align}\nEquation \\eqref{eqn:singular_perturbed_BVP} can be written $D u = f,$ where $D = \\epsilon \\frac{d^2}{dx^2} - \\frac{d}{dx}$ is a differential operator defined on the infinite-dimensional space of functions that are twice continuously differentiable on $[0,1]$ and satisfy $u(0) = 1$, $u(1) = 3$.\n\nWe look for an approximate solution $\\{U_i\\}_{i=-1}^{N-1}$ on an evenly spaced grid of $N$ subintervals, $a = x_{-1}, x_0, \\ldots, x_{N-1} = b$ with $h = x_{i+1}-x_i$ for each $i$.\nOur finite difference method will replace the differential operator $D = \\epsilon \\frac{d^2}{dx^2} - \\frac{d}{dx}$, defined on an infinite-dimensional space of functions, with difference operators defined on a finite vector space (the space of grid functions $\\{U_i\\}_{i=-1}^{N-1}$).\nTo do this, we replace derivative terms in the differential equation with appropriate difference expressions.\n\nRecalling that\n\\begin{align*}\n\t\\frac{d^2}{dx^2} u(x) &= \\frac{u(x+h)- 2u(x) + u(x-h)}{h^2} + \\mathcal{O}(h^2),\\\\\n\\frac{d}{dx} u(x) &= \\frac{u(x+h)-u(x-h)}{2h} + \\mathcal{O}(h^2).\n\\end{align*}\nwe define the finite difference operator $D_h$ by\n\\begin{align}\nD_h U_i = \\epsilon \\frac{1}{h^2}\\left(U_{i+1} -2U_i + U_{i-1}\\right) - \\frac{1}{2h} \\left(U_{i+1}-U_{i-1} \\right). \\label{fd_operator}\n\\end{align}\nThus we discretize equation \\eqref{eqn:singular_perturbed_BVP} using the equations\n\\begin{align*}\n\t\\frac{\\epsilon}{h^2} (U_{i+1}- 2U_i + U_{i-1}) - \\frac{1}{2h} \\left(U_{i+1}-U_{i-1} \\right) &= f(x_i), \\quad i = 0, \\ldots, N-2,\n\\end{align*}\nalong with boundary conditions $U_{-1} = 1,$ $U_{N-1} = 3$.\n\nThis gives $N+1$ equations and $N+1$ unknowns, and can be written in matrix form as\n\\[ \\frac{1}{h^2} \\begin{bmatrix}h^2 & 0 &0&\\hdots &0 \\\\ (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) &\\hdots &0\\\\ \\vdots & & \\ddots & &\\vdots \\\\\n0 & \\hdots & (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) \\\\ 0 & \\hdots & & 0 & h^2\n\\end{bmatrix} \\cdot \\begin{bmatrix}U_{-1}\\\\U_0\\\\ \\vdots \\\\U_{N-2} \\\\U_{N-1}\\end{bmatrix} = \\begin{bmatrix}f(x_{-1})\\\\f(x_0)\\\\ \\vdots \\\\ f(x_{N-2}) \\\\ f(x_{N-1}) \\end{bmatrix}.\n\\]\nWe can further modify the system to obtain an $(N-1)\\times (N-1)$ tridiagonal matrix on the left:\n\\begin{align}\n \\label{eqn:practical_fin_dif}\n \\begin{split}\n\\frac{1}{h^2} \\begin{bmatrix}-2\\epsilon & (\\epsilon - h/2) &0&\\hdots &0 \\\\ (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) &\\hdots &0\\\\ \\vdots & & \\ddots & &\\vdots \\\\\n0 & \\hdots & (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) \\\\ 0 & \\hdots & & (\\epsilon + h/2) &-2\\epsilon\n\\end{bmatrix} \\cdot \\begin{bmatrix}U_{0}\\\\U_1\\\\ \\vdots \\\\U_{N-3} \\\\U_{N-2}\\end{bmatrix}\\\\\n = \\begin{bmatrix}f(x_0) -\\alpha(\\epsilon + h/2)/h^2 \\\\f(x_1)\\\\ \\vdots \\\\ f(x_{N-3})\\\\ f(x_{N-2})-\\beta(\\epsilon - h/2)/h^2 \\end{bmatrix}.\n \\end{split}\n\\end{align}\n\n\n\n\\begin{problem}\nUse equation \\eqref{eqn:practical_fin_dif} to solve the singularly perturbed BVP \\eqref{eqn:singular_perturbed_BVP} with $\\epsilon = 1/10$, $f(x) = -1$.\nThis BVP is called singularly perturbed because of the location of the parameter $\\epsilon$.\nFor $\\epsilon = 0$ the ODE has a drastically different character - it then becomes first order, and can no longer support two boundary conditions.\n \\label{prob:finitedifference2:prob1}\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{figure2.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob1}.\nThe solution gets steeper near $x = 1$ as $\\epsilon $ gets small.}\n\\end{figure}\n\n\n\\begin{comment}\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.sparse import spdiags\nfrom scipy.sparse.linalg import spsolve\nimport matplotlib.pyplot as plt\n\ndef bvp(func, epsilon, alpha, beta, N):\n\ta,b = 0., 1. \t# Interval for the BVP\n\th = (b-a)/N \t# The length of each subinterval\n\t\n\t# Initialize and define the vector F on the right\n\tF = np.empty(N-1.)\t\t\t\n\tF[0] = func(a+1.*h)-alpha*(epsilon+h/2.)*h**(-2.)\n\tF[N-2] = func(a+(N-1)*h)-beta*(epsilon-h/2.)*h**(-2.)\n\tfor j in xrange(1,N-2):\n\t\tF[j] = func(a + (j+1)*h)\n\t\t\n\t# Here we define the arrays that will go on the diagonals of A\n\tdata = np.empty((3,N-1))\n\tdata[0,:] = -2.*epsilon*np.ones((1,N-1)) # main diagonal\n\tdata[1,:] = (epsilon+h/2.)*np.ones((1,N-1)) \t # off-diagonals\n\tdata[2,:] = (epsilon-h/2.)*np.ones((1,N-1))\n\t# Next we specify on which diagonals they will be placed, and create A\n\tdiags = np.array([0,-1,1])\n\tA=h**(-2.)*spdiags(data,diags,N-1,N-1).asformat('csr')\n\t\n\tU = np.empty(N+1)\n\tU[1:-1] = spsolve(A,F)\n\tU[0], U[-1] = alpha, beta\n\treturn np.linspace(a,b,N+1), U\n\nx, y = bvp(lambda x:-1., epsilon=.05,alpha=1, beta=3, N=400)\nplt.plot(x,y,'-k',linewidth=2.0)\nplt.show()\n\n\\end{lstlisting}\n\\end{comment}\n\n\n\\section*{A heuristic test for convergence}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=12cm]{example_convergence.pdf}\n\\caption{Demonstration of second order convergence for the finite difference approximation \\eqref{fd_operator} of the BVP given in \\eqref{eqn:singular_perturbed_BVP} with $\\epsilon = .5$. } \\label{fig:finitedifference2}\n\\end{figure}\n\nThe finite differences used above are second order approximations of the first and second derivatives of a function. It seems reasonable to expect that the numerical solution would converge at a rate of about $\\mathcal{O}(h^2)$. How can we check that a numerical approximation is reasonable?\n\n% One way to determine this is to compute solutions for various step sizes $h$ and see if the solutions are converging to something.\nSuppose a finite difference method is $\\mathcal{O}(h^p)$ accurate.\nThis means that the error $E(h) \\approx Ch^p$ for some constant $C$ as $h \\to 0$ (in other words, for $h>0$ small enough).\n\nSo compute the approximation $y_k$ for each stepsize $h_k$, $h_1 > h_2> \\ldots>h_m$.\n$y_m$ should be the most accurate approximation, and will be thought of as the true solution.\nThen the error of the approximation for\nstepsize $h_k, k < m,$ is\n\\begin{align*}\n\tE(h_k) &= \\max( \\abs{ y_k - y_m}) \\approx C h_k^p ,\\\\\n\t\\log(E(h_k)) &= \\log(C) + p \\log(h_k).\n\\end{align*}\n\nThus on a log-log plot of $E(h)$ vs. $h$, these values should be on a straight line with slope $p$ when $h$ is small enough to start getting convergence. We should note that demonstrating second-order convergence does NOT imply that the numerical approximation is converging to the correct solution.\n\n\n\\begin{problem}\nReturn to problem \\ref{prob:finitedifference2:prob1}. How many subintervals are needed to obtain 4 digits of accuracy?\n\nThis is a question about the convergence of your solution. The following code generates the log-log plot in Figure \\ref{fig:finitedifference2}, and demonstrates second-order convergence for our finite difference approximation of \\eqref{eqn:singular_perturbed_BVP}. Use this code to determine what $h$ (and hence what $N$) is needed for the error to be less than $10^{-4}$.\n\n\\textsc{note}: The function \\li{bvp} is not provided; you need to use your code from problem \\ref{prob:finitedifference2:prob1} to define it. Make sure your function is compatible with the code below. It must take 5 parameters as input and return both the solution and the grid.\n\n\t% If $\\alpha = 1$, $\\beta = 3$, and $f(x) = -1$, there is an exact solution:\n\t% \\[y(x) = \\alpha + x+ (\\beta - \\alpha -1)\\frac{e^{x/\\epsilon -1}}{e^{1/\\epsilon -1}}\\]\n\t\\label{prob:finitedifference2:prob2}\n\\end{problem}\n\n\n\\begin{lstlisting}\nnum_approx = 10 # Number of Approximations\nN = 5*np.array([2**j for j in range(num_approx)])\nh, max_error = (1.-0)/N[:-1], np.ones(num_approx-1)\n\n# Best numerical solution, used to approximate the true solution.\n# bvp returns the grid, and the grid function, approximating the solution\n# with N subintervals of equal length.\nmesh_best, num_sol_best = bvp(lambda x:-1, epsilon=.1, alpha=1, beta=3, N=N[-1])\nfor j in range(len(N)-1):\n mesh, num_sol = bvp(lambda x:-1, epsilon=.1, alpha=1, beta=3, N=N[j])\n max_error[j] = np.max(np.abs( num_sol- num_sol_best[::2**(num_approx-j-1)] ) )\nplt.loglog(h,max_error,'.-r',label=\"$E(h)$\")\nplt.loglog(h,h**(2.),'-k',label=\"$h^{\\, 2}$\")\nplt.xlabel(\"$h$\")\nplt.legend(loc='best')\nplt.show()\nprint \"The order of the finite difference approximation is about \", ( (np.log(max_error[0]) -\n np.log(max_error[-1]) )/( np.log(h[0]) - np.log(h[-1]) ) ), \".\"\n\\end{lstlisting}\n\n\n\\begin{problem}\nExtend your finite difference code to the case of a general second order linear BVP with Dirichlet conditions:\n\\begin{align*}\n\t&{ } a_1(x)y'' +a_2(x)y'+ a_3(x) y = f(x), \\quad x \\in (a,b),\\\\\n\t&{ } y(a) = \\alpha, \\quad y(b) = \\beta.\n\\end{align*}\nUse your code to solve the boundary value problem\n\\begin{align*}\n\t\\epsilon y'' - 4(\\pi - x^2)y = \\cos x, \\\\\n\ty(0) = 0, \\quad y(\\pi/2) = 1,\n\\end{align*}\nfor $\\epsilon = 0.1$.\n\\label{prob:finitedifference2:prob3}\n(Hint: How should the finite difference operator $D_h$ in \\eqref{fd_operator} be modified?)\n\n\\end{problem}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{figure3.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob3}.\n% The solution gets steeper near $x = 1$ as $\\epsilon $ gets small.\n}\n\\end{figure}\n\n\nThe next few problems will help you troubleshoot your finite difference code.\n\n\\begin{problem}\nNumerically solve the boundary value problem\n\\begin{align*}\n\t\\epsilon y'' + xy' = -\\epsilon \\pi^2 \\cos(\\pi x) - \\pi x \\sin(\\pi x), \\\\\n\ty(-1) = -2, \\quad y(1) = 0,\n\\end{align*}\nfor $\\epsilon = 0.1, 0.01,$ and $0.001$.\n\\label{prob:finitedifference2:prob4}\n\\end{problem}\n\n\\begin{problem}\nNumerically solve the boundary value problem\n\\begin{align*}\n\t(\\epsilon +x^2)y'' + 4xy' + 2y = 0, \\\\\n\ty(-1) = 1/(1+\\epsilon), \\quad y(1) = 1/(1+\\epsilon),\n\\end{align*}\nfor $\\epsilon = 0.05, 0.02$.\n\\label{prob:finitedifference2:prob5}\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=11cm]{figure4.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob4}.\n}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=11cm]{figure5.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob5}.\n}\n\\end{figure}\n\n", "meta": {"hexsha": "c5da87b8f6d66fb856b7ed654b8a9b119cc56af6", "size": 12565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FiniteDifferenceMethod/FiniteDifferenceMethod.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/FiniteDifferenceMethod/FiniteDifferenceMethod.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/FiniteDifferenceMethod/FiniteDifferenceMethod.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 43.3275862069, "max_line_length": 373, "alphanum_fraction": 0.6676482292, "num_tokens": 4441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542887603537, "lm_q2_score": 0.9019206811430764, "lm_q1q2_score": 0.8650810894400413}} {"text": "\\section{Convolution}\nFor simplicity of exposition, we denote \n\\begin{equation}\\label{eq:size_f}\nm = m_1 = 2^{s} + 1, \\quad n = n_1 = 2^t +1.\n\\end{equation}\n\\begin{definition}\nA convolution defined on $\\mathbb{R}^{m\\times n}$ is a linear mapping \n$K\\ast: \\mathbb{R}^{m\\times n}\\mapsto \\mathbb{R}^{m\\times n}$ defined with padding, \nfor any $g \\in \\mathbb{R}^{m\\times n}$ by:\n%We first consider $\\theta$ a convolution operator (with stride $1$) \n%and padding:\n\\begin{equation}\\label{con1}\n[K \\ast g]_{i,j} = \\sum_{p,q=-k}^k K_{p, q} g_{i + p, j + q}, \\quad i=1:m, j = 1:n.\n\\end{equation}\n\\end{definition}\nHere we note that the indices for the entries in $K$ are given un a special way. \nFor example, if $k=1, K\\in \\mathbb R^{3\\times 3}$, and \n$$\nK=\\begin{pmatrix}\n\tK_{-1,-1} &K_{-1,0} &K_{-1,1} \\\\\n\tK_{0,-1} &K_{0,0} &K_{0,1} \\\\\n\tK_{1,-1} &K_{1,0} &K_{1,1} \\\\\n\t\\end{pmatrix}.\n$$\n \nThe coefficients in \\eqref{con1} constitute a kernel matrix\n\\begin{equation}\nK \\in \\mathbb{R}^{(2k+1) \\times (2k+1)},\n\\end{equation}\nwhere $k$ is often taken as a small integer. \nHere padding means how $ g_{i+ p, j + q}$ is defined\nwhen $(i+ p, j + q)$ is out of $1:m$ or $1:n$. \nThe following three choices are often used\n\\begin{equation}\\label{eq:padding}\nf_{i + p, j + q} = \\begin{cases}\n0, \\quad &\\text{zero padding}, \\\\\nf_{(i + p)\\pmod{m}, (s + q)\\pmod{n}}, \\quad &\\text{periodic padding}, \\\\\nf_{|i-1 +p|, |j -1 +q|}, \\quad &\\text{reflected padding}, \\\\\n\\end{cases}\n\\end{equation}\nif \n\\begin{equation}\ni + p \\notin \\{1, 2, \\dots, m\\} ~\\text{or} ~ j+ q \\notin \\{1, 2, \\dots, n\\}.\n\\end{equation}\nHere $ d \\pmod{m} \\in \\{1, \\cdots, m\\} $ means the remainder when $d$ is divided by $m$.\n\n\n\\section{Convolution with stride}\n\\begin{definition}\nFor any given integer $s\\ge1$, a convolution with stride $s$ for $g \\in \\mathbb{R}^{m\\times n}$ is defined as:\n\t\\begin{equation}\\label{stride}\n\t[K \\ast_s g]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} g_{si + p, sj + q}, \n\t\\quad i = 1: \\lceil \\frac{m+1}{s}\\rceil, j = 1: \\lceil \\frac{n+1}{s}\\rceil.\n\t\\end{equation}\n\tHere $ \\lceil \\frac{m}{s}\\rceil$ denotes the smallest integer that greater than $\\frac{m}{s}$.\n\\end{definition}\nBoth in CNN and in multigrid method, convolution with stride $s=2$ is the most important case, namely\n\\begin{equation}\\label{stride_2}\n[K \\ast_2 g]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} g_{2i + p, 2j + q}, \n\\quad i = 1: \\frac{m+1}{2} , j = 1: \\frac{n+1}{2}.\n\\end{equation}\n\n\n\\begin{lemma}\nThe convolution with stride $2$ can be rewritten as:\n\\begin{equation}\\label{eq:convstride_2_1}\nK \\ast_2 g = \\mathcal S( K\\ast g),\n\\end{equation}\nwhere $\\mathcal S$ is a stride operator defined by:\n\\begin{equation}\\label{eq:strideopdim}\n\\mathcal S: \\mathbb{R}^{m \\times n} \\mapsto \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{n+1}{2}},\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:strideop}\n[\\mathcal S(g)]_{i,j} = g_{2i, 2j}, \\quad i = 1: \\frac{m+1}{2} j = 1: \\frac{n+1}{2}.\n\\end{equation}\n\\end{lemma}\n", "meta": {"hexsha": "0e818a76b4cd3c58a5fdda9762f677e542e0514a", "size": 2936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Convolution.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Convolution.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Convolution.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.641025641, "max_line_length": 110, "alphanum_fraction": 0.6301089918, "num_tokens": 1212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632247867717, "lm_q2_score": 0.9086179049750475, "lm_q1q2_score": 0.8648799691285491}} {"text": "\\subsection{Test 4}\r\n\\begin{enumerate}\r\n\t\\item For each of the following, determine if $\\vec{F}$ is conservative. Then evaluate $\\int\\limits_{C}{\\vec{F}\\cdot\\mathrm{d}\\vec{r}}$.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item $\\vec{F} = \\langle xz, x^2z, xy^2z \\rangle$ and $C$ given by $\\vec{r}(t) = \\langle t, e^{-t}, e^t\\rangle, 0 \\leq t \\leq 1$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\nabla \\times \\vec{F} = \\langle 2xyz-x^2, x-y^2z, 2xz \\rangle.\r\n\t\t\\end{equation*}\r\n\t\tSince $\\nabla \\times \\vec{F} \\neq \\vec{0}$, $\\vec{F}$ isn't conservative.\r\n\t\t\\begin{align*}\r\n\t\t\t\\vec{F}\\circ\\vec{r} &= \\langle te^t, t^2e^t, te^{-2t}e^t \\rangle \\\\\r\n\t\t\t&= \\vec{r^\\prime}(t) = \\langle 1, -e^{-t}, e^t\\rangle\r\n\t\t\\end{align*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\vec{r^\\prime}(t) = te^t - t^2 + t\r\n\t\t\\end{equation*}\r\n\t\t\\begin{align*}\r\n\t\t\t\\int\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} &= \\int_{0}^{1}{\\left(te^t - t^2 + t\\right)\\mathrm{d}t} \\\\\r\n\t\t\t&= \\frac{1}{2} - \\frac{1}{3} + \\lvert te^t\\rvert_{0}^{1} - \\int_{0}^{1}{e^t\\mathrm{d}t} \\\\\r\n\t\t\t&= 1 + \\frac{1}{2} - \\frac{1}{3} = \\frac{7}{6}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\\item $\\vec{F} = \\left< \\sqrt{\\frac{yz}{x}}, \\sqrt{\\frac{xz}{y}}, \\sqrt{\\frac{xy}{z}} \\right>$ and $C$ given by $\\vec{r} = \\langle \\cos{t}, \\sin{t}, \\sin{(4t)} \\rangle, 0 \\leq t \\leq 2\\pi$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{F} = \\nabla(2\\sqrt{xyz}) \\implies \\vec{F} \\text{ is conservative.}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r}(0) = \\vec{r}(2\\pi) \\implies C \\text{ is a circulation.}.\r\n\t\t\\end{equation*}\r\n\t\tSince $\\vec{F}$ is conservative and $C$ is a circulation,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = 0.\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item $\\vec{F} = \\langle yz, xz, xy \\rangle$ and $C$ given by $\\vec{r}(t) = \\langle 2t^2, e^{1-t^2}, \\tan^{-1}{(t^2/2)} \\rangle, 0 \\leq t \\leq \\sqrt{2}$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{F} = \\nabla(xyz) \\implies\\vec{F} \\text{ is conservative.}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\int\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\int\\limits_{C}{\\nabla f \\cdot \\mathrm{d}\\vec{r}} = f(\\vec{r}(\\sqrt{2})) - f(\\vec{r}(0)) = \\frac{4\\pi}{4e} - 0 = \\frac{\\pi}{e}\r\n\t\t\\end{equation*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item Let the surface $S$ be the portion of the paraboloid $z = 8 - \\frac{x^2}{2} - \\frac{y^2}{2}$ that lies above the xy-plane. Let $\\vec{F}(x,y,z) = \\left< \\frac{x}{\\sqrt{x^2 + y^2}}, \\frac{y}{\\sqrt{x^2 + y^2}}, 0 \\right>$.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item Parameterize $S = \\vec{r}(u,v)$ with appropriate bounds for $u$ and $v$.\r\n\t\tThe paraboloid is above the xy-plane when $z \\geq 0$.\r\n\t\t\\begin{equation*}\r\n\t\t\t8 - \\frac{x^2}{2} - \\frac{y^2}{2} = \\geq 0\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\tx^2 + y^2 \\leq 16.\r\n\t\t\\end{equation*}\r\n\t\tThis a circle with radius 4. So, we'll describe the region in polar form.\\\\\r\n\t\t\\begin{equation*}\r\n\t\t\tS = \\left\\{ (r,\\theta) \\mid 0 \\leq r \\leq 4, 0 \\leq \\theta \\leq 2\\pi \\right\\}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r}(u,v) = \\langle u\\cos{v}, u\\sin{v}, 8 - \\frac{1}{2}u^2 \\rangle, 0 \\leq u \\leq 4 \\text{ and } 0 \\leq v \\leq 2\\pi\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item Compute the surface area of $S$.\\\\\r\n\t\t\\begin{equation*}\r\n\t\t\tA = \\iint\\limits_{D}{\\norm{\\vec{r_u} \\times \\vec{r_v}}\\mathrm{d}A}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r_u} = \\langle \\cos{v}, \\sin{u}, -u \\rangle\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\tvec{r_v} = \\langle -u\\sin{v}, u\\cos{v}, 0 \\rangle\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{r_u} \\times \\vec{r_v} = \\langle u^2\\cos{v}, u^2\\sin{v}, u\\rangle\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\norm{\\vec{r_u} \\times \\vec{r_v}} = u\\sqrt{1 + u^2}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{align*}\r\n\t\t\tA &= \\int_{0}^{2\\pi}{int_{0}^{4}{u\\sqrt{1 + u^2}\\mathrm{d}u}\\mathrm{d}v} \\\\\r\n\t\t\t&= 2\\pi\\int_{0}^{4}{u\\sqrt{1 + u^2}\\mathrm{d}u} \\\\\r\n\t\t\t&= \\pi\\int_{1}^{17}{\\sqrt{w}\\mathrm{d}w} \\\\\r\n\t\t\t&= \\pi\\frac{34\\sqrt{17} - 2}{3}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\\item Compute the flux, $\\Phi$, of $\\vec{F}$ through $S$.\\\\\r\n\t\tWe will assume that the surface is outward-oriented, so that $\\Phi$ is positive.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\Phi = \\iint\\limits_{D}{\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\left(\\vec{r_u} \\times \\vec{r_v}\\right)\\mathrm{d}A}\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{F}\\circ\\vec{r} = \\langle \\cos{v}\\sin{v}, 0 \\rangle\r\n\t\t\\end{equation*}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\left(\\vec{r_u} \\times \\vec{r_v}\\right) = u^2\r\n\t\t\\end{equation*}\r\n\t\t\\begin{align*}\r\n\t\t\t\\Phi &= \\int_{0}^{2\\pi}{\\int_{0}^{4}{u^2\\mathrm{d}u}\\mathrm{d}v} \\\\\r\n\t\t\t&= \\frac{128\\pi}{3}\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item Consider a 3D vector field $\\vec{F}(x,y,z) = \\langle P(x,y,z), Q(x,y,z), R(x,y,z) \\rangle$ and a scalar function of two variables $f(x,y)$. Determine which of the following expressions is defined. If it is defined, evaluate it. If it is not defined, explain why. If you can deduce the value of the expression from a theorem, do so and state the theorem.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\nabla f \\cdot \\vec{F}.\r\n\t\t\\end{equation*}\r\n\t\tThis operation is not defined because $\\nabla f$ is a 2D vector, and the output of $\\vec{F}$ is a 3D vector.\\\\\r\n\t\t\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\nabla \\times \\nabla f.\r\n\t\t\\end{equation*}\r\n\t\tIf we allow the cross product in 2D to return a scalar that is the signed area spanned by the two vectors, then\r\n\t\t\\begin{equation*}\r\n\t\t\t\\nabla \\times \\nabla f = f_{yx} - f_{xy} = 0\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\nabla\\times(\\nabla\\cdot\\vec{F}).\r\n\t\t\\end{equation*}\r\n\t\tThis operation is not defined because $\\nabla \\cdot \\vec{F}$ results in a scalar function, and the curl of a scalar function is not defined.\\\\\r\n\t\t\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\nabla \\cdot (\\nabla \\times \\vec{F}).\r\n\t\t\\end{equation*}\r\n\t\tThis operation is defined and always has a value of 0 if $\\vec{F}$ is twice differentiable. The proof of which is below.\\\\\r\n\t\tLet \r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{F}(x,y,z) = \\langle P(x,y,z), Q(x,y,z), R(x,y,z) \\rangle\r\n\t\t\\end{equation*}\r\n\t\t\\begin{align*}\r\n\t\t\t\\nabla \\cdot (\\nabla \\times \\vec{F}) &= \\nabla \\cdot \\langle R_y-Q_z, P_z-R_x, Q_x-P_y \\rangle \\\\\r\n\t\t\t&= R_{yx}-Q_{zx} + P_{zy}-R_{xy} + Q_{xz}-P_{yz} = 0\r\n\t\t\\end{align*}\r\n\t\tby Fubini's Theorem\\\\\r\n\t\\end{enumerate}\r\n\r\n\t\\item Consider the vector field $\\vec{F}(x,y,z) = \\langle -z, 2y, x \\rangle$. Find the integral curve of $\\vec{F}$ with initial conditions $\\vec{r}(0) = \\langle 5, 1, 0\\rangle$.\\\\\r\n\t\\indent\r\n\tWe need to solve a system of differential equations.\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\tx' = -z \\\\\r\n\t\t\ty' = 2y \\\\\r\n\t\t\tz' = x\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\t$y(t) = Ce^{2t}$ and applying initial conditions, $y(t) = e^{2t}$\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\tx' = -z \\\\\r\n\t\t\tz' = x\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\t$z(t) = A\\cos{t} + B\\sin{t}$ and $x(t) = B\\cos{t} - A\\sin{t}$\\\\\r\n\tApplying initial conditions, $z(t) = 5\\sin{t}$ and $x(t) = 5\\cos{t}$. So, \r\n\t\\begin{equation*}\r\n\t\t\\vec{r}(t) = \\langle 5\\cos{t}, e^{2t}, 5\\sin{t}\\rangle\r\n\t\\end{equation*}\r\n\t\r\n\t\\item State and prove the Fundamental Theorem of Calculus for Line Integrals.\\\\\r\n\t\\begin{theorem}[FTC for Line Integrals]\r\n\t\tLet $\\vec{r}(t)$ parameterize $C$ on $a \\leq t \\leq b$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\int\\limits_{C}{\\nabla f \\cdot \\mathrm{d}\\vec{r}} = f(\\vec{r}(b)) - f(\\vec{r}(a))\r\n\t\t\\end{equation*}\r\n\t\\end{theorem}\r\n\t\\begin{proof}\r\n\t\t\\begin{align*}\r\n\t\t\t\\int\\limits_{C}{\\nabla f \\cdot \\mathrm{d}\\vec{r}} &= \\int_{a}^{b}{(\\nabla f\\circ\\vec{r}) \\cdot \\vec{r^\\prime}\\mathrm{d}t} \\\\\r\n\t\t\t&= \\int_{a}^{b}{\\frac{\\mathrm{d}}{\\mathrm{d}t}(f\\circ\\vec{r})\\mathrm{d}t} \\\\\r\n\t\t\t&= f(\\vec{r}(b)) - f(\\vec{r}(a))\r\n\t\t\\end{align*}\r\n\t\\end{proof}\r\n\\end{enumerate}", "meta": {"hexsha": "b3a09eb7a2e317c8c4e50612e1efa0e0b9b2de88", "size": 7701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/additionalMaterials/test4.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/additionalMaterials/test4.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/additionalMaterials/test4.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.2586206897, "max_line_length": 361, "alphanum_fraction": 0.5810933645, "num_tokens": 3362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632247867715, "lm_q2_score": 0.9086178907465061, "lm_q1q2_score": 0.8648799555849238}} {"text": "\n\\subsection{Norms}\n\nWe can use norms to denote the \"length\" of a single vector.\n\n\\(||v||=\\sqrt {\\langle v, v\\rangle }\\)\n\n\\(||v||=\\sqrt {v^*Mv}\\)\n\n\\subsubsection{Euclidian norm}\n\nIf \\(M=I\\) we have the Euclidian norm.\n\n\\(||v||=\\sqrt{v^*v}\\)\n\nIf we are using the real field this is:\n\n\\(||v||=\\sqrt{\\sum_{i=1}^{n}v^2_i}\\)\n\n\\subsubsection{Pythagoras' theorem}\n\nIf \\(n=2\\) we have in the real field we have:\n\n\\(||v||=\\sqrt{v_1^2+v_2^2}\\)\n\nWe call the two inputs \\(x\\) and \\(y\\), and the length \\(z\\).\n\n\\(z=\\sqrt {x^2+y^2}\\)\n\n\\(z^2=x^2+y^2\\)\n\n", "meta": {"hexsha": "b9eda9f547f637be39dc73487d6a5c39a0389cb3", "size": 538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/affineEuclid/04-01-norm.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/affineEuclid/04-01-norm.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/affineEuclid/04-01-norm.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8125, "max_line_length": 61, "alphanum_fraction": 0.5873605948, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305297023093, "lm_q2_score": 0.8976953003183443, "lm_q1q2_score": 0.8646875196369124}} {"text": "\\textbf{Write a function that solves Burgers equation\n\\begin{align*}\n&u_t+uu_x=\\varepsilon u_{xx},~~~~~x\\in(0,1),~~t\\in(0,t_{max}]\\\\\n&u(0,x)=sin^4(\\pi x)\n\\end{align*}\nand periodic boundary conditions. Use Fourier to compute derivatives in space and ode113 to advance in time. Solve this PDE for $\\varepsilon= 0.1,0.01,$ and $0.001$. In each case, can you find solutions that areaccurate to three digits at $t= 1$?}\n\\newline\n\nSince the domain is $1$-periodic, in order to use Fourier DFT comfortably we will change the space variable $x$ to work with a PDE and boundary conditions $2\\pi$-periodic. The convenient change of variable is $y = 2\\pi x$. Now $y$ is $2\\pi$-periodic. Then, the PDE is changed as follows,\n\\begin{align*}\n&u_t+2\\pi uu_y=4\\pi^2\\varepsilon u_{yy},~~~~~y\\in(0,2\\pi),~~t\\in(0,t_{max}]\\\\\n&u(0,y)=sin^4(y/2).\n\\end{align*}\nWe can easily solve this PDE using Fourier Derivatives, see code below. The errors I have obtained, using the infinity norm, are:\n\\begin{center}\n \\begin{tabular}{||c c c||} \n \\hline\n $\\varepsilon$ & $N$ & Error \\\\ [0.5ex] \n \\hline\\hline\n $0.1$ & $64$ & $0.4192\\cdot 10^{-3}$ \\\\ \n \\hline\n $0.01$ & $64$ & $0.4839\\cdot 10^{-3}$ \\\\\n \\hline\n $0.001$ & $512$ & $0.9414\\cdot 10^{-3}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\nWe can see how, the smaller the $\\varepsilon$ (and therefore more insignificant the diffusion), the more difficult it is to obtain an accurate solution.\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 3\ntmax = 1;\neps = [1e-1 1e-2 1e-3]';\ntol = 1e-3;\nmesh = zeros(length(eps),1);\nE = zeros(length(eps),1);\nfor m=1:length(eps)\n j = 5;\n N = 2^j;\n error = 1;\n u = PDE_solve(N,tmax,eps(m),false);\n while (error>tol && N<2048)\n j = j+1;\n N = 2^j;\n ufine = PDE_solve(N,tmax,eps(m),false);\n error = norm(u(end,:)-ufine(end,2:2:end),inf);\n u = ufine;\n j\n end\n m\n mesh(m) = N;\n E(m) = error;\nend\nmesh\nE\n\nfunction [u,x]=PDE_solve(N,tmax,eps,movie)\nx0 = 0;\nxf = 2*pi;\nh = (xf-x0)/N;\nx = x0 + h*(1:N)';\nu0 = sin(x/2).^4;\n \ntic;\n[t,u] = ode113(@(t,u) rhs(u,N,eps), [0 tmax], u0);\ntoc\nif movie\n figure\n for k = 1:2:length(t)\n plot(x,u(k,:));\n axis([x0 xf -.2 1.2]);\n drawnow\n end\nend\n\nend\n \nfunction y = rhs(u,N,eps)\n vhat = fft(u);\n what = 1i*[0:N/2-1 0 -N/2+1:-1]' .* vhat;\n what2 = -([0:N/2-1 N/2 -N/2+1:-1].^2)' .* vhat;\n \n ux = real(ifft(what));\n uxx = real(ifft(what2));\n \n y = 4*pi^2*eps*uxx-2*pi*u.*ux;\nend\n\\end{verbatim}", "meta": {"hexsha": "7d71991a0b54cd050a028af90a3123ae38f120b9", "size": 2518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework2/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework2/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework2/Latex/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2921348315, "max_line_length": 287, "alphanum_fraction": 0.5996822875, "num_tokens": 976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.933430812881347, "lm_q1q2_score": 0.8646404420442801}} {"text": "\\section{Norms of Vectors and Matrices}\n\\begin{defn}\nA vector norm on $\\RR^n$ is a function, $\\norms{\\cdot}$, from $\\RR^n $to $\\RR$ with the following properties.\n\\begin{enumerate}[(i)]\n \\item $\\norms{\\bfx}\\geq 0$ for all $\\bfx\\in\\RR^n$.\n \\item $\\norms{\\bfx}=0$ if and only if $\\bfx=\\bf 0$.\n \\item $\\norms{\\alpha\\bfx}=\\abs{\\alpha}\\norms{\\bfx}$ for all $\\alpha\\in\\RR$ and $\\bfx\\in\\RR^n$.\n \\item $\\norms{\\bfx+\\bfy}\\leq\\norms{\\bfx}+\\norms{\\bfy}$ for all $\\bfx,\\bfy\\in\\RR^n$.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}\nThe $l_1$, $l_2$, $l_\\infty$ norms for the vector $\\bfx=(x_1,x_2,\\ldots,x_n)^t$ are defined by\n\\begin{itemize}\n \\item $\\norms{\\bfx}_1$ = $\\sum_{i=1}^n\\abs{x_i}$\n \\item $\\norms{\\bfx}_2$ = $\\left[\\sum_{i=1}^n{x_i^2}\\right]^{1/2}$\n \\item $\\norms{\\bfx}_\\infty$ = $\\max_{1\\leq i\\leq n}\\abs{x_i}$\n\\end{itemize}\n\\end{defn}\n\n\\begin{theo}\nThe sequence of vectors ${\\bfx^{(k)}}$ converges to $\\bfx$ in $\\RR^n$ with respect to the $l\\infty$ norm if and only\nif $\\lim_{k\\to +\\infty}x_i^{(k)}=x_i$, for each $i=1,2,\\ldots,n$.\n\\end{theo}\n\n\\subsection{Matrix Norms and Distances}\n\\begin{defn}[Matrix Norms]\nA matrix norm on the set of all $n\\times n$ matrices s a real-valued function, $\\norms{\\cdot}$, defined on this ser, satisfying for all $n\\times n$ matrices $\\bfA$ and $\\bfB$ and all real numbers $\\alpha$.\n\\begin{enumerate}[(i)]\n \\item $\\norms{\\bfA}\\geq 0$.\n \\item $\\norms{\\bfA}=0$ if and only if $\\bfA$ is $\\bf 0$, the matrix with all 0 entries.\n \\item $\\norms{\\alpha\\bfA}=\\abs{\\alpha}\\norms{\\bfA}$.\n \\item $\\norms{\\bfA+\\bfB}\\leq\\norms{\\bfA}+\\norms{\\bfB}$.\n \\item $\\norms{\\bfA\\bfB}\\leq\\norms{\\bfA}\\norms{\\bfB}$.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{theo}\nIf $\\norms{\\cdot}$ is a vector norm on $\\RR$, then\n\\[\n\\norms{\\bfA}=\\max_{\\norms{\\bfx}=1}\\norms{\\bfA\\bfx}\n\\]\nis a matrix norm.\n\\end{theo}\n\n\\begin{theo}\nIf $\\bfA=(a_{ij})$ is on $n\\times n$ matrix, then\n\\[\n\\norms{\\bfA}_\\infty=\\max_{1\\leq i\\leq n}\\sum_{j=1}^n\\abs{a_{ij}}.\n\\]\n\\end{theo}\n", "meta": {"hexsha": "e36ce88c3db3b5071bc30b01ea83fa34616bb095", "size": 1979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/7.1_Norms_of_vectors_and_matrices.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/7.1_Norms_of_vectors_and_matrices.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/7.1_Norms_of_vectors_and_matrices.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0576923077, "max_line_length": 205, "alphanum_fraction": 0.6245578575, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9744347860767304, "lm_q2_score": 0.8872045840243196, "lm_q1q2_score": 0.8645230090400324}} {"text": "\\lab{Newton's Method, Julia Sets and Basins of Attraction}{Newton's Method}\n\\label{lab:NewtonsMethod}\n\\objective{Understand Newton's Method. Understand definition of basin of attraction. Basic understanding of Julia Sets.}\n\nNewton's method finds the zeros of functions; i.e., Newton's method finds $\\overline{x}$ such that $f\\left(\\overline{x}\\right) = 0$.\nThis method is used to optimize functions (find their maxima and minima), for example to find the zeros of the first derivative.\n\n\\section*{Newton's method}\nNewton's method begins with an initial guess $x_0$. \nThen recursively define a sequence by\n\\[\nx_{n+1} = x_n - \\frac{f(x_n)}{f'(x_n)}\n\\]\nIn other words, Newton's method approximates a function by its tangent line, and then uses the zero of the tangent line as the next guess for $x_n$ (see Figure \\ref{fig:newton}).\n\nThe sequence $\\{x_n\\}$ will converge to the zero $\\overline{x}$ if\n\\begin{enumerate}\n\\item $f$, $f'$, and $f''$ exist and are continuous,\n\\item $f'(\\overline{x})\\neq0$, and\n\\item $\\overline{x}$ is ``sufficiently close'' to $x_0$.\n\\end{enumerate}\nIn applications, the first two conditions usually hold.\nHowever, if $\\overline{x}$ and $x_0$ are not ``sufficiently close'', Newton's method may converge very slowly, or it may not converge at all.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\textwidth]{newton_iters}\n\\label{fig:newton}\n\\caption{An illustration of how one iteration of Newton's method works}\n\\end{figure}\n\nNewton's method is powerful because given the three conditions above, it converges quickly.\nIn these cases, the $\\{x_n\\}$ converge to the actual root quadratically, meaning that the maximum error is squared at every iteration.\n\nLet us do an example with $f(x) = x^2-1$. \nWe define $f(x)$ and $f'(x)$ in Python as follows. \n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n>>> f = lambda x : x**2 - 1\n>>> Df = lambda x : 2*x\n\\end{lstlisting}\nNow we set $x_0 = 1.5$ and iterate.\n\\begin{lstlisting}\n>>> xold = 1.5\n>>> xnew = xold - f(xold)/Df(xold)\n>>> xnew\n1.0833333333333333\n\\end{lstlisting}\nWe can repeat this as many times as we desire.\n\\begin{lstlisting}\n>>> xold = xnew\n>>> xnew = xold - f(xold)/Df(xold)\n>>> xnew\n1.0032051282051282\n\\end{lstlisting}\nWe have already computed the root 1 to two digits of accuracy.\n\n\n\\begin{problem}\n\\label{prob:newton_arr}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement Newton's method with the following function.\n\\begin{lstlisting}\ndef Newtons_method(f, x0, Df, iters=15, tol=.002):\n '''Use Newton's method to approximate a zero of a function.\n \n INPUTS:\n f - A function handle. Should represent a function from \n R to R.\n x0 - Initial guess. Should be a float.\n Df - A function handle. Should represent the derivative \n of `f`.\n iters - Maximum number of iterations before the function \n returns. Defaults to 15.\n tol - The function returns when the difference between \n successive approximations is less than `tol`.\n \n RETURN:\n A tuple (x, converged, numiters) with\n x - the approximation to a zero of `f`\n converged - a Boolean telling whether Newton's method \n converged\n numiters - the number of iterations the method computed\n '''\n\\end{lstlisting}\n\n\\item Run \\li{Newtons_method()} on $f=\\cos(x)$ with $x_0=1$ and $x_0=2$. \nHow many iterations are required to get 5 digits of accuracy?\n\\item Newton's method can be used to find zeros of functions that are hard to solve for analytically.\nPlot $f(x) = \\frac{sin(x)}{x}-x$ on $[-4, 4]$. \nNote that this function can be made continuous on this domain by defining $f(0)=1$. \nUse your function \\li{Newtons_method()} to compute the zero of this function to 7 digits of accuracy.\n\\item Run \\li{Newtons_method()} on $f(x)=x^9$ with $x_0=1$. \nHow many iterations are required to get 1 digit of accuracy? \nWhat is the reason for this slow convergence?\n\\item Run \\li{Newtons_method()} on $f(x)=x^{1/3}$ with $x_0=.01$. \nWhat happens and why?\nHint: The command \\li{x**(1/3)} will not work when \\li{x} is negative. \nHere is one way to define the function $f(x)=x^{1/3}$ in NumPy.\n\\begin{lstlisting}\nf = lambda x: np.sign(x)*np.power(np.abs(x), 1./3)\n\\end{lstlisting}\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}(Optional)\nModify the function \\li{Newtons_method()} in Problem \\ref{prob:newton_arr} so that the argument \\li{Df} defaults to \\li{None}.\nIf no derivative is passed to the function, use the centered coefficients method of Lab \\ref{lab:NumericalDerivatives} to compute the derivative.\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nExtend your Newton's method even further so that it will work on systems of equations.\nSuppose that $F: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n $.\nThe relevant equation is\n\\[\nx_{i+1} = x_i - J^{-1}F(x_i)\n\\]\nNote that you should not calculate the inverse Jacobian.\n\\li{scipy.linalg.solve(A,b)} gives you the solution $x$ to the equation $Ax=b$.\nUse this fact to calculate $J^{-1}F$ from $J$ and $F$.\nYou should be able to make this function work whether or not the user inputs a Jacobian.\nThis also means that you will have to use your own \\li{jacobian} function.\n\\end{problem}\n\\end{comment}\n\n\n\\section*{Basins of attraction: Newton fractals}\nWhen $f(x)$ has many roots, the root that Newton's method converges to depends on the initial guess $x_0$.\nFor example, the function $f(x)=x^2-1$ has roots at $-1$ and $1$.\nIf $x_0<0$, then Newton's method coverges to -1; if $x_0>0$ then it converges to 1 (see Figure \\ref{fig:basins1}).\nWe call the regions $(-\\infty, 0)$ and $(0, \\infty)$ \\emph{basins of attraction}.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.5]{basins1}\n\\caption{The plot of $f(x) = x^2 -1$ along with some values for $x_0$.\nWhen Newton's method is initialized with a blue value for $x_0$ it converges to -1; when it is initialized with a red value it converges to 1.}\n\\label{fig:basins1}\n\\end{center}\n\\end{figure}\n\nWhen $f$ is a polynomial of degree greater than 2, the basins of attraction are much more interesting.\nFor example, if $f(x) = x^3-x$, the basins are depicted in Figure \\ref{fig:fractal_1d}.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.5]{fractal1d}\n\\caption{The plot of $f(x) = x^3 -x$ along with some values for $x_0$.\nBlue values converge to $-1$, red converge to 0, and green converge to 1.}\n\\label{fig:fractal_1d}\n\\end{center}\n\\end{figure}\n\nWe can extend these examples to the complex plane. \nNewton's method works in arbitrary Banach spaces with slightly stronger hypotheses (see theorem in textbook), and in particular it holds over $\\mathbb{C}$.\n\nLet us plot the basins of attraction for $f(x) = x^3-x$ on the domain $\\{a+bi \\mid (a, b) \\in [-1.5, 1.5] \\times [-1.5, 1.5] \\}$ in the complex plane.\nWe begin by creating a $700 \\times 700$ grid of points in this domain. \nWe create the real and imaginary parts of the points separately, and then use \\li{np.meshgrid()} to turn them into a single grid of complex numbers.\n\\begin{lstlisting}\n>>> xreal = np.linspace(-1.5, 1.5, 700)\n>>> ximag = np.linspace(-1.5, 1.5, 700)\n>>> Xreal, Ximag = np.meshgrid(xreal, ximag)\n>>> Xold = Xreal+1j*Ximag\n\\end{lstlisting}\nRecall that \\li{1j} is the complex number $i$ in NumPy. \nThe array \\li{Xold} contains $700^2$ complex points evenly spaced in the domain.\n\nWe may now perform Newton's method on the points in \\li{Xold}. \n\\begin{lstlisting}\n>>> f = lambda x : x**3-x\n>>> Df = lambda x : 3*x**2 - 1\n>>> Xnew = Xold - f(Xold)/Df(Xold)\n\\end{lstlisting}\nAfter iterating the desired number of times, we have an array \\li{Xnew} whose entries are various roots of $x^3-x$.\n\nFinally, we plot the array \\li{Xnew}. The result is similar to Figure \\ref{fig:fractal_ex}.\n\\begin{lstlisting}\n>>> plt.pcolormesh(Xreal, Ximag, Xnew)\n\\end{lstlisting}\n\nNotice that in Figure \\ref{fig:fractal_ex}, whenever red and blue try to come together, a patch of green appears inbetween.\nThis behavior repeats on an infinitely small scale, producing a fractal.\nBecause it arises from Newton's method, this fractal is called a \\emph{Newton fractal}.\n\n\\begin{figure}\n\\begin{center}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{fractal_ex}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{fractal_zoom}\n\\end{subfigure}\n\\caption{ Basins of attraction for $x^3-x$ in the complex plane. \nThe picture on the right is a close-up of the figure on the left.}\n\\label{fig:fractal_ex}\n\\end{center}\n\\end{figure}\n\nNewton fractals tell us that the long-term behavior of the Newton method is extremely sensitive to the initial guess $x_0$.\nChanging $x_0$ by a small amount can change the output of Newton's method in a seemingly random way.\nThis is an example of \\emph{chaos}.\n\n\n\n\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Complete the following function to plot the basins of attraction of a function.\n\\begin{lstlisting}\ndef plot_basins(f, Df, roots, xmin, xmax, ymin, ymax, numpoints=100, iters=15, colormap='brg'):\n '''Plot the basins of attraction of f.\n \n INPUTS:\n f - A function handle. Should represent a function \n from C to C.\n Df - A function handle. Should be the derivative of f.\n roots - An array of the zeros of f.\n xmin, xmax, ymin, ymax - Scalars that define the domain \n for the plot.\n numpoints - A scalar that determines the resolution of \n the plot. Defaults to 100.\n iters - Number of times to iterate Newton's method. \n Defaults to 15.\n colormap - A colormap to use in the plot. Defaults to 'brg'. \n '''\n\\end{lstlisting}\nYou can test your function on the example $f(x) = x^3-x$ above. \n\nWhen the function \\li{plt.pcolormesh()} is called on a complex array, it evaluates only on the real part of the complex numbers.\nThis means that if two roots of \\li{f} have the same real part, their basins will be the same color if you plot directly using \\li{plt.pcolormesh()}.\n\nOne way to fix this problem is to compute \\li{Xnew} as usual.\nThen iterate through the entries of \\li{Xnew} and identify which root each entry is using the input \\li{roots}.\nFinally, create a new array whose entries are integers corresponding to these roots.\nPlot the array of integers to view the basins of attraction.\n\n\n\\item Run \\li{plot_basins()} on the function $x^3-1$ on the domain $\\{a+bi \\mid (a, b) \\in [-1.5, 1.5] \\times [-1.5, 1.5] \\}$. \nThe resulting plot should look like Figure \\ref{fig:fractal_hw}.\n\n\n\\end{enumerate}\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.66]{fractal_hw}\n\\caption{Basins of attraction for $x^3-1$.}\n\\label{fig:fractal_hw}\n\\end{center}\n\\end{figure}\n\\end{problem}\n\n\n% The remainder of the material has nothing to do with this lab, except that it mentions fractals.\n\\begin{comment}\nAnother well-studied fractal in the complex plane is the Mandelbrot set.\nIt is defined as the points $c \\in \\mathbb{C}$ for which the sequence\n\\[z_n = z_{n-1}^2 + c\\]\nis bounded.\n\n\\begin{problem}\nGenerate another grid of complex numbers on $[-1.5,.5]\\times[-i,i]$.\nConsider the recurrence relation $x_n = x_{n-1}^2 + c$.\nRun this iteration 30 times with a resolution of $200 \\times 200$ and display the plot.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "f500c1ddd97053c9adeedff1fcc4edac88b6561e", "size": 11295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/NewtonsMethod/NewtonsMethod.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/NewtonsMethod/NewtonsMethod.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/NewtonsMethod/NewtonsMethod.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.2226277372, "max_line_length": 178, "alphanum_fraction": 0.7128818061, "num_tokens": 3327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.9184802445831379, "lm_q1q2_score": 0.8640968050996035}} {"text": "\\section{Method}\n\n\\subsection{The Hopfield Network}\nThe Hopfield Network is a simple fully-connected neural network, i.e. all neurons are connected to each other. The network is a recurrent neural network popularized by John Hopfield in \\cite{hopfield}. Each neuron is either on (firing) or off (not firing) encoded as positive or negative values, as showed in mathematical terms in \\cref{eq:states}.\n\\begin{tcolorbox}[ams equation, title={Network States}] \\label{eq:states}\n \\mathbf{S} = \\begin{bmatrix}\n s_1 \\\\ s_2 \\\\ \\vdots \\\\ s_n\n \\end{bmatrix}, \\quad \\mathbf{S} \\in \\{1, -1\\}^{N\\times1}\n\\end{tcolorbox}\nThe connection between two seperate neurons is weighted, and there are no self-connections. We used the Hebbian learning rule where the weight matrix $\\bf W$ for storing $M$ different patterns $\\mathbf{V}^{(m)} \\in \\{1, -1\\}^{N\\times 1}$ can be implemented using \\cref{eq:weights}. Hebbian learning models how cells firing together gain stronger synaptic connections \\cite{hebb}.\n\\begin{tcolorbox}[ams align, title={Network Weights}] \\label{eq:weights}\n \\mathbf{W} &= {\\bar{\\mathbf{W}}} - diag^{-1}(\\bar{\\mathbf{W}}) & \\bar{\\mathbf{W}} &= \\frac{1}{M}\\sum_{m=1}^M \\mathbf{V}^{(m)} (\\mathbf{V}^{(m)})^T \\succeq 0 \n\\end{tcolorbox}\nEach element in \\cref{eq:energy} in the weight matrix then corresponds to \\cite{hopfield}:\n\\begin{equation*}\n w_{ij} = \\begin{cases}\n \\frac{1}{M}\\sum_{m=1}^M v_{i}^{(m)} v_{j}^{(m)} & \\forall i \\neq j \\\\\n 0 & \\forall i = j\n \\end{cases}\n\\end{equation*}\nThe weigths can be interpreted as whether neuron $i$ and neuron $j$ should be in the same or opposite states according to weight $w_{ij}$. A positive value indicates the neurons should be pulled toward the same state, while a negative value indicates they should be pushed away from each other. Each weight can be thought of as a spring connected between two neurons, either pushing or pulling depending on the state of the spring.\n\nThe network states can be updated by using the update rule in \\cref{eq:update}. Intuitively we can think of the update step as the updating neuron being pushed or pulled towards the state of all the other neurons, and the strongest state \"wins\".\n\\begin{tcolorbox}[ams align, title={Update Step}]\\label{eq:update}\n s_i &= sign(h_i) & h_i = \\sum_{j=1}^N w_{ij} s_j \\iff \\mathbf{H} = \\mathbf{W} \\mathbf{S}\n\\end{tcolorbox}\nThe neurons can either be updated using an asynchronous or synchronous approach. With asynchronous updating, the neurons are updated in random order at different times, while with syncrhonous updating they are updated all at once. We utilized the asynchronous approach, and selected one neruon each timestep. The neurons were shuffled using a random permuation.\n\n\\subsection{Energy of Hopfield Network}\nWe can associate a number to each state of the network, which we refer to as the energy $E$ of the network.\n\\begin{tcolorbox}[title={Energy contained in network}]\n \\begin{subequations}\\label{eq:energy}\n \\begin{align}\n E &= -\\frac{1}{2} \\sum_{i,j} w_{ij}s_i s_j \\label{eq:energy-sum} \\\\\n &= - \\frac{1}{2} \\mathbf{S}^T \\mathbf{W} \\mathbf{S} \\\\\n &= -\\frac{1}{2}( \\mathbf{S}^T \\bar{\\mathbf{W}} \\mathbf{S} - trace(\\bar{\\mathbf{W}})) \\label{eq:energy-trace} \\\\ \n &= -\\frac{1}{2}(\\mathbf{S}^T \\bar{\\mathbf{W}} \\mathbf{S} - N) \\label{eq:energy-compact}\n \\end{align}\n \\end{subequations}\n\\end{tcolorbox}\nA more in-depth derivation of \\cref{eq:energy} is available in \\cref{sec:proofenergy}.\n\nIt is worth noticing that $\\bf \\bar{W}$ is positive semi-definite, which can be shown using the definition of positive semi-definite matrices $\\mathbf{z}^T \\mathbf{A} \\mathbf{z} \\geq 0 \\iff \\mathbf{A} \\succeq 0$.\n\\begin{equation*}\n\\mathbf{z}^T\\bar{\\mathbf{W}} \\mathbf{z} = \\frac{1}{M}\\sum_{m=1}^M \\mathbf{z}^T \\mathbf{V}^{(m)}(\\mathbf{V}^{(m)})^T \\mathbf{z} = \\frac{1}{M}\\sum_{m=1}^M (\\mathbf{z}^T \\mathbf{V}^{(m)})^2 \\geq 0 \\implies \\mathbf{\\bar{W}} \\succeq 0\n\\end{equation*}\nUsing \\cref{eq:energy-compact} we can form upper and lower bounds for the energy. We can think of these limits as how deep valleys we possibly can create using $N$ neurons. Using the fact that $\\mathbf{\\bar{W}} \\succeq 0 \\iff \\mathbf{S}^T \\mathbf{\\bar{W}}\\mathbf{S} \\geq 0$, we get the upper limit.\n\\begin{equation*}\n E = -\\frac{1}{2}(\\mathbf{S}^T \\bar{\\mathbf{W}} \\mathbf{S} - N) \\leq \\frac{N}{2}\n\\end{equation*}\nFor the lower limit we assume all the addends in \\cref{eq:energy-sum} are $1$. With $N^2$ elements in the weight matrix and after removing the $N$ diagonal elements we get\n\\begin{equation*}\n E = -\\frac{1}{2}(\\mathbf{S}^T \\bar{\\mathbf{W}} \\mathbf{S} - N) \\geq -\\frac{1}{2} (N^2 - N) = -\\frac{N}{2} (N-1) \n\\end{equation*}\n\n\\begin{tcolorbox}[title={Energy Limits}]\n \\begin{equation}\\label{eq:energy-limits}\n -\\frac{N}{2}(N-1) \\leq E \\leq \\frac{N}{2}\n \\end{equation}\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[title={Intution behind the energy}]\n \\textit{We can get a more intuitive sense of how the Hopfield network is able to recall memories by comparing the energy in \\cref{eq:energy} to a ball resting on a peak between two valleys. The position of the ball represents the current state of the neurons, and the equilibrium points of the valleys represents the stored memories. If we give the ball even the slightest nudge to either side, the ball will eventually roll down until it reaches the lowest point of its closest valley, and the potential energy of the ball will decrease. To then move the ball further requires energy (i.e. work). As long as the ball is initialized within the correct valley, it will roll down to the correct equilibrium (memory). Using this intuition, the lower and upper energy limits in \\cref{eq:energy-limits} correspond to the deepest possible valley and the highest possible peak respectively. While the large number of dimentions in the Hopfield network makes it difficult to visualize the valleys, the energy can still be interpereted in a physical sense.}\n\\end{tcolorbox}\n\n\n\n\n\\subsection{Simulating the Hopfield network}\nThe Hopfield network can be simulated using MATLAB and \\crefrange{eq:states}{eq:energy}. The code is available in \\cref{sec:matlab_code}.\n\\subsubsection*{Stability of a single pattern}\nA single pattern can be simulated using $N=50$ neurons, and by storing a single (random generated) pattern $\\mathbf{V}$. Two simulations were used, one where the states $\\bf S$ were initialized to the pattern $\\bf V$ and one with $20\\%$ noise. The noise was generated by initializing $80\\%$ using the stored pattern, and initializing the remaining $20\\%$ randomly with equal probability of $1$ and $-1$. We ran the simulations using $T=50$ iterations to allow the network to properly converge.\n\\subsubsection*{Stability of multiple patterns}\nMultiple patterns can be simulated by storing multiple patterns in $\\bf W$ using \\cref{eq:weights}. Simulations were then run for each pattern, initializing the states with and without noise. Each simulation was then compared to the same reference pattern.\n\nThe capacity of the network can be tested by simulating the network with different number of memories, and record the proportion of memories the network is able to recover from noisy inital conditions. We used $N=50$ neurons and simulated with up to $10$ memories using different noise levels. The average over $100$ simulations were used to reduce random effects.\n\n\\subsubsection*{Creating patterns from QR codes}\nQR codes were generated using \\href{https://miniwebtool.com/qr-code-generator/}{an online QR-code generator}, and resulted in $50 \\times 50$ PNG images. The QR-codes were loaded in MATLAB, stripped for any white borders, converted from grayscale values to binary and encoded as a $\\{1, -1\\}^{N \\times 1}$ vector. Two QR codes were generated and stored in the Hopfield network using \\cref{eq:weights}. The first simulation was initialized to the first QR-code with large amounts of noise. The second simulation was initialized to the second QR-code with half of the bits forced to 1 (i.e. losing half of the pattern). The number of iterations was increased due to the large amount of neurons.\n\n\n\n", "meta": {"hexsha": "6be324dc8200e4221726c6ccd88649039ab158ed", "size": 8169, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/project2/methods.tex", "max_stars_repo_name": "HaavardM/nevr3004-neural-networks", "max_stars_repo_head_hexsha": "7acfe8f6a4fedabd1d2dbfebf2f21e045010f90e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/project2/methods.tex", "max_issues_repo_name": "HaavardM/nevr3004-neural-networks", "max_issues_repo_head_hexsha": "7acfe8f6a4fedabd1d2dbfebf2f21e045010f90e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/project2/methods.tex", "max_forks_repo_name": "HaavardM/nevr3004-neural-networks", "max_forks_repo_head_hexsha": "7acfe8f6a4fedabd1d2dbfebf2f21e045010f90e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.421686747, "max_line_length": 1052, "alphanum_fraction": 0.7300771208, "num_tokens": 2370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.9124361688107864, "lm_q1q2_score": 0.8637090405411262}} {"text": "\\chapter{Integral Transforms }\n\\section{Integral Transforms}\nFrequently in mathematical physics we encounter pairs of functions related by an expression of the form\n\\begin{equation}\ng(x)=\\int_{a}^{b} f(t) K(x, t) d t\\label{FT-01}\n\\end{equation}\nwhere it is understood that $a, b$, and $K(x, t)$ (called the kernel) will be the same for all function pairs $f$ and $g$. We can write the relationship expressed in Eq. (\\ref{FT-01}) in the more symbolic form\n\\begin{equation}\ng(x)=\\mathcal{L}{ f(t)}\n\\end{equation}\nthereby emphasizing the fact that Eq. $(\\ref{FT-01})$ can be interpreted as an operator equation. The function $g(x)$ is called the integral transform of $f(t)$ by the operator $\\mathcal{L}$, with the specific transform determined by the choice of $a, b$, and $K(x, t)$. The operator defined by Eq. (\\ref{FT-01}) will be linear:\n\\begin{align}\n\\int_{a}^{b}\\left[f_{1}(t)+f_{2}(t)\\right] K(x, t) d t&=\\int_{a}^{b} f_{1}(t) K(x, t) d t+\\int_{a}^{b} f_{2}(t) K(t) d t \\\\\n\\int_{a}^{b} c f(t) K(\\alpha, t) d t&=c \\int_{a}^{b} f(t) K(\\alpha, t) d t\n\\end{align}\nIn order for transforms to be useful, we will shortly see that we need to be able to \"undo\" their effect. From a practical viewpoint, this means that not only must there exist an operator $\\mathcal{L}^{-1}$, but also that we have a reasonably convenient and powerful method of evaluating\n\\begin{equation}\n\\mathcal{L}^{-1} g(x)=f(t)\n\\end{equation}\nfor an acceptably broad range of $g(x)$. The procedure for inverting a transform takes a wide variety of forms that depend on the specific properties of $K(x, t)$, so we cannot write a formula that is as general as that for $\\mathcal{L}$ in Eq. (\\ref{FT-01}).\\\\\nNot all superficially reasonable choices for the kernel $K(x, t)$ will lead to operators $\\mathcal{L}$ that have inverses, and even for strategically chosen kernels it may be the case that $\\mathcal{L}$ and $\\mathcal{L}^{-1}$ will only exist for substantially restricted classes of functions. Thus, the entire development of the present chapter is restricted (for any given integral transform) to functions for which the indicated operations can be carried out.\\\\\nOne of the frequent uses of integral transforms is to use one, together with its inverse, to form an \\textbf{integral representation} of a function that we originally had in an explicit form. This move (which appears to be in the direction of generating greater complexity) has value that arises from the relatively simple behavior of the transforms of differentiation and integration operators. Procedures involving integral representations are also presented in later sections of this chapter.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=9cm]{FT-01}\n\\end{figure}\n\\newpage\n\\begin{abox}\n\tFourier Transform\n\t\\end{abox}\n\nThe integral transform that has seen the widest use is the Fourier transform, defined as\n\\begin{equation}\ng(\\omega)=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} f(t) e^{i \\omega t} d t\n\\end{equation}\nThe notation for this transform is not entirely universal; some writers omit the prefactor $1 / \\sqrt{2 \\pi}$; we keep it because it causes the transform and its inverse to have formulas that are more symmetrical. In applications involving periodic systems, one occasionally encounters a definition with kernel $\\exp \\left(2 \\pi i \\omega t / a_{0}\\right)$, where $a_{0}$ is a lattice constant. These differences in notation do not change the mathematics, but cause formulas to differ by powers of $2 \\pi$ or $a_{0}$. Caution is therefore advised when combining material from different sources.\\\\\n\\section{Infinite Fourier Transform}\n\\begin{align*}\n\\text{The fourier transform of }f(x)[-\\infty0)$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tF\\left[e^{-a|x|}\\right] &=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{a x} e^{i s x} d x+\\int_{0}^{\\infty} e^{-a x} e^{i s x} d x\\right]=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left(\\frac{e^{(a+i s) x}}{(a+i s)}\\right)_{-\\infty}^{0}+\\left(\\frac{e^{-(a-i s) x}}{(i s-a)}\\right)_{0}^{\\infty}\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{1}{a+i s}+\\frac{1}{a-i s}\\right]=\\frac{2 a}{\\sqrt{2 \\pi}\\left(s^{2}+a^{2}\\right)} \\because\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\n\\section{Properties of Fourier Transform}\n(i) \\textbf{Linearity theorem:} \n\\begin{align*}\n\\text{If }F(x)&=a_{1} f_{1}(x)+a_{2} f_{2}(x)+\\ldots\\text{ then, }\\\\f(s)&=F[f(x)]=a_{1} f_{1}(s)+a_{2} f_{2}(s)+\\ldots\n\\end{align*}\n(ii) \\textbf{Change of scale property: }\n\\begin{align*}\n\\text{If }F[f(x)]&=f(s),\\text{ then }F\\{f(a x)\\}\\\\&=\\frac{1}{a} f(\\mathrm{~s} / a)\n\\end{align*}\n(iii) $\\text{If }F\\{f(x)\\}=f(s),\\text{ then }F\\left\\{f^{*}(x)\\right\\}=f^{*}(-s)$\\\\\\\\\n(iv) \\textbf{Shifting property:}\n \\begin{align*}\n\\text{ If $f(s)$ is the Fourier transform of }\\mathrm{f}(\\mathrm{x}), \\text{ then }F\\{f(x \\pm a)\\}=e^{\\mp i s a} f(s)\n \\end{align*}\n(v) \\textbf{Modulation theorem:} \\\\\\\\\nIf $F\\{f(x)\\}=f(s)$, then $F\\{f(x) \\cos a x\\}=\\frac{1}{2} f(s-a)+\\frac{1}{2} f(s+a)$\n\\section{Parseval Identity for Fourier Transform}\nIf the Fourier transform of $f(x)$ and $g(x)$ be $f(s) \\& g(s)$ respectively, then\\\\\\\\\n(i) $\\int_{-\\infty}^{\\infty} f(s) g^{*}(s) d s=\\int_{-\\infty}^{\\infty} f(x) g^{*}(x) d x$\\\\\\\\\nwhere $g^{*}(s)$ is complex conjugate of $g(s)$ and $g^{*}(x)$ is the complex conjugate of $g(x)$.\\\\\\\\\n(ii) $\\left.\\int_{-\\infty}^{\\infty}|f(s)|\\right.^{2} d s=\\int_{-\\infty}^{\\infty}|f(x)|^{2} d x$\n\\begin{exercise}Using parseval's identity show that $\\int_{b}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x=\\pi / 2$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\{f(x)\\}&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} f(x) e^{i x x} d x=\\sqrt{\\frac{2}{\\pi}} \\frac{\\sin a s}{s}\\\\\n\t\\text{Using parseval identity, }\\int_{-\\infty}^{\\infty}|f(x)|^{2} d x&=\\int_{-\\infty}^{\\infty}|f(s)|^{2} d s\\\\\n\t\\int_{-a}^{\\infty} l^{2} d x&=\\int_{-\\infty}^{\\infty} \\frac{2}{\\pi} \\frac{\\sin ^{2} a s}{s^{2}} d s \\\\ 2 a&=\\frac{2}{\\pi} \\int_{-\\infty}^{\\infty}\\left(\\frac{\\sin a s}{s}\\right)^{2} d s\\\\\n\t\\text{Putting }a s&=x \\Rightarrow a d s=d x\\\\\n\t\\Rightarrow \\pi&=\\int_{-\\infty}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x \\\\ \\int_{0}^{\\infty}\\left(\\frac{\\sin x}{x}\\right)^{2} d x&=\\frac{\\pi}{2}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tIf the fourier transform of $f(x)$ is $f(s)$, then find the fourier transform of $\\frac{d f}{d x}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\left[\\frac{d f}{d x}\\right]&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} \\frac{d f}{d x} e^{i s x} d x\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[e^{i s x} f(x)\\right]_{-\\infty}^{\\infty}-\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} i s e^{i s x} f(x) d x\\\\\n\t\\intertext{Since $f(x)$ should be a well behave function for the fourier tranform to exist, therefore, the first term of the above equation should be equal to zero.}\n\t\\text{Then }F\\left[\\frac{d f}{d x}\\right]&=-i s \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{i s x} f(x) d x=-is f( {s})\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind Fourier transform of $f(x)= \\begin{cases}x^{2}, & |x|a\\end{cases}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\{f(x)\\} &=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{i s x} f(x) d x=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-a}^{a} e^{i s x} x^{2} d x \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left(\\frac{e^{i s x}}{i s} \\cdot x^{2}\\right)_{x=-a}^{a}-\\frac{2}{i s} \\int_{-a}^{a} x e^{i s x} d x\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{a^{2}}{i s}\\left(e^{i s a}-e^{-i s a}\\right)-\\frac{2}{i s}\\left[\\left(\\frac{x e^{i s x}}{i s}\\right)_{x=-a}^{a}-\\frac{1}{i s} \\int_{-a}^{a} e^{i s x} d x\\right]\\right]\\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{2 a^{2}}{s} \\sin (s a)+\\frac{2 a}{s^{2}} \\cos (s a)-\\frac{4}{s^{3}} \\sin (s a)\\right]\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tFind the complex fourier transform $e^{-|x|}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tF\\left\\{e^{-|x|}\\right\\}&=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{-|x|} e^{i s x} d x\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{-|x|} e^{i s x} d x+\\int_{0}^{\\infty} e^{-|x|} \\cdot e^{i s x} d x\\right]\\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\int_{-\\infty}^{0} e^{x} \\cdot e^{i s x} d x+\\int_{0}^{\\infty} e^{-x(1-i s)} d x\\right]\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\left[\\frac{e^{x(1+i s)}}{1+i s}\\right]_{x=-\\infty}^{0}+\\left[\\frac{e^{-x(1-i s)}}{-(1-i s)}\\right]_{x=0}^{\\infty}\\right] \\\\\n\t&=\\frac{1}{\\sqrt{2 \\pi}}\\left[\\frac{1}{1-i s}+\\frac{1}{1+i s}\\right]\\\\&=\\frac{1}{\\sqrt{2 \\pi}}\\left(\\frac{2}{1+s^{2}}\\right)\n\t\\end{align*}\n\\end{answer}\n\n\n\\begin{exercise}\n\tThe graph of a real periodic function $f(x)$ for the range $[-\\infty, \\infty]$ is shown below\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{FT01}\n\t\\end{figure}\n\tWhich of the following graphs represents the real part of its Fourier transform?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-06}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{b.}]\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-05}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{c.}]\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT-03}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{d.}] \t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=2.5cm]{FT02}\n\t\t\\end{figure}\n\t\\end{tasks}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { The given graph in the question is of } f(x)&=\\cos \\omega x\\\\\n\tF(\\cos \\omega x)=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{+\\infty} \\cos \\omega x e^{i k x} d x&=\\frac{1}{\\sqrt{2 \\pi}}\\left(\\int_{-\\infty}^{+\\infty} \\frac{e^{i(k+\\omega) x}}{2} d x+\\int_{-\\infty}^{+\\infty} \\frac{e^{i(k-\\omega) x}}{2} d x\\right)\\\\\n\t&\\Rightarrow F(\\cos \\omega x) \\frac{1}{\\sqrt{2 \\pi}}\\left(\\frac{1}{2} \\delta(k+\\omega)+\\frac{1}{2} \\delta(k-\\omega)\\right)\n\t\\intertext{Therefore, the fourier transform of $f(x)=\\cos x \\omega x$ consist of two delta functions of same height at $k=\\omega$ and $k=-\\omega$.}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{option (b)}\n\\end{answer}\n\\newpage\n\\begin{abox}\n\tLaplace Transforms\n\\end{abox}\nThe Laplace transform $f(s)$ of a function $F(t)$ is defined by \n\\begin{equation}\nf(s)=\\mathcal{L}\\{F(t)\\}=\\int_{0}^{\\infty} e^{-s t} F(t) d t .\n\\end{equation}\nA few comments on the existence of the integral are in order. The infinite integral of $F(t)$,\n\\begin{equation*}\n\\int_{0}^{\\infty} F(t) d t,\n\\end{equation*}\nneed not exist. For instance, $F(t)$ may diverge exponentially for large $t$. However, if there are some constants $s_{0}, M$, and $t_{0} \\geq 0$ such that for all $t>t_{0}$\n\\begin{equation}\n\\left|e^{-s_{0} t} F(t)\\right| \\leq M,\\label{LT-01}\n\\end{equation}\nthe Laplace transform will exist for $s>s_{0} $. $F(t)$ is then said to be of exponential order. As a counter example, $F(t)=e^{t^{2}}$ does not satisfy the condition given by Eq. (\\ref{LT-01}) and is not of exponential order. Thus, $\\mathcal{L}\\left\\{e^{t^{2}}\\right\\}$ does not exist.\nThe Laplace transform may also fail to exist because of a sufficiently strong singularity in the function $F(t)$ as $t \\rightarrow 0$. For example,\n\\begin{equation*}\n\\int_{0}^{\\infty} e^{-s t} t^{n} d t\n\\end{equation*}\ndiverges at the origin for $n \\leq-1$. The Laplace transform $\\mathcal{L}\\left\\{t^{n}\\right\\}$ does not exist for $n \\leq-1$. \n\n\\section{Important Laplace Transforms:}\n\\begin{enumerate}\n\t\\item $\\mathcal{L}(1)=\\frac{1}{s}$\n\t\\begin{exercise}\n\t\t$$\n\t\t\\mathcal{L}(1)=\\frac{1}{s}\n\t\t$$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(1)&=\\int_{0}^{\\infty} 1 \\cdot e^{-s t} d t=\\left[\\frac{e^{-s t}}{-s}\\right]_{0}^{\\infty}\\\\&=-\\frac{1}{s}\\left[\\frac{1}{e^{s t}}\\right]_{0}^{\\infty}=-\\frac{1}{s}[0-1]\\\\&=\\frac{1}{s}\\\\\n\t\t\\text{ Hence }\\mathcal{L}(1)&=\\frac{1}{s}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}(n=0,1,2, \\ldots \\ldots . .)$\n\t\\begin{exercise}\n\t\t$\\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}$ where $n$ and $s$ are positive.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}\\left(t^{n}\\right)&=\\int_{0}^{\\infty} e^{-s t} t^{n} d t\\\\\n\t\t\\text{Putting }s t=&x \\quad\\text{ or }\\quad t=\\frac{x}{s} \\quad\\text{ or } \\quad d t=\\frac{d x}{s}\\\\\n\t\t\\text{Thus we have}\\mathcal{L}\\left(t^{n}\\right)&=\\int_{0}^{\\infty} e^{-x}\\left(\\frac{x}{s}\\right)^{n} \\frac{d x}{s_{r}} \\quad \\Rightarrow \\quad \\mathcal{L}\\left(t^{n}\\right)=\\frac{1}{s^{n+1}} \\int_{0}^{\\infty} e^{-x} \\cdot x^{n} d x\\\\\n\t\t\\Rightarrow \\mathcal{L}\\left(t^{n}\\right)&=\\frac{\\sqrt{n+1}}{s^{n+1}} \\Rightarrow \\mathcal{L}\\left(t^{n}\\right)=\\frac{n !}{s^{n+1}}\\hspace{2cm}\\left[\\begin{array}{c}\n\t\t{\\left[n+1=\\int_{0}^{\\infty} e^{-x} \\cdot x^{n} d x\\right] } \\\\\n\t\t\\text { and } \\quad \\mid \\overline{n+1}=n !\n\t\t\\end{array}\\right]\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}(s>a)$\n\t\\begin{exercise}\n\t\t$\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}, \\quad$ where $s>a$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}\\left(e^{a t}\\right) &=\\int_{0}^{\\infty} e^{-s t} \\cdot e^{a t} d t=\\int_{0}^{\\infty} e^{-s t+a t} \\cdot d t \\\\\n\t\t&=\\int_{0}^{\\infty} e^{(-s+a) t} \\cdot d t=\\int_{0}^{\\infty} e^{-(s-a) t} \\cdot d t=\\left[\\frac{e^{-(s-a) t}}{-(s-a)}\\right]_{0}^{\\infty}=-\\frac{1}{s-a}\\left[\\frac{1}{e^{(s-a) t}}\\right]_{0}^{\\infty}\\\\\n\t\t&=\\frac{-1}{(s-a)}(0-1)=\\frac{1}{s-a}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\cos a t)=\\frac{s}{s^{2}+a^{2}}$\n\t$(s>0)$\n\t\\begin{exercise}\n\t\t$L(\\cos a t)=\\frac{s}{s^{2}+a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\cos a t)&=\\mathcal{L}\\left(\\frac{e^{t a t}+e^{-i a t}}{2}\\right) \\quad\\left[\\because \\cos a t=\\frac{e^{i a t}+e^{-i a t}}{2}\\right]\\\\\n\t\t&=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{i a t}+e^{-i a t}\\right)\\right]=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{i a t}\\right)+\\mathcal{L}\\left(e^{i a t}\\right)\\right]=\\frac{1}{2}\\left[\\frac{1}{s-i a}+\\frac{1}{s+i a}\\right]=\\frac{1}{2} \\frac{s+i a+s-i a}{s^{2}+a^{2}}\\\\\n\t\t&=\\frac{s}{s^{2}+a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\sin a t)=\\frac{a}{s^{2}+a^{2}} \\quad(s>0)$\n\t\t\\begin{exercise}\n\t\t$\\mathcal{L}(\\sin a t)=\\frac{a}{s^{2}+a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\sin a t)&=\\mathcal{L}\\left[\\frac{e^{i a t}-e^{-i a t}}{2 i}\\right]\\hspace{3cm} \\left[\\because \\sin a t=\\frac{e^{i a t}-e^{-i a t}}{2 i}\\right]\\\\\n\t\t&=\\frac{1}{2 i}\\left[L\\left(e^{i a t}-e^{-i a t}\\right)\\right]=\\frac{1}{2 i}\\left[L\\left(e^{i a t}\\right)-\\mathcal{L}\\left(e^{-i a t}\\right)\\right] \\\\\n\t\t&=\\frac{1}{2 i}\\left[\\frac{1}{s-i a}-\\frac{1}{s+i a}\\right]=\\frac{1}{2 i} \\frac{s+i a-s+i a}{s^{2}+a^{2}}=\\frac{1}{2 i} \\frac{2 i a}{s^{2}+a^{2}}=\\frac{a}{s^{2}+2^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\\item $\\mathcal{L}(\\cosh a t)=\\frac{s}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\t\t\\begin{exercise}\n\t\t$\\mathcal{L}(\\cosh a t)=\\frac{s}{s^{2}-a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\cosh a t) &=L\\left[\\frac{e^{a t}+e^{-a t}}{2}\\right] \\hspace{4cm}\\left(\\therefore \\cosh a t=\\frac{e^{a t}+e^{-a t}}{2}\\right)\\\\\n\t\t&=\\frac{1}{2} \\mathcal{L}\\left(e^{a t}\\right)+\\frac{1}{2} L\\left(e^{-a t}\\right)=\\frac{1}{2}\\left[\\frac{1}{s-a}+\\frac{1}{s+a}\\right] \\hspace{2cm}\\left[\\mathcal{L}\\left(e^{a t}\\right)=\\frac{1}{s-a}\\right]\\\\\n\t\t&=\\frac{1}{2}\\left[\\frac{s+a+s-a}{s^{2}-a^{2}}\\right]=\\frac{s}{s^{2}-a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item $\\mathcal{L}(\\sinh a t)=\\frac{a}{s^{2}-a^{2}}\\left(s^{2}>a^{2}\\right)$\n\t\\begin{exercise}\n\t\t$L(\\sinh a t)=\\frac{a}{s^{2}-a^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathcal{L}(\\sinh a t) &=\\mathcal{L}\\left[\\frac{1}{2}\\left(e^{a t}-e^{-a t}\\right)\\right] \\\\\n\t\t&=\\frac{1}{2}\\left[\\mathcal{L}\\left(e^{a t}\\right)-L\\left(e^{-a t}\\right)\\right]=\\frac{1}{2}\\left[\\frac{1}{s-a}-\\frac{1}{s+a}\\right]=\\frac{1}{2}\\left[\\frac{s+a-s+a}{s^{2}-a^{2}}\\right] \\\\\n\t\t&=\\frac{a}{s^{2}-a^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\n\\subsubsection{Important properties:}\n\\begin{enumerate}\n\t\\item Linear Property: $\\mathcal{L}\\left[a_{1} f_{1}(t)+a_{2} f_{2}(t)\\right]=a_{1} \\mathcal{L}\\left[f_{1}(t)\\right]+a_{2} \\mathcal{L}\\left[f_{2}(t)\\right]$\n\t\\item Shifting Property: $\\mathcal{L}\\left[e^{a t} f(t)\\right]=f(s-a)$\n\t\\item Scaling Property: $\\mathcal{L}[f(a t)]=\\frac{1}{a} f\\left(\\frac{s}{a}\\right)$\n\t\\item $\\mathcal{L}\\left[t^{n} f(t)\\right]=(-1)^{n} \\frac{d^{n}}{d s^{n}}(f(s))$\n\t\\item $\\mathcal{L}\\left[\\frac{f(t)}{t}\\right]=\\int_{-\\infty}^{\\infty} f(s) d s$\n\t\\item $\\mathcal{L}\\left[\\int_{0}^{t} f(t) d t\\right]=\\frac{1}{s} f(s)$\n\t\\item $\\mathcal{L}\\left[f^{\\prime}(t)\\right]=s L[f(t)]-f(0)$\n\t\\item $\\mathcal{L}\\left[f^{\\prime \\prime}(t)\\right]=s^{2} L[f(t)]-f^{\\prime}(0)-s f(0)$\n\t\\item Laplace transform of a periodic function $f(t)$ having period ' $T$ ' is $$\\mathcal{L}[f({t})]=\\frac{1}{1-e^{-s T}} \\int_{0}^{T} e^{-s t} f({t}) d {t}$$\n\t\\item Laplace transform of the unit step function $u(t-a)=u_{a}(t)=\\left\\{\\begin{array}{lll}0 & \\text { for } & t\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nGive an $\\mathcal{O}(n \\log k)$-time algorithm to merge $k$ sorted lists into one sorted list, where $n$ is the total number of elements in all the input lists.\n\nHint 1: Use a min-heap for $k$-way merging.\n\nHint 2: Think of the merging part of \\texttt{MergeSort} and extend it to multiple lists.\nRemember that the lists are not necessarily the same size.\n\n\\subsection*{Solution}\n\nTo merge $k$ sorted lists, we slightly modify the merging function of the original \\textsc{MergeSort} algorithm so that it compares first elements of $k$ arrays instead of 2.\n\nWith no assumption on size of $k$ lists, we start with first elements of each array and build a min-heap structure.\n\nFor any heap structure with $n$ nodes where $n \\leq k$ we pop the root element once after a call to \\textsc{Heapify} and insert it into the final sorted array.\nOnce all nodes are popped, we take a new element (smallest element) from each $k$ list and repeat the procedure until all elements are inserted into the final sorted array.\n\nA more formal explanation of the algorithm is given in the following Algorithm in which \\textsc{Construct}($A$,$i$) would initialize array $A$ with elements in index $i$ of lists $L_1$ through $L_k$.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Merge-Sort-k-List}}\n\\begin{algorithmic}[1]\n\\For {$i \\leftarrow 1$ : max($L_1$.length, $L_2$.length, ..., $L_k$.length)}\n\\State \\textsc{Construct}($A$, $i$)\n\\State \\textsc{Build-Heap}($A$)\n\\State $A$.heapsize $\\leftarrow$ $A$.length\n\\For {$j$ $\\leftarrow$ $1$ to $A$.heapsize}\n\\State $F[k] \\leftarrow A[1]$\n\\State $k \\leftarrow k + 1$\n\\State \\textsc{Heap-Delete}($A$, $1$)\n\\EndFor\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\nThe outer loop of proposed algorithm will be executed $\\lceil \\frac{n}{k} \\rceil$ times while the inner loop is executed (at most) $k$ times.\nKnowing from previous question that runtime of \\textsc{Heap-Delete}($A$, $1$) would be $\\log{k}$, the inner loop would give a runtime of $k\\log{k}$.\nSince runtime of \\textsc{Build-Heap}($A$) is also known to be $\\mathcal{O}(k)$, runtime of the outer loop would be $k \\log k + k$.\n\nThus the runtime of the algorithm would be the runtime of the outer loop times the number of its execution, as given in Equation \\ref{eq2}.\n\n\\begin{equation}\\label{eq2}\n\\begin{aligned}\n\\mathcal{O}(f) &=\n\\mathcal{O}(\\frac{n}{k}[(k\\log k)+ k])\\\\ &= \\mathcal{O}(n \\log k + n)\\\\ &= \\mathcal{O}(n\\log k)\n\\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "d4671e748e448b6644cb6fac1ac3acbe3606e63e", "size": 2799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 49.9821428571, "max_line_length": 199, "alphanum_fraction": 0.6870310825, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538936, "lm_q2_score": 0.9136765269395709, "lm_q1q2_score": 0.8634194904144705}} {"text": "\\section{Multi-Index Notation}\nMulti-index notation makes high-dimensional things faster and easier. A collection is indices is represented by a tuple $\\alpha = \\left(\\alpha_1,\\alpha_2,\\alpha_3,... \\right)$. The absolute value $|\\alpha| = \\sum_i \\alpha$, partial derivatives $\\partial^\\alpha = \\prod \\partial^{\\alpha_i}$, powers $\\mathbf{x}^\\alpha = \\prod_i x_i^{\\alpha_i}$.\n\n\\subsection{Example: Multinomial Coefficients}\t\n\nInstead of:\n\\begin{equation}\n\\sum_{0\\leq i_1,i_2,i_3,...,i_k \\leq n} {n \\choose i_1,i_2,i_3,...,i_k} \n\\end{equation}\n\nWrite:\n\n\\begin{equation}\t\n\\sum_{0\\leq |\\alpha|\\leq n}{n \\choose \\alpha}\n\\end{equation}\n\n\\subsection{Example: Taylor Expansion}\n\nFor a vector valued function $\\mathbf{f}: \\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ that is analytical in a neighborhood of the point $\\mathbf{a}$:\n\n\\begin{equation}\nf(\\mathbf{x}) = \\sum_{|\\alpha|\\geq0} \\frac{(\\mathbf{x} - \\mathbf{a})^\\alpha}{\\alpha!}(\\partial^\\alpha)f\n\\end{equation}\n", "meta": {"hexsha": "b2ff39cade46535d16eabd249feb4020484d5850", "size": 953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_multiindex.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_multiindex.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_multiindex.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7083333333, "max_line_length": 343, "alphanum_fraction": 0.703043022, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9740426405416754, "lm_q2_score": 0.8856314858927012, "lm_q1q2_score": 0.8626428310657743}} {"text": "\\textbf{In this problem you will derive the barycentric weights for Chebyshev points of the second kind. Let}\n\\begin{align*}\nx_j = \\cos(j\\pi /n),~j = 0,\\dots,n,~~\\text{and}~~w_j = 1/ \\left( \\prod_{k=0,k \\neq j}^n (x_j - x_k) \\right)\n\\end{align*}\n\\textbf{In Matlab, use the formula above to evaluate $w_j$, $j = 0, \\dots, n$ with $n = 10$. Verify that the weights returned in Matlab are}\n\\begin{align}\nw_0 = 2^{n-1}/(2n),~w_j = 2^{n-1}(-1)^j/n,~j = 1,\\dots,n-1,~w_n = 2^{n-1}(-1)^n/(2n)~.\n\\end{align} \n\\textbf{Explain why the factor $2^{n-1}/n$ can be ignored when evaluating the barycentric formula. That is, one can use, instead, the weights}\n\\begin{align*}\n\\tilde{w}_0 = 1/2,~\\tilde{w}_j = (-1)^j, ~j = 1,\\dots, n-1,~\\tilde{w}_n = (-1)^n/2~.\n\\end{align*}\nBy coding matlab both ways of calculating the weights we found the claim to be true since we obtained an infinity norm of the difference of order $10^{-14}$. We can prove the previous by simply substituting the definition of the weights in the baricentric formula that when using the barycentric formula,\n\\begin{align*}\np(x) &= \\frac{\\sum_{j=0}^{n}\\frac{w_j}{(x - x_j)}f_j}{\\sum_{j=0}^{n}\\frac{w_j}{(x - x_j)}}\\\\\n&= \\frac{\\sum_{j=0}^{n}\\frac{\\frac{2^{n-1}(-1)^j}{n}}{(x - x_j)}}{\\sum_{j=0}^{n}\\frac{\\frac{2^{n-1}(-1)^j}{n}}{(x - x_j)}}f_j\\\\\n& = \\frac{\\frac{2^{n-1}}{n}}{\\frac{2^{n-1}}{n}}\\frac{\\sum_{j=0}^{n}\\frac{(-1)^j}{(x - x_j)}}{\\sum_{j=0}^{n}\\frac{(-1)^j}{(x - x_j)}}f_j \\\\\n& = \\frac{\\sum_{j=0}^{n}\\frac{(-1)^j}{(x - x_j)}}{\\sum_{j=0}^{n}\\frac{(-1)^j}{(x - x_j)}}f_j.\n\\end{align*}\nHence, since the factor $2^{n-1}/n$ gets cancelled, it can be ignored from the weights.\n\\newpage\n\\textbf{Show that, for $x_j = cos(j\\pi/n)$,}\n\\begin{align*}\n\\prod_{k=0}^n(x - x_k) = \\frac{1}{2^{n-1}}(x^2-1)U_{n-1}(x)\n\\end{align*} \n\\textbf{and}\n\\begin{align*}\nw_j = 1/ \\left( \\prod_{k=0,k \\neq j}^n (x_j - x_k) \\right) = \\lim_{x \\rightarrow x_j} \\frac{2^{n-1}(x-x_j)}{(x^2 - 1)U_{n-1}(x)}~.\n\\end{align*}\n\\textbf{Here $U_{n-1}(x) = \\frac{sin(n\\arccos x)}{sin(\\arccos x)}$ is the Chebyshev polynomial of the second kind of degree $n-1$.}\n\nWe start with the relation between the Chebishev's polynomials of first and second kind\n\\begin{align*}\nT'_n(x) = nU_{n-1}(x).\n\\end{align*}\nUsing that\n\\begin{align*}\nT_n(x) = 2^{n-1}\\prod_{k=0}^{n-1}(x - x_k),\n\\end{align*}\nand the previous relation we get\n\\begin{align*}\nnU_{n-1}(x) = T'_n(x) = n2^{n-1}\\prod_{k=1}^{n-1}(x - \\tilde{x}_k)~.\n\\end{align*}\nNote that now the roots have changed, now they are the roots of the Chebishev's polynomial of the second kind and the roots of the boundaries are missing. We can include them by multiplying\n\\begin{align*}\n\\prod_{k=0}^{n}(x - \\tilde{x}_k)=(x-x_0)(x-x_n)\\prod_{k=1}^{n-1}(x - \\tilde{x}_k) = (x-x_0)(x-x_n)\\frac{1}{2^{n-1}}U_{n-1}(x),\n\\end{align*}\nwhere we have made $\\tilde{x}_0=x_0$ and same for $x_n$. Lastly, recall that \n\\begin{align*}\n(x-x_0)(x-x_n)=(x+1)(x-1)=(x^2-1),\n\\end{align*}\nand we obtain the desired expression\n\\begin{align*}\n\\prod_{k=0}^{n}(x - \\tilde{x}_k)= \\frac{1}{2^{n-1}}(x^2-1)U_{n-1}(x).\n\\end{align*}\n\nFurther, observe that\n\\begin{align*}\n\\frac{d}{dx}\\prod_{k=0}^{n}(x - x_k) = \\sum_{k=0}^{n} \\left( \\prod_{j=0,j \\neq k}^{n}(x - x_j) \\right) = \\prod_{k=0, k \\neq j}^{n}(x_j - x_k).\n\\end{align*}\nHence,\n\\begin{align*}\n \\frac{1}{\\frac{d}{dx} \\prod_{k=0}^{n}(x - x_k)} = \\lim_{x \\rightarrow x_j} \\frac{(x - x_j)}{\\prod_{k=0}^{n}(x - x_k)} = \\lim_{x \\rightarrow x_j} \\frac{2^{n-1}(x-x_j)}{(x^2 - 1)U_{n-1}(x)}.\n\\end{align*}\n\n\\textbf{Use L'Hopital's Rule to evaluate the limit in (2) and derive the expressions in equation (1).}\n\nGiven the expression for $U_{n-1}(x)$ above we obtain the derivative\n\\begin{align*}\nU'_{n-1}(x) = \\frac{-n\\cos(n\\arccos(x))\\sin(\\arccos(x)) + \\sin(n\\arccos(x))\\cos(\\arccos(x))}{\\left(\\sqrt{1 - x^2}\\right)\\sin^2(\\arccos(x))}.\n\\end{align*}\nRecall the definition of $x_j=\\cos(j\\pi/n)$. Then,\n\\begin{align*}\nU'_{n-1}(x_j) & = \\frac{-n\\cos(j \\pi)}{\\left(\\sqrt{1 - x^2}\\right) \\sin(\\frac{j \\pi}{n})} + \\frac{\\sin(j \\pi) \\cos(\\frac{j \\pi}{n})}{\\left(\\sqrt{1 - x^2}\\right)\\sin^2(\\frac{j \\pi}{n})} \\\\\n&= \\frac{1}{\\sqrt{1 - x^2}} \\left( \\frac{n\\cos(j\\pi)}{\\sin(\\frac{j \\pi}{n})} \\right) \\\\\n& = \\frac{n(-1)^j}{\\sin^2(\\frac{j \\pi}{n})}~.\n\\end{align*}\nTo finish, use L'Hopital's rule and the result from the previous part,\n\\begin{align*}\nw_j & = \\lim_{x \\rightarrow x_j} \\frac{2^{n-1}(x-x_j)}{(x^2 - 1)U_{n-1}(x)} \\\\ &= \\lim_{x \\rightarrow x_j} \\frac{2^{n-1}}{2xU_{n-1}(x)+(x^2 -1)U'_{n-1}(x)} \\\\\n& = \\frac{2^{n-1}}{2x_jU_{n-1}(x_j)+(x_j^2 -1)U'_{n-1}(x_j)} \\\\\n& = \\frac {2^{n-1}}{\\sin^2(\\frac{j\\pi}{n})\\left( \\frac{n(-1)^j}{\\sin^2(\\frac{j\\pi}{n})}\\right)} \\\\\n& = \\frac{2^{n-1}(-1)^j}{n}.\n\\end{align*}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 5\nn=10;\nj=0:n;\nx=cos(j*pi/n);\nw_a=zeros(n+1,1);\nw_b=zeros(n+1,1);\nfor j=0:n\n xj=x(j+1);\n xk=x;\n xk(j+1)=[];\n w_a(j+1)=1/prod(xj-xk);\nend\nw_b(1)=2^(n-1)/(2*n);\nfor j=2:n\n w_b(j)=2^(n-1)*(-1)^(j-1)/n;\nend\nw_b(n+1)=2^(n-1)*(-1)^n/(2*n);\nerr=norm(w_a-w_b,inf)\n\\end{verbatim}", "meta": {"hexsha": "81fc16455e2825d52379245cd2b78dd25c844e3f", "size": 5024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem5.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem5.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem5.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.3962264151, "max_line_length": 304, "alphanum_fraction": 0.5979299363, "num_tokens": 2264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.9390248246808277, "lm_q1q2_score": 0.8624757543093751}} {"text": "\\section*{Exercises}\n\n\\begin{ex}\n Consider the set $\\R^2$ with the following non-standard addition\n operation $\\oplus$:\n \\begin{equation*}\n (a,b) \\oplus (c,d) = (a+d,b+c).\n \\end{equation*}\n Scalar multiplication is defined in the usual way. Is this a vector space?\n Explain why or why not.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Consider $\\R^2$ with the following non-standard addition operation\n $\\oplus$:\n \\begin{equation*}\n (a,b) \\oplus (c,d) = (0,b+d).\n \\end{equation*}\n Scalar multiplication is defined in the usual way. Is this a vector space?\n Explain why or why not.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Consider $\\R^2$ with the following non-standard scalar multiplication:\n \\begin{equation*}\n c\\odot(a,b) = (a,cb).\n \\end{equation*}\n Vector addition is defined as usual. Is this a vector space? Explain\n why or why not.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Consider $\\R^2$ with the following non-standard addition operation\n $\\oplus$:\n \\begin{equation*}\n (a,b) \\oplus (c,d) = (a-c,b-d).\n \\end{equation*}\n Scalar multiplication is defined as usual. Is this a vector space?\n Explain why or why not.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Prove that the set $\\Seq_K$ from\n Example~\\ref{exa:vector-space-sequences} is a vector space.\n Hint: this is a special case of\n Example~\\ref{exa:vector-space-function}, if you realize that a\n sequence $(a_i)_{i\\in\\N}$ is the same thing as a function $a:\\N\\to K$.\n\\end{ex}\n\n\\begin{ex}\n Prove that the set $\\Poly$ from\n Example~\\ref{exa:vector-space-polynomials} is a vector space.\n\\end{ex}\n\n\\begin{ex}\n Let $V$ be the set of functions defined on a set $X$ that have\n values in a vector space $W$. Is this a vector space? Explain.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Consider the set $\\R^2$ with the following non-standard operations\n of addition and scalar multiplication:\n \\begin{equation*}\n \\begin{array}{rcl}\n (a,b) \\oplus (c,d) &=& (a+c-1,\\, b+d-1), \\\\\n k \\odot (c,d) &=& (kc + (1-k),\\, kd + (1-k)). \\\\\n \\end{array}\n \\end{equation*}\n Show that $\\R^2$ is a vector space with these operations. Hint: the\n zero vector is not $(0,0)$, but $(1,1)$.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Consider the set $\\R$ of real numbers. Addition of real numbers is\n defined in the usual way, and scalar multiplication is just\n multiplication of one real number by another. In other words, $x+y$\n means to add the two numbers and $xy$ means to multiply them. Show\n that $\\R$, with these operations, is a real vector space.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $K=\\Q$ be the field of rational numbers, and let $V$ be the set\n of real numbers of the form $a+b\\sqrt{2}$, where $a$ and $b$ are\n rational numbers. Show that with the usual operations, $V$ is a\n $\\Q$-vector space.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $K=\\Q$ be the field of rational numbers, and let $V=\\R$ be the\n set of real numbers. Show that with the usual operations, $V$ is a\n $\\Q$-vector space.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $\\Poly_3$ be the set of all polynomials of degree 3 or\n less. That is, these are of the form $ax^3+bx^2+cx+d$. Addition and\n scalar multiplication of polynomials are defined as usual. Show\n that $\\Poly_3$ is a vector space.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Let $X=\\set{1,2,\\ldots,n}$, and consider the space $\\Func_{X,\\R}$ of\n real-valued functions defined on $X$. Explain how $\\Func_{X,\\R}$ can be\n considered as $\\R^n$.\n \\begin{sol}\n Let $f(i)$ be the $i\\th$ component of a vector\n $\\vect{x}\\in\\R^n$. Thus a typical element in $\\R^n$ is\n $(f(1),\\ldots,f(n))$.\n \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Prove the cancellation law from\n Proposition~\\ref{prop:vector-space-elementary}.\n\\end{ex}\n", "meta": {"hexsha": "428c705c19166867b9372de0522f312647ad9b03", "size": 3877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/VectorSpaces-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/VectorSpaces-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/VectorSpaces-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.5073529412, "max_line_length": 76, "alphanum_fraction": 0.6502450348, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.9390248246808277, "lm_q1q2_score": 0.8624757501186434}} {"text": "\\subsection{Multiplication of natural numbers}\n\n\n\\subsection{Definition}\n\nMultiplication can be defined by:\n\n\\(\\forall a \\in \\mathbb{N} (a.0=0)\\)\n\n\\(\\forall a b \\in \\mathbb{N} (a.s(b)=a.b+a)\\)\n\n\\subsection{Example}\n\nLet’s calculate \\(2.2\\).\n\n\\(2.2=2.s(1)\\)\n\n\\(2.s(1)=2.1+2\\)\n\n\\(2.1+2=2.s(0)+2\\)\n\n\\(2.s(0)+2=2.0+2+2\\)\n\n\\(2.0+2+2=2+2\\)\n\n\\(2+2=4\\)\n\n\\subsection{Commutative property of multiplication}\n\nMultiplication is commutative:\n\n\\(xy=yx\\)\n\n\\subsection{Associative property of multiplication}\n\nMultiplication is associative:\n\n\\(x(yz)=(xy)z\\)\n\n\\subsection{Distributive property of multiplication}\n\nMultiplication is distributive over addition:\n\n\\(a(b+c)=ab+ac\\)\n\n\\((a+b)c=ac+bc\\)\n\n\n\n", "meta": {"hexsha": "69f5e3818986ef29283f184218da892569d9c566", "size": 683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/peano/02-01-multiplication.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/peano/02-01-multiplication.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/peano/02-01-multiplication.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.66, "max_line_length": 52, "alphanum_fraction": 0.6603221083, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811631528337, "lm_q2_score": 0.8933093996634686, "lm_q1q2_score": 0.8623840673024789}} {"text": "\\section*{Exercises}\n\n\\begin{ex}\n Find the characteristic polynomial of the matrix\n \\begin{equation*}\n \\begin{mymatrix}{rr}\n 3 & -2 \\\\\n 1 & 0 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n Use the quadratic formula to find the eigenvalues.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Find the characteristic polynomial, eigenvalues, and basic\n eigenvectors of the matrix\n \\begin{equation*}\n \\begin{mymatrix}{rr}\n 9 & 10 \\\\\n -5 & -6 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n Find the characteristic polynomial, eigenvalues, and basic\n eigenvectors of the matrix\n \\begin{equation*}\n \\begin{mymatrix}{rrr}\n 0 & 3 & -1 \\\\\n -2 & 4 & -2 \\\\\n 2 & -3 & 3 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n One eigenvalue is $1$.\n\\end{ex}\n\n\\begin{ex}\n Find the characteristic polynomial, eigenvalues, and basic\n eigenvectors of the matrix\n \\begin{equation*}\n \\begin{mymatrix}{rrr}\n 3 & 0 & -2 \\\\\n -2 & 1 & 2 \\\\\n 0 & 0 & 1 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n One eigenvalue is $3$.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Find the characteristic polynomial, eigenvalues, and basic\n eigenvectors of the matrix\n \\begin{equation*}\n \\begin{mymatrix}{rrr}\n 9 & 2 & 8 \\\\\n 2 & -6 & -2 \\\\\n -8 & 2 & -5\n \\end{mymatrix}.\n \\end{equation*}\n One eigenvalue is $-3$.\n % \\begin{sol}\n % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Which of the following matrices have no real eigenvalue?\n \\begin{equation*}\n A = \\begin{mymatrix}{rr}\n 1 & 1 \\\\\n 1 & -1 \\\\\n \\end{mymatrix},\n \\quad\n B = \\begin{mymatrix}{rr}\n 1 & -1 \\\\\n 1 & 1 \\\\\n \\end{mymatrix},\n \\quad\n C = \\begin{mymatrix}{rr}\n 0 & 1 \\\\\n 1 & 0 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n Find the eigenvalues and eigenvectors of the following triangular\n matrix:\n \\begin{equation*}\n \\begin{mymatrix}{rrr}\n 3 & 2 & 2 \\\\\n 0 & 1 & -2 \\\\\n 0 & 0 & -1 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n Is it possible for a non-zero matrix to have only $0$ as an eigenvalue?\n \\vspace{1mm}\n \\begin{sol}\n Yes. $\\begin{mymatrix}{cc}\n 0 & 1 \\\\\n 0 & 0%\n \\end{mymatrix}$ works.\n \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "290de45981577449b1678e0278f7f1d12aa8c293", "size": 2283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Finding.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Finding.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Finding.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 20.203539823, "max_line_length": 73, "alphanum_fraction": 0.5593517302, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474155747541, "lm_q2_score": 0.9032941982430049, "lm_q1q2_score": 0.8623274718563543}} {"text": "\\section{The Cauchy-Schwarz inequality}\n\nThe Cauchy$-$Schwarz inequality states that for all vectors $x$ and $y$ of an inner product space it is true that\n$$\\left | \\left \\langle x, y \\right \\rangle \\right | \\leq \\left \\| x \\right \\| \\cdot \\left \\| y \\right \\|$$\n\n\n\n", "meta": {"hexsha": "a41748862feaab56629c4388c97144f5c16519e5", "size": 266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/CauchySchwarzInequality.tex", "max_stars_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_stars_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-12-28T05:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T05:56:59.000Z", "max_issues_repo_path": "src/CauchySchwarzInequality.tex", "max_issues_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_issues_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/CauchySchwarzInequality.tex", "max_forks_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_forks_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.25, "max_line_length": 113, "alphanum_fraction": 0.6729323308, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9787126475856414, "lm_q2_score": 0.8807970904940926, "lm_q1q2_score": 0.8620472524232031}} {"text": "\\section{DNN and CNN}\n\\subsection{Tensor notation}\n\\begin{definition}\nA tensor $T$ of order $d$ is a multi-index array,\n\\begin{equation}\nT \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d},\n\\end{equation}\nwith $i$-th dimension being $n_i$.\n\\end{definition}\n\\paragraph{Example 1: 2D grey image}\n\\begin{equation}\\label{2DGreyImage}\nT \\in \\mathbb{R}^{n_1 \\times n_2}.\n\\end{equation}\n\\paragraph{Example 2: 2D color image}\n\\begin{equation}\\label{2DColorImage}\nT \\in \\mathbb{R}^{3 \\times n_1 \\times n_2}.\n\\end{equation}\n\\paragraph{Example 3: 3D grey image - MRI}\n\\begin{equation}\\label{3DColorImage}\nT \\in \\mathbb{R}^{ n_1 \\times n_2 \\times n_3}.\n\\end{equation}\n\n\\begin{definition}[Tensor Product]\nIf $X \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d}$ and $Y \\in \\mathbb R^{m_1 \\times m_2 \\times \\cdots \\times m_e}$, then the tensor product is noted as $\\otimes$ with the next definition,\n\\begin{equation}\nX \\otimes Y \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d \\times m_1 \\times m_2 \\times \\cdots \\times m_e},\n\\end{equation}\nwith\n\\begin{equation}\n(X\\otimes y)_{i_1, \\cdots, i_d, j_1, \\cdots,j_e} = X_{i_1, \\cdots, i_d} Y_{j_1, \\cdots, j_e}.\n\\end{equation}\n\\end{definition}\n\\paragraph{Example 5: Rank one matrix} If $x \\in \\mathbb{R}^n$ and $y \\in \\mathbb{R}^m$, then\n\\begin{equation}\\label{3DColorImage}\nx \\otimes y \\in \\mathbb{R}^{n \\times m},\n\\end{equation}\nwith\n\\begin{equation}\nx \\otimes y = x y^\\top.\n\\end{equation}\n\n\\paragraph{Example 6: } If $X \\in \\mathbb{R}^{n_1\\times n_2}$ and $Y \\in \\mathbb{R}^{m_1 \\times m_2}$, then\n\\begin{equation}\\label{3DColorImage}\nX \\otimes Y \\in \\mathbb{R}^{n_1 \\times n_1 \\times m_1 \\times m_1},\n\\end{equation}\nwith\n\\begin{equation}\n(X \\otimes Y)_{i_1, i_2, j_1 ,j_2} = X_{i_1, i_2} Y_{j_1, j_2}.\n\\end{equation}\n\n\\begin{definition}[Tensor ``inner product\"]\nIf\n$$\nX \\in \\mathbb R^{(n_1 \\times n_2 \\times \\cdots \\times n_d )\\times\n (t_1\\times t_2\\times\\cdots\\times t_k)}\n$$ and\n$$\nY\\in \\mathbb R^{ (t_k\\times t_{k-1}\\times\\cdots\\times t_1)\\times\n (m_1 \\times m_2 \\times \\cdots \\times m_e)},\n$$\nthen the tensor ``inner product\" with order $k$ is given by\n\\begin{equation}\nX\\odot_k Y \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d \\times m_1 \\times m_2 \\times \\cdots \\times m_e},\n\\end{equation}\nwith\n\\begin{equation}\n(X\\odot_k Y)_{i_1, \\cdots, i_d, j_1, \\cdots,j_e}\n=\\sum_{s_1=1}^{t_1} \\cdots\\sum_{s_k=1}^{t_k}X_{i_1, \\cdots, i_d, s_1,\\cdots,s_k} Y_{s_k,\\cdots,s_1,,j_1, \\cdots, j_e}.\n\\end{equation}\n\\end{definition}\nWe note that\n$$\nX\\otimes Y =X\\odot_0Y\n$$\nFor simplicity, we denote\n\\begin{equation}\nX\\cdot Y=X\\odot_1Y \\mbox{ and } X:Y=X\\odot_2 Y .\n\\end{equation}\n\\paragraph{Example 7: } If $x \\in \\mathbb{R}^{1\\times n}$ and $y \\in \\mathbb{R}^{n}$, then\n\\begin{equation}\\label{3DColorImage}\nx \\odot_1 y =xy= \\sum_{i=1}^n x_{1,i} y_{i,1}.\\in \\mathbb{R}^{1}.\n\\end{equation}\n\n\n\\paragraph{Example 8: } If $X \\in \\mathbb{R}^{n_1 \\times m}$ and $Y \\in \\mathbb{R}^{m \\times n_2}$, then\n\\begin{equation}\\label{3DColorImage}\nX \\odot_1 Y =XY\\in \\mathbb{R}^{n_1 \\times n_2},\n\\end{equation}\nwith\n\\begin{equation}\n(X \\cdot Y)_{i,j} = \\sum_{k=1}^m X_{i,k} Y_{k,j}.\n\\end{equation}\nwhich is again the product of two matrices.\n\n\\begin{remark}\nWithout loss of generality, if the dimension and operation is clear, we note $\\odot$ without $\\odot_k$\n\\end{remark}\n\n\\newpage\n\\subsection{Single layer}\nA singular layer linear neural network can be written as\n$$\nf(x, \\theta)\n=\n\\begin{pmatrix}\n f_1(x,\\theta_1)\\\\\n\\vdots\n\\\\\n f_m(x,\\theta_m)\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n w_1 x+b_1, \\\\\n\\vdots\n\\\\\n w_m x+b_m, \\\\\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n w_1\\\\\n\\vdots\n\\\\\n w_m\n\\end{pmatrix}x\n+\n\\begin{pmatrix}\nb_1\\\\\n\\vdots\n\\\\\nb_m\n\\end{pmatrix}\n=Wx+b=\\theta \\tilde x\n$$\nwhere\n\\begin{equation}\nW\\in \\mathbb R^{m\\times n},\n\\theta=(W,b)=\n\\begin{pmatrix}\n \\theta_1\\\\\n\\vdots\\\\\n\\theta_m\n\\end{pmatrix}, \\quad\n\\tilde x=\n\\begin{pmatrix}\n x\\\\\n1\n\\end{pmatrix}\n\\end{equation}\n\n\nWe have\n\\begin{equation}\nf(x; \\theta )= W x+b, ~ \\Theta = \\{ \\theta = (W,b) ~|~ W \\in \\mathbb{R}^{m \\times n}, b \\in \\mathbb{R}^m \\}.\n\\end{equation}\n\nwith $f: \\mathbb{R}^n \\to \\mathbb{R}^m$.\n\n\\subsection{Deep neural networks (DNN)}\n\\begin{figure}[!ht]\n\\center{\\includegraphics[width=12cm,height=6cm] {figures/ANN.png}}\n\\caption{A typical deep neural network}\n\\end{figure}\nWe consider a sequence of affine operations:\n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat{n}_{j}}\\mapsto \\mathbb R^{ n_{j}}.\n\\end{equation}\nwith\n\\begin{equation}\\label{DNN_affinemap}\n\\theta^j(x) = W^j x + b^j\n=\n(W^j, b^j)\n\\begin{pmatrix}\n x \\\\\n1\n\\end{pmatrix}\n=\n\\theta^j\n\\begin{pmatrix}\n x \\\\\n1\n\\end{pmatrix}\n\\end{equation}\nand\n\\begin{equation}\nW^j\\in \\mathbb R^{n_j \\times \\hat n_{j}}, b^j\\in \\mathbb R^{n_j}.\n\\end{equation}\nWith a slight abuse of notation, we also denote\n\\begin{equation}\n\\theta^j=(W^j, b^j)\n=\n\\begin{pmatrix}\n\\theta^j_{1}\\\\\n\\vdots \\\\\n\\theta^j_{n_j}\\\\\n\\end{pmatrix}\n\\in \\mathbb R^{n_j\\times (\\hat n_{j}+1)}.\n\\end{equation}\n\nFor $j=0$, we have the input data\n$$\nx\\in \\mathbb R^{\\hat n_{0}}\n$$\nFor MNIST data base, we have\n$$\n\\hat n_0 = 784.\n$$\n\nWe consider nonlinear activation function that is applied componentwise:\n\\begin{equation}\\label{DNN_iteration_vector}\ng:\\mathbb R^{ n_{j-1}}\\mapsto \\mathbb R^{n_{j-1}},\n\\end{equation}\nand polling functions\n\\begin{equation}\\label{DNN_iteration_vector}\nr^j:\\mathbb R^{ n_{j-1}}\\mapsto \\mathbb R^{\\hat n_{j}}.\n\\end{equation}\nPoolling is not always applied after each application of activation.\nWhen it is not applied, $r^j$ is identity and $\\hat n_j=n_{j-1}$; when\nit is applied, $r_j$ is usually nonlinear and\n$$\n\\hat n_j 0.\n\t\\end{cases}\n\t$$\n\t\\item The new activation function as ReLU1 is:\n\t$$\n\t\\tau(x) = r(x) - r(x-1) = \\begin{cases}\n\t0 \\quad &\\text{if} ~ x \\le 0, \\\\\n\tx \\quad &\\text{if} ~ 0 < x \\le 1, \\\\\n\t1 \\quad &\\text{if} ~ x > 1.\n\t\\end{cases}\n\t$$\n\n\t\\end{itemize}\n\n\\subsection{Classification properties under this notation}\n\\begin{theorem}\n If $\\{A_k\\}_{k=1}^c$ are separable with positive distance, then it\n can be separated by $f(x; \\Theta) = f^2$, with $W^2= id, b^2=0$ and\n all activation function is $\\tau$.\n\\end{theorem}\n\n\\subsection{CNN for images}\n\\subsection{General setup}\n\\begin{enumerate}\n\\item Data:\n\t\\begin{itemize}\n\t\\item Input set: $\\bm{X} = \\{x_1, \\cdots, x_N\\}$\n\t\\item Output set: $\\bm{y} = \\{y_1, \\cdots, y_N\\}$\n\t\\item Generally, input use $x \\in \\mathbb{R}^{\\hat c_0 \\times \\hat n_1\\times \\cdots \\times \\hat n_d }$, with a label $y \\in \\mathbb{R}^c$ (output for classification problem)\n\t\\item Here $\\hat c_0$ means the channel dimension and $\\hat n_1\\times \\cdots \\times \\hat n_d$ means the essential dimension.\n\t\\end{itemize}\n \\item Here we use $x \\in \\mathbb{R}^{\\hat c_0 \\times n \\times n} $,\n $y \\in \\mathbb{R}^c$ as example.\n\\item Kernels: in CNN they generally use $K^i$ and $b^i$ to stand for the kernels and bias.\n\\end{enumerate}\n\n\\paragraph{Example 1: 2D grey image}\n\\begin{equation}\\label{2DGreyImage}\nc_0=1, d=2\n\\end{equation}\n\\paragraph{Example 2: 2D color image}\n\\begin{equation}\\label{2DColorImage}\nc_0=3, d=2\n\\end{equation}\n\\paragraph{Example 3: 3D grey image - MRI}\n\\begin{equation}\\label{2DColorImage}\nc_0=1, d=3\n\\end{equation}\n\n\n\\subsection{DNN for images under tensor notation}\n\n Multilayer structures in convolutional layers is totally the same for \\eqref{DNN_affinemap} - \\eqref{DNN_finallayer}: the only difference is the structure of affine map:\n\n\\begin{equation}\\label{CNN_affinemap}\n\\theta^j_{p}(x) = W^j_p \\odot_3 x + b^j_p \\in \\mathbb R^{n_j \\times n_j}, \\quad p=1:c_j\n\\end{equation}\n\n\\begin{equation}\\label{CNN_affinemap}\n\\theta^j(x) = W^j\\odot_3 x + b^j\n\\end{equation}\nwith\n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat c_j \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\\end{equation}\n\nHere\n\\begin{equation}\nW^j \\in \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n (\\hat{n}_{j} \\times \\hat n_{j}\\times \\hat c_{j} )}, \\quad\nb^j\\in \\mathbb R^{c_j \\times n_{j} \\times n_j},\n\\end{equation}\nand\n\\begin{align}\n\\theta^j &= \\{W^j , b^j\\} \\in \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n (\\hat{n}_{j} \\times \\hat n_{j}\\times \\hat c_{j} )} \\oplus \\mathbb R^{c_j \\times n_{j} \\times n_j} \\\\\n &\\cong \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n (\\hat{n}_{j} \\times \\hat n_{j}\\times c_{j} + 1 )}\n\\end{align}\n\nWe note that\n\\begin{equation}\n\\hat n_0 =n .\n\\end{equation}\n\nWe consider nonlinear activation function applied element wise:\n\\begin{equation}\\label{CNN_iteration_vector}\ng: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1}},\n\\end{equation}\nand polling functions\n\\begin{equation}\\label{CNN_iteration_vector}\nr^j: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times\\hat n_j }.\n\\end{equation}\n\nWe also consider ``pooled-activation'' functions:\n\\begin{equation}\\label{CNN_iteration_vector}\ng^j=r^j\\circ g: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto\n\\mathbb \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times \\hat n_j }, \\quad j = 1:J.\n\\end{equation}\n\n\n\nWe have the multi-layer DNN structure like:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tf^j(x,\\Theta^j) = (\\theta^j\\circ g^{j}\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\t\\end{equation}\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0\n\\end{equation}\n\twith\n\t\\begin{equation}\n\tf^0(x)=\\theta^0(x).\n\t\\end{equation}\n\nAt last, we get\n\t\\begin{equation}\\label{CNN_finallayer}\n\tf(x; \\Theta) = f^J.\n\t\\end{equation}\n\n Roughly speaking, \\eqref{CNN_affinemap} -\n \\eqref{CNN_finallayer} is totally the same for \\eqref{DNN_affinemap}\n - \\eqref{DNN_finallayer} in tensor notation.\n\n\\subsection{CNN for image}\nA convolution operation is a special linear mapping of the following form:\n\\begin{equation}\n\\theta^j(x) = K^j \\circledast x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\\end{equation}\nwith\n\t\\begin{equation}\n\tK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)}, \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\t\\end{equation}\nfor $k = 0, 1, 2, 3...$.\n\nGive $p\\in \\{1,\\ldots c_j\\}$\n\\begin{equation}\n(\\theta^j(x))_p= (K^j \\circledast x)_p+b^j_p{\\bm 1}_{n_j\\times n_j}\n\\end{equation}\nand\n\\begin{equation}\n (K^j \\circledast x)_p\n= \\sum_{q=1}^{\\hat c_{j}} K^{j}_{p,q} \\ast x_q \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_j.\n\\end{equation}\nwhere\n$$\nK^{j}_{p,q}\\in \\mathbb R^{(2k+1)\\times (2k+1)}, x_q\\in \\mathbb\nR^{\\hat n_{j}\\times \\hat n_{j}}.\n$$\nHere $\\ast$ is the traditional convolution defined as:\n\\begin{equation}\\label{ConvPadding}\n(K \\ast x)_{i,j} :=\\sum_{s, t = -k}^k K_{s+k+1,t+k+1} x_{i + s, j + t},\n\\end{equation}\nHere we assume implicitly that a special ``padding'' is used such that\n\\begin{equation}\n \\label{zero-padding}\nx_{i,j}=0 \\mbox{ if } i, j\\le 0 \\mbox{ or } i, j > n_j.\n\\end{equation}\n\n\n\\subsection{CNN with stride for image}\n\\subsubsection{Polling and stride}\nIf we use stride $s$, we have have the stander convolution operator with stride $s$ as:\n\\begin{equation}\\label{equ:convstride}\n(K\\ast_{s} x)_{i,j} = \\sum_{p, q = -k}^k K_{p+k+1,q+k+1}x_{is + p, js + q} .\n\\end{equation}\nThis stride properties in some application are often used as pooling(subsampling, coarsening).\n\nHere we can define a special pooling operator as $S(\\cdot,s)$ which likes the $C/F$ split for choosing coarse point:\n\\begin{equation}\nS(X,s)_{i,j} = X_{is, js },\n\\end{equation}\nthen we have:\n\\begin{equation}\\label{equ:stride}\nX \\ast_s K = S(X\\ast K, s),\n\\end{equation}\nwith the $\\ast$ and $\\ast_s$ defined by \\eqref{ConvPadding} and \\eqref{equ:convstride}\n\\begin{proof}\n\\begin{align}\nS(X \\ast K,s)_{i,j} &= (X \\ast K)_{is, js} \\\\\n&= \\sum_{p, q = -k}^k K_{p+k+1,q+k+1}x_{is + p, js + q} \\\\\n&= (X \\ast_s K)_{i,j}.\n\\end{align}\n\\end{proof}\n\n\nWe note convolution with stride as:\n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat c_j \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\\end{equation}\nwith\n\\begin{equation}\n\\theta^j(x) = K^j \\circledast_{s^j} x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\\end{equation}\nwith\n\t\\begin{equation}\n\tK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)}, \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\t\\end{equation}\nfor $k = 0, 1, 2, 3...$.\n\nGive $p\\in \\{1,\\ldots c_j\\}$\n\\begin{equation}\n(\\theta^j(x))_p= (K^j \\circledast_{s^j} x)_p+b^j_p{\\bm 1}_{n_j\\times n_j}\n\\end{equation}\nand\n\\begin{equation}\n (K^j \\circledast_{s^j} x)_p\n= \\sum_{q=1}^{\\hat c_{j}} K^{j}_{p,q} \\ast_{s^j} x_q \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_j.\n\\end{equation}\nwhere\n$$\nK^{j}_{p,q}\\in \\mathbb R^{(2k+1)\\times (2k+1)}, x_q\\in \\mathbb\nR^{\\hat n_{j}\\times \\hat n_{j}}.\n$$\nHere $\\ast_{s^j}$ is the stander convolution with stride as definition before.\n", "meta": {"hexsha": "6b260cf962f43a5db99c86858ad365fea0bb2c54", "size": 14692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNN-CNNforstudents.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DNN-CNNforstudents.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DNN-CNNforstudents.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0355731225, "max_line_length": 199, "alphanum_fraction": 0.6558671386, "num_tokens": 6089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338057771058, "lm_q2_score": 0.8962513731336202, "lm_q1q2_score": 0.8617759937421268}} {"text": "\\section{Linear equations}\n\\subsection{Linear and affine functions}\n\\textbullet Superposition condition:$f(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)$\\\\\n\\textbullet Such an f is called Linear\\\\\n\\textbf{Matrix vector product function}:\\\\\n\\textbullet A is $m \\times n$ matrix such that $f(x)=Ax$\\\\\n\\textbullet f is linear: $f(\\alpha x + \\beta y)=A(\\alpha x + \\beta y)=\\alpha f(x) + \\beta f(y)$\\\\\n\\textbullet Converse is true: If $f:R^{n} \\mapsto R^{m}$ is linear, then \\\\\n$f(x)=f(x_{1}e_{1}+x_{2}e_{2}+...x_{n}e_{n})$\\\\\n$=x_{1}f(e_{1})+x_{2}f(e_{2})+...x_{n}f(e_{n})$\n$=Ax$ with $A = [f(e_{1})+f(e_{2})+...f(e_{n})]$\n\\newline \\textbf{Affine Functions}: $f:R^{n} \\mapsto R^{m}$ is affine if it is a linear function plus a constant i.e $f(x)=Ax+b$ same as $f(\\alpha x + \\beta y)=\\alpha f(x)+\\beta f(y)$ holds for all x, y and $\\alpha,\\beta$ such that $\\alpha+\\beta=1$ \n\\newline A and b can be calculated as \\\\\n$A=[f(e_{1})-f(0)\\thickspace f(e_{2})-f(0) ... f(e_{n})-f(0)]] ; $\\\\\n$b= f(0)$\\\\\n\\textbullet Affine functions sometimes incorrectly called linear functions\n\\subsection{Linear function models}\nPrice elasticity of demand\n$\\delta_i^{price}=(p_i^{new}-p_{i})/p_{i}$: fractional changes in prices\n$\\delta_i^{dem}=(d_i^{new}-d_{i})/d_{i}$: fractional change in demand\nPrice demand elasticity model: $\\delta^{dem}=E\\delta^{price}$\\\\\n\\textbf{Taylor series approximation}\\\\\n\\textbullet The (first-order) Taylor approximation of f near (or at) the point z:\\\\\n\\begin{scriptsize}\n$\\hat{f}(x)= f(z) + \\frac{\\partial f}{\\partial x_1}(z)(x_1 - z_1) + ... + \\frac{\\partial f}{\\partial x_n}(z)(x_n - z_n)$\n\\end{scriptsize}\\\\\n\\textbullet in compact notation: \\\\$\\hat{f}(x) = f (z) + Df (z)(x - z)$\n\\subsection{Systems of linear equations}\n\\textbullet set (or system) of m linear equations in n variables $x_1,.., x_n$: \\\\\n$A_{11}x_1 + A_{12}x_2 + ... + A_{1n}x_n = b_1$\\\\\n$A_{21}x_1 + A_{22}x_2 + ... + A_{2n}x_n = b_2$\\\\\n.\\\\\n.\\\\\n$A_{m1}x_1 + A_{m2}x_2 + ... + A_{mn}x_n = b_m$\\\\\n\n\\textbullet \\textbf{systems of linear equations classified as}\\\\\n\\thickspace -- under-determined if m < n (A wide)\\\\\n\\thickspace -- square if m = n (A square)\\\\\n\\thickspace -- over-determined if m > n (A tall)\\\\\n\n\\textbf{Balancing equation example}\\\\\n\\textbullet consider reaction with m types of atoms, p reactants, q products\\\\\n\\textbullet $m \\times p$ reactant matrix R is defined by\\\\\n$R_{ij}$ = number of atoms of type i in reactant $R_j$\\\\\nfor i = 1,..,m and j = 1,..,p\\\\\n\\textbullet with $a = (a_1,..,a_p)$ (vector of reactant coefficients)\\\\\n$Ra$ = (vector of) total numbers of atoms of each type in reactants\\\\\n\\textbullet define product $m \\times q$ matrix P in similar way\\\\\n\\textbullet m-vector $Pb$ is total numbers of atoms of each type in products\\\\\n\\textbullet conservation of mass is $Ra = Pb$\n\\textbullet conservation of mass is\\\\\n$[R - P][a\\thickspace b]^T = 0$\\\\\n\\textbullet simple solution is $a = b = 0$\\\\\n\\textbullet to find a nonzero solution, set any coefficient (say, $a_1$) to be 1\\\\\n\\textbullet balancing chemical equations can be expressed as solving a set of m + 1 linear equations in p + q variables \\\\\n$\n\\begin{bmatrix}\n R & -P \\\\\n e_1^T & 0\n \n\\end{bmatrix} \n\\begin{bmatrix}\n a \\\\\n b\n\\end{bmatrix}=e_{m+1}\n$\\\\\n(we ignore here that $a_i$ and $b_i$ should be nonnegative integers)", "meta": {"hexsha": "a010a8372801dee0648b25c0df5251e7445e6cf6", "size": 3302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_stars_repo_name": "meanmachin3/COT5615", "max_stars_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_issues_repo_name": "meanmachin3/COT5615", "max_issues_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_forks_repo_name": "meanmachin3/COT5615", "max_forks_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 49.2835820896, "max_line_length": 249, "alphanum_fraction": 0.6547546941, "num_tokens": 1196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660949832345, "lm_q2_score": 0.9032942008463507, "lm_q1q2_score": 0.8617120414023947}} {"text": "\\section*{Ex.2.1}\n\\subsection*{Is the truly independent hash function universal}\n\nYes - the truly independent hash function is universal. \nTo prove it we want to show that $P(h(x) = h(y))\\leq 1/m$. \n\nThe truly random hash function $h$ is an independent and identical discrete uniformly distributed random variable. \nHence $h(x)\\sim U(0,m-1)$ which means $P(h(x) = j) = 1/m$ for all $j\\in[m]$. So for two distinct keys $x,y \\in U$\n\\begin{align*}\nP(h(x) = h(y)) &= \\sum_{j=0}^{m-1} P([h(x)=j] \\cap [h(y)=j])&\\\\\n &= \\sum_{j=0}^{m-1} P(h(x)=j) P(h(y)=j) &\\text{equality holds as $h$ is independent}\\\\\n\t\t\t\t\t\t\t &= m P^2(h(x)=j) &\\text{equality holds as $h$ is identical distributed}\\\\\n\t\t\t\t\t\t\t &= m \\left(\\frac{1}{m}\\right)^2 &\\text{equality holds as $h$ is uniform distributed}\\\\\n\t\t\t\t\t\t\t &= \\frac{1}{m} &\n\\end{align*}\nWhich shows that the truly independent hash function universial.", "meta": {"hexsha": "b14a5cc0887706b5891cc1a6be0eee5e50506ab2", "size": 966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.2.1.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.2.1.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.2.1.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.375, "max_line_length": 115, "alphanum_fraction": 0.5797101449, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.976310532836284, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.8615236144503452}} {"text": "\n\\subsection{Integral}\n$integral(f,x)$ returns the integral of $f$ with respect to $x$.\nThe $x$ can be omitted for expressions in $x$.\nThe argument list can be extended for multiple integrals.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nintegral(x^2)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{3}x^3$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nintegral(x*y,x,y)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{4}x^2y^2$\n\n$defint(f,x,a,b,\\ldots)$\ncomputes the definite integral of $f$ with respect to $x$ evaluated from\n$a$ to $b$.\nThe argument list can be extended for multiple integrals.\nThe following example computes the integral of $f=x^2$\nover the domain of a semicircle.\nFor each $x$ along the abscissa, $y$ ranges from 0 to $\\sqrt{1-x^2}$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ndefint(x^2,y,0,sqrt(1-x^2),x,-1,1)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{8}\\pi$\n\nAs an alternative, the $eval$ function can be used to compute a definite integral step by step.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nI = integral(x^2,y)\nI = eval(I,y,sqrt(1-x^2))-eval(I,y,0)\nI = integral(I,x)\neval(I,x,1)-eval(I,x,-1)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{8}\\pi$\n", "meta": {"hexsha": "7713218a090edd56a5a01908c77fd41e32ed3dcd", "size": 1200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/integrals.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/integrals.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/integrals.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9069767442, "max_line_length": 95, "alphanum_fraction": 0.7125, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.9005297914570319, "lm_q1q2_score": 0.8614775999665532}} {"text": "%\n% Chapter 2.2\n%\n\n\\section*{2.2 Derivatives as Functions}\n\n$$f'(x)=\\lim_{h \\to 0}\\frac{f(x+h)-f(x)}{h}$$\n\\(f'(x)\\) can be interpreted geometrically as the slope of the tangent line to the graph of \\(f\\) at the point \\((x, f(x))\\)\n\\\\\\\\\nA function \\(f\\) is \\(\\textbf{differentiable}\\) at \\(a\\) if \\(f'(a)\\) exists. It is differentiable on an open interval \\((a,b)\\) if it is differentiable at every number in the interval.\n\\\\\\\\\nIf \\(f\\) is differentiable at \\(a\\), the \\(f\\) is continuous at \\(a\\).\n\n\\subsection*{Ways a Function can be Discontinuous}\n\n\\begin{enumerate}\n \\item corner point\n \\item discontinuity\n \\item vertical tangent\n\\end{enumerate}\n\n", "meta": {"hexsha": "72a0ff6e990a41fe1440c5c1d711f12d9c293d47", "size": 660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-2.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-2.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-2.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0, "max_line_length": 185, "alphanum_fraction": 0.65, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995723244552, "lm_q2_score": 0.891811041124754, "lm_q1q2_score": 0.861399903216627}} {"text": "\\chapter{Relations}\n\\label{chapter:relations}\nNonetheless that function are used almost everywhere in mathematics, many\nrelations are not functional by their nature. For example, for any real\n$a$, there are two solutions of $x^2 = a$ and there are zero solutions for\n$a < 0$. To work with such situations, relations are used.\n\nIn order to define a relation we need to relax the definition of the graph of a\nfunction (Section~\\ref{section:graph}) by allowing more than one ``result'' and\nby allowing zero ``results''. In other words we just say that any set $R\n\\subseteq X_1 \\times \\dots \\times X_k$ is a $k$-ary \\emph{relation} on $X_1$,\n\\dots, $X_k$. We also say that $x_1 \\in X_1$, \\dots, $x_k \\in X_k$ are in the\nrelation $R$ iff $(x_1, \\dots, x_k) \\in R$. If $k = 2$ such a relation is\ncalled a \\emph{binary relation} and we write $x R y$ if $x$ and $y$ are in\nthe relation $R$. If $X_1 = \\dots = X_k = X$, we say that $R$ is a $k$-ary\nrelation on $X$.\n\nNote that $=$, $\\le$, $\\ge$, $<$, and $>$ define relations on $\\R$ (or any\nsubset $S$ of $\\R$). For example, if $S = \\set{0, 1, 2}$, then $<$ defines\nthe relation $R = \\set{(0, 1), (0, 2), (1, 2)}$.\n\nAnother widely used family of relations on $\\Z$ can be defined as follows. Let\n$n, a, b \\in \\Z$. If $n$ divides $a - b$, we say that\n``$a$ equivalent to $b$ modulo $n$'' and denote it as $a \\equiv b \\pmod{n}$.\nFor example, $1$ and $4$ are equivalent modulo $3$ since $3$ divides\n$1 - 4 = -3$.\n\n\\section{Equivalence Relations}\nThe definition of a relation is way too broad. Hence, quite often we consider\nsome types of relation. Probably the most interesting type of the relations is\nequivalence relations.\n\n\\begin{definition}\n Let $R$ be a binary relation on a set $X$. We say that $R$ is an\n \\emph{equivalence relation} if it satisfies the following conditions:\n \\begin{description}\n \\item[(reflexivity)] $x R x$ for any $x \\in X$;\n \\item[(symmetry)] $x R y$ iff $y R x$ for any $x, y \\in X$;\n \\item[(transitivity)] for any $x, y, z \\in X$, if $x R y$ and $y R Z$,\n then $x R z$.\n \\end{description}\n\\end{definition}\nOne may guess that the equivalence relation are mimicking $=$, so it is not a\nsurprise that $=$ is an equivalence relation.\n\nThe definition seems quite bizarre, however, all of you are already familiar\nwith another important example: you know that equivalent fractions represent the\nsame number. For example, $\\frac{2}{4}$ is the same as $\\frac{1}{2}$.\nLet us consider this example more thorough, let $S$ be a set of symbols of the\nform $\\frac{x}{y}$ (note that it is not a set of numbers) where $x, y \\in Z$\nand $y \\neq 0$. We define a binary relation $R$ on $S$ such that\n$\\frac{x}{y}$ and $\\frac{z}{w}$ are in the relation $R$ iff $xw = zy$.\nIt is easy to prove that this relation is an equivalence relation.\n\\begin{description}\n \\item[(reflexivity)] Let $\\frac{a}{b} \\in S$. Since $ab = ab$, we have that\n $\\frac{a}{b} R \\frac{a}{b}$.\n \\item[(symmetry)] Let $\\frac{a}{b}, \\frac{c}{d} \\in S$. Suppose that\n $\\frac{a}{b} R \\frac{c}{d}$, by the definition of $R$, it implies that\n $ac = db$. As a result, $\\frac{c}{d} R \\frac{a}{b}$.\n \\item[(transitivity)] Let $\\frac{a}{b}, \\frac{c}{d}, \\frac{e}{f} \\in S$ with\n $\\frac{a}{b} R \\frac{c}{d}$ and $\\frac{c}{d} R \\frac{e}{f}$. Then\n $ad = cb$ and $cf = ed$. The first equality can be rewritten as\n $c = ad / b$.\n Hence, $adf / b = ed$ and $af = eb$ since $d \\neq 0$. So $\\frac{a}{b} R\n \\frac{e}{f}$.\n\\end{description}\n\n\\subsection{Partitions}\nLet $S$ be some set. We say that $\\set{P_1, \\dots, P_k}$ form a partition of\n$S$ iff $P_1$, \\dots, $P_k$ are pairwise disjoint and\n$P_1 \\cup \\dots \\cup P_k = S$; in other words, a partition is a way of dividing\na set into overlapping pieces.\n\n\\begin{exercise}\n Let $\\set{P_1, \\dots, P_k}$ be a partition of a set $S$ and $R$ be a binary\n relation of $S$ such that $a R b$ iff $a, b \\in P_i$ for some\n $i \\in \\range{k}$. Show that $R$ is an equivalence relation.\n\\end{exercise}\n\nThis exercise shows that one may transform a partition of the set $S$ into an\nequivalence relation on $S$. However, it is possible to do the opposite.\n\\begin{theorem}\n\\label{theorem:partition}\n Let $R$ be a binary equivalence relation on a set $S$. For any element\n $x \\in S$, define $R_x = \\set[x R y]{y \\in S}$ (the set of all the elements\n of $S$ related to $x$) we call such a set the equivalence class of $x$.\n Then $\\set[x \\in S]{R_x}$ is a partition of $S$.\n\\end{theorem}\n\n\\begin{exercise}\n Prove Theorem~\\ref{theorem:partition}.\n\\end{exercise}\n\n\\subsection{Modular Arithmetic}\nThe relation ``$\\equiv \\pmod{n}$'' is actively used in the number theory. One\nof the important properties of this relation is that it is an equivalence\nrelation.\n\\nomenclature[U]{$a \\equiv b \\pmod{n}$}{says that $n$ divides $a - b$}\n\\begin{theorem}\n The relation $\\equiv \\pmod{n}$ is an equivalence relation.\n\\end{theorem}\n\\begin{proof}\n To prove this statement we need to prove all three properties: reflexivity,\n symmetry, and transitivity.\n \\begin{description}\n \\item[(reflexivity)] Note that for any integer $x$, $x - x = 0$ is divisible\n by any integer including $n$. Hence, $x \\equiv x \\pmod{n}$.\n \\item[(symmetry)] Let us assume that $x \\equiv y \\pmod{n}$; i.e.,\n $x - y = kn$ for some integer $k$. Note that $y - x = (-k) n$, so\n $y \\equiv x \\pmod{n}$.\n \\item[(transitivity)] finally, assume that $x \\equiv y \\pmod{n}$ and\n $y \\equiv z \\pmod{n}$; i.e. $x - y = k n$ and $y - z = \\ell n$\n for some integers $k$ and $\\ell$. It is easy to note that\n $x - z = (x - y) + (y - z) = (k + \\ell) n$. As a result,\n $x \\equiv z \\pmod{n}$.\n \\end{description}\n Thus, we proved that $\\equiv \\pmod{n}$ is an equivalence relation.\n\\end{proof}\n\nLet $x \\in \\Z$; we denote by $r_{x, n}$ the equivalence class of $x$ with\nrespect to the relation $\\equiv \\pmod{n}$, we also denote by $\\Z / n\\Z$ the set\nof all the equivalence classes with respect to the relation $\\equiv \\pmod{n}$.\n\nAnother important property of these relations is that they behave well with\nrespect to the arithmetic operations.\n\\begin{theorem}\n Let $x, y \\in Z$ and $n \\in \\N$. Suppose that $a \\in r_{x, n}$ and $b \\in\n r_{y, n}$, then $(a + b) \\in r_{x + y, n}$ and $ab \\in r_{xy, n}$.\n\\end{theorem}\n\nUsing this theorem we may define arithmetic operations on the equivalence\nclasses with respect to the relation $\\equiv \\pmod{n}$.\nLet $x, y \\in \\Z$ and $n \\in \\N$. Then\n$r_{x, n} + r_{y, n} = \\set[a \\in r_{x, n}, b \\in r_{y, n}]{a + b} =\nr_{x + y, n}$ and\n$r_{x, n} r_{y, n} = \\set[a \\in r_{x, n}, b \\in r_{y, n}]{ab} = r_{xy, n}$.\nMoreover, these operations have plenty of good properties.\n\\begin{exercise}\n Let $a, b, c \\in \\Z / n\\Z$.\n Show that the following equalities are true:\n \\begin{itemize}\n \\item $a + (b + c) = (a + b) + c$,\n \\item $a + r_{0, n} = a$ (thus we denote $r_{0, n}$ as $0$),\n \\item $a r_{1, n} = a$ (thus we denote $r_{1, n}$ as $1$),\n \\item there is a class $d \\in \\Z / n\\Z$ such that $a + d = r_{0, n}$\n (thus we denote this $d$ as $-a$),\n \\item $a + b = b + a$,\n \\item $ab = ba$,\n \\item $a(b + c) = ab + ac$,\n \\end{itemize}\n\\end{exercise}\n\n\\section{Partial Orderings}\nIn the previous section we discussed a generalization of ``$=$''.\nIn this section we are going to give a way to analyze relations similar to\n``$<$''.\n\n\\begin{definition}\n A binary relation $R$ on $S$ is a partial ordering if it satisfies the\n following constraints.\n \\begin{description}\n \\item[(reflexivity)] $x R x$ for any $x \\in S$;\n \\item[(antisymmetry)] if $x R y$ and $y R x$, then $x = y$ for all\n $x, y \\in S$;\n \\item[(transitivity)] for any $x, y, z \\in S$, if $x R y$ and $y R Z$, then\n $x R z$;\n \\end{description}\n\n We say that a partial ordering $R$ on a set $S$ is total iff for any \n $x, y \\in S$, either $x R y$ or $y R x$.\n\\end{definition}\n\\noindent Note that $\\le$ defines a partial ordering on any $S \\subseteq \\R$;\nmoreover, it defines a total order.\n\nTypically we use symbols similar to $\\preceq$ to denote partial orderings and we\nwrite $a \\prec b$ to express that $a \\preceq b$ and $a \\neq b$.\n\nLet $\\divides$ be the relation on $\\Z$ such that $d \\divides n$ iff $d$\ndivides $n$.\n\\nomenclature[U]{$a \\divides b$}{says that $a$ divides $b$}\n\\begin{theorem}\n The relation $\\divides$ is a partial ordering of the set $\\N$.\n\\end{theorem}\n\\begin{proof}\n To prove that this relation is a partial ordering we need to check all three\n properties.\n \\begin{description}\n \\item[(reflexivity)] Note that $x = 1 \\cdot x$ for any integer $x$;\n hence, $x \\divides x$ for any integer $x$.\n \\item[(antisymmetry)] Assume that $x \\divides y$ and $y \\divides x$. Note\n that it means that $k x = y$ and $\\ell y = x$ for some integers $k$ and\n $\\ell$. Hence, $y = (k \\cdot \\ell) y$ which implies that\n $k \\cdot \\ell = 1$ and $k = \\ell = 1$. Thus, $x = y$.\n \\item[(transitivity)] finally, assume that $x \\divides y$ and\n $y \\divides z$; i.e., $k x = y$ and $\\ell y = z$. As a result,\n $(k \\cdot \\ell) x = z$ and $x \\divides z$.\n \\end{description}\n\\end{proof}\n\n\\begin{exercise}\n Let $S$ be some set, show that $\\subseteq$ defines a partial ordering on the\n set $2^S$.\n\\end{exercise}\n\n\\subsection{Topological Sorting}\nPartial orderings are very useful for describing complex processes. Suppose\nthat some process consists of several tasks, $T$ denotes the set of these tasks.\nSome tasks can be done only after some others e.g. when you cooking a salad you\nneed to wash vegetables before you chop them. If $x, y \\in T$ be some tasks, $x\n\\preceq y$ if $x$ should be done before $y$ and this is a partial ordering.\n\nIn the applications this order is not a total order because some steps do not\ndepend on other steps being done first (you can chop tomatoes and chop\ncucumbers in any order). However, if we need to create a schedule in which the\ntasks should be done, we need to create a total ordering on $T$. Moreover, this\norder should be compatible with the partial ordering. In other words, if $x\n\\preceq y$, then $x \\preceq_t y$ for all $x, y \\in T$, where $\\preceq_t$ is the\ntotal order. The technique of finding such a total ordering is called\n\\emph{topological sorting}.\n\n\\begin{theorem}\n\\label{theorem:topological-order}\n Let $S$ be a finite set and $\\preceq$ be a partial order on $S$. Then there is\n a total order $\\preceq_t$ on $S$ such that if $x \\preceq y$, then\n $x \\preceq_t y$ for all $x, y \\in S$\n\\end{theorem}\n\nThis sorting can be done using the following procedure.\n\\begin{itemize}\n \\item Initiate the set $S$ being equal to $T$\n \\item Choose the minimal element of the set $S$ with respect to the ordering\n $\\preceq$ (such an element exists since $S$ is a finite set, see\n Chapter~\\ref{chapter:bijections-surjections-injections}).\n Add this element to the list, remove it from the set $S$, and repeat this\n step if $S \\neq \\emptyset$.\n\\end{itemize}\n\nLet us consider the following example. In the left column we list the classes\nand in the right column the prerequisite.\n\\begin{center}\n \\begin{tabular}{l l}\n \\toprule\n Courses & Prerequisite \\\\\n \\midrule\n Math 20A \\\\\n Math 20B & Math 20A \\\\\n Math 20C & Math 20B \\\\\n Math 18 \\\\\n Math 109 & Math 20C, Math 18 \\\\\n Math 184A & Math 109 \\\\\n \\bottomrule\n \\end{tabular}\n\\end{center}\nWe need to find an order to take the courses.\n\\begin{enumerate}\n \\item We start with\n \\[\n S = \\set{\\text{Math 20A}, \\text{Math 20B},\n \\text{Math 20C}, \\text{Math 18}, \\text{Math 109}, \\text{Math 184}}.\n \\]\n There are two minimal elements: Math 20A and Math 18. Let us remove Math 18\n from $S$ and add it to the resulting list $R$.\n \\item Now we have\n \\[\n R = \\text{Math 18}\n \\]\n and\n \\[\n S = \\set{\\text{Math 20A},\n \\text{Math 20B}, \\text{Math 20C}, \\text{Math 109}, \\text{Math 184}}.\n \\]\n There is only one minimal element Math 20A. We remove it and add it to the\n list $R$.\n \\item On this step\n \\[\n R = \\text{Math 18}, \\text{Math 20A}\n \\]\n and\n \\[\n S = \\set{\n \\text{Math 20B}, \\text{Math 20C}, \\text{Math 109}, \\text{Math 184}}.\n \\]\n Again there is only one minimal element: Math 20B.\n \\item\n \\[\n R = \\text{Math 18}, \\text{Math 20A}, \\text{Math 20B}\n \\] and\n \\[\n S = \\set{\\text{Math 20C}, \\text{Math 109}, \\text{Math 184}}.\n \\]\n There is only one minimal element: Math 20C.\n \\item\n \\[\n R = \\text{Math 18}, \\text{Math 20A}, \\text{Math 20B}, \\text{Math 20C}\n \\]\n and\n \\[\n S = \\set{\\text{Math 109}, \\text{Math 184}}.\n \\]\n There is only one minimal element: Math 109.\n \\item Finally,\n \\[\n R = \\text{Math 18}, \\text{Math 20A}, \\text{Math 20B}, \\text{Math 20C},\n \\text{Math 109}\n \\]\n and\n \\[\n S = \\set{\\text{Math 184}}.\n \\]\n There is only one minimal element: Math 184A.\n\\end{enumerate}\nAs a result, the final list is\n\\[\n R = \\text{Math 18}, \\text{Math 20A}, \\text{Math 20B}, \\text{Math 20C},\n \\text{Math 109}, \\text{Math 184A}.\n\\]\n\n\n\\begin{chapterendexercises}\n \\exercise[recommended] Show that the relation $\\divides$ does not define a partial\n ordering on $\\Z$.\n \\exercise Let a relation $R$ be defined on the set of real numbers as\n follows: $x R y$ iff $2x + y = 3$. Show that it is antisymmetric.\n \\exercise Are there any minimal elements in $\\N$ with respect to\n $\\divides$? Are there any maximal elements?\n\\end{chapterendexercises}\n", "meta": {"hexsha": "202191f937be6fab2b0d4b7a0bd12d1677105b79", "size": 13552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_8_relations.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_1/chapter_8_relations.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_1/chapter_8_relations.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.4434250765, "max_line_length": 84, "alphanum_fraction": 0.6413075561, "num_tokens": 4498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.9173026618464796, "lm_q1q2_score": 0.86136996769776}} {"text": "\\section{$\\mathbf{X}=\\mathbf{W}\\mathbf{H}$ Non-Negative Matrix Factorization}\n\nNon-Negative Matrix Factorization (NNMF) is an approximate decomposition technique for positive data. It can be used, for example, for dimensionality reduction, blind source detection or topic extraction. The reputation is that it can often generate decompositions that are \"sparse and meaningful\". \n\nFollowing the convention in \\citeasnoun{gillis2014nonnegative}, it works by expressing a positive data matrix $\\mathbf{X}\\in\\mathbb{R}^{p\\times n}_+$ in terms of two smaller positive matrices $\\mathbf{W}\\in\\mathbb{R}_+^{p\\times r}$ and $\\mathbf{H}\\in \\mathbb{R}^{r\\times n}_+$. Here the $n$ columns of the data matrix are data points and the rows are the $p$ features. An excellent introduction to NNMF is found in \\possessivecite{morningpaper2019nnmf} blog post and in \\citeasnoun{gillis2014nonnegative}. Dimensionality reduction derives from the ability to adjust the rank of the decomposition via the dimension $r$. The decomposition is simply:\n\n\\begin{equation}\n\\mathbf{X} \\approx \\mathbf{WH}\n\\end{equation}\n\nWhere the error $||\\mathbf{X} - \\mathbf{WH}||_\\alpha$ is minimized with respect to some norm (normally, the Frobenius norm with $\\alpha=2$). The decomposition allows the interpretation of $\\mathbf{W} \\in \\mathbb{R}^{p\\times r}$ as a matrix with a number of $r$ $p$-dimensional strictly positive basis vectors and of $\\mathbf{H} \\in \\mathbb{R}^{r\\times n}$ as a matrix of coefficients that express the $n$ data points in terms of linear sums of the $r$ basis vectors with strictly positive coefficients. \n\nOne might ask: why NNMF when I can create linear decompositions of my data with SVD and PCA? After all, these techniques are well established and are known to give the optimal approximation under the Frobenius nurm. In my perception, the key difference is that NNMF solves the constrained problem of forcing both coefficients and basis vectors to be strictly positive. For many data types, negative values (word frequencies, pixel values) are unnatural, and so the results of NNMF are immediately more interpretable. NNMF is promising in particular in situations where a signal arises from the addition of a number of positive signals. A canonical example is hyperspectral imaging, where, assuming incoherent light, the measured spectrum is the linear sum of the spectra of the individual light sources. If all goes well, the basis vectors from NNMF of a hyperspectral image will be the source spectra. In the context of natural language processing, NNMF on a collection of documents can be interpreted as \\textit{topics}. Figure \\ref{fig:nnmf_eigenfaces} shows the NNMF-based decomposition and approximation of the \"labeled faces in the wild\" dataset, analogous to the SVD of the dataset shown in Figure \\ref{fig:svd_eigenfaces}. The two are quite different. While for SVD, the faces look as if they are gradually coming into focus, for NNMF the faces are at first not recognizable. The portraits also become brighter in the plot as more basis components are added, because, in contrast to the SVD case, the composition is purely additive. \n\nThe drawback is that NNMF is computationally more difficult (possibly NP hard), nor is the matrix approximation optimal, nor is the decomposition unique. \n\n\n\\begin{figure}\n\\centering\n \\includegraphics[width=\\textwidth]{nnmf_eigenfaces.png}\n \\caption{Left: The first 34 basis faces stored in the $\\mathbf{W}$ matrix extracted using NNMF under Frobenius norm from the \"Labeled Faces in the Wild\" Dataset. The basis images are normalized and shown on a log scale because they have very different contrast and brightness. The normalized images are then all shown on the same color scale. Right: Five sample portraits from the dataset approximated using different numbers of basis faces. The NNMF was done for a value of $r=300$. The original portraits had $2914$ pixels. In contrast to SVD, the basis vectors obtained through NNMF do not necessarily have an internal ordering in terms of how much of the variance in the dataset they explain.}\n \\label{fig:nnmf_eigenfaces}\n\\end{figure}\n\n\n\\begin{figure}\n\\centering\n \\includegraphics[width=\\textwidth]{nnmf_eigenfaces2.png}\n \\caption{Left: The first 6 basis faces stored in the $\\mathbf{W}$ matrix extracted using NNMF under Frobenius norm from the \"Labeled Faces in the Wild\" Dataset. Right: Sample images expressed in the reduced basis.}\n \\label{fig:nnmf_eigenfaces2}\n\\end{figure}", "meta": {"hexsha": "2ef8b76669d647bfdbf8e30e932db8e591a84be2", "size": 4485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_nnmf.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/unsup_nnmf.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/unsup_nnmf.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 144.6774193548, "max_line_length": 1542, "alphanum_fraction": 0.786845039, "num_tokens": 1082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.909907001151883, "lm_q1q2_score": 0.8613149402238399}} {"text": "\\section{Basic Artificial Neural Network}\nArtificial neural networks (ANNs) are biologically inspired computer programs designed to simulate the way in which the human brain processes information.\n%This model is just a model for a class of parameterized function with some special function structure which can be presented simply using some simple network graph. This method is began from the approximation of neural network in human.\n\\subsection{basic element: Nonlinear active function with affine map}\nMc Culloch-Pitts Neuron, also known as M-P Neuron, is the earliest neural network that was discovered in 1943. In this model, the neurons are connected by connection weights, and the activation function is used in binary. The threshold is used to determine whether the neuron will fire or not.\n\nM-P element(approximation of one neuron): this is a very simple example for interpolating a function $f: \\mathbb{R}^m \\to \\mathbb{R}$, with the next definition:\n\\begin{equation}\\label{eq:M-P}\nf_{M-P}(x) = \\sigma( w \\cdot x + b)\n\\end{equation}\nwith $w \\in \\mathbb{R}^{m} $ and $\\sigma$ is called active function which can be chosen like:\n\\begin{equation}\n\\sigma (x) = \\frac{1}{1 + e^{-x}},\n\\end{equation}\nor\n\\begin{equation}\n\\sigma(x) = tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}}.\n\\end{equation}\nBasically, both these two functions are smooth and have two horizontal asymptotic lines, which can be seen as a smoothing approximation for\n\\begin{equation}\nH(x) =\n\\begin{cases}\n1 &\\text{if} ~x < 0, \\\\\n0 &\\text{if}~ x \\le 0.\n\\end{cases}\n\\end{equation}\nBut now, the most commonly used activation function is the so-called ``Rectified Linear Unit'' (ReLU), which is defined by\n\\begin{equation}\n{\\rm ReLU}(x) = \\max\\{0,x\\}.\n\\end{equation}\n%We will talk about some basic stuff about variant of activation function in the next chapter and \nIt is also very important in the approximation theory for such as one hidden layer ANN networks.\nThis is often shown as the next picture:\n\\begin{figure}[!ht]\n\t\\center{\\includegraphics[width=10cm] {M-P.jpeg}}\n\t\\caption{M-P neuron.}\n\\end{figure}\n\n\\subsection{neural network}\nNow we want to use this simple basic element to construct some more complex model(from one neuron to neural network). A bionic but simple construction is to increase the basic element in both horizontal and vertical direction, which means the network would be like the one in Fig~\\ref{fig:ANN}.\n\\begin{figure}[!ht]\n\t\\center{\\includegraphics[width=12cm,height=6cm] {ANN.png}}\n\t\\caption{ANN}\n\t\\label{fig:ANN}\n\\end{figure}\n\nThis is called fully connected feedforward neural network. Now we want to give a more compressive expression, we collect all the output in $k$-th level $[f^{k}]_l$, $l = 1,\\cdots, n_k$.\nSo we can have the output in $k+1$-th level under this setting with\n\\begin{equation}\n{f}^{k+1} = \\theta^{k+1}\\circ \\sigma (f^{k})\n\\end{equation}\nwith\n\\begin{equation}\n\\theta^k(x) = w^kx+b \\in\\mathbb{R}^{n_{k+1}},\n\\end{equation} \nwhere \n\\begin{equation}\nw^k= \n\\begin{pmatrix}\nw_1 \\\\\n\\vdots \\\\\nw_{n_{k+1}}\n\\end{pmatrix},\\qquad \\mbox{ with }\\qquad w_i \\in \\mathbb{R}^{n_k}.\n\\end{equation} \n\nSo, we get the final iterative definition with the last output and initial input of this network like:\n\\begin{equation}\n\\begin{cases}\nf^{0} &= \\theta^0(x), \\\\\nf^{\\ell} &= \\theta^{\\ell}\\circ \\sigma(f^{\\ell-1}), \\quad \\ell = 1:J, \\\\\nf(x;\\Theta) &= f^J.\n\\end{cases}\n\\end{equation}\nHere we note \n\\begin{equation}\n\\Theta = \\{ (\\theta^0, \\cdots, \\theta^J) \\}.\n\\end{equation}\n\n%\\subsection{Interpolation by optimization}\n%So the interpolation process can be seen as a optimization problem in the special function class if the activation function for every elements and the network structure parameter $\\mathcal{N}_K$ are given:\n%\\begin{equation}\n%\\mathcal{F} = \\{\\bm{f}_K(W_K;\\bm{x}) ~|~ \\bm{f}_0 = (\\bm{x}^{T},1)^{T}\\},\n%\\end{equation}\n%and the optimization problem can be seen as\n%\\begin{equation}\n%%\\mathop{\\min}_{f \\in \\mathcal{F}} \\frac{1}{N}\\sum_{i=1}^N \\|f(X^i) - Y^i\\|^2 =\n%\\mathop{\\min}_{W_K \\in T_3(\\mathcal{N}_K)} L(W_K) := \\frac{1}{N}\\sum_{i=1}^N \\|\\bm{f}_K(W_K; X^i) - Y^i\\|^2.\n%\\end{equation}\n%But $\\mathcal{F}$ this is neither a linear space nor a convex set.\n\n%\\iffalse\n\\subsection{Back-Propagation}\nHere we will talk about how to compute $\\nabla_{\\Theta} f(x;\\Theta)$ by using chain rule which is called Back-Propagation (BP) algorithm in deep learning. \nThus we have\n\\begin{equation}\n\\frac{\\partial {f}(x; \\Theta)}{ \\partial w^k} = \\frac{\\partial {f}^J}{\\partial {f}^{J-1}} \\cdot \\frac{ \\partial {f}^{J-1}}{\\partial {f}^{J-2}} \\cdots \\frac{ \\partial {f}^k}{\\partial w^k}.\n\\end{equation}\nWe can see from the above that, we only need to compute those terms like:\n\\begin{equation}\n\\frac{ \\partial {f}^k}{\\partial w^{k}} \\quad \\text{and} \\quad \\frac{\\partial {f}^k}{\\partial {f}^{k-1}} \\quad k = 1,2,\\cdots,J.\n\\end{equation}\nWe have\n\\begin{equation}\\label{eq:partial-f}\n\\frac{\\partial {f}^k}{\\partial {f}^{k-1}} =\nw^k{\\rm Diag}(\\sigma'(f^{k-1})) ,\n\\end{equation}\nand\n\\begin{equation}\n\\frac{ \\partial {f}^k}{\\partial w^{k}} = \\delta \\otimes \\sigma(f^{k-1}).\n\\end{equation}\n\n\nIn short, BP algorithm can be expressed as:\n\\begin{algorithm}[H]\n\t\\begin{algorithmic}[1]\n\t\t\\State {\\bf{Input:}} $X^i$ and $W_K$;\n\t\t\\For{$k = K:-1:1$}\n\t\t\\State Compute and save\n\t\t$$\\frac{ \\partial {f}^k}{\\partial w^{k}} \\quad \\text{and} \\quad \\frac{\\partial {f}^k}{\\partial {f}^{k-1}}$$.\n\t\t\\State Compute\n\t\t$$\\frac{ \\partial {f}^J}{\\partial w^{k}} = \\frac{\\partial {f}^J}{\\partial {f}^{J-1}} \\cdot \\frac{ \\partial {f}^{J-1}}{\\partial {f}^{J-2}} \\cdots \\frac{ \\partial {f}^k}{\\partial w^{k}}$$ \n\t\t\\EndFor\n\t\\end{algorithmic}\n\t\\caption{Back-Propagation Algorithm}\n\\end{algorithm}\n\n\n\n\n%\\input{6DL/juncai_dnn}\n\n", "meta": {"hexsha": "8fb3e5c6f71d6df1966c48bde0da4116403f66d3", "size": 5698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.1666666667, "max_line_length": 294, "alphanum_fraction": 0.6926991927, "num_tokens": 1901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9674102524151826, "lm_q2_score": 0.8902942370375484, "lm_q1q2_score": 0.8612797725762772}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Multiple Hypothesis Testing}\n\nWhen you perform a hypothesis test, it has some probability, $\\alpha$, of rejecting the null when, in fact, the null is true. For one test this is manageable. However, when you perform multiple tests, the chance quickly becomes very high that you will reject the null at least once when it's true (a false positive). If you test a lot of hypotheses and don't correct your significance level to account for that, you're likely going to end up with many, many false positives.\n\n\\subsection{An Experiment}\n\nImagine you take random samples of size $40$ in one of two ways, decided by the flip of a [fair] coin. You either (heads) take two groups of $20$ samples each, both from the green distribution (below) or you take one group of $20$ from the green distribution and the other $20$ from the black [dashed] distribution. The difference in means between the two distributions here is 0.5. \n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/multiple-hypothesis-example-2a.png}\n\\end{center}\n\nImagine doing this $10000$ times and, for each run, performing a $T$-test between the two samples. If the $p$-value for that test is below the significance level, $\\alpha$, reject the null. Now, measure the fraction of simulations for which the null is rejected and both samples were taken from the same distribution (false positives) and divide that by the total number of simulations where the null was rejected (true positives + false positives). That quotient is the \\textbf{False Discovery Rate (FDR)}. Here's how it varies in this experiment with respect to $\\alpha$ and effect size: \n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/multiple-hypothesis-example-1.png}\n\\end{center}\n\n\\begin{mdframed}\n\\textbf{Question 2.9:} If the FDR decreases monotonically with decreasing significance level, why not just set $\\alpha = 0.0000000001$ or something to minimize FDR?\n\\vspace{20mm}\n\\end{mdframed}\n\nThere are several algorithms that have been developed and proven to control FDR even though it's impossible to know what the true underlying distribution of effect sizes is. One is called the \\textbf{Benjamini-Hochberg} method. Look that up and compare it to the \\textbf{Bonferroni correction}, which controls - not the FDR - but the FWER (the probability that at least one significant result is a false positive). \n", "meta": {"hexsha": "c22ed71fe8225228138484e5e0ce4b0bf50c1d33", "size": 2443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-multiple-hypothesis-testing.tex", "max_stars_repo_name": "blpercha/mcds-notes", "max_stars_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-10T16:51:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:31:23.000Z", "max_issues_repo_path": "tex/mcds-multiple-hypothesis-testing.tex", "max_issues_repo_name": "blpercha/mcds-notes", "max_issues_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/mcds-multiple-hypothesis-testing.tex", "max_forks_repo_name": "blpercha/mcds-notes", "max_forks_repo_head_hexsha": "33531a443afb154b5c415299276a2ad215463896", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T17:16:44.000Z", "avg_line_length": 90.4814814815, "max_line_length": 590, "alphanum_fraction": 0.7539909947, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.9284087980793998, "lm_q1q2_score": 0.8609722408305353}} {"text": "\\section{Problem Formulation}\n\\label{sec:problem_formulation}\n\nGiven a model $\\mathcal{M}$ parameterized by $\\bm{\\omega}$ and a dataset $\\mathcal{D} = \\{(\\mathbf{x}_i,\\mathbf{y}_i)\\}_{i=1}^{\\mathbb{N}}$, the inference goal is to determine the posterior distribution $p(\\bm{\\omega} \\mid \\mathbf{X}, \\mathbf{Y})$ through Bayes' rule. Since this posterior is generally intractable we consider the parameterized variational distribution $q(\\bm{\\omega};\\bm{\\theta})$ that is optimal for $\\bm{\\theta}^*$ in terms of KL Divergence.\n\n$$\n\\bm{\\theta}^* = \\argmin_{\\bm{\\theta}\\in\\Theta} KL\\left[q(\\bm{\\omega};\\bm{\\theta})||p(\\bm{\\omega} \\mid \\mathbf{X}, \\mathbf{Y})\\right]\n$$\n\nGiven a prior, $p(\\bm{\\omega})$, we can can reformulate this as the evidence lower bound (ELBO):\n\n\\begin{equation}\n\\bm{\\theta}^* = \\argmax_{\\bm{\\theta}\\in\\Theta}\\left\\{\\mathbb{E}_{\\bm{\\omega}\\sim q}\\big[\\log p(\\mathbf{Y} \\mid \\mathbf{X}, \\bm{\\omega})\\big] - KL\\big[q(\\bm{\\omega};\\bm{\\theta} || p(\\bm{\\omega})\\big]\\right\\}\n\\end{equation}\n\nThe goal of this paper is to derive an explicit deterministic approximation of the first term, known as reconstruction term, and choose priors $p(\\bm{\\omega})$ empirically to increase robustness to the choice of variance parameters.\n\n", "meta": {"hexsha": "60e3841edd8e3007b0dc7294d1c91ea979b8fbc2", "size": 1238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_notes/paper-summary/DVI-2019-05-23/tex/Problem.tex", "max_stars_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_stars_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_notes/paper-summary/DVI-2019-05-23/tex/Problem.tex", "max_issues_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_issues_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_notes/paper-summary/DVI-2019-05-23/tex/Problem.tex", "max_forks_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_forks_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.7777777778, "max_line_length": 461, "alphanum_fraction": 0.697092084, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075744568837, "lm_q2_score": 0.894789454880027, "lm_q1q2_score": 0.86088371208422}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade \n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item A researcher claimed that she discovered a comparison-based sorting algorithm that runs in $\\mathcal{O}(n\\log (\\sqrt{n}))$.\nGiven the existence of an $\\Omega(n\\log n)$ lower bound for sorting, how can this be possible?\n\n\\item Let $S$ be an unsorted array of $n$ integers.\nGive an algorithm that finds the pair $x,y \\in S$ that maximizes $|x - y|$.\nYour algorithm must run in $\\mathcal{O}(n)$ worst-case time.\n\n\\item Explain why your algorithm is indeed $\\mathcal{O}(n)$.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item It suffices to show that a comparison-based sorting algorithm with runtime $\\mathcal{O}(n\\log \\sqrt{n})$ does not necessarily violate the lower-bound runtime of sorting algorithms, in which case the researcher's claim will be justified.\nUsing fundamental properties of logarithms,\n\\begin{equation}\\label{eq31}\n\\begin{aligned}\n\\mathcal{O}(n\\log \\sqrt{n}) &= \\mathcal{O}(n\\log n^{0.5})\\\\\n&= \\mathcal{O}(0.5 n \\log n)\\\\\n&= \\mathcal{O}(n\\log n)\n\\end{aligned}\n\\end{equation}\nTherefore, researcher's proposed sorting algorithm is of the same lower-bound run-time and the claim is justified.\n\\item Expression $|x-y|$ is maximized when $x$ and $y$ are minimum and maximum elements of the unsorted array.\nThe problem could now be simplified as finding minimum and maximum of an unsorted array in $\\mathcal{O}(n)$ runtime.\nTo achieve this goal, Algorithm \\ref{alg1} shown below is proposed.\n\\begin{algorithm}[H]\n\\caption{\\textsc{$|x-y|$-Maximizer}}\\label{alg1}\n\\begin{algorithmic}[1]\n\\State $min \\leftarrow +\\infty$\n\\State $max \\leftarrow -\\infty$\n\\For {$i \\leftarrow 1$ to $A.length$}\n\\If {$A[i] < min$}\n\\State min $\\leftarrow A[i]$\n\\ElsIf {$A[i] > max$}\n\\State max $\\leftarrow A[i]$\n\\EndIf\n\\EndFor\n\\State \\Return $min$, $max$\n\\end{algorithmic}\n\\end{algorithm}\n\\item There are $n$ iterations of the for loop in each of which either $A[i] < min$ or $A[i] > max$ or none.\nIn first two cases there would be one assignment of cost $c$.\nTherefore, the whole algorithm has a run time of $\\mathcal{O}(nc+d)=\\mathcal{O}(n)$, so algorithm is linear in $n$.\n\\end{enumerate}\n", "meta": {"hexsha": "0e0dc5e5e7b6d4ed5e12a8175e890f47d087ad03", "size": 2525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m01/m01q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/m01/m01q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/m01/m01q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 45.0892857143, "max_line_length": 242, "alphanum_fraction": 0.683960396, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.9241418236349501, "lm_q1q2_score": 0.8608034651117694}} {"text": "\\section{ICP Math}\n\nAssume we have a model point cloud with points $p_i$ and surface\nnormals $n_i$ and we want to align the currently sensed point cloud\nwith points $q_i$ to the model by estimating the relative\ntransformation $(R_{mc}, t_{mc})$. The ICP point-to-plane distance\nerror function is given as:\n\\begin{align}\n \\sum_i \\| ( R_{mc} q_i + t_{mc} - p_i )^T n_i \\|^2_2\n\\end{align}\nNote that this already assumes a data association between model and current point cloud.\nThis association can be obtained efficiently in the case of RGBD frames\nby projecting the current point cloud into the model camera frame and\nforming the association by the pixel positions of the projected current point cloud.\n\n\\subsection{Solution using small angle assumption}\nLocally, around the current relative transformation estimate $(R_{mc},\nt_{mc})$ the cost function can be approximated by small perturbations $\\xi$\nin the tangent space $\\se{3}$ around the current pose:\n\\begin{align}\n \\sum_i \\| ( R_{mc} \\exp(\\xi_w) q_i + t_{mc} + \\xi_t - p_i )^T n_i \\|^2_2\n\\end{align}\n\nSlide 13 of \n\\url{{http://resources.mpi-inf.mpg.de/deformableShapeMatching/EG2011_Tutorial/slides/2.1%20Rigid%20ICP.pdf}} and \n\\url{https://www.comp.nus.edu.sg/~lowkl/publications/lowk_point-to-plane_icp_techrep.pdf}\nshow how to linearize this system assuming small rotations:\n\\begin{align}\n &\\sum_i \\| ( \\exp(\\xi_w) R_{mc} q_i + t_{mc} + \\xi_t - p_i )^T n_i \\|^2_2 \\\\\n =& \\sum_i \\| ( (I + [\\xi_w]_\\times) R_{mc} q_i + t_{mc} + \\xi_t - p_i )^T n_i \\|^2_2\\\\\n =& \\sum_i \\| ( [\\xi_w]_\\times R_{mc} q_i + R_{mc} q_i + t_{mc} + \\xi_t - p_i )^T n_i \\|^2_2\\\\\n =& \\sum_i \\| n_i^T (\\xi_w \\times (R_{mc} q_i)) + n_i^T R_{mc} q_i + n_i^T t_{mc} + n_i^T \\xi_t -n_i^T p_i \\|^2_2\\\\\n =& \\sum_i \\| ( (R_{mc} q_i) \\times n_i)^T \\xi_w + n_i^T \\xi_t + n_i^T ( R_{mc} q_i + t_{mc} - p_i) \\|^2_2\\\\\n =& \\| A \\xi - b \\|^2_2 \\,,\\quad\n A = \\begin{pmatrix}\n ((R_{mc} q_i) \\times n_i)^T & n_i^T \\\\\n \\vdots & \\vdots\n \\end{pmatrix}\\,,\\;\n \\xi = \\begin{pmatrix} \\xi_w \\\\ \\xi_t \\end{pmatrix}\\,,\\;\n b = \\begin{pmatrix}\n n_i^T ( - R_{mc} q_i - t_{mc} + p_i) \\\\\n \\vdots\n \\end{pmatrix}\n\\end{align}\nwhere we have used that the $\\SO{3}$ exponential maps first order\nexpansion is $I + [\\xi_w]_\\times$ for small angular magnitude.\n\nThis can be solved in the standard approach using the pseudo inverse $A^TA$:\n\\begin{align}\n \\xi = (A^TA)^{-1} A^Tb\n\\end{align}\nFor efficiency reasons $A$ and $b$ should never be constructed\ndirectly. Instead we directly accumulate $A^TA$ and $A^Tb$:\n\\begin{align}\n A^TA = \\begin{pmatrix}\n \\sum_i A_{i0}^2 & \\sum_i A_{i0} A_{i1} & \\cdots \\\\\n \\sum_i A_{i0} A_{i1} & \\sum_i A_{i1}^2 & \\cdots \\\\\n \\vdots & \\vdots & \\ddots \n \\end{pmatrix}\n & \n A^Tb = \\begin{pmatrix}\n \\sum_i A_{i0} b_{i} \\\\\n \\sum_i A_{i1} b_{i} \\\\\n \\vdots \n \\end{pmatrix}\n\\end{align}\nDue to symmetry we only need to accumulate $21$ values ($22$ if we want\nthe cost function value as well).\n\n\\subsection{Alternative using gradient descent}\n\nThe optimum perturbation $\\xi$ to minimize the cost function around the\ncurrent pose estimate can be found by gradient descent in the direction of derivative with\nrespect to $\\xi$:\n\\begin{align}\n & \\deriv{}{\\xi} \\sum_i \\| ( R_{mc} \\exp(\\xi_w) q_i + t_{mc} + \\xi_t - p_i )^T n_i \\|^2_2\\\\\n =& \\sum_i 2 ( R_{mc} \\exp(\\xi_w) q_i + t_{mc} + \\xi_t - p_i )^T n_i \\deriv{}{\\xi}\n \\left[ n_i^T R_{mc} \\exp(\\xi_w) q_i + n_i^T \\xi_t\n \\right]\\\\\n =& \\sum_i 2 ( R_{mc} \\exp(\\xi_w) q_i + t_{mc} + \\xi_t - p_i )^T n_i \n \\begin{pmatrix}\n - n_i^T [R_{mc} q_i]_\\times & n_i^T\n \\end{pmatrix}\n\\end{align}\n", "meta": {"hexsha": "66a67f85cbc3e1a32e62bb2670c0806e1dcdfdea", "size": 3610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/icp.tex", "max_stars_repo_name": "jstraub/tdp", "max_stars_repo_head_hexsha": "dcab53662be5b88db1538cf831707b07ab96e387", "max_stars_repo_licenses": ["MIT-feh"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-17T19:25:47.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-17T19:25:47.000Z", "max_issues_repo_path": "docs/icp.tex", "max_issues_repo_name": "jstraub/tdp", "max_issues_repo_head_hexsha": "dcab53662be5b88db1538cf831707b07ab96e387", "max_issues_repo_licenses": ["MIT-feh"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-02T06:04:06.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-02T06:04:06.000Z", "max_forks_repo_path": "docs/icp.tex", "max_forks_repo_name": "jstraub/tdp", "max_forks_repo_head_hexsha": "dcab53662be5b88db1538cf831707b07ab96e387", "max_forks_repo_licenses": ["MIT-feh"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-09-17T18:46:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-11T12:52:57.000Z", "avg_line_length": 42.4705882353, "max_line_length": 116, "alphanum_fraction": 0.6493074792, "num_tokens": 1345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.9149009613738741, "lm_q1q2_score": 0.8607294475663292}} {"text": "\\section*{Exercises}\n\n\\begin{ex}\n Which of the following linear transformations $T:\\R^3\\to\\R^3$ are\n orthogonal?\n \\begin{enumerate}\n \\item A rotation by 30 degrees about the $z$-axis.\n \\item A reflection about the plane $x=y$.\n \\item A scaling by a factor of $2$.\n \\item A scaling by a factor of $-1$.\n \\end{enumerate}\n \\begin{sol}\n (a) Yes. (b) Yes. (c) No. (d) Yes.\n \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Which of the following matrices define orthogonal transformations?\n Which ones define isometries?\n \\begin{equation*}\n A = \\begin{mymatrix}{rr}\n 1 & 0 \\\\\n 0 & -1 \\\\\n \\end{mymatrix},\\quad\n B = \\frac{1}{2}\\begin{mymatrix}{rr}\n 1 & 1 \\\\\n -1 & 1 \\\\\n \\end{mymatrix},\\quad\n C = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{rr}\n 1 & -2 \\\\\n 2 & 1 \\\\\n \\end{mymatrix},\\quad\n D = \\frac{1}{4}\\begin{mymatrix}{rr}\n 1 & 2 \\\\\n 2 & 2 \\\\\n 2 & -1 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n \\begin{sol}\n $A$ and $C$ are orthogonal (and therefore isometries). $D$ is an\n isometry but not orthogonal. $B$ is neither orthogonal nor an isometry.\n \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n Determine which of the following matrices are orthogonal by checking\n whether the columns form an orthonormal set.\n \\begin{equation*}\n A = \\frac{1}{3}\n \\begin{mymatrix}{rrr}\n 1 & 2 & 2 \\\\\n 2 & 1 & -2 \\\\\n -2 & 2 & -1 \\\\\n \\end{mymatrix},\n \\quad\n B = \\begin{mymatrix}{rrr}\n 0 & 0 & 2 \\\\\n 0 & 2 & 0 \\\\\n 2 & 0 & 0 \\\\\n \\end{mymatrix},\n \\quad\n C = \\frac{1}{3}\n \\begin{mymatrix}{rrr}\n 2 & -1 & 2 \\\\\n -1 & 2 & -2 \\\\\n 2 & -2 & 1 \\\\\n \\end{mymatrix},\n \\quad\n D =\n \\frac{1}{5}\n \\begin{mymatrix}{rrr}\n 3 & 4 & 0 \\\\\n 4 & -3 & 0 \\\\\n 0 & 0 & 5 \\\\\n \\end{mymatrix}.\n \\end{equation*}\n \\begin{sol}\n $A$ and $D$ are orthogonal, but $B$ and $C$ are not.\n \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "cd86d1943840ef6a484480adf7a1a56357643016", "size": 1918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-OrthogonalMaps.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-OrthogonalMaps.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-OrthogonalMaps.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 23.3902439024, "max_line_length": 75, "alphanum_fraction": 0.5260688217, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.9230391690674338, "lm_q1q2_score": 0.8606909291372682}} {"text": "\\subsubsection{Method of Lagrange Multipliers}\r\n\\noindent\r\nGiven an objective function, $f(x,y)$ and a constraint equation $g(x,y) = k$, define $F(x,y,\\lambda) = f(x,y) + \\lambda(k-g(x,y))$.\r\nThe solution, $(x, y, \\lambda)$, to $\\nabla F = \\vec{0}$ will be the solution to the constrained optimization problem.\\\\\r\n\r\n\\noindent\r\nFor example, let's maximize $f(x,y)=xy$ subject to $(x-1)^2 + (y-1)^2 = 1$.\r\n\\begin{equation*}\r\n\tF(x,y,\\lambda) = xy + \\lambda(1 - (x-1)^2 - (y-1)^2)\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\nabla F = \\langle y + 2\\lambda(x-1), x+2\\lambda(y-1), 1 - (x-1)^2 - (y-1)^2 = 1 \\rangle = \\vec{0}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\ty - 2\\lambda(x-1) = 0 \\\\ \r\n\t\tx - 2\\lambda(y-1) = 0 \\\\ \r\n\t\t1 - (x-1)^2 - (y-1)^2 = 0\r\n\t\\end{cases}\r\n\t\\implies \\begin{cases}\r\n\t\ty = 2\\lambda(x-1) \\\\ \r\n\t\tx = 2\\lambda(y-1) \\\\ \r\n\t\t(x-1)^2 + (y-1)^2 = 1\r\n\t\\end{cases}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\ty = 2\\lambda(2\\lambda(y-1) - 1) = 4\\lambda^2 y - 4\\lambda^2 - 2\\lambda = \\frac{2\\lambda}{2\\lambda+1}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tx = 2\\lambda\\left(\\frac{2\\lambda}{2\\lambda+1} - 1\\right) = \\frac{2\\lambda}{2\\lambda+1} \\implies x = y\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t2(x-1)^2 = 1 \\implies x = y = 1 \\pm \\frac{1}{\\sqrt{2}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\implies \\text{ Max/Min of } \\frac{3 \\pm 2\\sqrt{2}}{2}.\r\n\\end{equation*}", "meta": {"hexsha": "1624a16fc21058dfe221b1baf319ac6ee94185ed", "size": 1363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/methodLagrangeMultipliers.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/methodLagrangeMultipliers.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/methodLagrangeMultipliers.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8378378378, "max_line_length": 132, "alphanum_fraction": 0.5803374908, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079104, "lm_q2_score": 0.9032942125614059, "lm_q1q2_score": 0.860454700659109}} {"text": "\n\\subsection{Calculating eigenvalues and eigenvectors using the characteristic polynomial}\n\nThe characteristic polynomial of a matrix is a polynomial whose roots are the eigenvalues of the matrix.\n\nWe know from the definition of eigenvalues and eigenvectors that:\n\n\\(Av=\\lambda v\\)\n\nNote that\n\n\\(Av-\\lambda v=0\\)\n\n\\(Av-\\lambda Iv=0\\)\n\n\\((A-\\lambda I)v=0\\)\n\nTrivially we see that \\(v=0\\) is a solution.\n\nOtherwise matrix \\(A-\\lambda I\\) must be non-invertible. That is:\n\n\\(Det(A-\\lambda I)=0\\)\n\n\\subsection{Calculating eigenvalues}\n\nFor example\n\n\\(A=\\begin{bmatrix}2&1\\\\1 & 2\\end{bmatrix}\\)\n\n\\(A-\\lambda I=\\begin{bmatrix}2-\\lambda &1\\\\1 & 2-\\lambda \\end{bmatrix}\\)\n\n\\(Det(A-\\lambda I)=(2-\\lambda )(2-\\lambda )-1\\)\n\nWhen this is \\(0\\).\n\n\\((2-\\lambda )(2-\\lambda )-1=0\\)\n\n\\(\\lambda =1,3\\)\n\n\\subsection{Calculating eigenvectors}\n\nYou can plug this into the original problem.\n\nFor example\n\n\\(Av=3v\\)\n\n\\(\\begin{bmatrix}2&1\\\\1 & 2\\end{bmatrix}\\begin{bmatrix}x_1\\\\x_2\\end{bmatrix}=3\\begin{bmatrix}x_1\\\\x_2\\end{bmatrix}\\)\n\nAs vectors can be defined at any point on the line, we normalise \\(x_1=1\\).\n\n\\(\\begin{bmatrix}2&1\\\\1 & 2\\end{bmatrix}\\begin{bmatrix}1\\\\x_2\\end{bmatrix}=\\begin{bmatrix}3\\\\3x_2\\end{bmatrix}\\)\n\nHere \\(x_2=1\\) and so the eigenvector corresponding to eigenvalue \\(3\\) is:\n\n\\(\\begin{bmatrix}1\\\\1\\end{bmatrix}\\)\n\n", "meta": {"hexsha": "7e5dbcfcef7d0a8279e69902c5ecf907ccd9633b", "size": 1320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-04-characteristicPolynomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-04-characteristicPolynomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-04-characteristicPolynomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7586206897, "max_line_length": 116, "alphanum_fraction": 0.6931818182, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.904650536386234, "lm_q1q2_score": 0.8604513220019255}} {"text": "\\section{Probability and Statistics}\n\\subsection{Basics}\nThe set of all possible outcomes of an experiment is known as the sample space\nand denoted by $S$. Any subset $E$ of the sample space is known as an event.\nAn event is a set consisting of possible outcomes of the experiment.\n\\subsubsection{Axioms of Probability}\nFor each event $E$, we denote $P(E)$ as the probability of event $E$ occuring.\n$P(E)$ satisfies the following properties:\n\\begin{enumerate}\n \\item Every probability is between 0 and 1 included:\n \\begin{equation} 0 \\leq P(E) \\leq 1 \\end{equation}\n \\item The probability that at least one event in the sample space will occur\n is $1$: \\begin{equation} P(S) = 1 \\end{equation}\n \\item For any sequence of mutually exclusive events $E_1,\\hdots,E_n$ we have:\n \\begin{equation} P\\left(\\bigcup_{i=1}^nE_i\\right)=\\sum_{i=1}^nP(E_i) \\end{equation}\n\\end{enumerate}\n\\subsubsection{Permutation}\nA permutation is an arrangement of $r$ objects from a pool of $n$ objects, in\na given order. The number of such arrangements is given by $P(n, r)$:\n\\begin{equation} P(n, r) = \\frac{n!}{(n-r)!} \\end{equation}\n\\subsubsection{Combination}\nA combination is an arrangement of $r$ objects from a pool of $n$ objects, where\norder does not matter. The number of such arrangements is given by $C(n, r)$:\n\\begin{equation} C(n, r) = \\frac{P(n, r)}{r!} = \\frac{n!}{r! (n-r)!} \\end{equation}\nNote that for $0 \\leq r \\leq n$ we have $P(n, r) \\geq C(n, r)$.\n\\subsection{Conditional Probability}\nLet $B$ be an event with non-zero probability, the conditional proability of\nany event $A$ given $B$ is:\n\\begin{equation} P(A | B) = \\frac{P(A \\cap B)}{P(B)} \\end{equation}\n\\subsubsection{Bayes Rule}\nFor events $A, B$ such that $P(B) > 0$, we have:\n\\begin{equation} P(A | B) = \\frac{P(B|A) P(A)}{P(B)} \\end{equation}\nFrom Bayes rule, we have:\n\\begin{equation} P(A \\cap B) = P(A|B)P(B) = P(A)P(B|A) \\end{equation}\nLet $\\{ A_i, i \\in [1, n] \\}$ be such that for all $i$, $A_i \\not= \\varnothing$.\nWe say that $\\{A_i\\}$ is a partition if we have:\n\\begin{equation} \\forall i\\neq j, A_i\\cap A_j=\\emptyset\\quad\\mbox{ and }\\quad\\bigcup_{i=1}^nA_i=S \\end{equation}\nRemark that for any event $B$ in the sample space, we have:\n\\begin{equation} P(B)=\\sum_{i=1}^n P(B|A_i)P(A_i) \\end{equation}\nLet $\\{ A_i, i \\in [1, n] \\}$ be a partition of the sample space, we can\nextend bayes rule as:\n\\begin{equation} P(A_k|B)=\\frac{P(B|A_k)P(A_k)}{\\displaystyle\\sum_{i=1}^nP(B|A_i)P(A_i)} \\end{equation}\n\\subsubsection{Independence}\nTwo events $A$ and $B$ are independent if and only if we have:\n\\begin{equation} P(A \\cap B) = P(A) P(B) \\end{equation}\n\\subsection{Random Variables}\nA random variable $X$ is a function that maps every element in a sample space\nto a real line.\n\\subsubsection{Cumulative Distribution Function (CDF)}\nThe cumulative distribution function $F$, which is monotonically non-decreasing\nand is such that $\\lim_{x \\to -\\infty}F(X) = 0$ and $\\lim_{x \\to \\infty}F(X) = 1$\nis defined as:\n\\begin{equation} F(x) = P(X \\leq x) \\end{equation}\nIn addition:\n\\begin{equation} P(a < X \\leq b) = F(b) - F(a) \\end{equation}\n\\subsubsection{Probability Density Function (PDF)}\nThe probability density function is the derivative of the CDF.\nIt has the following properties:\n\\begin{enumerate}\n \\item $f(x) \\geq 0$\n \\item $\\int^{\\infty}_{-\\infty} f(x) = 1$\n \\item $\\int_{x \\in A} f(x) dx = P(X \\in A)$\n\\end{enumerate}\n\\subsubsection{Discrete PDF/CDF}\nIf $X$ is discrete, by denoting $f$ as the PDF and $F$ as the CDF, we have:\n\\begin{equation}\n F(X) = \\sum_{x_i \\leq x} P(X = x_i)\n\\end{equation}\n\\begin{equation}\n f(x_j) = P(X = x_j)\n\\end{equation}\nAnd the following properties for the PDF:\n\\begin{equation}\n 0 \\leq f(x_j) \\leq 1\n\\end{equation}\n\\begin{equation}\n \\sum_j f(x_j) = 1\n\\end{equation}\n\\subsubsection{Continuous PDF/CDF}\nIf $X$ is continuous, by denoting $f$ as the PDF and $F$ as the CDF, we have:\n\\begin{equation}\n F(X) = \\int_{-\\infty}^x f(y) dy\n\\end{equation}\n\\begin{equation}\n f(x) = \\frac{dF}{dx}\n\\end{equation}\nAnd the following properties for the PDF:\n\\begin{equation}\n f(x) \\geq 0\n\\end{equation}\n\\begin{equation}\n \\int_{-\\infty}^{\\infty} f(x) dx = 1\n\\end{equation}\n\\subsubsection{Expectation}\nThe expected value of a random variable, also known as the mean value or\nfirst moment, is denoted as $\\mathbb { E }[X]$ or $\\mu$. It is the value obtained by\naveraging the results of a random variable.\nWe use $\\mbox{(D)}$ for discrete, $\\mbox{(C)}$ for continuous.\n\\begin{equation}\n \\mbox{(D)}\\quad \\mathbb { E }[X]=\\sum_{i=1}^nx_if(x_i)\\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad \\mathbb { E }[X]=\\int_{-\\infty}^{+\\infty}xf(x)dx\n\\end{equation}\nThe expected value of a function of a random variable $g(X)$ is:\n\\begin{equation}\n \\mbox{(D)}\\quad \\mathbb { E }[g(X)]=\\sum_{i=1}^ng(x_i)f(x_i)\\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad \\mathbb { E }[g(X)]=\\int_{-\\infty}^{+\\infty}g(x)f(x)dx\n\\end{equation}\nThe $k$-th moment, noted $\\mathbb { E }[X^k]$ is the value of $X^k$ that we expect to observe\non average on infinitely many trials. The $k$-th moment is a case of the previous\ndefinition with $g \\,:\\, X \\mapsto X^k$.\n\\begin{equation}\n \\mbox{(D)}\\quad \\mathbb { E }[X^k]=\\sum_{i=1}^nx_i^kf(x_i) \\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad \\mathbb { E }[X^k]=\\int_{-\\infty}^{+\\infty}x^kf(x)dx\n\\end{equation}\nA characteristic function $\\psi(\\omega)$ is derived from a probability density\nfunction $f(x)$ and is defined as:\n\\begin{equation}\n \\mbox{(D)}\\quad \\psi(\\omega)=\\sum_{i=1}^nf(x_i)e^{i\\omega x_i} \\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad \\psi(\\omega)=\\int_{-\\infty}^{+\\infty}f(x)e^{i\\omega x}dx\n\\end{equation}\nRemark that $e^{i\\omega x} = \\cos(\\omega x)+ i \\sin(\\omega x)$. The $k$-th moment\ncan also be computed with the characteristic function as:\n\\begin{equation}\n \\mathbb { E }[X^k]=\\frac{1}{i^k}\\left[\\frac{\\partial^k\\psi}{\\partial\\omega^k}\\right]_{\\omega=0}\n\\end{equation}\n\\subsubsection{Variance and Standard Deviation}\nThe variance of a random variable, often noted $\\mbox{Var}(X)$ or $\\sigma^2$,\nis a measure of the spread of its distribution function.\nIt is determined as follows:\n\\begin{equation}\n \\mbox{Var}[X]=\\mathbb { E }[(X-\\mathbb { E }[X])^2]=\\mathbb { E }[X^2]-\\mathbb { E }[X]^2\n\\end{equation}\nThe standard deviation of a random variable, often noted $\\sigma$, is a\nmeasure of the spread of its distribution function which is\ncompatible with the units of the actual random variable.\nIt is determined as follows:\n\\begin{equation}\n \\sigma = \\sqrt{\\mbox{Var}[X]}\n\\end{equation}\nNote that the variance for any constant $a$ is $\\mbox{Var}[a]= 0$, and\n$\\mbox{Var}[af(X)]=a^2\\mbox{Var}[f(X)]$.\n\\subsection{Discrete Random Variables}\n\\subsubsection{Bernoulli}\nFor $X\\sim Bernoulli(p)$, we define a binary event with a probability of $p$\nfor a true event, and a false event with probability of $q=1-p$.\n\\begin{equation}\n P(X=x) = \\begin{cases} q=1-p & \\textrm{if } x=0 \\\\ p & \\textrm{if } x=1 \\end{cases}\n\\end{equation}\nIt can also be expressed as:\n\\begin{equation}\n f(x; p) = p^k (1-p)^{1-k} \\quad \\mbox{for } k\\in \\{0, 1\\}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = p\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = pq = p (1-p)\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = (1-p) + p e^{i\\omega}\n\\end{equation}\n\\subsubsection{Binomial}\nFor $X\\sim Binomial(n, p)$, the number of true events in $n$ independent\nexperiments, with true probability of $p$, false probability of $q=1-p$.\n\\begin{equation}\n \\displaystyle P(X=x)=\\displaystyle\\binom{n}{x} p^x(1-p)^{n-x}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = np\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = npq = np(1-p)\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = (pe^{i\\omega}+(1-p))^n\n\\end{equation}\n\\subsubsection{Geometric}\nFor $X\\sim Geometric(p)$, is the number of experiments with true\nprobability of $p$ until the first true event (number of trials to get one success).\n\\begin{equation}\n \\displaystyle P(X=x)=p(1-p)^{x-1}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = \\frac{1}{p}\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = \\frac{1-p}{p^2}\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = \\frac{pe^{i \\omega}}{1-(1-p)e^{i \\omega}}\n\\end{equation}\n\\subsubsection{Poisson}\nFor $X\\sim Poisson(\\lambda)$, for $\\lambda > 0$, a probability distribution\nover the nonnegative integers\nused for modeling the frequency of rare events.\n\\begin{equation}\n \\displaystyle P(X=x)=\\frac{\\lambda^x}{x!}e^{-\\lambda}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = \\lambda\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = \\lambda\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = e^{\\lambda(e^{i\\omega}-1)}\n\\end{equation}\n\\subsection{Continuous Random Variables}\n\\subsubsection{Uniform}\nFor $X\\sim Uniform(a,b)$, we have equal probability density to every value\nbetween $a$ and $b$.\n\\begin{equation}\n f(x) = \\begin{cases} \\frac{1}{b-a} & \\textrm{if } a \\leq x \\leq b \\\\ 0 & \\textrm{otherwise} \\end{cases}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = \\frac{a+b}{2}\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = \\frac{(b-a)^2}{12}\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = \\displaystyle\\frac{e^{i\\omega b}-e^{i\\omega a}}{(b-a)i\\omega}\n\\end{equation}\n\\subsubsection{Exponential}\nFor $X\\sim Exponential(\\lambda)$, $\\lambda > 0$, is the\ndecaying probability density over the nonnegative reals.\n\\begin{equation}\n f(x) = \\begin{cases} \\lambda e^{-\\lambda x} & \\textrm{if } x \\geq 0 \\\\ 0 & \\textrm{otherwise} \\end{cases}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = \\frac{1}{\\lambda}\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = \\frac{1}{\\lambda^2}\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = \\displaystyle\\frac{1}{1-\\frac{i\\omega}{\\lambda}}\n\\end{equation}\n\\subsubsection{Gaussian (Normal)}\nFor $X\\sim Normal(\\mu, \\sigma)$, denoted also $X \\sim \\mathcal{N}(\\mu, \\sigma)$.\n\\begin{equation}\n \\displaystyle f(x)=\\frac{1}{\\sqrt{2\\pi}\\sigma}e^{-\\frac{1}{2}\\left(\\frac{x-\\mu}{\\sigma}\\right)^2}\n\\end{equation}\nOther properties:\n\\begin{equation}\n \\mathbb { E }[X] = \\mu\n\\end{equation}\n\\begin{equation}\n \\mbox{Var}[X] = \\sigma^2\n\\end{equation}\n\\begin{equation}\n \\psi(\\omega) = e^{i\\omega\\mu-\\frac{1}{2}\\omega^2\\sigma^2}\n\\end{equation}\n\\subsection{Jointly Distributed Random Variables}\nThe joint probability distribution of two random variables $X$ and $Y$, denoted\nas $f_{XY}$ is defined as:\n\\begin{equation}\n \\mbox{(D)}\\quad f_{XY}(x_i,y_j)=P(X=x_i\\mbox{ and }Y=y_j)\n\\end{equation}\n\\begin{equation}\n \\mbox{(C)}\\quad f_{XY}(x,y)\\Delta x\\Delta y=P(x\\leqslant X\\leqslant x+\\Delta x\\mbox{ and }y\\leqslant Y\\leqslant y+\\Delta y)\n\\end{equation}\nAgain, denote $\\mbox{(D)}$ as the discrete case, and $\\mbox{(C)}$ as the\ncontinuous case.\n\\subsubsection{Marginal Density}\nThe marginal density for a random variable $X$ is:\n\\begin{equation}\n \\mbox{(D)}\\quad f_X(x_i)=\\sum_{j}f_{XY}(x_i,y_j) \\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad f_X(x)=\\int_{-\\infty}^{+\\infty}f_{XY}(x,y)dy\n\\end{equation}\n\\subsubsection{Cumulative Distribution}\nThe cumulative distribution $F_{XY}$ is:\n\\begin{equation}\n \\mbox{(D)}\\quad F_{XY}(x,y)=\\sum_{x_i\\leqslant x}\\sum_{y_j\\leqslant y}f_{XY}(x_i,y_j) \\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad F_{XY}(x,y)=\\int_{-\\infty}^x\\int_{-\\infty}^yf_{XY}(x',y')dx'dy'\n\\end{equation}\n\\subsubsection{Conditional Density}\nThe conditional density of $X$ with respect to $Y$, denoted $f_{X|Y}$ is\ndefined as:\n\\begin{equation}\n f_{X|Y} = \\frac{f_{XY}(x, y)}{f_Y(y)}\n\\end{equation}\n\\subsubsection{Independence}\nTwo random variables $X$ and $Y$ are independent if:\n\\begin{equation}\n f_{XY}(x,y) = f_X(x)f_Y(y)\n\\end{equation}\n\\subsubsection{Expectation}\nGiven two random variables $X,Y$ and $g : \\mathbb{R}^2 \\to \\mathbb{R}$ is a\nfunction of these two variables. Then the expected value of $g$ is:\n\\begin{equation}\n \\mbox{(D)}\\quad\\mathbb{E}[g(X, Y)] = \\sum_i \\sum_j g(x_i, y_i) f(x_i, y_i) \\quad\\quad\\mbox{and}\\quad\\mbox{(C)}\\quad\\mathbb{E}[g(X, Y)] = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} g(x_i, y_i) f(x_i, y_i) dy dx\n\\end{equation}\n\\subsubsection{Covariance}\nThe covariance of two random variables $X$ and $Y$, denoted $\\sigma^2_{XY}$ or\nas $\\mbox{Cov}[X, Y]$ is defined as:\n\\begin{equation}\n \\mbox{Cov}[X,Y]\\triangleq\\sigma_{XY}^2=\\mathbb{E}[(X-\\mu_X)(Y-\\mu_Y)]=\\mathbb{E}[XY]-\\mu_X\\mu_Y\n\\end{equation}\nWhere $\\mu_X = \\mathbb{E}[X]$ and $\\mu_Y = \\mathbb{E}[Y]$ respectively. If $X$\nand $Y$ are independent, the covariance is $0$.\n\\begin{equation}\n \\mbox{Var}[X + Y] = \\mbox{Var}[X] + \\mbox{Var}[Y] + 2 \\mbox{Cov}[X, Y]\n\\end{equation}\n\\subsubsection{Correlation}\nBy noting $\\sigma_X$, $\\sigma_Y$ as the standard deviations of $X$ and $Y$, we\ndefine the correlation between the random variables $X$ and $Y$ as $\\rho_{XY}$:\n\\begin{equation}\n \\rho_{XY} = \\frac{\\sigma_{XY}^2}{\\sigma_{X}\\sigma_{Y}}\n\\end{equation}\nCorrelation for $X, Y$ is $\\rho_{XY} \\in [-1, 1]$. If $X,Y$ independent, then\n$\\rho_{XY}=0$\n\\subsection{Parameter Estimation}\n\n\n\n\n\\subsubsection{Definitions}\n\\subsubsection{Bias}\n\\subsubsection{Mean and Central Limit Theorem}\n\\subsubsection{Variance}\n\n\n\n\n\n\n\n\\subsection{Probability Bounds and Inequalities}\nThis section looks at various bounds that define how likely a random variable\nis to be close to its expectation.\n\\subsubsection{Markov}\nLet $X \\geq 0$ be a non-negative random variable. Then for all $a \\geq 0$:\n\\begin{equation}\n P(X \\geq a) \\leq \\frac{\\mathbb{E}[X]}{a}\n\\end{equation}\n\\subsubsection{Chebyshev}\nLet $X$ be any random variable with finite expected value $\\mu = \\mathbb{E}[X]$\nand finite non-zero variance $\\sigma^2$.\nThen for all $k > 0$:\n\\begin{equation}\n P(|X - \\mathbb{E}[X]| \\geq k \\sigma) \\leq \\frac{1}{k^2}\n\\end{equation}\n\\subsubsection{Chernoff}\nRecall that the moment generating function for a random variable $X$ is:\n\\begin{equation}\n M_X(\\lambda) := \\mathbb{E}[e^{\\lambda X}]\n\\end{equation}\nThen the chernoff bound for a random variable $X$, obtained by applying the\nmarkov inequality to $e^{\\lambda X}$, for every $\\lambda > 0$:\n\\begin{equation}\n P(X \\geq a) = P(e^{\\lambda X} \\geq e^{\\lambda a}) \\leq \\frac{\\mathbb{E}[e^{\\lambda X}]}{e^{\\lambda a}}\n\\end{equation}\nFor the multiplicative chernoff bound, suppose $X_1, \\hdots, X_n$ are independent\nrandom variables taking values in $\\{0, 1\\}$. Let $X$ denote the sum, $\\mu=\\mathbb{E}[X]$\ndenote the sum's expected value. Then for any $0 < \\delta < 1$,\n\\begin{equation}\n P(X > (1+\\delta) \\mu ) < \\left( \\frac{e^{\\delta}}{(1+\\delta)^{(1+\\delta)}} \\right)^{\\mu} \\leq e^{-\\frac{\\delta^2 \\mu}{3}}\n\\end{equation}\n\\begin{equation}\n P(X < (1-\\delta) \\mu ) < \\left( \\frac{e^{-\\delta}}{(1-\\delta)^{(1-\\delta)}} \\right)^{\\mu} \\leq e^{-\\frac{\\delta^2 \\mu}{2}}\n\\end{equation}\nFor $\\delta \\geq 0$,\n\\begin{equation}\n P(X \\geq (1+\\delta) \\mu ) \\leq e^{-\\frac{\\delta^2 \\mu}{2+\\delta}}\n\\end{equation}\n\\begin{equation}\n P(X \\leq (1-\\delta) \\mu ) \\leq e^{-\\frac{\\delta^2 \\mu}{2}}\n\\end{equation}\n\\subsubsection{Hoeffding}\nLet $X_1, \\hdots, X_n$ be independent random variables such that $a_i \\leq X_i \\leq b_i$.\nThe sum of these variables $S_n = \\sum_i X_i$, then the Hoeffding\ninequality is:\n\\begin{equation}\n P\\left(S_n - \\mathbb{E}\\left[S_n\\right] \\geq t \\right) \\leq \\exp\\left(-\\frac{2t^2}{\\sum_i(b_i-a_i)^2}\\right)\n\\end{equation}\n\\begin{equation}\n P\\left(\\left|S_n - \\mathbb{E}\\left[S_n\\right]\\right| \\geq t \\right) \\leq 2\\exp\\left(-\\frac{2t^2}{\\sum_i(b_i-a_i)^2}\\right)\n\\end{equation}\nThe hoeffding lemma states that for a real-valued random variable $X$ with expected\nvalue $\\mathbb{E}[X] = 0$ and such that $a \\leq X \\leq b$, then for all\n$\\lambda \\in \\mathbb{R}$ we have,\n\\begin{equation}\n \\mathbb{E}[e^{\\lambda X}] \\leq \\exp\\left(\\frac{\\lambda^2(b-a)^2}{8}\\right)\n\\end{equation}\n", "meta": {"hexsha": "f6cc3280001a646b46b86edf65065604e41fa16d", "size": 15729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/prob_stat.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/prob_stat.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/prob_stat.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.7487046632, "max_line_length": 215, "alphanum_fraction": 0.6785555344, "num_tokens": 5854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104953173166, "lm_q2_score": 0.8902942333990422, "lm_q1q2_score": 0.8603896910773191}} {"text": "\\begin{solution}\n\\textbf{Part a) }The error\n\\begin{align*}\n\\left|\\frac{f(x+h)-f(x)}{h}-\\frac{fl(f(x+h))-fl(f(x))}{h}\\right|&=\\left|\\frac{f(x+h)-f(x)}{h}-\\frac{f(x+h)(1+\\delta_1)-f(x)(1+\\delta_2)}{h}\\right|\\\\\n&=\\left|-\\frac{f(x+h)\\delta_1-f(x)\\delta_2}{h}\\right|\\\\\n&\\leq\\left|\\frac{f(x+h)\\delta_1}{h}\\right|+\\left|\\frac{f(x)\\delta_2}{h}\\right|\\\\\n&<\\left|f(x+h)\\right|\\frac{\\epsilon}{h}+\\left|f(x)\\right|\\frac{\\epsilon}{h}\\\\\n&=\\left(\\left|f(x)+hf'(x)+\\mathcal{O}(h^2)\\right|+\\left|f(x)\\right|\\right)\\frac{\\epsilon}{h}\\\\\n&\\leq \\left(2\\left|f(x)\\right|+\\left|hf'(x)\\right|+\\left|\\mathcal{O}(h^2)\\right|\\right)\\frac{\\epsilon}{h}\\sim\\mathcal{O}\\left(\\frac{\\epsilon}{h}\\right),\n\\end{align*}\nis proportional to $\\epsilon/h$ in the worst case as $h\\rightarrow 0$.\n\n\\textbf{Part b)} We just proved that the rounding error is proportional to $\\epsilon/h$, then\n\\begin{align*}\ne_{\\delta}=k_1\\frac{\\epsilon}{h}.\n\\end{align*}\nOn the other hand, the truncation error is\n\\begin{align*}\ne_T=\\left|f'(x)-\\frac{f(x+h)-f(x)}{h}\\right|=k_2h,\n\\end{align*}\nsince it is a first order approximation. To minimize the total error\n\\begin{align*}\ne=e_{\\delta}+e_T=k_1\\frac{\\epsilon}{h}+k_2h,\n\\end{align*}\nwe just have to solve the optimization problem,\n\\begin{align*}\n\\frac{\\partial e}{\\partial h}=-k_1\\frac{\\epsilon}{h^2}+k_2=0,\n\\end{align*}\nwhich gives us $h^*=\\sqrt{\\frac{k_1}{k_2}\\epsilon}$. We check that it is indeed a minimum by checking that\n\\begin{align*}\n\\left.\\frac{\\partial^2e}{\\partial h^2}\\right|_{h=h^*}=\\frac{2k_1\\epsilon}{(h^*)^3}=\\frac{2k_1\\epsilon}{\\left(\\frac{k_1}{k_2}\\epsilon\\right)^{3/2}}>0.\n\\end{align*}\n\n\\textbf{Part c)} In equispaced finite difference methods of order $p$ the rounding error is\n\\begin{align*}\ne_{\\delta}&=\\left|\\sum_{j=0}^{p}\\frac{w_j}{h}f_j-\\sum_{j=0}^{p}\\frac{w_j}{h}f_j(1+\\delta_j)\\right|\\\\\n&=\\left|-\\sum_{j=0}^{p}\\frac{w_j}{h}f_j\\delta_j\\right|\\\\\n&<\\left|\\sum_{j=0}^{p}w_jf_j\\right|\\frac{\\epsilon}{h}=k_1\\frac{\\epsilon}{h},\n\\end{align*}\nand the truncation error of order $p$ is \n\\begin{align*}\ne_T=k_2h^p.\n\\end{align*}\nTo minimize the total error\n\\begin{align*}\ne=e_{\\delta}+e_T=k_1\\frac{\\epsilon}{h}+k_2h^p,\n\\end{align*}\nwe just have to solve the optimization problem,\n\\begin{align*}\n\\frac{\\partial e}{\\partial h}=-k_1\\frac{\\epsilon}{h^2}+pk_2h^{p-1}=0,\n\\end{align*}\nwhich gives us $h^*=\\left(p\\frac{k_1}{k_2}\\epsilon\\right)^{1/p+1}$. We check that it is indeed a minimum by checking that\n\\begin{align*}\n\\left.\\frac{\\partial^2e}{\\partial h^2}\\right|_{h=h^*}=\\frac{2k_1\\epsilon}{(h^*)^3}+p(p-1)k_2(h^*)^{p-2}=\\frac{2k_1\\epsilon}{\\left(p\\frac{k_1}{k_2}\\epsilon\\right)^{3/p+1}}+p(p-1)k_2\\left(p\\frac{k_1}{k_2}\\epsilon\\right)^{\\frac{p-2}{p+1}}>0.\n\\end{align*}\n\n\\textbf{Part d)} We are given the function $\\tan{(x)}$ and asked to approximate its derivative at $x_0=\\pi/3$. We can calculate it analytically,\n\\begin{align*}\nf'(x)=\\frac{1}{\\cos^2{x}},~~~~~f'(\\pi/3)=4.\n\\end{align*}\nWith the same procedure as in the previous problem, we have derived the following approximations and the leading error terms:\n\\begin{itemize}\n\\item First order:\n\\begin{align*}\nf'(x)=\\frac{f(x+h)-f(x)}{h}-\\frac{h}{2}f''(x)+\\mathcal{O}(h^2)\n\\end{align*}\n\\item Second order:\n\\begin{align*}\nf'(x)=\\frac{f(x+h)-f(x-h)}{2h}-\\frac{h^2}{6}f'''(x)+\\mathcal{O}(h^3)\n\\end{align*}\n\\item Fourth order:\n\\begin{align*}\nf'(x)=\\frac{2}{3}\\frac{f(x+h)-f(x-h)}{h}-\\frac{1}{12}\\frac{f(x+2h)-f(x-2h)}{h}+\\frac{4h^4}{5!}f^{(V)}(x)+\\mathcal{O}(h^5)\n\\end{align*}\n\\item Sixth order:\n\\begin{align*}\nf'(x)=15\\frac{f(x+h)-f(x-h)}{20h}-6\\frac{f(x+2h)-f(x-2h)}{40h}+\\frac{f(x+3h)-f(x-3h)}{60h}-\\frac{h^6}{140}f^{(VII)}(x)+\\mathcal{O}(h^7)\n\\end{align*}\n\\end{itemize}\nIn the next figure we can see, in logarithmic scale, the dependency of the truncation error on $h$ for every approximation. The lines are have slopes $1,2,4,6$ (from top to bottom) mathching its respective data. This proves the order of the truncation error for the four approximations considered. Note that the minimal error is achieved \"sooner\" (in the sense of not needing to reduce $h$ as much) for higher order approximations. In addition, we can check that once the rounding error is dominant, the dependency is the same for all the approximations. It cannot be any other way if we remember that $e_{\\delta}\\sim\\frac{\\epsilon}{h}$ regardless of the order of our approximation. We can check that this error would in fact have a slope of minus 1 in logarithmic scale, as we see in the figure.\n\\begin{figure}[H]\n\\centering %%% not \\center\n{\\includegraphics[scale=0.4]{IMAGES/problem3.eps}}\n\\caption{Error dependency on $h$ for the four different approximations.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\nformat long\nx_0=pi/3;\nf = @(x) tan(x);\nfp = @(x) (1/cos(x))^2;\nH=logspace(-1,-14,100);\nfor k = 1:length(H)\n h = H(k);\n df1(k) = (f(x_0+h)-f(x_0))/h;\n df2(k) = (f(x_0+h)-f(x_0-h))/(2*h);\n df4(k) = (-5/60*f(x_0+2*h)+2/3*f(x_0+h)-2/3*f(x_0-h)+5/60*f(x_0-2*h))/h;\n df6(k) = 0.1*(15*(f(x_0+h)-f(x_0-h))/(2*h)-6*(f(x_0+2*h)-f(x_0-2*h))/(4*h)\n +(f(x_0+3*h)-f(x_0-3*h))/(6*h));\nend\nfigure('units','normalized','outerposition',[0 0 1 1])\nloglog(H,abs(df1-fp(x_0)),'*',H,abs(df2-fp(x_0)),'*',H,abs(df4-fp(x_0)),'*',\n\t H,abs(df6-fp(x_0)),'*',H,H/2,'--',H,H.^(2)/6,'--',H,H.^(4)/30,'--',H,H.^6/140,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$h$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem3','epsc')\n\\end{verbatim}\n\n\\end{solution}", "meta": {"hexsha": "9613f46bcadbdb3dd7ca665f165fea9f6a314c78", "size": 5511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 1/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 1/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 1/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.6486486486, "max_line_length": 796, "alphanum_fraction": 0.6545091635, "num_tokens": 2209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.9343951689351065, "lm_q1q2_score": 0.8603814186646676}} {"text": "\\section{Principal Component Analysis}\nPrincipal Component Analysis is a dimension reduction technique that finds\nthe variance maximizing the directions onto which to project the data.\n\\subsection{Eigenvalues, Eigenvectors, and the Spectral Theorem}\nRecall that for a given matrix $A\\in \\mathbb{R}^{n \\times n}$, $\\lambda$ is said\nto be an eigenvalue of $A$ if there exists a vector\n$z \\in \\mathbb{R}^n \\backslash \\{ 0 \\}$, called an eigenvector, such that:\n\\begin{equation}\n Az=\\lambda z\n\\end{equation}\nThe spectral theorem states that given matrix $A\\in \\mathbb{R}^{n \\times n}$, if\n$A$ is symmetric then $A$ is diagonalizable by a real orthogonal matrix\n$U\\in \\mathbb{R}^{n \\times n}$. Note\n$\\Lambda = \\textrm{diag}(\\lambda_1, \\hdots, \\lambda_n)$. Then $\\exists \\, \\Lambda$\nsuch that:\n\\begin{equation}\n A=U\\Lambda U^T\n\\end{equation}\nNote that the eigenvector associated with the largest eigenvalue is called the\nprincipal eigenvector of matrix $A$.\n\\subsection{Algorithm}\nThe PCA procedure projects the data onto $k$ dimensions by maximizing the variance\nof the data as follows:\n\\begin{enumerate}\n \\item Normalize the data to have mean $0$, standard deviation $1$:\n \\begin{equation} x^{(i)}\\leftarrow\\frac{x^{(i)}-\\mu}{\\sigma} \\end{equation}\n where $\\mu$ and $\\sigma^2$ are:\n \\begin{equation} \\mu = \\frac{1}{m}\\sum_{i=1}^mx^{(i)} \\end{equation}\n \\begin{equation} \\sigma^2=\\frac{1}{m}\\sum_{i=1}^m(x^{(i)}-\\mu)^2 \\end{equation}\n \\item Compute covariance matrix $\\Sigma$, which is symmetric with real eigenvalues.\n \\begin{equation} \\Sigma = \\frac{1}{m}\\sum_{i=1}^m x^{(i)}x^{(i)^T} \\in \\mathbb{R}^{n \\times n} \\end{equation}\n \\item Compute $u_1, \\hdots, u_k \\in \\mathbb{R}^{n}$ the $k$ orthogonal principal\n eigenvectors of $\\Sigma$, i.e. the orthogonal eigenvectors of the $k$\n largest eigenvalues.\n \\item Project the data on $\\textrm{span}_\\mathbb{R}(u_1,...,u_k)$ to create\n a vector $y^{(i)}$ from point $x^{(i)}$:\n \\begin{equation} y^{(i)} = U^T x^{(i)} = \\left( \\begin{array} { c } { u _ { 1 } ^ { T } x ^ { ( i ) } } \\\\ { u _ { 2 } ^ { T } x ^ { ( i ) } } \\\\ { \\vdots } \\\\ { u _ { k } ^ { T } x ^ { ( i ) } } \\end{array} \\right) \\in \\mathbb { R } ^ { k } \\end{equation}\n\\end{enumerate}\nThis procedure maximizes the variance among all $k$-dimensional spaces.\n\\subsection{Algorithm: SVD}\nEigenvalue decomposition is deifned for square matricies, and using the SVD of a\ndata matrix $X$ is often used in practice.\n\\begin{enumerate}\n \\item Zero-mean the data to have mean $0$:\n \\begin{equation} x^{(i)}\\leftarrow x^{(i)}-\\mu \\end{equation}\n where $\\mu$ is:\n \\begin{equation} \\mu = \\frac{1}{m}\\sum_{i=1}^mx^{(i)} \\end{equation}\n \\item Computed the singular value decomposition of $X_{\\mu}$, our zero-meaned\n data matrix:\n \\begin{equation}\n X_{\\mu} = USV\n \\end{equation}\n \\item Take the first $k$ columns of $U$ as our transform matrix, denoted $U_k$.\n \\item Project the data to create a matrix $Y$ from data matrix $X_{\\mu}$:\n \\begin{equation} Y = X U_k\\end{equation}\n\\end{enumerate}\n", "meta": {"hexsha": "b406287b18df5ecb46b9a07456648845d1b8b97f", "size": 3058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/pca.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/pca.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/pca.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.649122807, "max_line_length": 260, "alphanum_fraction": 0.6635055592, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.9005297774417915, "lm_q1q2_score": 0.8602933267159396}} {"text": "\\section{Optimization Functions}\n\nThe functions in this section are models with analytic optimal points.\n\n\\subsection{General}\n\n\\subsubsection{Beale's Function}\nBeale's function has a two-dimensional input space and a single global/local minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n \\item Function: $f(x,y) = (1.5-x+xy)^2+(2.25-x+xy^2)^2+(2.625-x+xy^3)^2$\n \\item Domain: $-4.5 \\leq x,y \\leq 4.5$\n \\item Global Minimum: $f(3,0.5)=0$\n\\end{itemize}\n\n\n\\subsubsection{Rosenbrock Function}\nThe Rosenbrock function can take a varying number of inputs. For up to three inputs, a single global minimum\nexists. For four to seven inputs, there is one local minimum and one global maximum.\nSee \\url{https://en.wikipedia.org/wiki/Rosenbrock_function}.\n\n\\begin{itemize}\n \\item Function: $f(\\vec x) = \\sum_{i=1}^{n-1}\\left[100\\left(x_{i+1}-x_i^2\\right)^2+\\left(x_i-1)^2\\right) \\right]$\n \\item Domain: $ -\\infty \\leq x_i \\leq \\infty \\hspace{10pt} \\forall \\hspace{10pt} 1\\leq i \\leq n$\n \\item Global Minimum: $f(1,1,\\cdots,1,1)=0$\n \\item Local minimum ($n\\geq4$): near $f(-1,1,\\cdots,1)$\n\\end{itemize}\n\n\n\\subsubsection{Goldstein-Price Function}\nThe Goldstein-Price function is a two-dimensional input function with a single global minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n \\item Function:\n \\begin{align}\n f(x,y) =& \\left[1+(x+y+1)^2\\left(19-14x+3x^2-14y+6xy+3y^2\\right)\\right] \\\\ \\nonumber\n & \\cdot\\left[30+(2x-3y)^2(18-32x+12x^2+48y-36xy+27y^2)\\right]\n \\end{align}\n \\item Domain: $-2 \\leq x,y \\leq 2$\n \\item Global Minimum: $f(0,-1)=3$\n\\end{itemize}\n\n\\subsubsection{McCormick Function}\nThe McCormick function is a two-dimensional input function with a single global minimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n \\item Function: $f(x,y) = \\sin(x+y) + (x-y)^2 - 1.5x + 2.5y + 1$\n \\item Domain: $-1.5 \\leq x \\leq 4$, $-3 \\leq y \\leq 4$\n \\item Global Minimum: $f(-0.54719,-1.54719) = -1.9133$\n\\end{itemize}\n\n\n\\subsubsection{2D Canyon}\nThe two-dimensional canyon offers a low region surrounded by higher walls.\n\n\\begin{itemize}\n \\item Function: $f(x,y) = xy\\cos(x+y)$\n \\item Domain: $0 \\leq x,y \\leq \\pi$\n \\item Global Minimum: $f(1.8218,1.8218)=-2.90946$\n\\end{itemize}\n\n\n\n\n\\subsubsection{Time-Parabola}\nThis model features the sum of a parabola in both $x$ and $y$; however, the parabola in $y$ moves in time and\nhas a reduced magnitude as time increases. As such, the minimum is always found at $x=0$ and at $(t-y)=0$, with\n$y$ values at low $t$ being more impactful than at later $t$, and $x$ as impactful as $y(t=0)$.\n\n\\begin{itemize}\n \\item Function: $f(x,y,t) = x^2 + \\sum_{t} (t-y)^2 \\exp{-t}$\n \\item Domain: $-10 \\leq x,y,t \\leq 10$\n \\item Global Minimum: $f(0,y=t,t) = 0$\n\\end{itemize}\n\n\n\n\\subsection{Constrained}\n\\subsubsection{Mishra's Bird Function}\nThe Mishra bird function offers a constrained problem with multiple peaks, local minima, and one steep global\nminimum.\nSee \\url{https://en.wikipedia.org/wiki/Test_functions_for_optimization}.\n\n\\begin{itemize}\n \\item Function: $f(x,y) = \\sin(y)\\exp[1-\\cos(x)]^2 + \\cos(x)\\exp[1-\\sin(y)]^2 + (x-y)^2$\n \\item Constraint: $(x+5)^2 + (y+5)^2 < 25$\n \\item Domain: $-10 \\leq x \\leq 0$, $-6.5 \\leq y \\leq 0$\n \\item Global Minimum: $f(-3.1302468, -1.5821422) = -106.7645367$\n\\end{itemize}\n", "meta": {"hexsha": "3331cf5fad3819e6dd56854f2f22e6607b721ab3", "size": 3431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/optimization_functions.tex", "max_stars_repo_name": "mattdon/raven", "max_stars_repo_head_hexsha": "b5b4a9fc96cec37ca5fb3757c45653eec66522f1", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/tests/optimization_functions.tex", "max_issues_repo_name": "mattdon/raven", "max_issues_repo_head_hexsha": "b5b4a9fc96cec37ca5fb3757c45653eec66522f1", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/tests/optimization_functions.tex", "max_forks_repo_name": "mattdon/raven", "max_forks_repo_head_hexsha": "b5b4a9fc96cec37ca5fb3757c45653eec66522f1", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8924731183, "max_line_length": 115, "alphanum_fraction": 0.6863888079, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813463747182, "lm_q2_score": 0.8991213738910259, "lm_q1q2_score": 0.8595432615666293}} {"text": "\\section{Bayesian Statistics}\nBayesian inference conceptually amounts to weighting the likelihood $L_n(\\theta)$ by a prior knowledge we might have on $\\theta$.\nGiven a statistical model we technically model our parameter $\\theta$ as if it were a random variable. We therefore define the \\textbf{prior distribution} (PDF):\n\\begin{align*}\n\\pi(\\theta)\n\\end{align*}\nLet $X_1,...,X_n$. We note $L_n(X_1,...,X_n|\\theta)$ the joint probability distribution of $X_1,...,X_n$ conditioned on $\\theta$ where $\\theta \\sim \\pi$. This is exactly the likelihood from the frequentist approach.\n\\subsection{Bayes' formula}. \nThe {posterior distribution} verifies:\n\\begin{align*}\n\\forall \\theta \\in \\Theta, \\pi(\\theta|X_1,...,X_n) \\propto\\\\ \\pi(\\theta)L_n(X_1,...,X_n | \\theta)\n\\end{align*}\nThe constant is the normalization factor to ensure the result is a proper distribution, and does not depend on $\\theta$:\n\\begin{align*}\n\\pi(\\theta|X_1,...,X_n) = \\frac{\\pi(\\theta)L_n(X_1,...,X_n | \\theta)}{\\int_\\Theta\\pi(\\theta)L_n(X_1,...,X_n | \\theta)d\\theta}\n\\end{align*}\nWe can often use an \\textbf{improper prior}, i.e. a prior that is not a proper probability distribution (whose integral diverges), and still get a proper posterior. For example, the improper prior $\\pi(\\theta) = 1$ on $\\Theta$ gives the likelihood as a posterior.\n\\subsection{Jeffreys Prior}\n\\begin{align*}\n\\pi_J(\\theta) \\propto \\sqrt{det I(\\theta)}\n\\end{align*}\nwhere $I(\\theta)$ is the Fisher information. This prior is \\textbf{invariant by reparameterization}, which means that if we have $\\eta = \\phi(\\theta)$, then the same prior gives us a probability distribution for $\\eta$ verifying:\n\\begin{align*}\n\\tilde\\pi_J(\\eta) \\propto \\sqrt{det \\tilde I(\\eta)}\n\\end{align*}\nThe change of parameter follows the following formula:\n\\begin{align*}\n\\tilde\\pi_J(\\eta) = det(\\nabla \\phi^{-1}(\\eta)) \\pi_J(\\phi^{-1}(\\eta))\n\\end{align*}\n\\subsection{Bayesian confidence region}\nLet $\\alpha \\in (0, 1)$. A *Bayesian confidence region with level $\\alpha$* is a random subset $\\mathcal{R} \\subset \\Theta$ depending on $X_1,...,X_n$ (and the prior $\\pi$) such that:\n\\begin{align*}\nP[\\theta \\in \\mathcal{R} | X_1,...,X_n] \\geq 1 - \\alpha\n\\end{align*}\nBayesian confidence region and confidence interval are \\textbf{distinct notions}.The Bayesian framework can be used to estimate the true underlying parameter. In that case, it is used to build a new class of estimators, based on the posterior distribution.\n\\subsection{Bayes estimator}\n\n\\textbf{posterior mean}:\n\\begin{align*}\n\\hat{\\theta}_{(\\pi)} = \\int_\\Theta\\theta\\pi(\\theta | X_1,...,X_n)d\\theta\n\\end{align*}\n\\textbf{Maximum a posteriori estimator (MAP):}\n\\begin{align*}\n\\hat{\\theta}^{MAP}_{(\\pi)} = argmax_{\\theta\\in\\Theta}\\pi(\\theta | X_1,...,X_n)\n\\end{align*}\nThe MAP is equivalent to the MLE, if the prior is uniform.", "meta": {"hexsha": "44b00264745a7728a826f04cd70cbdaf8b53ccb8", "size": 2808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/bayesian.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/bayesian.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/bayesian.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 61.0434782609, "max_line_length": 263, "alphanum_fraction": 0.7179487179, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9852713878802045, "lm_q2_score": 0.8723473663814337, "lm_q1q2_score": 0.8594989003882765}} {"text": "\\lab{Applications}{Regression on a Circle}{Statistics 2}\n\\label{LeastSquaresCircle}\n\n\\objective{This section will introduce a more advanced application of Least Squares: fitting data to an circle.}\n\n\\section*{Fitting data to a circle}\n\nRecall that the equation of a circle, with radius $r$ centered at $(c_1,c_2)$, is given by\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nSuppose we are given a set of data points closely forming a circle $\\{(x_i,y_i)\\}^n_{i=1}$. The ``best'' fit is found via least squares by expanding \\eqref{circle} to get\n\\[\n2 c_1 x + 2 c_2 y + c_3 = x^2 + y^2,\n\\]\nwhere $c_3 = r^2 - c_1^2 - c_2^2$. Then we can write the linear system $A x = b$ as\n\\[\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix},\n\\]\nwhere the matrix $A$ and the vector $b$ are obtained by the given data and the unknown $x$ contains the information about the center and radius of the circle and is obtained by finding the least squares solution.\n\n\\section*{Example}\n\nIn this section, we fit the following points to a circle:\n\\begin{align*}\n&(134,76),(104,146),(34,176),(-36,146),\\\\\n&(-66,76),(-36,5),(34,-24),(104,5),(134,76)\n\\end{align*}\n\nWe enter them into Python as a $9\\times 2$ array:\n\\begin{lstlisting}[style=python]\n: P = sp.array([[134,76],[ 104,146],[ 34,176],[ -36,146],[ -66,76],[ -36,5],[ 34,-24],[ 104,5],[ 134,76]])\n\\end{lstlisting}\nThen we can separate the $x$ and $y$ coordinates by the commands \\li{P[:,0]} and \\li{P[:,1]}, respectively. Hence, we compute $A$ and $b$ by entering the following:\n\\begin{lstlisting}[style=python]\n: A = sp.column_stack((2*P,sp.ones((9,1),dtype=sp.int_)))\n: b = P[:,0]**2 + P[:,1]**2\n\\end{lstlisting}\nHence, we get the least squares solution\n\\begin{lstlisting}[style=python]\n: x = sp.dot(sp.dot(la.inv(sp.dot(A.T,A)),A.T),b)\n\\end{lstlisting}\nThen we find $c_1$, $c_2$, and $r$ by:\n\\begin{lstlisting}[style=python]\n: c1 = x[0]\n: c2 = x[1]\n: c3 = x[2]\n: r = sp.sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\nWe plot this by executing\n\\begin{lstlisting}[style=python]\n: theta = sp.linspace(0,2*sp.pi,200)\n: plt.plot(r*sp.cos(theta)+c1,r*sp.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n: plt.show()\n\\end{lstlisting}\n\n\n\\begin{problem}\nDownload the file lab10.txt from the following link:\n\\url{http://www.math.byu.edu/~jeffh/teaching/m343h/lab10.txt}\nYou can load this datafile into Python by typing\n\\begin{lstlisting}[style=python]\n: lab10 = sp.genfromtxt(\"lab10.txt\")\n\\end{lstlisting}\nNow the data is available in the matrix \\li{lab10}. This consists of two columns corresponding to the $x$ and $y$ values of a given data set. Use least squares to find the center and radius of the circle that best fits the data. Then plot the data points and the circle on the same graph. Finish off the problem with a discussion of what you've learned.\n\\end{problem}\n\n\\begin{problem}\nThe general equation for an ellipse is:\n\\[\nA(x-x_0)^2 + B(x-x_0)(y-y_0) + C(y-y_0)^2 = 1\n\\]\n\nWrite a program that uses least squares to fit data to an ellipse. One option to finding the center point $(x_0,y_0)$ is to use the mean function. Test the program on \\li{lab10}. Also test it against sp.dot(lab10,sp.array([[2,0],[0,1]]) ) . Plot the result. How well does your function work?\n\\end{problem}\n", "meta": {"hexsha": "3543084991ab0099a32b1501963d4313cd26dc26", "size": 3429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Statistics/Stats2_C.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/Statistics/Stats2_C.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/Statistics/Stats2_C.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 36.8709677419, "max_line_length": 357, "alphanum_fraction": 0.6818314377, "num_tokens": 1191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.9207896677397366, "lm_q1q2_score": 0.859493441230395}} {"text": "\n\\subsection{Single equality constraint}\n\n\\subsubsection{Constrained optimisation}\n\nRather than maximise \\(f(x)\\), we want to maximise \\(f(x)\\) subject to \\(g(x)=0\\).\n\nWe write this, the Lagrangian, as:\n\n\\(\\mathcal{L}(x,\\lambda )=f(x)-\\sum^m_k\\lambda_k [g_k(x)-c_k]\\)\n\nWe examine the stationary points for both vector \\(x\\) and \\(\\lambda \\). By including the latter we ensure that these points are consistent with the constraints.\n\n\\subsubsection{Solving the Langrangian with one constraint}\n\nOur function is:\n\n\\(\\mathcal{L}(x, \\lambda )=f(x)-\\lambda [g(x)-c]\\)\n\nThe first-order conditions are:\n\n\\(\\mathcal{L}_{\\lambda }= -[g(x)-c]\\)\n\n\\(\\mathcal{L}_{x_i}=\\dfrac{\\delta f}{\\delta x_i}-\\lambda \\dfrac{\\delta g}{\\delta x_i}\\)\n\nThe solution is stationary so:\n\n\\(\\mathcal{L}_{x_i}=\\dfrac{\\delta f}{\\delta x_i}-\\lambda \\dfrac{\\delta g}{\\delta x_i}=0\\)\n\n\\(\\lambda \\dfrac{\\delta g}{\\delta x_i}=\\dfrac{\\delta f}{\\delta x_i}\\)\n\n\\(\\lambda =\\dfrac{\\dfrac{\\delta f}{\\delta x_i}}{\\dfrac{\\delta g}{\\delta x_i}}\\)\n\nFinally, we can use the following in practical applications.\n\n\\(\\dfrac{\\dfrac{\\delta f}{\\delta x_i}}{\\dfrac{\\delta g}{\\delta x_i}}=\\dfrac{\\dfrac{\\delta f}{\\delta x_j}}{\\dfrac{\\delta g}{\\delta x_j}}\\)\n\n", "meta": {"hexsha": "5b57f226a2ac8e17af495da7941701a8d77984a5", "size": 1200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/02-01-equality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/02-01-equality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/02-01-equality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5789473684, "max_line_length": 161, "alphanum_fraction": 0.675, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.90192067257508, "lm_q1q2_score": 0.8591462959269901}} {"text": "\\section{Exercises in Characteristic Functions}\\label{S:xsCFs}% {S:xsExpectationsOfRVs} %S:xsMultivariateRVs\n\\begin{ExerciseList}\n%CF\n\\Exercise\nLet $X$ be a discrete random variable (RV) with probability mass function (PMF)\n\\[\nf_X(x) = \n\\begin{cases}\n\\frac{1}{3} & \\text{ if } x=0\\\\\n\\frac{1}{3} & \\text{ if } x=1\\\\\n\\frac{1}{3} & \\text{ if } x=2\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\n\\be\n\\item~Find the characteristic function (CF) of $X$\n\\item~Using the CF find $V(X)$, the variance of $X$. {Hint: $V(X)=E(X^2)-(E(X))^2$}\n\\ee\n\n\\Answer\n~\\\\\n\\be\n\\item~The CF of the discrete RV $X$ is\n\\begin{align*}\n\\cf_X(t) \n&= E(e^{\\imath t X}) = \\sum_{x\\in\\{0,1,2\\}} e^{\\imath t x} f_X(x)\n= e^{\\imath t \\times 0} \\times \\frac{1}{3} + e^{\\imath t \\times 1} \\times \\frac{1}{3}+e^{\\imath t \\times 2} \\times \\frac{1}{3}\\\\\n&= \\frac{1}{3} \\left(1+e^{\\imath t} + e^{\\imath 2 t}\\right) \\enspace .\n\\end{align*}\n\n\\item~To find $V(X)$ using $V(X)=E(X^2)-(E(X))^2$ we need the first two moments of $X$. First, differentiate $\\cf_X(t)$ w.r.t.~$t$\n\\begin{align*}\n\\frac{d}{dt}\\cf_X(t)\n= \\frac{d}{dt} \\left( \\frac{1}{3} \\left(1+e^{\\imath t} + e^{\\imath 2 t}\\right) \\right)\n= \\frac{1}{3} \\left(0+ \\imath e^{\\imath t} + 2 \\imath e^{\\imath 2 t} \\right)\n= \\frac{\\imath}{3} \\left(e^{\\imath t} + 2 e^{\\imath 2 t} \\right)\n\\end{align*}\nWe get the $k$-th moment $E(X^k)$ by multiplying the $k$-th derivative of $\\cf_X(t)$ evaluated at $t=0$ by $\\frac{1}{\\imath^k}$ as follows:\n\\begin{align*}\nE(X) \n= \\frac{1}{\\imath} \\left[ \\frac{d}{dt}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath} \\left[ \\frac{\\imath}{3} \\left(e^{\\imath t} + 2 e^{\\imath 2 t} \\right)\\right]_{t=0} \n= \\frac{1}{\\imath} \\frac{\\imath}{3} \\left(e^0+2e^0\\right) = \\frac{1}{3}(1+2)=1 \\enspace .\n\\end{align*}\n\\begin{align*}\nE(X^2) \n&= \\frac{1}{\\imath^2} \\left[ \\frac{d^2}{dt^2}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\frac{\\imath}{3} \\left(e^{\\imath t} + 2 e^{\\imath 2 t} \\right) \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left[ \\frac{\\imath}{3} \\left(\\imath e^{\\imath t} + 4 \\imath e^{\\imath 2 t} \\right) \\right]_{t=0}\\\\\n& = \\frac{1}{3} \\left(e^0 + 4 e^0\\right) = \\frac{5}{3} \\enspace .\n\\end{align*}\nFinally,\n\\[\nV(X) = E(X^2)-(E(X))^2 = \\frac{5}{3} - 1^2 = \\frac{5-3}{3}=\\frac{2}{3} \\enspace .\n\\] \n\\ee\n\n\\Exercise\nRecall that the $\\geometric(\\theta)$ RV $X$ has the following PMF\n\\[\nf_X(x;\\theta) = \n\\begin{cases}\n\\theta (1-\\theta)^x & \\text{ if } x \\in \\{0,1,2,3,\\ldots\\}\\\\\n0 & \\text{ otherwise}\n\\end{cases}\n\\]\n\\be\n\\item~Find the CF of $X$. (Hint: the sum of the infinite geometric series $\\sum_{x=0}^{\\infty} a r^x = \\frac{a}{1-r}$.)\n\\item~Using the CF find $E(X)$.\n\\ee\n\\Answer\n~\\\\\n\\be\n\\item~\n\\[\n\\cf_X(t) = E \\left(e^{\\imath t X}\\right) = \\sum_{x=0}^{\\infty} e^{\\imath t x}\\theta(1-\\theta)^x\n= \\sum_{x=0}^{\\infty} \\theta \\left(e^{\\imath t} (1-\\theta)\\right)^x = \\frac{\\theta}{1-e^{\\imath t} (1-\\theta)} \\enspace .\n\\]\nThe last equality is due to $\\sum_{x=0}^{\\infty} a r^x = \\frac{a}{1-r}$ with $a=\\theta$ and $r=e^{\\imath t} (1-\\theta)$.\n\\item~\n\\begin{align*}\nE(X)\n&= \\frac{1}{\\imath} \\left[ \\frac{d}{dt} \\left( \\frac{\\theta}{1-e^{\\imath t}(1-\\theta)} \\right) \\right]_{t=0} \n= \\frac{1}{\\imath} \\theta \\left[ \\frac{d}{dt} \\left( \\left(1-e^{\\imath t}(1-\\theta)\\right)^{-1} \\right) \\right]_{t=0} \\\\\n&= \\frac{1}{\\imath} \\theta \\left[ -\\left(1-e^{\\imath t} (1-\\theta)\\right)^{-2} \\frac{d}{dt} \\left( 1-e^{\\imath t}(1-\\theta)\\right) \\right]_{t=0}\\\\ \n&= \\frac{1}{\\imath} \\theta \\left[ -\\left(1-e^{\\imath t} (1-\\theta)\\right)^{-2} \\left( 0-\\imath e^{\\imath t}(1-\\theta)\\right) \\right]_{t=0}\\\\\n&= \\frac{1}{\\imath} \\theta \\left( -\\left(1-e^{0} (1-\\theta)\\right)^{-2} \\left( -\\imath e^{0}(1-\\theta)\\right) \\right)\\\\ \n&= \\frac{1}{\\imath} \\theta \\left( -\\left(1- 1+\\theta\\right)^{-2} \\left( -\\imath (1-\\theta)\\right) \\right)\\\\\n&=\\frac{1-\\theta}{\\theta} \\enspace .\n\\end{align*}\n\\ee\n\n\\Exercise\nLet $X$ be the $\\uniform(a,b)$ RV with the following probability density function (PDF)\n\\[\nf_X(x; a,b) = \n\\begin{cases}\n\\frac{1}{b-a} & \\text{ if } x \\in [a,b] \\\\\n0 & \\text{ otherwise} \\enspace.\n\\end{cases}\n\\]\nFind the CF of $X$.\n\\Answer\n~\\\\\n\\begin{align*}\n\\cf_X(t) \n&= E\\left( e^{\\imath t X} \\right) \n= \\int_{-\\infty}^{\\infty} e^{\\imath t x} f_X(x;a,b) dx\n= \\int_{a}^{b} e^{\\imath t x} \\frac{1}{b-a} dx\n= \\frac{1}{b-a} \\int_{a}^{b} e^{\\imath t x} dx\n= \\frac{1}{b-a} \\left[ \\frac{e^{\\imath t x}}{\\imath t} \\right]_{x=a}^b\\\\\n&= \\frac{1}{(b-a)\\imath t} \\left( e^{\\imath t b} - e^{\\imath t a}\\right) \\enspace .\n\\end{align*}\n\n\\Exercise\n%\\vspace{0.5cm}\n\n%A nice property of CFs we will use for some of the exercises below is the following. If $X_1,X_2,\\ldots,X_n$ are independent RVs and $a_1,a_2,\\ldots,a_n$ are some constants, then the CF of the linear combination $Y=\\sum_{i=1}^n a_i X_i$ is\n%\\begin{equation}\\label{E:LinCombCFtut}\n%\\cf_Y (t) = \\cf_{X_1} (a_1 t) \\times \\cf_{X_2} (a_2 t) \\times \\cdots \\times \\cf_{X_n} (a_n t) = \\prod_{i=1}^n \\cf_{X_i} (a_i t) \\enspace .\n%\\end{equation}\n\nRecall that the $\\poisson(\\lambda)$ RV has the following PMF\n\\[\nf_X(x;\\lambda) = \n\\begin{cases}\n\\frac{\\lambda^x}{x!}e^{-\\lambda} & \\text{ if } x \\in \\{0,1,2,3,\\ldots \\}\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\n{Hint: the power series of $e^{\\alpha} = \\sum_{x=0}^{\\infty} \\frac{\\alpha^x}{x!}$.}\n\\be\n\\item~\nFind the CF of $X$.\n\\item~\nFind the variance of $X$ using its CF.\n\\ee\n\\Answer\n~\\\\\n\\be\n\\item~\n\\[\n\\cf_X(t) = E\\left(e^{\\imath t X}\\right)\n= \\sum_{x=0}^{\\infty} e^{\\imath t x} \\frac{\\lambda^x}{x!}e^{-\\lambda}\n= e^{-\\lambda} \\sum_{x=0}^{\\infty} \\frac{e^{\\imath t x} \\lambda^x}{x!}\n= e^{-\\lambda} \\sum_{x=0}^{\\infty} \\frac{\\left(\\lambda e^{\\imath t}\\right)^x}{x!}\n= e^{-\\lambda} e^{\\lambda e^{\\imath t}} = e^{\\lambda e^{\\imath t} - \\lambda} \\enspace .\n\\]\nThe second-last equality above is using $e^{\\alpha} = \\sum_{x=0}^{\\infty} \\frac{\\alpha^x}{x!}$ with $\\alpha=\\lambda e^{\\imath t}$.\n\\item~\nTo find $V(X)$ using $\\cf_X(t)$ we need $E(X)$ and $E(X^2)$.\n\\begin{align*}\nE(X) \n&= \\frac{1}{\\imath} \\left[ \\frac{d}{dt} \\cf_X(t) \\right]_{t=0}\n= \\frac{1}{\\imath} \\left[ \\frac{d}{dt} e^{\\lambda e^{\\imath t} - \\lambda} \\right]_{t=0}\n= \\frac{1}{\\imath} \\left[ e^{\\lambda e^{\\imath t} - \\lambda} \\frac{d}{dt} \\left(\\lambda e^{\\imath t} - \\lambda \\right) \\right]_{t=0}\\\\\n&= \\frac{1}{\\imath} \\left[ e^{\\lambda e^{\\imath t} - \\lambda} \\lambda \\imath e^{\\imath t} \\right]_{t=0}\n= \\frac{1}{\\imath} \\left( e^{\\lambda - \\lambda} \\lambda \\imath \\right)\n= \\frac{1}{\\imath} \\left( \\lambda \\imath \\right) = \\lambda \\enspace .\n\\end{align*}\n\\begin{align*}\nE(X^2) \n&= \\frac{1}{\\imath^2} \\left[ \\frac{d^2}{dt^2} \\cf_X(t) \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\left( e^{\\lambda e^{\\imath t} - \\lambda} \\lambda \\imath e^{\\imath t} \\right) \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\left( \\lambda \\imath e^{\\lambda e^{\\imath t} - \\lambda + \\imath t} \\right) \\right]_{t=0}\\\\\n&= \\frac{1}{\\imath^2} \\left[ \\lambda \\imath e^{\\lambda e^{\\imath t} - \\lambda + \\imath t} \\frac{d}{dt} \\left( \\lambda e^{\\imath t} - \\lambda + \\imath t \\right) \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left[ \\lambda \\imath e^{\\lambda e^{\\imath t} - \\lambda + \\imath t} \\left( \\lambda \\imath e^{\\imath t} - 0 + \\imath \\right) \\right]_{t=0}\\\\\n&= \\frac{1}{\\imath^2} \\left( \\lambda \\imath e^{\\lambda e^{0} - \\lambda + 0} \\left( \\lambda \\imath e^{0} + \\imath \\right) \\right)\n= \\frac{1}{\\imath^2} \\left( \\lambda \\imath \\left( \\lambda \\imath + \\imath \\right) \\right)\n= \\frac{1}{\\imath^2} \\left( \\lambda \\imath^2 \\left( \\lambda + 1 \\right) \\right)\n= \\lambda^2 + \\lambda \\enspace .\n\\end{align*}\nFinally,\n\\[\nV(X) = E(X^2) - (E(X))^2 = \\lambda^2 + \\lambda - \\lambda^2 = \\lambda \\enspace .\n\\]\n\\ee\n\n\\Exercise\nLet $X$ be a $\\poisson(\\lambda)$ RV and $Y$ be another $\\poisson(\\mu)$ RV. \nSuppose $X$ and $Y$ are independent.\nUse Eqn.~\\eqref{E:LinCombCF} to first find the CF of the RV $W=X+Y$. \nFrom the CF of $W$ try to identify what RV it is. \n\n\\Answer\n~\\\\\n\\[\n\\cf_{W}(t) = \\cf_{X+Y}(t) = \\cf_X(t) \\times \\cf_Y(t) \n= e^{\\lambda e^{\\imath t}-\\lambda} \\times e^{\\mu e^{\\imath t}-\\mu}\n= e^{\\lambda e^{\\imath t}-\\lambda + \\mu e^{\\imath t}-\\mu} \n= e^{(\\lambda+\\mu) e^{\\imath t} -(\\lambda+\\mu)} \\enspace . \n\\]\nSo, $W$ is a $\\poisson(\\lambda+\\mu)$ RV. Thus the sum of two independent Poisson RVs is also a Poisson RV with parameter given by the sum of the parameters of the two RVs being added. The same idea generalizes to the sum of more than two Poisson RVs. \n\n\\Exercise\nRecall from lecture that if $Y=a+bX$ for some constants $a$ and $b$ with $b\\neq 0$ then $\\cf_Y(t) = e^{\\imath a t} \\cf_X(bt)$ and that $\\cf_Z(t)=e^{-t^2/2}$ if $Z$ is the $\\normal(0,1)$ RV. \nUsing these facts find the CF of $-Z$, the RV obtained from $Z$ by simply switching its sign.\nFrom the CF of $-Z$ identify what RV it is.\n\\Answer\n~\\\\\nWe can use the facts by noting $Y=-Z = 0 + (-1) \\times Z$, with $a=0$ and $b=-1$ in $Y=a+bX$ and get\n\\[\n\\cf_{Y}(t) = e^{\\imath \\times 0 \\times t} \\cf_Z(-1 \\times t) = \\cf_Z(-t) = e^{-((-1 \\times t))^2/2} = e^{-t^2/2} = \\cf_Z(t)\n\\]\nThus, $\\cf_{-Z}(t) = \\cf_Z(t)$ and therefore the distributions of $Z$ and $-Z$ are the same. This should make sense because by switching signs of a symmetric (about $0$) RV you have not changed its distribution! Note: we are not saying $Z=-Z$ but just that their distibutions are the same, i.e., $F_Z(z) = F_{-Z}(z)$ for every $z \\in \\Rz$.\n\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "3c823b3bcb6e4aab4ff423baa9c940974b350987", "size": 9291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInCharacteristicFunctions.tex", "max_stars_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_stars_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-19T07:54:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:55:18.000Z", "max_issues_repo_path": "matlab/csebook/ExsInCharacteristicFunctions.tex", "max_issues_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_issues_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/csebook/ExsInCharacteristicFunctions.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 44.4545454545, "max_line_length": 340, "alphanum_fraction": 0.5898181035, "num_tokens": 4109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870767, "lm_q2_score": 0.907312215721497, "lm_q1q2_score": 0.8588587195000911}} {"text": "\n\\subsection{Pearson correlation coefficient}\n\nThe Pearson correlation coefficient is definited as the covariance normalised by the individual variances.\n\nIt is between \\(-1\\) (total negative linear correlation), \\(0\\) (no linear correlation) and \\(1\\) (total negative linear correlation). \n\n\\(p_{X,Y}=\\dfrac{cov (X,Y)}{\\sigma_X\\sigma_Y}\\)\n\n", "meta": {"hexsha": "b46e21921b8e2844a4a4561f85bc1f7526ee73f1", "size": 341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summaryMultiple/02-01-pearson.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/summaryMultiple/02-01-pearson.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/summaryMultiple/02-01-pearson.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1, "max_line_length": 135, "alphanum_fraction": 0.7478005865, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9678992969868543, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.8587247054289542}} {"text": "\\subsubsection{Euler's Identity}\r\n\\noindent\r\nLet's see what happens when we look at the Maclaurin series for $e^{ix}$.\r\n\\begin{equation*}\r\n\te^{ix} = 1 + (ix) + \\frac{(ix)^2}{2!} + \\frac{(ix)^3}{3!} + \\frac{(ix)^4}{4!} + \\frac{(ix)^5}{5!} \\ldots\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= 1 + ix - \\frac{x^2}{2!} - i\\frac{x^3}{3!} + \\frac{x^4}{4!} + i\\frac{x^5}{5!} - \\ldots\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= \\left(1 - \\frac{x^2}{2!} + \\frac{x^4}{4!} - \\ldots \\right) + i\\left(x - \\frac{x^3}{3!} + \\frac{x^5}{5!} - \\ldots \\right)\r\n\\end{equation*}\r\nThe two expressions in parenthesis are exactly the Maclaurin series for $\\cos{x}$ and $\\sin{x}$. So,\r\n\\begin{equation*}\r\n\te^{ix} = \\cos{x} + i\\sin{x}\r\n\\end{equation*}\r\nIn the case that $x = \\pi$,\r\n\\begin{equation*}\r\n\te^{i\\pi} = \\cos{\\pi} + i\\sin{\\pi} = -1 + 0\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\te^{i\\pi} + 1 = 0\r\n\\end{equation*}\r\n", "meta": {"hexsha": "e7ba95518da7d16ed017e139c4bd12d2c05cdadc", "size": 888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/singleVariableCalc/eulersIdentity.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/singleVariableCalc/eulersIdentity.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/singleVariableCalc/eulersIdentity.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.52, "max_line_length": 124, "alphanum_fraction": 0.5630630631, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.9086178969328287, "lm_q1q2_score": 0.8586391019332281}} {"text": "\\subsubsection{Sphere Volume}\r\n\\noindent\r\nSince a sphere of radius $R$ is spherically symmetric, it should be simple to find its volume using spherical coordinates.\r\n\\begin{align*}\r\n\tV &= \\int_{0}^{R}{\\int_{0}^{\\pi}{\\int_{0}^{2\\pi}{\\rho^2\\sin{\\phi}\\mathrm{d}\\theta}\\mathrm{d}\\phi}\\mathrm{d}\\rho}\t\\\\\r\n\t&= \\int_{0}^{R}{\\rho^2\\mathrm{d}\\rho} \\cdot \\int_{0}^{\\pi}{\\sin{\\phi}\\mathrm{d}\\phi} \\cdot \\int_{0}^{2\\pi}{\\mathrm{d}\\theta} \\\\\r\n\t&= \\frac{R^3}{3} \\cdot 2 \\cdot 2\\pi \\\\\r\n\t&= \\frac{4\\pi}{3}R^3\r\n\\end{align*}", "meta": {"hexsha": "6d721bfce276fe62b98f0b7ddc7bb2f2b6d5495f", "size": 506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/sphereVolume.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/sphereVolume.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/sphereVolume.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 56.2222222222, "max_line_length": 129, "alphanum_fraction": 0.6205533597, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542887603538, "lm_q2_score": 0.8947894555814343, "lm_q1q2_score": 0.8582411438584748}} {"text": "\\section{Calculus}\n\n\\subsection{Derivative}\n\n$d(f,x)$ returns the derivative of $f$ with respect to $x$.\nThe $x$ can be omitted for expressions in $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nd(x^2)\n\\end{verbatim}\n}\n\n\\noindent\n$2x$\n\n\\bigskip\n\\noindent\nThe following table summarizes the various ways to obtain multi-derivatives.\n\n\\begin{center}\n\\begin{tabular}{cllllll}\n$\\displaystyle{\\frac{\\partial^2f}{\\partial x^2}}$ & & \\verb$d(f,x,x)$ & & \\verb$d(f,x,2)$ \\\\\n\\\\\n$\\displaystyle{\\frac{\\partial^2f}{\\partial x\\,\\partial y}}$ & & \\verb$d(f,x,y)$ \\\\\n\\\\\n$\\displaystyle{\\frac{\\partial^{m+n+\\cdot\\cdot\\cdot} f}{\\partial x^m\\,\\partial y^n\\cdots}}$ & &\n\\verb$d(f,x,...,y,...)$ & & \\verb$d(f,x,m,y,n,...)$ \\\\\n\\end{tabular}\n\\end{center}\n\n\\subsection{Gradient}\n\nThe gradient of $f$ is obtained by using a vector for $x$ in $d(f,x)$.\n\n{\\color{blue}\n\\begin{verbatim}\nr = sqrt(x^2 + y^2)\nd(r,(x,y))\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}\\frac{x}{(x^2+y^2)^{1/2}}\\\\ \\frac{y}{(x^2+y^2)^{1/2}}\\end{bmatrix}$\n\n\\bigskip\n\\noindent\nThe $f$ in $d(f,x)$ can be a tensor function.\nGradient raises the rank by one.\n\n{\\color{blue}\n\\begin{verbatim}\nF = (x + 2 y,3 x + 4 y)\nX = (x,y)\nd(F,X)\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}1&2\\\\3&4\\end{bmatrix}$\n\n\\subsection{Template functions}\n\nThe function $f$ in $d(f)$ does not have to be defined.\nIt can be a template function with just a name and an argument list.\nEigenmath checks the argument list to figure out what to do.\nFor example, $d(f(x),x)$ evaluates to itself because $f$ depends on $x$.\nHowever, $d(f(x),y)$ evaluates to zero because $f$ does not depend on $y$.\n\n{\\color{blue}\n\\begin{verbatim}\nd(f(x),x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\operatorname{d}(f(x),x)$\n\n{\\color{blue}\n\\begin{verbatim}\nd(f(x),y)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n{\\color{blue}\n\\begin{verbatim}\nd(f(x,y),y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\operatorname{d}(f(x,y),y)$\n\n{\\color{blue}\n\\begin{verbatim}\nd(f(),t)\n\\end{verbatim}\n}\n\n\\noindent\n$\\operatorname{d}(f(),t)$\n\n\\bigskip\n\\noindent\nAs the final example shows, an empty argument list causes\n$d(f)$ to always evaluate to itself, regardless\nof the second argument.\n\n\\bigskip\n\\noindent\nTemplate functions are useful for experimenting with differential forms.\nFor example, let us check the identity\n$$\\operatorname{div}(\\operatorname{curl}{F})=0$$\nfor an arbitrary vector function $F$.\n\n{\\color{blue}\n\\begin{verbatim}\nF = (F1(x,y,z),F2(x,y,z),F3(x,y,z))\ncurl(U) = (d(U[3],y) - d(U[2],z),d(U[1],z) - d(U[3],x),d(U[2],x) - d(U[1],y))\ndiv(U) = d(U[1],x) + d(U[2],y) + d(U[3],z)\ndiv(curl(F))\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n", "meta": {"hexsha": "3ee5f7f2623091624695571b64befe8cef662c20", "size": 2568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/derivative.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/derivative.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/derivative.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 19.7538461538, "max_line_length": 94, "alphanum_fraction": 0.6503115265, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799451753696, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.8580477204418374}} {"text": "\\section{Linear equations}\n\\subsection{Linear and affine functions}\n\\textbullet Superposition condition:$f(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)$\\\\\n\\textbullet Such an f is called Linear\\\\\n\\textbf{Matrix vector product function}:\\\\\n\\textbullet A is $m \\times n$ matrix such that $f(x)=Ax$\\\\\n\\textbullet f is linear: $f(\\alpha x + \\beta y)=A(\\alpha x + \\beta y)=\\alpha f(x) + \\beta f(y)$\\\\\n\\textbullet Converse is true: If $f:R^{n} \\mapsto R^{m}$ is linear, then \\\\\n$f(x)=f(x_{1}e_{1}+x_{2}e_{2}+...x_{n}e_{n})$\\\\\n$=x_{1}f(e_{1})+x_{2}f(e_{2})+...x_{n}f(e_{n})$\n$=Ax$ with $A = [f(e_{1})+f(e_{2})+...f(e_{n})]$\n\\newline \\textbf{Affine Functions}: $f:R^{n} \\mapsto R^{m}$ is affine if it is a linear function plus a constant i.e $f(x)=Ax+b$ same as $f(\\alpha x + \\beta y)=\\alpha f(x)+\\beta f(y)$ holds for all x, y and $\\alpha,\\beta$ such that $\\alpha+\\beta=1$ \n\\newline A and b can be calculated as \\\\\n$A=[f(e_{1})-f(0)\\thickspace f(e_{2})-f(0) ... f(e_{n})-f(0)]] ; $\\\\\n$b= f(0)$\\\\\n\\textbullet Affine functions sometimes incorrectly called linear functions\n\\subsection{Linear function models}\nPrice elasticity of demand\n$\\delta_i^{price}=(p_i^{new}-p_{i})/p_{i}$: fractional changes in prices\n$\\delta_i^{dem}=(d_i^{new}-d_{i})/d_{i}$: fractional change in demand\nPrice demand elasticity model: $\\delta^{dem}=E\\delta^{price}$\\\\\n\\textbf{Taylor series approximation}\\\\\n\\textbullet The (first-order) Taylor approximation of f near (or at) the point z:\\\\\n\\begin{scriptsize}\n$\\hat{f}(x)= f(z) + \\frac{\\partial f}{\\partial x_1}(z)(x_1 - z_1) + ... + \\frac{\\partial f}{\\partial x_n}(z)(x_n - z_n)$\n\\end{scriptsize}\\\\\n\\textbullet in compact notation: \\\\$\\hat{f}(x) = f (z) + Df (z)(x - z)$\n\\subsection{Systems of linear equations}\n\\textbullet set (or system) of m linear equations in n variables $x_1,.., x_n$: \\\\\n$A_{11}x_1 + A_{12}x_2 + ... + A_{1n}x_n = b_1$\\\\\n$A_{21}x_1 + A_{22}x_2 + ... + A_{2n}x_n = b_2$\\\\\n.\\\\\n.\\\\\n$A_{m1}x_1 + A_{m2}x_2 + ... + A_{mn}x_n = b_m$\\\\\n\n\\textbullet \\textbf{systems of linear equations classified as}\\\\\n\\thickspace -- under-determined if m < n (A wide)\\\\\n\\thickspace -- square if m = n (A square)\\\\\n\\thickspace -- over-determined if m > n (A tall)\\\\", "meta": {"hexsha": "07fb8e2c5c694cda1ee6b4ef3682ed8f9690df75", "size": 2187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.0769230769, "max_line_length": 249, "alphanum_fraction": 0.638774577, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811641488385, "lm_q2_score": 0.8887588023318196, "lm_q1q2_score": 0.8579910072426193}} {"text": "\\subsection{Higher Order to System}\r\n\\noindent\r\nLet's say we have the linear, $n^{th}$ order differential equation\r\n\\begin{equation*}\r\n\ta_ny^{(n)} + \\ldots + a_0y = f\r\n\\end{equation*}\r\nwhere $a_0, \\ldots a_n$ and $f$ are functions.\\\\\r\n\r\n\\noindent\r\nIf we let $x_1 = y, x_2 = y', \\ldots x_n = y^{(n-1)}$, then we have a system of equations,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' &= y' = x_2 \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_{n-1}' &= y^{(n-1)} = x_n \\\\\r\n\t\tx_n' &= y^{(n)} = \\frac{1}{a_n}\\left(f - a_{n-1}x_n - \\ldots - a_0x_1\\right)\r\n\t\\end{cases}\r\n\\end{equation*}\r\nRewriting in matrix form,\r\n\\begin{equation*}\r\n\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t0 & 1 & 0 & \\ldots & 0 \\\\\r\n\t\t0 & 0 & 1 & \\ldots & 0 \\\\\r\n\t\t\\vdots & \\vdots\t& \\vdots & \\ddots & \\vdots \\\\\r\n\t\t0 & 0 & 0 & \\ldots & 1 \\\\\r\n\t\t\\frac{-a_0}{a_n} & \\frac{-a_1}{a_n} & \\frac{-a_2}{a_n} & \\ldots & \\frac{-a_{n-1}}{a_n} \r\n\t\\end{bmatrix} \\vec{x} + \\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t\\vdots \\\\\r\n\t\t0 \\\\\r\n\t\t\\frac{f}{a_n}\r\n\t\\end{bmatrix}\r\n\\end{equation*}\r\nThe square matrix has characteristic polynomial $p(\\lambda) = \\frac{(-1)^{n}}{a_n}\\left(a_n\\lambda^n + a_{n-1}\\lambda^{n-1} + \\ldots + a_0\\right)$ which has the same zeroes as the the auxiliary equation $a_nr^n + \\ldots + a_0$.\\\\\r\n\r\n\\noindent\r\nNote that if one starts with a higher order equation, converts it to a system, and the converts the system back to a higher order equation, the result is the original equation. This does not hold true when converting a system to an equation and back to a system. The two solutions will have the same eigenvalues but different eigenvectors.", "meta": {"hexsha": "cee8dfd5adc6be2b3a7d57015112686b8f38df66", "size": 1562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/higherOrderToSystem.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/higherOrderToSystem.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/higherOrderToSystem.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2162162162, "max_line_length": 339, "alphanum_fraction": 0.6229193342, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357702, "lm_q2_score": 0.9284088000602381, "lm_q1q2_score": 0.857981405930687}} {"text": "\\section{Expectation}\n\n$\\mathbb{E}\\left[X\\right]=\\int_{-inf}^{+inf}{x \\cdot f_X\\left(x\\right)\\ \\ dx}$\\\\\n\n$\\mathbb{E}\\left[g\\left(X\\right)\\right]=\\int_{-inf}^{+inf}{g\\left(x\\right) \\cdot f_X\\left(x\\right)dx}$\\\\\n\n$\\mathbb{E}\\left[X\\middle| Y=y\\right]=\\int_{-inf}^{+inf}{x \\cdot { f}_{X|Y}\\left(x|y\\right)\\ \\ dx}$\\\\\n\nIntegration limits only have to be over the support of the pdf. Discrete r.v. same as continuous but with sums and pmfs.\\\\\n\nTotal expectation theorem:\\\\\n\n$\\mathbb{E}\\left[X\\right]=\\int_{-inf}^{+inf}{f_Y\\left(y\\right)\\cdot\\mathbb{E}\\left[X\\middle| Y=y\\right]dy}$\\\\\n\nLaw of iterated expectation:\\\\\n\n$\\mathbb E[Y] = \\mathbb E[\\mathbb E[Y\\rvert {X}]]$\\\\\n\nExpectation of constant $a$:\\\\\n\n$\\mathbb{E}[a] = a$\\\\\n\nProduct of \\textbf{independent} r.vs $X$ and $Y$ :\\\\\n\n$\\mathbb{E}[X \\cdot Y] = \\mathbb{E}[X] \\cdot \\mathbb{E}[Y]$\\\\\n\nProduct of \\textbf{dependent} r.vs $X$ and $Y$ :\\\\\n\n$\\mathbb{E}[X \\cdot Y] \\neq \\mathbb{E}[X] \\cdot \\mathbb{E}[Y]$\\\\\n\n$\\mathbb{E}[X \\cdot Y] = \\mathbb{E}[\\mathbb{E}[Y \\cdot X|Y]] = \\mathbb{E}[Y \\cdot \\mathbb{E}[X|Y]]$\\\\\n\nLinearity of Expectation where $a$ and $c$ are given scalars:\\\\\n\n$\\mathbb{E}[aX + c Y] = a\\mathbb{E}[X] + c\\mathbb{E}[Y]$\\\\\n\nIf Variance of $X$ is known:\\\\\n\n$\\mathbb{E}[X^2] = var(X) - \\mathbb{E}[X]$\\\\\n\n\n\\section{Variance}\n\nVariance is the squared distance from the mean.\\\\\n\n$Var(X)=\\mathbb{E}[(X-\\mathbb{E}(X))^2]$\\\\\n\n$Var\\left(X\\right)=\\mathbb{E}\\left[X^2\\right]-\\left(\\mathbb{E}\\left[X\\right]\\right)^2$\\\\\n\nVariance of a product with constant $a$:\\\\\n\n$Var(aX)=a^2 Var\\left(X\\right)$\\\\\n\nVariance of sum of two \\textbf{dependent} r.v.:\\\\\n\n$Var(X + Y)=Var(X)+Var(Y)+2Cov(X,Y)$\\\\\n\nVariance of sum/difference of two \\textbf{independent} r.v.:\\\\\n\n$Var(X + Y)=Var(X)+Var(Y)$\\\\\n\n$Var(X - Y)=Var(X)+Var(Y)$\\\\\n\n\\section{Covariance}\n\nThe Covariance is a measure of how much the values of each of two correlated random variables determine each other\\\\\n\n$Cov(X,Y) = \\mathbb E[(X - \\mu _ X)(Y - \\mu _ Y)]$ \\\\\n\n$Cov(X,Y) = \\mathbb E[XY] - \\mathbb E[X]\\mathbb E[Y] $\\\\\n\n$ Cov(X,Y)= \\displaystyle \\mathbb E[(X)(Y-\\mu _ Y)]$\\\\\n\nPossible notations:\\\\\n\n$Cov(X,Y) = \\sigma(X,Y) = \\sigma_ {(X,Y)}$\\\\\n\nCovariance is commutative:\\\\\n\n$Cov(X,Y) = Cov(Y,X)$\\\\\n\nCovariance with of r.v. with itself is variance:\\\\\n\n$Cov(X,X) = \\mathbb E[(X - \\mu _ X)^2] = Var(X)$\\\\\n\nUseful properties:\\\\\n\n$Cov(aX + h,bY + c)= abCov(X,Y)$\\\\\n\n$Cov(X,X + Y)= Var(X) + cov(X,Y)$\\\\\n\n$\\displaystyle Cov(aX+ bY, Z) \\displaystyle = aCov(X,Z) + bCov(Y,Z)$\\\\\n\nIf $Cov(X,Y) = 0$, we say that X and Y are uncorrelated. If $X$ and $Y$ are independent, their Covariance is zero. The converse is not always true. It is only true if $X$ and $Y$ form a gaussian vector, ie. any linear combination $\\alpha X + \\beta Y$ is gaussian for all $(\\alpha,\\beta) \\in \\mathbb{R}^2$ without $\\{0,0\\}$.\n\n\\section{correlation coefficient}\n\n$\\rho(X,Y) = \\frac{Cov(X,Y)}{\\sqrt{Var(X}Var(Y}$", "meta": {"hexsha": "bcef347b2bb4fa43980d506a3ea494bef558164c", "size": 2875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/expectation_variance.tex", "max_stars_repo_name": "r2cp/MITx_capstone_1", "max_stars_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2020-03-30T18:06:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:11:56.000Z", "max_issues_repo_path": "content/expectation_variance.tex", "max_issues_repo_name": "r2cp/MITx_capstone_1", "max_issues_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/expectation_variance.tex", "max_forks_repo_name": "r2cp/MITx_capstone_1", "max_forks_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2020-03-30T21:12:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-12T10:41:57.000Z", "avg_line_length": 29.3367346939, "max_line_length": 323, "alphanum_fraction": 0.6156521739, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.9136765298777718, "lm_q1q2_score": 0.85796493509821}} {"text": "\n\\subsection{Divergence}\n\nThis takes a vector field and produces a scalar field.\n\nIt is the dot product of the vector field with the del operator.\n\n\\(div F = \\nabla . F\\)\n\nWhere \\(\\nabla =(\\sum_{i=1}^n e_i\\dfrac{\\delta }{\\delta x_i})\\)\n\n\\(div F = \\sum_{i=1}^n e_i\\dfrac{\\delta F_i}{\\delta x_i}\\)\n\n\\subsection{Divergence as net flow}\n\nDivergence can be thought of as the net flow into a point.\n\nFor example, if we have a body of water, and a vector field as the velocity at any given point, then the divergence is \\(0\\) at all points.\n\nThis is because water is incompressible, and so there can be no net flows.\n\nAreas which flow out are sources, while areas that flow inwards are sinks.\n\n\\subsection{Solenoidal vector fields}\n\nIf there is no divergence, then the vector field is called solenoidal.\n\n\\subsection{The Laplace operator}\n\nCross product of divergence with the gradient of the function.\n\n\\(\\Delta f= \\nabla . \\nabla f\\)\n\n\\(\\Delta f= \\sum_{i=1}^n \\dfrac{\\delta^2 f}{\\delta x^2_i}\\)\n\n", "meta": {"hexsha": "d3519c38b9f2a981becdac0e058d5042bf4eb98a", "size": 991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/03-01-divergence.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculus/03-01-divergence.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculus/03-01-divergence.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5277777778, "max_line_length": 139, "alphanum_fraction": 0.7225025227, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.966914018751051, "lm_q2_score": 0.8872046034098933, "lm_q1q2_score": 0.8578505685374923}} {"text": "\\subsection*{RA Ex. 1.3}\nWe consider a Monte Carlo algorithm $A$ for a problem $\\Pi$ whose expected running time is at most $T(n)$ on any instance of size $n$ and that produces a correct solution with probability $\\gamma(n)$. Furthermore, given a solution to $\\Pi$, we can verify its correctness in time $t(n)$.\n\nWe wish to obtain a Las Vegas algorithm that always gives a correct answer to $\\Pi$ and runs in expected time at most\n$$\n\\frac{T(n) + t(n)}{\\gamma(n)}\n$$\nThis can be obtained, by repeating the Monte Carlo algorithm $A$, until a correct solution to $\\Pi$ is produced.\n\nWe know, that the expected running time is at most $T(n)$ on any instance of size $n$, so the expected running time would also be $T(n)$ for each repetition in the new algorithm.\n\\\\\nFurthermore, for each repetition, we also need to verify that the solution is correct, which adds $t(n)$ to the running time of each repetition.\n\nSince the running time for each repetition is $T(n) + t(n)$, we just need to determine, how many repetitions are needed to produce a correct solution to $\\Pi$. We call this number $X$.\n\\\\\nTo determine $X$, we first consider the following observations:\n\\\\\n- In each repetition, the solution produced is either correct, which we consider a success, or incorrect, which we consider a failure.\n\\\\\n- Each repetition is independent.\n\\\\\n- Each repetition has the same probability $\\gamma(n)$ for producing a success (meaning a correct solution to $\\Pi$).\n\\\\\nHence, we can model the number of failures, before the one success, as a geometric distribution. Then we know from App. C.4 (C.32), that\n$$\nE\\left[X\\right] = \\frac{1}{\\gamma(n)}\n$$\nSince we have now determined $X$, we can show that the new Las Vegas algoritm runs in expected time at most\n$$\nE\\left[\\left(T(n) + t(n)\\right) \\cdot X \\right]= \\frac{T(n) + t(n)}{\\gamma(n)}\n$$", "meta": {"hexsha": "0ffe6c8a0f07b7561596a397b81b98cb13ec2bc9", "size": 1833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.RA-1.3.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge2/Ex.RA-1.3.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge2/Ex.RA-1.3.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.1290322581, "max_line_length": 286, "alphanum_fraction": 0.7234042553, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757596, "lm_q2_score": 0.9207896688265684, "lm_q1q2_score": 0.857681058571076}} {"text": "\n\\subsection{Cardinality}\n\n\\subsubsection{Cardinality of finite sets}\n\nThe cardinality of a set \\(s\\) is shown as \\(|s|\\). It is the number of elements in the set. We define it formally below.\n\n\\subsubsection{Injectives, surjectives and bijectives}\n\nConsider \\(2\\) sets. If there is an injective from \\(a\\) to \\(b\\) then for every element in \\(a\\) there is a unique element in \\(b\\).\n\nIf this injective exists then we say \\(|a|\\le |b|\\).\n\nSimilarly, if there is a surjective, that is for every element in \\(b\\) there is a unique element in \\(a\\), then \\(|a|\\ge |b|\\).\n\nTherefore, if there is a bijection, \\(|a|=|b|\\), and if there is only an injective or a surjective then \\(|a|<|b|\\) or \\(|a|>|b|\\) respectively.\n\n\\subsubsection{Cardinality as a function}\n\nEvery set has a cardinality. As a result cardinality cannot be a well-defined function, for the same reason there is no set of all sets.\n\nCardinality functions can be defined on subsets.\n\n", "meta": {"hexsha": "5ace06f92398e00cde2c0cf49d50069ac9d9d29d", "size": 946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/01-07-cardinality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsSpecification/01-07-cardinality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsSpecification/01-07-cardinality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4166666667, "max_line_length": 144, "alphanum_fraction": 0.7093023256, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428692, "lm_q2_score": 0.9124361557147439, "lm_q1q2_score": 0.8576109220844533}} {"text": "The $n$-body problem is a classic one from the \\textbf{Newtonian mechanics}: it consists in \\textbf{resolving the gravity equations}.\nHowever, this problem can be generalized (from the algorithmic point of view) and we can often find it in numerical simulation: this is why it is a good real case study.\n\nAt the problem beginning (the time $t$), for each body $i$, its position $q_{i}(t)$, its mass $m_i$ and its velocity $\\vec{v_i}(t)$ are known.\nThe applied force between two bodies $i$ and $j$, at the $t$ time, is defined by:\n\\begin{equation}\n\\label{eq:force}\n\t\\vec{f_{ij}}(t) = G.\\frac{m_i.m_j}{||\\vec{r_{ij}}||^2}.\\frac{\\vec{r_{ij}}}{||\\vec{r_{ij}}||},\n\\end{equation}\nwith $G$ the gravitational constant ($G = 6,67384\\times10^{-11} m^3.kg^{-1}.s^{-2}$) and $\\vec{r_{ij}} = q_j(t) - q_i(t)$ the vector from body $i$ to body $j$.\nThe resulting force (alias the total force) for a given $i$ body, at the $t$ time, is defined by:\n\\begin{equation}\n\\label{eq:sumForces}\n\t\\vec{F_i}(t) = \\sum_{j \\ne i}^{n} \\vec{f_{ij}}(t) = G.m_i.\\sum_{j \\ne i}^{n}\\frac{m_j.\\vec{r_{ij}}}{||\\vec{r_{ij}}||^3},\n\\end{equation}\nwith $n$ the number of bodies in space.\nFor the time integration, the acceleration is required. For a given body $i$, at the $t$ time, the acceleration characteristic is defined by:\n\\begin{equation}\n\\label{eq:acceleration}\n\t\\vec{a_i}(t) = \\frac{\\vec{F_i}(t)}{m_i} = G.\\sum_{j \\ne i}^{n}\\frac{m_j.\\vec{r_{ij}}}{||\\vec{r_{ij}}||^3}.\n\\end{equation}\n\n\\subsection{An approximation of the total force}\n\nThe total force $\\vec{F_i}$ is given by Eq.~\\ref{eq:sumForces}:\n\\begin{equation*}\n\t\\vec{F_i}(t) = G.m_i.\\sum_{j \\ne i}^{n}\\frac{m_j.\\vec{r_{ij}}}{||\\vec{r_{ij}}||^3}.\n\\end{equation*}\nAs bodies approach each other, \\textbf{the force between them grows without bound}, which is an undesirable situation for numerical integration. \nIn astrophysical simulations, collisions between bodies are generally precluded; this is reasonable if the bodies represent galaxies that may pass right through each other. \nTherefore, \\textbf{a softening factor} $\\epsilon^2 > 0$ is added, and the denominator is rewritten as follows:\n\\begin{equation}\n\\label{eq:sumForcesSoft}\n\t\\vec{F_i}(t) \\approx G.m_i.\\sum_{j = 1}^{n}\\frac{m_j.\\vec{r_{ij}}}{(||\\vec{r_{ij}}||^2 + \\epsilon^2)^\\frac{3}{2}}.\n\\end{equation}\n\nNote the condition $j\\ne i$ is no longer needed in the sum, because $\\vec{f_{ii}} = 0$ when $\\epsilon ^2 > 0$.\nThe softening factor models the interaction between two Plummer point masses: masses that behave as if they were spherical galaxies.\nIn effect, \\textbf{the softening factor limits the magnitude of the force between the bodies}, which is desirable for numerical integration of the system state.\n\nAs before, we need to compute the acceleration in order to perform the integration over the time:\n\\begin{equation}\n\\label{eq:accelerationSoft}\n\t\\vec{a_i}(t) = \\frac{\\vec{F_i}(t)}{m_i} \\approx G.\\sum_{j = 1}^{n}\\frac{m_j.\\vec{r_{ij}}}{(||\\vec{r_{ij}}||^2 + \\epsilon^2)^\\frac{3}{2}}.\n\\end{equation}", "meta": {"hexsha": "0669c2b3bd7ea477ff4d15f9bb64fb6508c4aa50", "size": 2994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/murb/sections/equations.tex", "max_stars_repo_name": "MisterFruits/MUrB", "max_stars_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-07-08T16:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T08:45:01.000Z", "max_issues_repo_path": "doc/murb/sections/equations.tex", "max_issues_repo_name": "MisterFruits/MUrB", "max_issues_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-08T14:35:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-10T07:53:18.000Z", "max_forks_repo_path": "doc/murb/sections/equations.tex", "max_forks_repo_name": "MisterFruits/MUrB", "max_forks_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T07:08:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:08:08.000Z", "avg_line_length": 66.5333333333, "max_line_length": 173, "alphanum_fraction": 0.6963927856, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305297023093, "lm_q2_score": 0.8902942203004186, "lm_q1q2_score": 0.8575585734108766}} {"text": "\\chapter{Probability}\n\n\n\\section{Shuffle}\nEqual probability shuffle algorithm.\n\n\\subsection{Incorrect naive solution}\nSwap current card $A_i$ with a random card from the entire deck $A$. \n\\begin{java}\nfor (int i = 0; i < N; i++) {\n int j = (int) Math.random()*N;\n swap(a[i], a[j]);\n}\n\\end{java}\n\\begin{python}\ndef shuffle(A):\n n = len(A)\n for i in xrange(n):\n j = random.randrange(n)\n A[i], A[j] = A[j], A[i]\n\\end{python}\nConsider 3 cards, the easiest proof that this algorithm does not produce a uniformly random permutation is that it generates $3^3=27$ possible plans (consider steps in plans, duplicated result included), but there are only 3! = 6 permutations. Since $27\\%3 \\neq 0$, there must be some permutation is that is picked too much, and some that is picked too little.\n\\subsection{Knuth Shuffle}\nKnuth (aka Fisher-Yates) shuffling algorithm guarantees to rearrange the elements in uniformly random order. \n\\\\\nCore clues:\n\\begin{enumerate}\n\\item choose index uniformly $\\in [i, N)$.\n\\item just like shuffling the poker card.\n\\end{enumerate}\n\\begin{java}\npublic void shuffle(Object[] a) {\n int N = a.length;\n for (int i = 0; i < N; i++) {\n // choose index uniformly in [i, N)\n int j = i + (int) (Math.random() * (N - i));\n swap(a[i], a[j]);\n }\n}\n\\end{java}\n\n\\begin{python}\ndef shuffle(A):\n n = len(A)\n for i in xrange(n):\n j = random.randrange(i, n)\n A[i], A[j] = A[j], A[i]\n\\end{python}\n\n\\runinhead{Proof:}\n\n$n!$ permutations. \n\n\\subsection{Random Maximum}\nFind the index of maximum number in an array with a probability of $\\frac{1}{\\#maxima}$.\n\n\n\\runinhead{Code:}\n\\begin{python}\ndef random_max(A):\n maxa, maxa_idx, k = A[0], 0, 1\n for i in xrange(1, len(A)):\n if maxa < A[i]:\n maxa, maxa_idx, k = A[i], i, 1\n elif maxa == A[i]:\n k += 1 \n if random.random() < float(1)/k:\n maxa_idx = i\n\n return maxa_idx\n\n\\end{python}\n \n\\runinhead{Proof:} Prove via mathematical induction. \n\nThat is, assuming it works for any array of size $N$, prove it works for any array of size $N+1$.\n\nSo, given an array of size $N+1$, think of it as a sub-array of size $N$ followed a new element at the end. By assumption, your algorithm uniformly selects one of the max elements of the sub-array... And then it behaves as follows:\n\nIf the new element is larger than the max of the sub-array, return that element. This is obviously correct.\n\nIf the new element is less than the max of the sub-array, return the result of the algorithm on the sub-array. Also obviously correct.\n\nThe only slightly tricky part is when the new element equals the max element of the sub-array. In this case, let the number of max elements in the sub-array be $k$. Then, by hypothesis, your algorithm selected one of them with probability $\\frac{1}{k}$. By keeping that same element with probability $\\frac{k}{k+1}$, you make the overall probability of selecting that same element equal $$\\frac{1}{k} \\cdot \\frac{k}{k+1} = \\frac{1}{k+1}$$, as desired. You also select the last element with the same probability.\n\nTo complete the inductive proof, just verify the algorithm works on an array of size 1\n\n\\section{Sampling}\n\\subsection{Reservoir Sampling}\nSample $k$ from $A$, where the length of $A$ is either very large or unknown or dynamic. \n\\begin{python}\ndef reservoir_sample(A, sz):\n R = A[:sz] # sz for size\n \n for i in xrange(sz, len(A)):\n rv = random.randrange(0, i+1)\n if rv < sz: # rv for random variable\n R[rv] = A[i]\n\\end{python}\n\nUntil index $i$, with elements of length $i+1$ scanned, every element has a probability of $\\frac{sz}{i+1}$ in the reservoir. \n\n\\runinhead{Random pick index.} Given an array of integers with possible duplicates, randomly output the index of a given target number.\n\\begin{python}\ndef pick(self, target):\n sz = 0\n ret = None\n for idx, val in enumerate(A):\n if val == target:\n sz += 1\n rv = random.randrange(0, sz)\n if rv == 0:\n ret = idx\n\n return ret\n\\end{python}\n\n\\section{Distribution}\n\\subsection{Geometric Distr}\n$$\nP(X=k) = (1-p)^{k-1}p\n$$\n\nExpected number of trials of get a specific outcome:\n$$\nE[T] = \\frac{1}{p}\n$$\n, which is the mean of the Geometric Distr. \n\\subsection{Binomial Distr}\nNotations:\n$$\nB(n, p)\n$$\npmf:\n$$\n{n \\choose k}\\,p^{k}(1-p)^{n-k}\n$$\n\n\\section{Expected Value}\n\\subsection{Dice value}\nExpected value of rolling dice until getting a 3\n\\subsection{Coupon collector's problem}\nGiven n coupons, how many coupons do you expect you need to draw with replacement before having drawn each coupon at least once?\n\n$$\nE[T] = \\Theta(n \\lg n)\n$$\n, where $T$ is number of trial (i.e. time).\n\nLet $T$ be the time to collect all. $t_i$ be the time to collect the $i$-th new different coupon. $p_i$ be the probability of collecting the $i$-th coupon after $i-1$ coupons have been collected. Observe that:\n\\begin{align*}\np_1 &= \\frac{n}{n} \\\\ \np_2 &= \\frac{n-1}{n} \\\\\np_i &= \\frac{n-i+1}{n}\n\\end{align*}\nThus,\n\n\\begin{align*}\nE[T] &= \\sum_{i=1}^n E[t_i] \\\\\n&= \\sum \\frac{1}{p_i} \\\\\n&= n(\\frac{1}{1}+\\frac{1}{2}+...+\\frac{1}{n})\n\\end{align*}\n\n\\runinhead{Dice.} How many times must you roll a die until each side has appeared?\n", "meta": {"hexsha": "48ab9e2ceae533e279ea30a4659e4d4b7c83b9d0", "size": 5245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterProbability.tex", "max_stars_repo_name": "algorhythms/Algo-Quicksheet", "max_stars_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 902, "max_stars_repo_stars_event_min_datetime": "2015-08-16T08:25:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T05:23:50.000Z", "max_issues_repo_path": "chapterProbability.tex", "max_issues_repo_name": "andysli6590/Algo-Quicksheet", "max_issues_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-06T17:24:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T00:01:38.000Z", "max_forks_repo_path": "chapterProbability.tex", "max_forks_repo_name": "andysli6590/Algo-Quicksheet", "max_forks_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 92, "max_forks_repo_forks_event_min_datetime": "2015-10-09T03:13:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:57:08.000Z", "avg_line_length": 31.7878787879, "max_line_length": 511, "alphanum_fraction": 0.6642516683, "num_tokens": 1538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.9324533149608595, "lm_q1q2_score": 0.8575237206148341}} {"text": "\\subsection{Runge's phenomenon}\nA natural way to approximate a given function on any interval $[a,b]$ is to use an $n$-degree polynomial $p_n(x)$ by $n+1$ equispaced points, namely\n$$\nx_i=a+{b-a\\over n},\\quad i=0,1,2,\\cdots,n.\n$$\nBy Weierstrass' theorem, we expect a more accurate reconstruction of $f(x)$ by using more points. But this is not always true as shown in the following example. \n%Consider the case where one desires to interpolate through $n+1$ equispaced points of a function $f(x)$ using the n-degree polynomial $p_n(x)$ that passes through those points. Naturally, one might expect from Weierstrass' theorem that using more points would lead to a more accurate reconstruction of $f(x)$. However, this particular set of polynomial functions $p_n(x)$ is not guaranteed to have the property of uniform convergence; the theorem only states that a set of polynomial functions exists, without providing a general method of finding one.\n\nConsider the Runge function (a scaled version of the Witch of Agnesi)\n$$ \nf(x)=\\frac{1}{1+25x^{2}}.\n$$\nRunge found that if this function is interpolated at equidistant points $x_i$ between $-1$ and $1$ such that:\n$$\nx_{i}={\\frac{2i}{n}}-1,\\quad i\\in \\left\\{0,1,\\dots ,n\\right\\}\n$$\nwith a polynomial $p_n(x)$ of degree $\\leq n$, the resulting interpolation oscillates toward the ends of the interval, i.e. close to $-1$ and $1$. It can even be proven that the interpolation error increases (without bound) when the degree of the polynomial is increased:\n\n$$\\lim_{{n\\rightarrow \\infty }}\\left(\\max_{{-1\\leq x\\leq 1}}|f(x)-p_{n}(x)|\\right)=+\\infty.$$\nThis shows that high-degree polynomial interpolation at equidistant points can be troublesome.\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale=0.1]{6DL/pic/Runge.jpeg}\n\t\t\\caption{Runge's phenomenon: Runge function $f(x)=\\frac{1}{1+25x^{2}}$ and its polynomial interpolation $p_n(x)$.}\n\t\\end{center}\n\\end{figure}\n\nThe experiment shows that the polynomials $p_n(x)$ produced in this manner may in fact diverge away from $f(x)$ as $n$ increases. This typically occurs in an oscillating pattern that magnifies near the ends of the interpolation points. This phenomenon is attributed to Runge.\n\nThus, this particular set of polynomial functions $p_n(x)$ is not guaranteed to have the property of uniform convergence. In other words, Weierstrass' theorem guarantees the existence of the polynomial functions, but how to find such polynomials is not provided.\n", "meta": {"hexsha": "841064a56ed582bc6e3ac6f47f5eb3831ced9726", "size": 2459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Runge.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Runge.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Runge.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.84375, "max_line_length": 553, "alphanum_fraction": 0.7515250102, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.9449947159666146, "lm_q1q2_score": 0.8574052525493009}} {"text": "\\section*{Problem 2: Locality-Sensitive Hashing (LSH) for Angle Similarity}\n\nSuppose our set of $n$ points $D = \\left\\{p_1,\\ldots,p_n\\right\\}$ are vectors in\n$d$ dimensions. Our problem is: given a query point $q$ find a point $p \\in D$,\nwhich has a small angle with $q$. Recall that the angle between two vectors $a$\nand $b$ is\n$\\cos^{-1}\\left(\\frac{a \\cdot b}{\\lVert a \\rVert \\lVert b \\rVert} \\right).$\n\nAs doing this exactly may be computationally expensive, let us try to do this\napproximately with a fast algorithm. The approximate objective is as follows:\nsuppose there exists a point $p \\in D$ which has angle less than $\\theta$ with\n$p$, then our goal is return a point with angle less than $c\\theta$, where\n$c > 1$.\n\nLet us try to do this with LSH. Let us consider the a family of hash functions,\nwhere $h(p) = \\operatorname{sign}\\left(u \\cdot p\\right)$ where we will sample\n$u$ uniformly at random from a Gaussian (or from a unit sphere).\n\n\\begin{enumerate}\n\\item Provide an exact expression for\n $\\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right)$ based on\n some geometric relation between $p$ and $p^\\prime$.\n\n \\subsection*{Solution}\n\n Define\n \\begin{equation}\n \\operatorname{angle}\\left(u, v\\right) =\n \\cos^{-1}\\left(\\frac{u \\cdot v}{\\lVert u \\rVert \\lVert v \\rVert} \\right),\n \\end{equation}\n which is the angle between two vectors.\n\n Then,\n \\begin{equation}\n \\boxed{\\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right)\n = 1 - \\frac{\\operatorname{angle}\\left(p,p^\\prime\\right)}{\\pi}.}\n \\end{equation}\n\\item Provide an expression for $P_1$ and $P_2$ in terms of $\\theta$ and\n $c\\theta$. Note that since we want a small angle, we should use:\n \\begin{enumerate}\n \\item If $\\operatorname{angle}\\left(p,p^\\prime\\right) < \\theta$, then\n $\\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right) \\geq P_1$. \n \\item If $\\operatorname{angle}\\left(p,p^\\prime\\right) > c\\theta$, then\n $\\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right) \\leq P_2$.\n \\end{enumerate}\n\n \\subsection*{Solution}\n\n If $\\operatorname{angle}\\left(p,p^\\prime\\right) < \\theta$, then\n \\begin{align*}\n \\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right)\n &= 1 - \\frac{\\operatorname{angle}\\left(p,p^\\prime\\right)}{\\pi} \n \\geq 1 - \\frac{\\theta}{\\pi},\n \\end{align*}\n so $\\displaystyle\\boxed{P_1 = 1 - \\frac{\\theta}{\\pi}.}$\n\n If $\\operatorname{angle}\\left(p,p^\\prime\\right) > c\\theta$, then\n \\begin{align*}\n \\mathbb{P}\\left(h\\left(p\\right) = h\\left(p^\\prime\\right)\\right)\n &= 1 - \\frac{\\operatorname{angle}\\left(p,p^\\prime\\right)}{\\pi}\n \\leq 1 - \\frac{c\\theta}{\\pi},\n \\end{align*}\n so $\\displaystyle\\boxed{P_2 = 1 - \\frac{c\\theta}{\\pi}.}$\n\\item Provide expressions for query time for point $q$, the space to store the\n hash tables, and the construction time of our datastructure.\n\n \\subsection*{Solution}\n\n Suppose we have $L$ hash functions. If we use the algorithm discussed in\n class, to query a point, we need to compute $L$ hashes. Then, up to $3$ times,\n we iterate through the buckets: for each bucket, we choose a point and check\n how close it is to $q$; if it is $c\\theta$ close, we stop. The worst case is\n that we decide there exists no point that is $\\theta$ close to $q$. In this\n case, we iterate through the $L$ buckets $3$ times, so the time complexity is\n $O(L)$.\n \n For the space needed to store the hash tables, we need to store $L$ bits for\n each point, so the space needed is $O(nL)$\n \n For construction, we need to compute $L$ hashes for each point, so the\n computational complexity is $O(nL)$ as well. \n\\end{enumerate}\n", "meta": {"hexsha": "9198089c6af58ff80b6fd1a712045320ee77cf99", "size": 3653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/problem2/problem2.tex", "max_stars_repo_name": "kspathak/cse547", "max_stars_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw3/problem2/problem2.tex", "max_issues_repo_name": "kspathak/cse547", "max_issues_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw3/problem2/problem2.tex", "max_forks_repo_name": "kspathak/cse547", "max_forks_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-18T01:39:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-18T01:39:20.000Z", "avg_line_length": 44.0120481928, "max_line_length": 87, "alphanum_fraction": 0.6769778264, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.9184802456988518, "lm_q1q2_score": 0.8573377572554791}} {"text": "\n\\subsection{Multivariable Gaussian distribution}\n\n\\subsubsection{Definition}\n\nFor univariate:\n\n\\(x \\sim N(\\mu, \\sigma^2 )\\)\n\nWe define the multivariate gaussian distribution as the distribution where any linear combination of components are gaussian.\n\nFor multivariate:\n\n\\(X \\sim N(\\mu, \\Sigma )\\)\n\nWhere \\(\\mu \\) is now a vector, and \\(\\Sigma \\) is the covariance matrix.\n\nDensity function is :\n\n\\(f_x=\\dfrac{1}{\\sqrt {(2\\pi )^n|\\Sigma |}} e^{-\\dfrac{1}{2}(x-\\mu )^T\\Sigma^{-1}(x-\\mu)}\\)\n\nFor normal gaussian it is:\n\n\\(f_x=\\dfrac{1}{\\sqrt {2\\pi |\\sigma^2}} e^{-\\dfrac{1}{2\\sigma^2}(x-\\mu )^2)}\\)\n\nThis is the same wher \\(n=1\\).\n\n\\subsubsection{Singular Gaussians}\n\nNeed det \\(|\\Sigma |\\) and \\(\\Sigma^{-1}\\). These rely on the covariance matrix not being degenerate.\n\nIf the covariance matrix is degenerate we can instead use the pseudo inverse, and the pseudo determinant.\n\n", "meta": {"hexsha": "2064fc0b4a1c8754497343975038ef5561a940db", "size": 877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iidCLT/03-03-multiGaussian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/iidCLT/03-03-multiGaussian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/iidCLT/03-03-multiGaussian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7941176471, "max_line_length": 125, "alphanum_fraction": 0.685290764, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639669551474, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.8573351109742025}} {"text": "% Cholesky Decomposition\n\\section{$\\mathbf{A} = \\mathbf{L}\\mathbf{L}^{\\dagger}$ Cholesky Decomposition}\n\\label{sec:cholesky}\n\nThe Cholesky Decomposition exists when a matrix is hermitian and positive-definite. It expresses the matrix $\\mathbf{A}$ as:\n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{L}\\mathbf{L^\\dagger}\n\\end{equation}\n\nWhere $\\mathbf{L}$ is a lower-triangular matrix with positive, real diagonal entries. When $\\mathbf{A}$ is real, then so is $\\mathbf{L}$. The Cholesky decomposition enables fast solution of a linear system, but it can also be used to create correlated random variables in Monte Carlo simulations. \n\n\\subsection{Creating Correlated Random Variables}\nLet $\\mathbf{u}_t$ be a vector of uncorrelated samples with mean 0 and \tstandard deviation 1. If the covariance matrix of the system to be simulated is $\\mathbf{\\Sigma}$ with Cholesky decomposition $\\mathbf{\\Sigma} = \\mathbf{LL}^\\dagger$, then the vector $\\mathbf{v}_t = \\mathbf{Lu}_t$ has the desired covariance.\n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.5]{cholesky1.png}\n\\includegraphics[scale=0.5]{cholesky2.png}\n\\caption{Creating correlated random variables from uncorrelated random variables using the Cholesky decomposition of the covariance matrix. The 5 uncorrelated random variables are sampled from a standard normal distribution. It is difficult to see a difference between the correlated and uncorrelated random walks.}\n\\end{figure}\n\n", "meta": {"hexsha": "e4533231fb4379eb29149e36858358ef7dfb17b3", "size": 1434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_cholesky.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_cholesky.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_cholesky.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.347826087, "max_line_length": 315, "alphanum_fraction": 0.7789400279, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188345, "lm_q2_score": 0.91117969855511, "lm_q1q2_score": 0.8572285216459608}} {"text": "%\n% Chapter 4.2\n%\n\n\\section*{4.2 Definite Integral}\n\n\\subsection*{Definition of a Definite Integral}\n\nIf \\(f\\) is a function defined for \\(a \\leq x \\leq b\\), we divide the interval \\([a, b]\\) into \\(n\\) subintervals of equal width \\(\\Delta x=\\frac{(b-a)}{n}\\). We let \\(x_0\\) (\\(=a\\)), \\(x_1\\), \\(x_2\\), \\ldots,\\(x_n\\) (\\(=b\\)) be the endpoints of these subintervals and we let \\(x_1^*, x_2^*, \\ldots, x_n^*\\) be any sample points in these subintervals, so \\(x_i^*\\) lies in the \\(i\\)th subinterval \\([x_{i-1}, x_i]\\). Then the definite integral of \\(f\\) from \\(a\\) to \\(b\\) is \n$$ \\int_a^b f(x)dx=\\lim_{n \\to \\infty} \\sum_{i=1}^n f(x_i^*)\\Delta x $$\nprovided that this limit exists and gives the same value for all possible choices of sample points. If it does exist, we say that \\(f\\) is \\textbf{integrable} on \\([a, b]\\).\n\n\\subsection*{Precise Meaning of the Limit that Defines the Integral}\n\nFor every number \\(\\epsilon > 0\\) there is an integer \\(N\\) such that\n$$ \\left|\\int_a^b f(x)dx- \\sum_{i=1}^n f(x_i^*)\\Delta x\\right|< \\epsilon $$\nfor every integer \\(n > N\\) and for every choice of \\(x_i^*\\) in \\([x_{i-1}, x_i]\\).\n\n\\subsubsection*{Theorem}\n\nIf \\(f\\) is continuous on \\([a, b]\\), or if \\(f\\) has only a finite number of jump discontinuities, then \\(f\\) is integrable on \\([a, b]\\); that is, the definite integral \\(\\int_a^b f(x)dx\\) exists.\n\n\\subsubsection*{Theorem}\n\nIf \\(f\\) is integrable on \\([a, b]\\), then\n$$ \\int_a^b f(x)dx=\\lim_{x \\to \\infty} \\sum_{i=1}^n f(x_i) \\Delta x $$\nwhere \n$$ \\Delta x=\\frac{b-a}{n} \\quad \\text{ and } \\quad x_i=a+i \\Delta x $$ \n\n\\subsection*{Formulae for Sums of Powers of Positive Integers}\n\n$$ \\sum_{i=1}^n i=\\frac{n(n+1)}{2} $$\n$$ \\sum_{i=1}^n i^2=\\frac{n(n+1)(2n+1)}{6} $$\n$$ \\sum_{i=1}^n i^3= {\\left [ \\frac{n(n+1)}{2} \\right]}^2 $$\n\n\\subsection*{Formulae for Sigma Notation}\n\n$$ \\sum_{i=1}^n c=nc \\quad \\text{where } c \\text{ is a constant} $$\n$$ \\sum_{i=1}^n ca_i=c \\sum_{i=1}^n a_i \\quad \\text{where } c \\text{ is a constant} $$\n$$ \\sum_{i=1}^n (a_i+b_i)=\\sum_{i=1}^n a_i + \\sum_{i=1}^n b_i $$\n$$ \\sum_{i=1}^n (a_i-b_i)=\\sum_{i=1}^n a_i - \\sum_{i=1}^n b_i $$\n\n\\subsection*{Midpoint Rule}\n\n$$ \\int_a^b f(x)dx \\approx \\sum_{i=1}^{n} f(\\overline{x}_i) \\Delta x = \\Delta x [f(\\overline{x}_1)+\\cdots+f(\\overline{x}_n)]$$\nwhere \n$$ \\Delta x = \\frac{b-a}{n} \\text{ and } \\overline{x}_i = \\frac{1}{2}(x_{i-1} + x_i) \\text{ = midpoint of } [x_{i-1},x_i] $$\n\n\\subsection*{Properties of the Definite Integral}\n\n$$ \\int_b^a f(x)dx = -\\int_a^b f(x)dx $$\n$$ \\int_a^a f(x)dx = 0 $$\n$$ \\int_a^b c dx = c(b-a) \\quad \\text{where } c \\text{ is any constant} $$\n$$ \\int_a^b [f(x)+g(x)] dx = \\int_a^b f(x)dx + \\int_a^b g(x)dx $$\n$$ \\int_a^b cf(x) dx = c\\int_a^b f(x) dx \\quad \\text{where } c \\text{ is any constant} $$\n$$ \\int_a^b [f(x)-g(x)] dx = \\int_a^b f(x)dx - \\int_a^b g(x)dx $$\n$$ \\int_a^c f(x) dx + \\int_c^b f(x)dx = \\int_a^b f(x)dx $$\n\n\\subsubsection*{Comparison Properties of the Definite Integral}\n\n$$ \\text{If } f(x) \\geq 0 \\text{ for } a \\leq x \\leq b \\text{, then} \\int_a^b f(x)dx \\geq 0 $$\n$$ \\text{If } f(x) \\geq g(x) \\text{ for } a \\leq x \\leq b \\text{, then} \\int_a^b f(x)dx \\geq \\int_a^b g(x)dx $$\n$$ \\text{If } m \\leq f(x) \\leq M \\text{ for } a \\leq x \\leq b \\text{, then } m(b-a) \\leq \\int_a^b f(x)dx \\leq M(b-a) $$\n", "meta": {"hexsha": "7934c4fda9602ebe3e6123546fb8da7be34b8387", "size": 3269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4-2.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/4-2.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/4-2.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.078125, "max_line_length": 476, "alphanum_fraction": 0.5959008871, "num_tokens": 1370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.9284088020410761, "lm_q1q2_score": 0.8569576926305604}} {"text": "\\section{Matrix examples}\n\\subsection{Geometric transformations}\n\\textbullet \\textit{Scaling}: $y = Ax$ with $A = aI$ stretches a vector by the factor $|a|$ (or shrinks it when $|a| < 1$), and it flips the vector (reverses its direction) if $a < 0$\\\\\n\\textbullet \\textit{Dilation}: $y = Dx$, where D is a diagonal matrix, $D = diag(d1,d2)$. Stretches the vector x by different factors along the two different axes. (Or shrinks, if $|d_i| < 1$, and flips, if $di < 0$.)\\\\\n\\textbullet \\textit{Rotation Matrix}: \n\\[\ny = \n\\begin{bmatrix}\n cos \\theta & -sin \\theta \\\\\n sin \\theta & cos \\theta\n\\end{bmatrix}x\n\\]\n\\textbullet \\textit{Reflection}\nSuppose that y is the vector obtained by reflecting x through the line that passes through the origin, inclined $\\theta$ radians with respect to horizontal.\n\\[\ny = \n\\begin{bmatrix}\n cos (2\\theta) & sin(2\\theta) \\\\\n sin (2\\theta) & -cos (2\\theta)\n\\end{bmatrix}x\n\\]\n\\subsection{Selectors}\nAn $m \\times n$ selector matrix A is one in which each row is a unit vector (transposed):\n\\[\n\\begin{bmatrix}\n e^T_{k_1}\\\\\n .\\\\\n .\\\\\n e^T_{k_m}\\\\\n\\end{bmatrix}\n\\]\nWhen it multiplies a vector, it simply copies the $k_i$th entry of x into the $i$th entry of $y = Ax$:\\\\\n$y = (x_{k_1},x_{k_2},...,x_{k_m})$\n\n\\subsection{Incidence matrix}\n\\textbf{Directed graph}: A \\textit{directed graph} consists of a set of \\textit{vertices} (or nodes), labeled 1,...,n, and a set of \\textit{directed edges} (or branches), labeled 1,...,m. \\\\\n$\nA_{ij} = \\left\\{\n \\begin{array}{@{}ll@{}}\n 1, & \\text{edge j points to node i} \\\\\n -1, & \\text{edge j points from node i}\\\\\n 0, & \\text{otherwise}\n \\end{array}\\right.\n$\\\\\n\\subsection{Convolution}\n", "meta": {"hexsha": "463ea555c9230cfa4144853162e174c1a8603ba6", "size": 1683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_stars_repo_name": "ksb25395/COT5615", "max_stars_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_issues_repo_name": "ksb25395/COT5615", "max_issues_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter7.tex", "max_forks_repo_name": "ksb25395/COT5615", "max_forks_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5869565217, "max_line_length": 219, "alphanum_fraction": 0.6559714795, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995742876885, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.856950539377435}} {"text": "An exponential family distribution $p(x | \\theta)$\nis parameterized by \nnatural parameter function $\\eta(\\theta)$,\nsufficient statistics function $t(x)$,\nand log-partition function $\\log Z(\\eta(\\theta))$,\nsuch that\n\\begin{align*}\n p(x | \\theta) = \\exp{\\left\\langle\\eta(\\theta), t(x)\\right\\rangle - \\log Z(\\eta(\\theta))}\n\\end{align*}\n\n\\section{Categorical distribution}\n\\label{sec:stats-categorical}\nThe categorical distribution is a distribution\nover discrete sets (one-hot vectors $z$) in $R^K$,\nand is parametrized by a $K$-simplex vector $\\pi$.\n\n\\begin{align*}\n p(z | \\pi) = \\pi^Tz\n\\end{align*}\n\\subsection{Exponential family parametrization}\n\\begin{align*}\n \\eta(\\pi) &= \\log \\pi \\\\\n t(z) &= z \\\\\n \\log Z(\\eta(\\pi)) &= \\log\\sum_{k = 1}^K \\exp{\\eta(\\pi)_k} = 0\\\\\n\\end{align*}\n\n\\section{Dirichlet distribution}\n\\label{sec:stats-dirichlet}\nThe Dirichlet distribution is a distribution\nover the $K$-simplex\nand is parametrized by a vector $\\alpha$.\n\n\\begin{align*}\n p(\\pi | \\alpha) = \\frac{\\Gamma\\left(\\sum_k \\alpha_k\\right)}{\\prod_k\\Gamma(\\alpha_k)}\\prod_{k = 1}^K \\pi_k^{\\alpha_k - 1}\n\\end{align*}\n\n\\subsection{Exponential family parametrization}\n\\begin{align*}\n \\eta(\\alpha) &= \\alpha - 1\\\\\n t(\\pi) &= \\log \\pi \\\\\n \\log Z(\\eta(\\alpha)) &= \\sum_{k = 1}^K \\log \\Gamma(\\alpha_k) - \\log \\Gamma\\left(\\sum_{k = 1}^K \\alpha_k\\right)\n\\end{align*}\n\n\\section{Gaussian distribution}\n\\label{sec:stats-gaussian}\n\nThe Gaussian distribution is a distribution\ndistribution over vectors in $\\R^d$,\nand is parametrized by mean $\\mu$ and covariance $\\Sigma$.\n\n\\begin{align}\n p(x | \\mu, \\Sigma) = \\frac{1}{(2\\pi)^{\\frac{d}{2}}|\\Sigma|^{\\frac{1}{2}}} \\exp{(x - \\mu)^T\\Sigma^{-1}(x - \\mu)}\n\\end{align}\n\n\\subsection{Exponential family parametrization}\n\n\\begin{align*}\n \\eta(\\mu, \\Sigma) &= \\begin{bmatrix}-\\frac{1}{2}\\Sigma^{-1} \\\\ \\Sigma^{-1}\\mu\\end{bmatrix} \\\\\n t(x) &= \\begin{bmatrix}xx^T \\\\ x\\end{bmatrix} \\\\\n \\log Z(\\eta(\\mu, \\Sigma)) &= \\frac{1}{2}\\mu^T\\Sigma^{-1}\\mu + \\frac{1}{2}\\log |\\Sigma| + \\frac{d}{2}\\log 2\\pi\n\\end{align*}\n\n\\section{Inverse-Wishart (IW) distribution}\n\\label{sec:stats-iw}\n\nThe inverse-Wishart (IW) distribution is a\ndistribution over positive definite matrices in $\\R^{d \\times d}$\nand is parametrized by scale matrix $\\Psi$ and degrees of freedom $\\nu$.\n\n\\begin{align}\n p(\\Sigma | \\Psi, \\nu) = \\frac{|\\Psi|^{\\frac{\\nu}{2}}}{2^{\\frac{\\nu d}{2}}\\Gamma_d(\\frac{\\nu}{2})}|\\Sigma|^{\\frac{-(\\nu + d + 1)}{2}} \\exp{-\\frac{1}{2}\\tr(\\Psi\\Sigma^{-1})}\n\\end{align}\n\n\\subsection{Exponential family parametrization}\n\n\\begin{align*}\n \\eta(\\Psi, \\nu) &= \\begin{bmatrix}\\Psi \\\\ \\nu + d + 1\\end{bmatrix} \\\\\n t(\\Sigma) &= \\begin{bmatrix}-\\frac{1}{2}\\Sigma^{-1} \\\\ -\\frac{1}{2}\\log |\\Sigma|\\end{bmatrix} \\\\\n \\log Z(\\eta(\\Psi, \\nu)) &= -\\frac{\\nu}{2}\\log |\\Psi| + \\frac{\\nu d}{2}\\log 2 + \\log \\Gamma_d\\left(\\frac{\\nu}{2}\\right)\n\\end{align*}\n\n\\section{Normal-inverse-Wishart (NIW) distribution}\n\\label{sec:stats-niw}\n\nThe Normal-inverse-Wishart (NIW) is a\ndistribution over the tuple of vectors in $\\R^d$ and \npositive definite matrices in $\\R^{d \\times d}$\nand is parametrized by\nscale matrix $\\Psi$,\nmean $\\mu_0$,\nscale $\\kappa$,\nand degrees of freedom $\\nu$.\n\n\\begin{align}\n p(\\mu, \\Sigma | \\Psi, \\mu_0, \\kappa, \\nu) &= \\IW(\\Sigma|\\Psi,\\nu)\\N(\\mu|\\mu_0,\\frac{1}{\\kappa}\\Sigma) \\\\\n\\end{align}\n\n\\subsection{Exponential family parametrization}\n\\begin{align*}\n \\eta(\\Psi, \\mu_0, \\kappa, \\nu) &= \\begin{bmatrix}\\Psi + \\kappa\\mu_0\\mu_0^T\\\\\\kappa \\mu_0\\\\\\kappa\\\\\\nu + d + 1\\end{bmatrix} \\\\\n t(\\mu, \\Sigma) &= \\begin{bmatrix}-\\frac{1}{2}\\Sigma^{-1}\\\\\\Sigma^{-1}\\mu\\\\-\\frac{1}{2}\\mu^T\\Sigma^{-1}\\mu\\\\-\\frac{1}{2}\\log|\\Sigma|\\end{bmatrix} \\\\\n \\log Z(\\eta(\\Psi, \\nu)) &= -\\frac{\\nu}{2}\\log |\\Psi| + \\frac{\\nu d}{2}\\log 2 + \\log \\Gamma_d\\left(\\frac{\\nu}{2}\\right) - \\frac{d}{2} \\log \\kappa\n\\end{align*}\n\n\\section{Matrix normal (MN) distribution}\n\\label{sec:stats-mn}\n\nThe matrix normal (MN) is \na distribution over $\\R^{m \\times n}$\nmatrices, parametrized by \nmean $M_0 \\in \\R^{m \\times n}$,\nrow covariance $S \\in \\R^{m \\times m}$,\nand column covariance $V \\in \\R^{n \\times n}$ .\n\n\n\\begin{align}\n p(M | M_0, S, V) &= \\frac{1}{(2\\pi)^{\\frac{mn}{2}}|S|^{\\frac{n}{2}}|V|^{\\frac{m}{2}}} \\exp{-\\frac{1}{2}\\tr\\left(V^{-1}(M - M_0)^TS^{-1}(M - M_0)\\right)}\n\\end{align}\n\n\\subsection{Exponential family parametrization}\n\\begin{align*}\n \\eta(M_0, S, V) &= \\begin{bmatrix}-\\frac{1}{2}(V \\otimes S)^{-1}\\\\(V \\otimes S)^{-1}\\vec(M_0)\\end{bmatrix} \\\\\n t(M) &= \\begin{bmatrix}\\vec(M)\\vec(M)^T\\\\\\vec(M)\\end{bmatrix} \\\\\n \\log Z(\\eta(M_0, S, V)) &= \\frac{mn}{2}\\log 2\\pi + \\frac{n}{2}\\log|S| + \\frac{m}{2}\\log|V| + \\frac{1}{2}\\tr(V^{-1}M_0^TS^{-1}M_0) \n\\end{align*}\n\n\\section{Matrix normal inverse-Wishart (MNIW) distribution}\n\\label{sec:stats-mniw}\n\nThe matrix normal inverse Wishart (MNIW) is \na distribution over the tuple of $\\R^{m \\times n}$\nmatrices and $\\R^{m \\times m}$ covariance matrices, parametrized by \nscale matrix $\\Psi$,\nmean $M_0 \\in \\R^{m \\times n}$,\ncolumn covariance $V \\in \\R^{n \\times n}$,\nand degrees of freedom $\\nu$.\n\n\n\\begin{align}\n p(\\Sigma, M | \\Psi, M_0, V, \\nu) &= \\IW(\\Sigma|\\Psi, \\nu) \\times \\MN(M|M_0, \\Sigma, V) \\\\\n &= \\frac{|\\Psi|^{\\frac{\\nu}{2}}}{2^{\\frac{\\nu m}{2}}\\Gamma_m(\\frac{\\nu}{2})}|\\Sigma|^{\\frac{-(\\nu + m + 1)}{2}} \\exp {-\\frac{1}{2}\\tr(\\Psi\\Sigma^{-1})} \\\\\n &\\times \\frac{1}{(2\\pi)^{\\frac{mn}{2}}|\\Sigma|^{\\frac{n}{2}}|V|^{\\frac{m}{2}}} \\exp{-\\frac{1}{2}\\tr\\left(V^{-1}(M - M_0)^T\\Sigma^{-1}(M - M_0)\\right)}\n\\end{align}\n\n\\subsection{Exponential family parametrization}\n\\begin{align*}\n \\eta(\\Psi, M_0, V, \\nu) &= \\begin{bmatrix}\\Psi + M_0V^{-1}M_0^T\\\\M_0V^{-1}\\\\V^{-1}\\\\\\nu + m + n + 1\\end{bmatrix} \\\\\n t(\\Sigma, M) &= \\begin{bmatrix}-\\frac{1}{2}\\Sigma^{-1}\\\\\\Sigma^{-1}M\\\\-\\frac{1}{2}M^T\\Sigma^{-1}M\\\\-\\frac{1}{2}\\log|\\Sigma|\\end{bmatrix} \\\\\n \\log Z(\\eta(\\Psi, M_0, V, \\nu)) &= \\frac{m}{2}\\log|V| + \\frac{mn}{2}\\log 2\\pi - \\frac{\\nu}{2}\\log |\\Psi| + \\frac{\\nu m}{2}\\log 2 + \\log \\Gamma_d\\left(\\frac{\\nu}{2}\\right)\n\\end{align*}\n", "meta": {"hexsha": "3482f0aa7e5e7283e402d2954289fcfe96581dd9", "size": 6062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/content/appendix/stats-appendix.tex", "max_stars_repo_name": "sharadmv/thesis", "max_stars_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-30T01:28:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-30T01:28:54.000Z", "max_issues_repo_path": "writeup/content/appendix/stats-appendix.tex", "max_issues_repo_name": "sharadmv/thesis", "max_issues_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writeup/content/appendix/stats-appendix.tex", "max_forks_repo_name": "sharadmv/thesis", "max_forks_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1456953642, "max_line_length": 179, "alphanum_fraction": 0.6064005279, "num_tokens": 2351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.965899575269305, "lm_q2_score": 0.8872045817875224, "lm_q1q2_score": 0.8569505287255492}} {"text": "\\section{Tikhonov Regularization}\n\\label{sec:tikhonov_regularization}\nThe goal of the optimization of the ESN output weights is to find a $\\wmatr{out}$\nsuch that for a given state $x_t$ we can produce a prediction of the next time step:\n\\begin{equation}\n y_t = \\wmatr{out} x_t\n\\end{equation}\n\nBy collecting a number of states $ \\matr{X} = (x_1, ..., x_T)$, that are produced by the inputs\n$u_1, ..., u_T$, we can write\n\\begin{equation}\n \\matr{D} = \\wmatr{out} \\matr{X},\n\\end{equation}\nwith $\\matr{D} = (d_1, ..., d_T)$ as the conactenated desired outputs.\nThe optimal output weights can then be found by simply solving the overdetermined\nsystem:\n\\begin{equation}\n \\wmatr{out} = \\matr{D} \\XT (\\matr{X} \\XT)^{-1}\n\\end{equation}\n\nWith this simple least squares solution, the output weights are very prone to\noverfitting, which is why a regularized version, also known as Tikhonov Regularization,\noften yields more general results, that let the ESN perform much better in the\nfreely running mode.\n\nTikhonov Regularization minimizes the function $\\Phi$:\n\\begin{equation}\n \\label{eq:phi}\n \\Phi(\\wmatr{out}) = || \\matr{D} - \\wmatr{out} \\matr{X} ||^2\n + \\beta^2 || \\wmatr{out} ||^2,\n\\end{equation}\nwhere the first term represents the \\emph{misfit} of the outputs to the target\nand the second term introduces a the regularization.\nA larger coefficient $\\beta$ will favor smaller output weights in the solution,\nwhich prevents them from overfitting.\n\nEq.~\\ref{eq:phi} can be written as:\n\\begin{equation}\n \\Phi(\\wmatr{out}) = \\bigg | \\bigg| \n \\vect{\\matr{D}}{0}\n - \\wmatr{out} \\vect{\\matr{X}}{\\beta \\matr{I}}\n \\bigg | \\bigg| ^2,\n\\end{equation}\nwhich can be solved by:\n\n\\begin{align}\n \\vect{\\matr{D}}{0} &= \\wmatr{out} \\XbI \\\\\n \\vect{\\matr{D}}{0} \\XbI^{\\text{T}} &= \\wmatr{out} \\XbI \\XbI^{\\text{T}}\\\\\n \\vect{\\matr{D}}{0} \\XbI^{\\text{T}} \\bigg[\\XbI \\XbI^{\\text{T}}\\bigg]^{-1} &= \\wmatr{out} \\\\\n \\wmatr{out} &= \\matr{D} \\XT (\\matr{X}\\XT + \\beta^2 \\matr{I})^{-1}\n\\end{align}\n", "meta": {"hexsha": "a73ddaa7d9b0f42935a071d44a2c1941cf05ec2f", "size": 2052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "backmatter/tikhonov.tex", "max_stars_repo_name": "nmheim/thesis", "max_stars_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-22T12:17:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-22T12:17:23.000Z", "max_issues_repo_path": "backmatter/tikhonov.tex", "max_issues_repo_name": "nmheim/thesis", "max_issues_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backmatter/tikhonov.tex", "max_forks_repo_name": "nmheim/thesis", "max_forks_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4615384615, "max_line_length": 95, "alphanum_fraction": 0.6549707602, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813488829418, "lm_q2_score": 0.8962513828326955, "lm_q1q2_score": 0.8567996058986022}} {"text": "\n\\subsection{Logistic function (AKA sigmoid, logit)}\n\n\\subsubsection{The function}\n\n\\(\\sigma (z)=\\dfrac{1}{1+e^{-z}}\\)\n\nThe range of this activation is between \\(0\\) and \\(1\\).\n\n\\subsubsection{The derivative}\n\n\\(\\sigma '(z)=\\dfrac{e^{-z}}{(1+e^{-z})^2}\\)\n\n\\(\\sigma '(z)=\\sigma (z)\\dfrac{1+e^{-z}-1}{1+e^{-z}}\\)\n\n\\(\\sigma '(z)=\\sigma (z)[1-\\sigma (z)]\\)\n\n\\subsubsection{Notes}\n\n\n", "meta": {"hexsha": "0239ed4a85766d599babbde149a5cc491bb1be77", "size": 378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glm/03-03-sigmoid.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glm/03-03-sigmoid.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glm/03-03-sigmoid.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.0, "max_line_length": 56, "alphanum_fraction": 0.5873015873, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9669140244715405, "lm_q2_score": 0.8856314632529871, "lm_q1q2_score": 0.856329482332565}} {"text": "\\section{OLS}\n\nGiven two random variables $X$ and $Y$, how can we predict the values of $Y$ given $X$?\n\nLet us consider $(X_1, Y_1), \\ldots, (X_n, Y_n) \\sim^{iid } \\mathbb{P}$ where $\\mathbb{P}$ is an unknown joint distribution. $\\mathbb{P}$ can be described entirely by:\n\n\\begin{align*}\ng(X) = \\int f(X, y)dy\\\\\nh(Y|X=x) = \\frac{f(x, Y)}{g(x)}\n\\end{align*}\n\nwhere $f$ is the joint PDF, $g$ the marginal density of $X$ and $h$ the conditional density. What we are interested in is $h(Y|X)$.\n\n\\textbf{Regression function:} For a partial description, we can consider instead the conditional expection of $Y$ given $X=x$:\n\n\\begin{align*}\nx \\mapsto f(x) = \\mathbb{E}[Y | X=x] = \\int yh(y|x)dy\n\\end{align*}\n\nWe can also consider different descriptions of the distribution, like the median, quantiles or the variance.\\\\\n\\textbf{Linear regression:} trying to fit any function to $\\mathbb{E}[Y | X=x]$ is a nonparametric problem; therefore, we restrict the problem to the tractable one of linear function:\n\\begin{align*}\nf: x \\mapsto a + bx\n\\end{align*}\n\n\\textbf{Theoretical linear regression:} let $X, Y$ be two random variables with two moments such as $\\mathbb{V}[X] > 0$. The theoretical linear regression of $Y$ on $X$ is the line $a^{*} + b^{*}x$ where\n\n\\begin{align*}\n(a^{*}, b^{*}) = argmin_{(a, b) \\in \\mathbb{R}^2}\\mathbb{E}\\left[(Y - a - bX)^2\\right]\n\\end{align*}\n\nWhich gives:\n\n\\begin{align*}\nb^{*} = \\frac{Cov(X, Y)}{\\mathbb{V}[X]}, \\quad a^{*} = \\mathbb{E}[Y] - b^{*} \\mathbb{E}[X]\n\\end{align*}\n\n\\textbf{Noise:} we model the noise of $Y$ around the regression line by a random variable $\\varepsilon = Y - a^{*} - b^{*} X$, such as:\n\n\\begin{align*}\n\\mathbb{E}[\\varepsilon] = 0, \\quad Cov(X, \\varepsilon) = 0\n\\end{align*}\n\nWe have to estimate $a^{*}$ and $b^{*}$ from the data. We have $n$ random pairs $(X_1, Y_1), \\ldots, (X_n, Y_n) \\sim_{iid} (X, Y)$ such as:\n\n\\begin{align*}\nY_i = a^{*} + b^{*} X_i + \\varepsilon_i\n\\end{align*}\n\nThe \\textbf{Least Squares Estimator (LSE)} of $(a^{*}, b^{*})$ is the minimizer of the squared sum:\n\n\\begin{align*}\n(\\hat{a}_n, \\hat{b}_n) = argmin_{(a, b) \\in \\mathbb{R}^2}\\sum_{i=1}^n(Y_i - a - bX_i)^2\n\\end{align*}\n\nThe estimators are given by:\n\\begin{align*}\n\\hat{b}_n = \\frac{\\overline{XY} - \\bar{X}\\bar{Y}}{\\overline{X^2} - \\bar{X}^2}, \\quad \\hat{a}_n = \\bar{Y} - \\hat{b}_n \\bar{X}\n\\end{align*}\n\nThe \\textbf{Multivariate Regression} is given by:\n\n\\begin{align*}\nY_i = \\sum_{j=1}^pX_i^{(j)}\\beta_j^{*} + \\varepsilon_i= \\underbrace{X_i^\\top}_{1 \\times p}\\underbrace{\\beta^{*}}_{p \\times 1} + \\varepsilon_i\n\\end{align*}\n\nWe can assuming that the $X_i^{(1)}$ are 1 for the intercept.\n\n\\begin{itemize}\n\\item If $\\beta^{*} = (a^{*}, b^{*}\\top)^\\top$, $\\beta_1^{*} = a^{*}$ is the intercept.\n\\item the $\\varepsilon_i$ is the noise, satisfying $Cov(X_i, \\varepsilon_i) = 0$\n\\end{itemize}\n\nThe \\textbf{Multivariate Least Squares Estimator (LSE)} of $\\beta^{*}$ is the minimizer of the sum of square errors:\n\\begin{align*}\n\\hat{\\beta} = argmin_{\\beta \\in \\mathbb{R}^p}\\sum_{i=1}^n(Y_i - X_i^\\top\\beta)^2\n\\end{align*}\n\n\\textbf{Matrix form:} we can rewrite these expressions. Let $Y = (Y_1, \\ldots, Y_n)^\\top \\in \\mathbb{R}^n$, and $\\epsilon = (\\varepsilon_1, \\ldots, \\varepsilon_n)^\\top$. \n\nLet\n\\begin{align*}\nX = \\begin{pmatrix} X_1^\\top \\\\ \\vdots \\\\ X_n^\\top \\end{pmatrix} \\in \\mathbb{R}^{n \\times p}\n\\end{align*}\n\n$X$ is called the **design matrix**. The regression is given by:\n\n\\begin{align*}\nY = X\\beta^{*} + \\epsilon\n\\end{align*}\n\nand the LSE is given by:\n\n\\begin{align*}\n\\hat{\\beta} = argmin_{\\beta \\in \\mathbb{R}^p} \\|Y - X\\beta\\|^2_2\n\\end{align*}\n\n\nLet us suppose $n \\geq p$ and $rank(X) = p$. If we write:\n\n\\begin{align*}\nF(\\beta) = \\|Y - X\\beta\\|^2_2 = (Y - X\\beta)^\\top(Y - X\\beta)\n\\end{align*}\n\n\nThen:\n\n\\begin{align*}\n\\nabla F(\\beta) = 2 X^\\top(Y - X\\beta)\n\\end{align*}\n\n\n\\textbf{Least squares estimator}: setting $\\nabla F(\\beta) = 0$ gives us the expression of $\\hat{\\beta}$:\n\n\\begin{align*}\n\\hat{\\beta} = (X^\\top X)^{-1}X^\\top Y\n\\end{align*}\n\n\n**Geometric interpretation**: $X\\hat{\\beta}$ is the orthogonal projection of $Y$ onto the subspace spanned by the columns of $X$:\n\n$$ X\\hat{\\beta} = PY$$\n\nwhere $P = X(X^\\top X)^{-1}X^\\top$ is the expression of the projector.\n\n**Statistic inference**: let us suppose that:\n\n* The design matrix $X$ is deterministic and $rank(X) = p$.\n* The model is **homoscedastic**: $\\varepsilon_1, \\ldots, \\varepsilon_n$ are i.i.d.\n* The noise is Gaussian: $\\epsilon \\sim N_n(0, \\sigma^2I_n)$.\n\nWe therefore have:\n\n$$Y \\sim N_n(X\\beta^{*}, \\sigma^2 I_n)$$\n\nProperties of the LSE:\n\n$$\\hat{\\beta} \\sim N_p(\\beta^{*}, \\sigma^2(X^\\top X)^{-1})$$\n\nThe quadratic risk of $\\hat{\\beta}$ is given by:\n\n$$\\mathbb{E}\\left[\\|\\hat{\\beta} - \\beta^{*}\\|^2_2\\right] = \\sigma^2 Tr \\left((X^\\top X)^{-1}\\right)$$\n\nThe prediction error is given by:\n\n$$\\mathbb{E}\\left[\\|Y - X\\hat{\\beta}\\|^2_2\\right] = \\sigma^2(n - p)$$\n\nThe unbiased estimator of $\\sigma^2$ is:\n\n$$\\hat{\\sigma^2} = \\frac{1}{n-p}\\|Y - X\\hat{\\beta}\\|^2_2 = \\frac1{n-p}\\sum_{i=1}^n\\hat{\\varepsilon}_i^2$$\n\nBy **Cochran's Theorem**:\n\n$$ (n-p)\\frac{\\hat{\\sigma^2}}{\\sigma^2} \\sim \\chi^2_{n-p}, \\quad \\hat\\beta \\perp \\hat{\\sigma^2}$$\n\n**Significance test**: let us test $H_0: \\beta_j = 0$ against $H_1: \\beta_j \\neq 0$. Let us call\n\n$$\\gamma_j = \\left((X^\\top X)^{-1}\\right)_{jj} > 0$$\n\nthen:\n\n$$\\frac{\\hat{\\beta}_j- \\beta_j}{\\sqrt{\\hat{\\sigma^2}\\gamma_j}} \\sim t_{n-p}$$\n\nWe can define the test statistic for our test:\n\n$$T_n^{(j)} = \\frac{\\hat{\\beta}_j}{\\sqrt{\\hat{\\sigma^2}\\gamma_j}}$$\n\nThe test with non-asymptotic level $\\alpha$ is given by:\n\n$$\\psi_\\alpha^{(j)} = \\textbf{1}\\{|T_n^{(j)}| > q_{\\alpha/2}(t_{n-p})\\}$$\n\n**Bonferroni's test**: if we want to test the significance level of multiple tests at the same time, we cannot use the same level $\\alpha$ for each of them. We must use a stricter test for each of them. Let us consider $S \\subseteq \\{1, \\ldots, p\\}$. Let us consider\n\n$$H_0: \\forall j \\in S, \\beta_j = 0, \\quad H_1: \\exists j \\in S, \\beta_j \\neq 0$$\n\nThe *Bonferroni's test* with significance level $\\alpha$ is given by:\n\n$$\\psi_\\alpha^{(S)} = \\max_{j \\in S}\\psi_{\\alpha/K}^{(j)}$$\n\nwhere $K = |S|$. The rejection region therefore is the union of all rejection regions:\n\n$$R_\\alpha^{(S)} = \\bigcup_{j \\in S}R_{\\alpha/K}^{(j)}$$\n\nThis test has nonasymptotic level at most $\\alpha$:\n\n$$\\P_{H_0}\\left[R_\\alpha^{(S)}\\right] \\leq \\sum_{j\\in S}\\P_{H_0}\\left[R_{\\alpha/K}^{(j)}\\right] = \\alpha$$\n\nThis test also works for implicit testing (for example, $\\beta_1 \\geq \\beta_2$).\n", "meta": {"hexsha": "7324546f34157800deeb260664d29271b2fc89ba", "size": 6514, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/OLS.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/OLS.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/OLS.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 34.4656084656, "max_line_length": 266, "alphanum_fraction": 0.6324838809, "num_tokens": 2498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110587, "lm_q2_score": 0.8962513648201266, "lm_q1q2_score": 0.8562060704365567}} {"text": "% !TEX root = main.tex\n\n\\section{Events}\\label{sec:events}\n\nA set is a collection of distinct elements. If $\\omega$ is an element of the set $A$, we denote this by $\\omega\\in A$.\nThe set containing no elements is called the \\emph{empty set} and denoted by $\\emptyset$.\n \n\\begin{definition}[Set relations]\nLet $A$ and $B$ be sets.\n\\ben\n\\it $A$ is a \\emph{subset} of $B$ if $\\omega\\in B$ for every $\\omega\\in A$. This is denoted by $A\\subseteq B$.\n\\it $A$ is \\emph{equal} to $B$ if $A\\subseteq B$ and $B\\subseteq A$. This is denoted by $A=B$.\n\\it $A$ is a \\emph{proper subset} of $B$ if $A\\subseteq B$ and $A\\neq B$. This is denoted by $A\\subset B$.\n\\it $A$ and $B$ are \\emph{disjoint} (or \\emph{mutually exclusive}) if $A\\cap B=\\emptyset$.\n\\een\n\\end{definition}\n\n\\begin{definition}[Set operations]\nLet $\\Omega$ be a set, and let $A$ and $B$ be subsets of $\\Omega$.\n\\ben\n\\it The \\emph{complement} of $A$ (relative to $\\Omega$) is the set \n$A^c=\\{\\omega\\in\\Omega:\\omega\\notin A\\}$.\n\\it The \\emph{union} of $A$ and $B$ is the set \n$A\\cup B = \\{\\omega\\in\\Omega: \\omega\\in A \\text{ or }\\omega\\in B\\}$.\n\\it The \\emph{intersection} of $A$ and $B$ is the set\n$A\\cap B = \\{\\omega\\in\\Omega: \\omega\\in A \\text{ and }\\omega\\in B\\}$.\n\\een\n\\end{definition}\n\nTable~\\ref{tab:sets_and_logic} shows the connection between set theory and logic.\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{|c|c||c|c|c|} \\hline\nSet Theory \t\t& \t\t\t& Logic\t\t\t&\t\t& \\\\ \\hline\nUnion\t\t\t& $A\\cup B$\t& Disjunction \t& OR \t& $\\lor$\t\\\\\nIntersection\t& $A\\cap B$\t& Conjunction\t& AND \t& $\\land$\\\\\nComplement\t\t& $A^c$\t\t& Negation\t\t& NOT \t& $\\lnot$\t\\\\ \\hline\n\\end{tabular}\n\\caption{Correspondence between set operations and logical connectives.\\label{tab:sets_and_logic}}\n\\end{table}\n\n%\\begin{definition}[Set algebra]\n%\\ben\n%\\it Commutative property.\n%\\bit \n%\\it $A\\cup B = B\\cup A$,\n%\\it $A\\cap B = B\\cap A$.\n%\\eit\n%\\it Associative property.\n%\\bit \n%\\it $(A\\cup B)\\cup C = A\\cup (B\\cup C)$,\n%\\it $(A\\cap B)\\cap C = A\\cap (B\\cap C)$.\n%\\eit\n%\\it Distributive property.\n%\\bit \n%\\it $A\\cup (B\\cap C) = (A\\cup B)\\cap(A\\cup C)$,\n%\\it $A\\cap (B\\cup C) = (A\\cap B)\\cup(A\\cap C)$.\n%\\eit\n%\\een\n%\\end{definition}\n\n\\begin{definition}[Set algebra]\nThe union and intersection operations have the following properties.\n\\bit\n\\it The \\emph{commutative} property: $A\\cup B = B\\cup A$ and $A\\cap B = B\\cap A$.\n\\it The \\emph{associative} property: $(A\\cup B)\\cup C = A\\cup (B\\cup C)$ and $(A\\cap B)\\cap C = A\\cap (B\\cap C)$.\n\\it The \\emph{distributive} property: $A\\cup (B\\cap C) = (A\\cup B)\\cap(A\\cup C)$ and $A\\cap (B\\cup C) = (A\\cap B)\\cup(A\\cap C)$.\n\\eit\nNote that a statement such as $A\\cup B\\cap C$ is ambiguous. \n\\end{definition}\n\n\\begin{exercise}\n\\begin{questions}\n\\question\nThe \\emph{set difference} $A\\setminus B$ is the set containing those elements of $A$ that are not contained in $B$. Express $A\\setminus B$ using only the intersection and complementation operations.\n\\question\nProve De Morgan's laws: $(A\\cup B)^c = A^c\\cap B^c$ and $(A\\cap B)^c = A^c\\cup B^c$.\n\\end{questions}\n\\end{exercise}\n\n\\subsection{Countable unions and intersections}\nLet $A_1,A_2,\\ldots$ be a countable family of sets. The union and intersection of this countable family are defined by\n\\begin{align*}\n\\medcup_{i=1}^{\\infty} A_i \n\t& = \\{\\omega:\\omega\\in A_i\\text{ for some } i=1,2,\\ldots\\} \\\\[2ex]\n\\medcap_{i=1}^{\\infty} A_i \n\t& = \\{\\omega:\\omega\\in A_i\\text{ for all } i=1,2,\\ldots\\}\n\\end{align*}\n\n\\begin{exercise}\nShow that De Morgan's laws hold for countable unions and intersections:\n\\[\n\\big(\\medcup_{i=1}^{\\infty}A_i\\big)^c = \\medcap_{i=1}^{\\infty}A_i^c\n\\quad\\text{and}\\quad\n\\big(\\medcap_{i=1}^{\\infty}A_i\\big)^c = \\medcup_{i=1}^{\\infty}A_i^c.\n\\]\n\\end{exercise}\n\n\n\n%%-------------------------------------------------\n%\\section{Sample spaces}\\label{sec:sample_spaces}\n\n\\begin{definition}\n\\ben\n\\it A \\emph{random experiment} is any process of observation or measurement whose result is uncertain.\n\\it The result of a random experiment is called the \\emph{outcome}.\n\\it The \\emph{sample space} of a random experiment is the set of all possible outcomes.\n\\it A \\emph{random event} is a subset of the sample space.\n\\een\n\\end{definition}\n\nSample spaces can be \\emph{finite}, \\emph{countably infinite} or \\emph{uncountable} sets.\n\\begin{example}\n\\ben\n\\it A coin is tossed $10$ times. The outcome is the total number of heads.\n\t\\bit\n\t\\it The sample space is a finite set: $\\Omega = \\{0,1,2,\\ldots,10\\}$.\n\t\\it $A = \\{1,3,5,7,9\\}$ is the event that the total is odd.\n\t\\eit\n\\it A coin is tossed repeatedly until the first head occurs. The outcome is the number of times the coin is tossed.\n\t\\bit\n\t\\it The sample space is a countably infinite set: $\\Omega = \\{1,2,3,\\ldots\\}$.\n\t\\it $A = \\{1,3,5,\\ldots\\}$ is the event that the number is odd.\n\t\\it $B_n = \\{n, n+1,n+2,\\ldots\\}$ is the event that the coin is tossed at least $n$ times.\n\t\\eit\n\\it A spinning top is spun and comes to rest at a random angle relative to the horizontal axis.\n\t\\bit\n\t\\it The sample space is an uncountable set: $\\Omega = [0,2\\pi)$.\n\t\\it $A = [0,\\pi/2]$ is the event that the angle lies in the positive quadrant.\n\t\\eit\n\\een\n\\end{example}\n\n\\begin{definition}\nLet $\\Omega$ be the sample space of some random experiment and let $A\\subseteq\\Omega$ be an event. Suppose we perform the experiment and observe the outcome $\\omega$. If $\\omega\\in A$ we say that event \\emph{$A$ occurs}, otherwise we say that \\emph{$A$ does not occur}.\n\\end{definition}\n\n\\begin{example}\nA coin is tossed $10$ times. Let the outcome of the experiment be the total number of heads, and let $A$ be the event that the total is odd. \n\\bit\n\\it If we observe a total of $5$ heads then $A$ occurs. \n\\it If we observe a total of $6$ heads, $A$ does not occur.\n\\eit\n\\end{example}\n\n\\begin{exercise}\nLet $A$ and $B$ be two random events.\n\\ben\n\\it Show that if $A$ occurs and $A\\subseteq B$ then $B$ also occurs.\n\\it Show that if $A$ occurs and $A\\cap B=\\emptyset$ then $B$ does not occur. \n\\een\n\\end{exercise}\n\n% correspondence\nTable~\\ref{tab:sets_and_probability} shows the correspondence between terms used in set theory and those used in probability theory.\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{|l|l|l|} \\hline\nNotation \t\t\t& Set theory\t\t& Probability theory \\\\ \\hline\n$\\Omega$\t\t\t& Universal set\t\t& Sample space, certain event \\\\ \n$\\omega\\in\\Omega$\t& Element\t\t\t& Elementary event, outcome \\\\\n$A\\subseteq\\Omega$\t& Subset\t\t\t& Event $A$ \\\\\n$A\\subseteq B$\t\t& Inclusion\t\t\t& If $A$ occurs, then $B$ occurs \\\\\n$A^c$\t\t\t\t& Complement\t\t& $A$ does not occur \\\\\n$A\\cap B$\t\t\t& Intersection\t\t& $A$ and $B$ both occur\\\\ \n$A\\cup B$\t\t\t& Union\t\t\t\t& $A$ or $B$ (or both) occur \\\\ \n$A\\setminus B$\t\t& Set difference\t& $A$ occurs, but $B$ does not \\\\ \n$\\emptyset$\t\t\t& Empty set\t\t\t& Impossible event \\\\ \\hline\n\\end{tabular}\n\\captionsetup{justification=centering}\n\\caption{Set theory and probability theory (Grimmett \\& Stirzaker 2001).\\label{tab:sets_and_probability}}\n\\end{table}\n\n\n\n\n\n", "meta": {"hexsha": "85ace9c52109754421172cb88836e8a587edb35c", "size": 6921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/01A_events.tex", "max_stars_repo_name": "gillardjw/notes", "max_stars_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "L5/MA2500/01A_events.tex", "max_issues_repo_name": "gillardjw/notes", "max_issues_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "L5/MA2500/01A_events.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 38.6648044693, "max_line_length": 269, "alphanum_fraction": 0.6704233492, "num_tokens": 2435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.9241418147556224, "lm_q1q2_score": 0.8560360159691418}} {"text": "\\section{Logistic equation}\n\n\\subsection{Why Logistic Equation}\n\n\\textbf{Logistic equation} is an \\textit{Ordinary Differential Equation} that is\nused to analyze the population change in a system. Before the theory of logistic\nmodel is established, people were considering population using exponential\nmodel (in which the rate of growth/decay is directly proportional to the current\npopulation), and the differential equation that describes this is:\n\n$$\n\\frac{dN}{dt}=rN\n\\footnote{$N$ stands for the current population, $t$ stands for time, and $r$\nis the speed factor of the rate of change}\n$$\n\nIn fact, a system may also have a limitation of resources for a species to live,\nso the proposer Malthus believed that the population in a system may oscillate\nand eventually will reach a number, which is known as the \\textbf{Carrying\ncapacity}. Therefore, the differential equation of logistic model is:\n\n$$\n\\frac{dN}{dt}=rN\\left(\\frac{K-N}K\\right)\n\\footnote{$K$ is the carrying capacity}\n$$\n\nAs you can see, when $N$ is greater than $K$, the population will decrease, and\nif $N$ is less than $K$, the population will increase. Since the size of $N$\naffects the sign of the derivative.\n\n\\subsection{Solve Logistic Equation}\n\nSince we have known the origin and the meaning of this differential equation,\nwe can now figure a function out that can satisfy this population model along\nwith the equation.\n\nUsing Leibniz notation to represent derivatives can help us solve differential\nequation by separating the differentiated variables:\n\n$$dN=rN\\left(\\frac{K-N}k\\right)dt$$\n\nSince $r$ and $K$ are constants, we can leave $r$ alone and let the whole\npolynomial related to $N$ be on the left side of the equation:\n\n$$\n\\begin{aligned}\n\t\\frac{dN}{N(K-N)}=\\frac{r}Kdt \\\\\n\t\\int\\frac{dN}{N(K-N)}=\\int\\frac{r}Kdt\n\\end{aligned}\n$$\n\nThe right part we can immediately come up with the answer $\\frac{r}Kt+C$, but\nthe left part we need to cope with it longer:\n\n$$\n\\begin{aligned}\n\t\\because\\int\\frac{dN}{N(K-N)}=\\int\\frac{A}{N}dN+\\frac{B}{K-N}dN \\\\\n\t\\therefore A(K-N)+BN=1 \\\\\n\t\\therefore AK-AN+BN=1 \\\\\n\t\\therefore AK-N(A-B)=1 \\\\\n\\end{aligned}\n$$\n\nSince we know that $N$ is a variable and $K$ is a constant, we can quickly\nconclude that the factor of the variable must be zero in order to let the result\nbe $1$:\n\n$$\n\\begin{aligned}\n\t\\because\\begin{cases}\n\t\tAK=1 \\\\\n\t\tA-B=0\n\t\\end{cases} \\\\\n\t\\therefore A=B=\\frac1K\n\\end{aligned}\n$$\n\nTherefore the integral of the left part is:\n\n$$\n\\begin{aligned}\n\t\\int\\frac{dN}{N(K-N)}\n\t&=\\frac1K\\left(\\int\\frac{dN}{N}+\\int\\frac{dN}{K-N}\\right) \\\\\n\t&=\\frac1K\\left(\\ln(N)-\\ln(K-N)+C_0\\right) \\\\\n\t&=\\frac1K\\ln(\\frac{N}{K-N})+C'\n\\end{aligned}\n$$\n\nBecause both left and right parts of the equations are integrated, we can now\nevaluate them to the original equation:\n\n$$\n\\begin{aligned}\n\t\\frac1K\\ln(\\frac{N}{K-N})+C'=\\frac{r}Kt+C \\\\\n\t\\ln(\\frac{N}{K-N})=rt+C'' \\\\\n\t\\frac{N}{K-N}=C_0e^{rt} \\\\\n\tN=C_0e^{rt}(K-N) \\\\\n\tN(1+C_0e^{rt})=KC_0e^{rt} \\\\\n\tN=\\frac{KC_0e^{rt}}{1+C_0e^{rt}} \\\\\n\tN=N(t)=\\frac{K}{1+C_1e^{-rt}}\n\\end{aligned}\n$$\n\nFinally we obtain the solution of this equation, which is called logistic\nfunction. However this is not finished yet, the meaning of $C_1$ is not clear\nenough. We can add a limiting condition where $N(0)=N_0$\\footnote{To specify\nthe initial population of the system}:\n\n$$\nN(0)=\\frac{K}{1+C_1e^{-r0}}=\\frac{K}{1+C_1}\n$$\n\nWe know that when $t=0$, $N$ shall be equal to the initial population $N_0$, so:\n\n$$\n\\begin{aligned}\n\tN_0=\\frac{K}{1+C_1} \\\\\n\tN_0(1+C_1)=K \\\\\n\tN_0C_1=K-N_0 \\\\\n\tC_1=\\frac{K-N_0}{N_0}\n\\end{aligned}\n$$\n\nLet's plug $C_1$ in terms of $N_0$ to the function:\n\n$$\n\\begin{aligned}\n\tN(t)\n\t&=\\frac{K}{1+\\frac{K-N_0}{N_0}e^{-rt}} \\\\\n\t&=\\frac{KN_0}{N_0+(K-N_0)e^{-rt}}\n\\end{aligned}\n$$\n\nFinally we have the formula for logistic function:\n\n$$\nN(t)=\\frac{KN_0}{N_0+(K-N_0)e^{-rt}}\n$$\n", "meta": {"hexsha": "ede5fbb244366aafc9965934240fb6f23bf84d0b", "size": 3822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "logistic-ode.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "logistic-ode.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "logistic-ode.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 27.4964028777, "max_line_length": 80, "alphanum_fraction": 0.6967556253, "num_tokens": 1277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.9230391600697869, "lm_q1q2_score": 0.8559926393462975}} {"text": "\\chapter{Topology}\n\n\\section{Open set topology}\n\nLet \\(X\\) be a set.\nLet \\(P(A) = 2^A\\) be the power set of \\(A\\).\nWe say that \\(T \\subseteq P(P(X))\\) is a \\emph{topology} on \\(X\\) iff\n\\begin{enumerate*}[label={(\\arabic*)}]\n \\item \\(\\{ \\emptyset, X \\} \\subseteq T\\),\n \\item \\(T\\) is closed under union, and\n \\item \\(T\\) is closed under intersection.\n\\end{enumerate*}\n\nA \\emph{topological space} is \\(S = (X,T)\\) where \\(X\\) is a set and \\(T\\) is a topology on \\(X\\).\nEach element of \\(T\\) is an \\emph{open set} of \\(S\\).\n\n\\section{Topological manifold}\n\n% https://en.wikipedia.org/wiki/Topological_manifold#Formal_definition\n\n% topological manifold\n\n% locally Euclidean\n\n% Hausdorff space\n", "meta": {"hexsha": "8688301e2ac0a847a13fdf5b427df44c289de0cc", "size": 698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/topology.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/topology.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/topology.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 26.8461538462, "max_line_length": 98, "alphanum_fraction": 0.6446991404, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.962673109443157, "lm_q2_score": 0.8887587846530938, "lm_q1q2_score": 0.855584182766915}} {"text": "\\subsubsection{Gaussian Integral}\r\n\\noindent\r\nLet's compute $\\iint\\limits_{D}{e^{-x^2-y^2}\\mathrm{d}A}$ where $D$ is the unit disk.\r\n\\begin{equation*}\r\n\tA = \\int_{-1}^{1}{\\int_{-\\sqrt{1 - x^2}}^{\\sqrt{1 - x^2}}{e^{-x^2 - y^2}\\mathrm{d}y}\\mathrm{d}x} = \\int_{0}^{1}{\\int_{0}^{2\\pi}{e^{-r^2}r\\mathrm{d}\\theta}\\mathrm{d}r} = \\int_{0}^{1}{re^{-r^2}\\mathrm{d}r} \\cdot \\int_{0}^{2\\pi}{\\mathrm{d}\\theta}.\r\n\\end{equation*}\r\nLet $u = -r^2$, $\\mathrm{d} u =-2r\\mathrm{d}r$.\\\\\r\n\\begin{align*}\r\n\t&= \\frac{1}{2}\\int_{0}^{-1}{e^u\\mathrm{d}u} \\cdot 2\\pi\t\\\\\r\n\t&= \\pi\\left(1 - \\frac{1}{e}\\right).\r\n\\end{align*}\r\nNow, let's have $D = \\mathbb{R}^2$. This is the famous Gaussian Integral.\r\n\\begin{align*}\r\n\t&= \\int_{0}^{\\infty}{\\int_{0}^{2\\pi}{re^{-r^2}\\mathrm{d}\\theta}\\mathrm{d}r} \\\\\r\n\t&= \\int_{0}^{\\infty}{re^{-r^2}\\mathrm{d}r} \\cdot \\int_{0}^{2\\pi}{\\mathrm{d}\\theta}.\r\n\\end{align*}\r\nLet $ u =-r^2$, $\\mathrm{d}u = -2r\\mathrm{d}r$.\r\n\\begin{align*}\r\n\t&= -\\pi\\int_{0}^{-\\infty}{e^{u}\\mathrm{d}u} \\\\\r\n\t&= -\\pi\\left(\\left(\\lim_{a\\to -\\infty}{e^{a}}\\right) - e^0\\right) \\\\\r\n\t&= -\\pi\\left(0 - 1\\right) \\\\\r\n\t&= \\pi\r\n\\end{align*}\r\n", "meta": {"hexsha": "e23ddc5aa0500f4a5541ba7e455bee711e9d6259", "size": 1106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/gaussianIntegral.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/gaussianIntegral.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/gaussianIntegral.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 46.0833333333, "max_line_length": 246, "alphanum_fraction": 0.5452079566, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.9184802440252811, "lm_q1q2_score": 0.8555299124478629}} {"text": "\n%!TEX root = sympy_tutorial.tex\n\n\n\n\n%======================================================================= matrices\n\\section{Linear algebra}\n\\label{sec:linear_algebra}\n\n%\\ifthenelse{\\boolean{FORLA}}{\n\n\n\\small\n\\begin{verbatimtab}\nfrom sympy import Matrix\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nA matrix $A \\in \\mathbb{R}^{m\\times n}$ is a rectangular array of real numbers with $m$ rows and $n$ columns.\nTo specify a matrix $A$, we specify the values for its $mn$ components $a_{11}, a_{12}, \\ldots, a_{mn}$\nas a list of lists:\n\n\\small\n\\begin{verbatimtab}\n>>> A = Matrix( [[ 2,-3,-8, 7],\n [-2,-1, 2,-7],\n [ 1, 0,-3, 6]] )\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nUse the square brackets to access the matrix elements or to obtain a submatrix:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> A[0,1] # row 0, col 1of A \n-3\n>>> A[0:2,0:3] # top-left 2x3 submatrix of A \n[ 2, -3, -8]\n[-2, -1, 2]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nSome commonly used matrices can be created with shortcut methods:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> eye(2) # 2x2 identity matrix\n[1, 0]\n[0, 1]\n>>> zeros((2, 3))\n[0, 0, 0]\n[0, 0, 0]\n\\end{verbatimtab}\n\\normalsize\n\n%TODO explain matrix concatenation operations: \n%>>> M1.row_join(M2)\n%[1 0 0 0 0 0 0]\n%[ ]\n%[0 1 0 0 0 0 0]\n%[ ]\n%[0 0 1 0 0 0 0]\n%>>> M3 = zeros((4, 3))\n%>>> M1.col_join(M3)\n\n\n\\noindent\nStandard algebraic operations like \naddition \\texttt{+}, subtraction \\texttt{-}, multiplication \\texttt{*},\nand exponentiation \\texttt{**} work as expected for \\texttt{Matrix} objects.\n%\nThe \\texttt{transpose} operation flips the matrix through its diagonal:\n\n\\small\n\\begin{verbatimtab}\n>>> A.transpose() # the same as A.T\n[ 2, -2, 1]\n[-3, -1, 0]\n[-8, 2, -3]\n[ 7, -7, 6]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nRecall that the transpose is also used to convert row vectors into column vectors and vice versa.\n\n\n\\subsection{Row operations}\n\\label{matrices:row_operations}\n\n\\small\n\\begin{verbatimtab}\n>>> M = eye(3)\n>>> M[1,:] = M[1,:] + 3*M[0,:]\n>>> M\n[1, 0, 0]\n[3, 1, 0]\n[0, 0, 1] \\end{verbatimtab}\n\\normalsize\n\nThe notation \\texttt{M[i,:]} refers to entire rows of the matrix.\nThe first argument specifies the $0$-based row index,\nfor example the first row of~\\texttt{M} is \\texttt{M[0,:]}.\nThe code example above implements the row operation $R_2 \\gets R_2 + 3R_1$.\nTo scale a row \\texttt{i} by constant \\texttt{c}, use the command \\texttt{ M[i,:] = c*M[i,:]}.\nTo swap rows \\texttt{i} and \\texttt{j}, use can use the \\texttt{Python} tuple-assignment syntax \\texttt{ M[i,:], M[j,:] = M[j,:], M[i,:]}.\n%The method \\texttt{row\\_op} takes two arguments as inputs:\n%the first argument specifies the $0$-based index of the row you want to act on,\n%while the second argument is a function of the form \\texttt{f(val,j)}\n%that describes how you want the value \\texttt{val=M[i,j]} to be transformed.\n% The above call to \\texttt{row\\_op} implements the row operation $R_2 \\gets R_2 + 3R_1$.\n%The expression \\texttt{lambda a,b: a+b} is the \\texttt{Python} syntax for creating an anonymous function with arguments\n%\\texttt{a} and \\texttt{b}, which computes their sum \\texttt{a+b}.\n\n\\vspace{-2mm}\n\n\\subsection{Reduced row echelon form}\n\\label{matrices:reduced_row_echelon_form}\n\nThe Gauss--Jordan elimination procedure is a sequence of row operations you can perform\non any matrix to bring it to its \\emph{reduced row echelon form} (RREF).\nIn \\texttt{SymPy}, matrices have a \\texttt{rref} method that computes their RREF: \n\n\\small\n\\begin{verbatimtab}\n>>> A = Matrix( [[2,-3,-8, 7],\n [-2,-1,2,-7],\n [1 ,0,-3, 6]])\n>>> A.rref()\n([1, 0, 0, 0] # RREF of A\n [0, 1, 0, 3] # locations of pivots\n [0, 0, 1, -2], [0, 1, 2] )\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote the \\texttt{rref} method returns a tuple of values:\nthe first value is the RREF of $A$,\nwhile the second tells you the indices of the leading ones (also known as pivots) in the RREF of $A$.\nTo get just the RREF of $A$, select the $0$\\textsuperscript{th} entry form the tuple: \\texttt{A.rref()[0]}.\n\n%\n%\\small\n%\\begin{verbatimtab}\n%>>> Arref = A.rref()[0]\n%>>> Arref\n%[1, 0, 0, 0]\n%[0, 1, 0, 3]\n%[0, 0, 1, -2]\n%\\end{verbatimtab}\n%\\normalsize\n\n\\vspace{-2mm}\n\n\n\\subsection{Matrix fundamental spaces}\n\\label{matrices:matrix_fundamental_spaces}\n\nConsider the matrix $A \\in \\mathbb{R}^{m\\times n}$.\nThe fundamental spaces of a matrix are its column space $\\mathcal{C}(A)$, \nits null space $\\mathcal{N}(A)$,\nand its row space $\\mathcal{R}(A)$.\nThese vector spaces are important when you consider the matrix product\n$A\\vec{x}=\\vec{y}$ as ``applying'' the linear transformation $T_A:\\mathbb{R}^n \\to \\mathbb{R}^m$\nto an input vector $\\vec{x} \\in \\mathbb{R}^n$ to produce the output vector $\\vec{y} \\in \\mathbb{R}^m$.\n\n\\textbf{Linear transformations} $T_A:\\mathbb{R}^n \\to \\mathbb{R}^m$ (vector functions)\n\\textbf{are equivalent to $m\\times n$ matrices}.\nThis is one of the fundamental ideas in linear algebra.\nYou can think of $T_A$ as the abstract description of the transformation \nand $A \\in \\mathbb{R}^{m\\times n}$ as a concrete implementation of $T_A$.\nBy this equivalence, \nthe fundamental spaces of a matrix $A$\ntell us facts about the domain and image of the linear transformation $T_A$.\nThe columns space $\\mathcal{C}(A)$ is the same as the image space space $\\textrm{Im}(T_A)$ (the set of all possible outputs).\nThe null space $\\mathcal{N}(A)$ is the same as the kernel $\\textrm{Ker}(T_A)$ (the set of inputs that $T_A$ maps to the zero vector).\nThe row space $\\mathcal{R}(A)$ is the orthogonal complement of the null space.\nInput vectors in the row space of $A$ are in one-to-one correspondence with the output vectors in the column space of $A$.\n\nOkay, enough theory! Let's see how to compute the fundamental spaces of the matrix $A$ defined above.\nThe non-zero rows in the reduced row echelon form of $A$ are a basis for its row space:\n\n\\small\n\\begin{verbatimtab}\n>>> [ A.rref()[0][r,:] for r in A.rref()[1] ] # R(A)\n[ [1, 0, 0, 0], [0, 1, 0, 3], [0, 0, 1, -2] ]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe column space of $A$ is the span of the columns of $A$ that contain the pivots\nin the reduced row echelon form of $A$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> [ A[:,c] for c in A.rref()[1] ] # C(A)\n[ [ 2] [-3] [-8]\n [-2], [-1], [ 2]\n [ 1] [ 0] [-3] ]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote we took columns from the original matrix $A$ and not its RREF.\n\n\nTo find the null space of $A$, call its \\texttt{nullspace} method:\n\n\\small\n\\begin{verbatimtab}\n>>> A.nullspace() # N(A)\n[ [0, -3, 2, 1] ]\n\\end{verbatimtab}\n\\normalsize\n\\subsection{Determinants}\n\\label{matrices:determinants}\n\nThe determinant of a matrix, \ndenoted $\\det(A)$ or $|A|$, \nis a particular way to multiply the entries of the matrix to produce a single number.\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> M = Matrix( [[1, 2, 3], \n [2,-2, 4],\n [2, 2, 5]] )\n>>> M.det() \n2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nDeterminants are used for all kinds of tasks:\nto compute areas and volumes,\nto solve systems of equations, \nand to check whether a matrix is invertible or not.\n\n\\subsection{Matrix inverse}\n\\label{matrices:matrix_inverse}\n\nFor every invertible matrix $A$,\nthere exists an inverse matrix $A^{-1}$ which \\emph{undoes} the effect of $A$.\nThe cumulative effect of the product of $A$ and $A^{-1}$ (in any order)\nis the identity matrix: $AA^{-1}= A^{-1}A=\\mathbbm{1}$.\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> A = Matrix( [[1,2], \n [3,9]] ) \n>>> A.inv() \n[ 3, -2/3]\n[-1, 1/3]\n>>> A.inv()*A\n[1, 0]\n[0, 1]\n>>> A*A.inv()\n[1, 0]\n[0, 1]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe matrix inverse $A^{-1}$ plays the role of division by $A$.\n\n\n\\vspace{-3mm}\n\n\\subsection{Eigenvectors and eigenvalues}\n\\label{matrices:eigenvectors_and_eigenvalues}\n\n\\vspace{-1mm}\n\n\t\tWhen a matrix is multiplied by one of its eigenvectors the output\n\t\tis the same eigenvector multiplied by a constant $A\\vec{e}_\\lambda =\\lambda\\vec{e}_\\lambda$.\n\t\tThe constant $\\lambda$ (the Greek letter \\emph{lambda}) is called an \\emph{eigenvalue} of $A$.\n\t\t%\t\tand the vector is called an \\emph{eigenvector}.\t\t\n\t\t%\t\\[ \n\t\t%\t \\Rightarrow\n\t\t%\t \\quad\n\t\t%\t \\left( A-\\lambda \\mathbbm{1}\\right)\t\\vec{e}_\\lambda \t= \\vec{0}.\n\t\t%\t\\]\n\t\t%Thinking of matrices in term of their eigenvalues and eigenvectors is\n\t\t%a very powerful technique for describing their properties.\n\t\t%In particular \n\t\t\n\t\tTo find the eigenvalues of a matrix, start from the definition $A\\vec{e}_\\lambda =\\lambda\\vec{e}_\\lambda$,\n\t\tinsert the identity $\\mathbbm{1}$, \n\t\tand rewrite it as a null-space problem:\n\t\t\\[\n\t\t\tA\\vec{e}_\\lambda =\\lambda\\mathbbm{1}\\vec{e}_\\lambda\n\t\t\t\\qquad\n\t\t\t\\Rightarrow\n\t\t\t\\qquad\n\t\t\t\\left(A - \\lambda\\mathbbm{1}\\right)\\vec{e}_\\lambda = \\vec{0}.\n\t\t\\]\n\t\tThis equation will have a solution whenever $|A - \\lambda\\mathbbm{1}|=0$.\\footnote{The invertible matrix theorem states\n\t\tthat a matrix has a non-empty null space if and only if its determinant is zero.}\n\t\t%\n\t\tThe eigenvalues of $A \\in \\mathbb{R}^{n \\times n}$, \n\t\tdenoted $\\{ \\lambda_1, \\lambda_2, \\ldots, \\lambda_n \\}$,\n\t\tare the roots of the \\emph{characteristic polynomial} $p(\\lambda)=|A - \\lambda \\mathbbm{1}|$.\n\t\t\n\t\t\n\n\\small\n\\begin{verbatimtab}\n>>> A = Matrix( [[ 9, -2],\n [-2, 6]] )\n>>> A.eigenvals() # same as solve( det(A-eye(2)*x), x)\n{5: 1, 10: 1} # eigenvalues 5 and 10 with multiplicity 1\n>>> A.eigenvects() \n[(5, 1, [ 1] \n [ 2] ), (10, 1, [-2]\n [ 1] )]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\n\n\n\t\tCertain matrices can be written entirely in terms of their eigenvectors and their eigenvalues.\n\t\tConsider the matrix $\\Lambda$ (capital Greek \\emph{L}) that has the eigenvalues of the matrix $A$ on the diagonal, \n\t\tand the matrix $Q$ constructed from the eigenvectors of~$A$ as columns:\n\t\t \\[\n\t\t \\Lambda = \n\t\t \\scriptscriptstyle\n\t\t \\begin{bmatrix}\n\t\t \\lambda_1\t& \\cdots & 0 \\\\\n\t\t \\vdots \t& \\ddots & 0 \\\\\n\t\t 0 \t& 0 & \\lambda_n\n\t\t \\end{bmatrix}\\!,\n\t\t \\ \\ \n\t\t {\\textstyle Q} \\: \n\t\t = \n\t\t \\begin{bmatrix}\n\t\t \\big| & &\\Huge| \\\\[1.2mm]\n\t\t \\vec{e}_{\\lambda_1} & \\! \\cdots \\! & \\large\\vec{e}_{\\lambda_n} \\\\[1.2mm]\n\t\t \\big| & & \\Huge| \n\t\t \\end{bmatrix}\\!,\n\t\t \\ \\ \n\t\t {\\textstyle\n\t\t \\textrm{then}\n\t\t \\ \\ \n\t\t A = Q\\Lambda Q^{-1}.\n\t\t }\n\t\t \\]\n\n\t\tMatrices that can be written this way are called \\emph{diagonalizable}.\t\t\n\t\t%The matrix $A$ can be written as the product of three matrices\n\t\t%$A=Q\\Lambda Q^{-1}$.\n\t\t%This is called the \\emph{eigendecomposition} of $A$.\n\t\t%The matrix $Q$ contains the eigenvectors of $A$ as columns.\n\t\t%The matrix $\\Lambda$ contains the eigenvalues of $A$ on its diagonal.\nTo \\emph{diagonalize} a matrix $A$ is to find its $Q$ and $\\Lambda$ matrices:\n\n\\small\n\\begin{verbatimtab}\n>>> Q, L = A.diagonalize()\n>>> Q # the matrix of eigenvectors \n[1, -2] # as columns \n[2, 1]\n>>> Q.inv()\n[ 1/5, 2/5]\n[-2/5, 1/5]\n>>> L # the matrix of eigenvalues\n[5, 0]\n[0, 10]\n>>> Q*L*Q.inv() # eigendecomposition of A\n[ 9, -2]\n[-2, 6]\n>>> Q.inv()*A*Q # obtain L from A and Q \n[5, 0]\n[0, 10]\n\\end{verbatimtab}\n\\normalsize\n\t\t\n\t\t\nNot all matrices are diagonalizable.\nYou can check if a matrix is diagonalizable by calling its \\texttt{is\\_diagonalizable} method:\n\n\\small\n\\begin{verbatimtab}\n>>> A.is_diagonalizable()\nTrue\n>>> B = Matrix( [[1, 3],\n \t [0, 1]] )\n>>> B.is_diagonalizable()\nFalse\n>>> B.eigenvals()\n{1: 2} # eigenvalue 1 with multiplicity 2\n>>> B.eigenvects()\n[(1, 2, [1]\n [0] )]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe matrix $B$ is not diagonalizable because it doesn't have a full set of eigenvectors.\nTo diagonalize a $2\\times 2$ matrix, we need two orthogonal eigenvectors but $B$ has only a single eigenvector.\nTherefore, we can't construct the matrix of eigenvectors $Q$ (we're missing a column!) \nand so $B$ is not diagonalizable.\n\nNon-square matrices don't have eigenvectors and therefore don't have an eigendecomposition.\nInstead, we can use the \\emph{singular value decomposition} to break up a non-square matrix $A$ into \nleft singular vectors,\nright singular vectors, \nand a diagonal matrix of singular values.\nUse the \\texttt{singular\\_values} method on any matrix to find its singular values.\n\n%\\subsection{QR decomposition}\n%\\label{matrices:qr_decomposition}\n\n%It is possible to write a matrix $A$ as the product of an orthogonal matrix $Q$\n%and an upper triangular matrix $R$.\n%This is known as the QR-decomposition.\n\n%\\small\n%\\begin{verbatimtab}\n%>>> A=Matrix( [[12,-51,4], \n% [6,167,-68], \n% [-4,24,-41]] )\n%>>> Q,R = A.QRdecomposition()\n%>>> Q\n%[ 6/7, -69/175, -58/175]\n%[ 3/7, 158/175, 6/175]\n%[-2/7, 6/35, -33/35]\n%>>> Q*Q.T # verify Q is orthogonal \n%[1, 0, 0] \n%[0, 1, 0]\n%[0, 0, 1] \n%>>> R # and R is upper triangular\n%[14, 21, -14] \n%[ 0, 175, -70] \n%[ 0, 0, 35]\n%>>> Q*R # verify QR = A \n%[12, -51, 4]\n%[ 6, 167, -68]\n%[-4, 24, -41]\n%\\end{verbatimtab}\n%\\normalsize\n%\n%\\noindent\n%Each \\texttt{sympy} matrix is also equipped with \n%\\href{https://en.wikipedia.org/wiki/LU_decomposition}{\\texttt{LUdecomposition}}\n%and \\href{https://en.wikipedia.org/wiki/Cholesky_decomposition}{\\texttt{cholesky}} decomposition methods.\n\n\n", "meta": {"hexsha": "f6a5bc27ccff0bfa7d8296b17eaa8a306976f3c3", "size": 13652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "99.LA_sympy_tutorial.tex", "max_stars_repo_name": "ivanistheone/sympy_tutorial", "max_stars_repo_head_hexsha": "fa13b4d82c9bdbf4d2fc6083e603dace36a00fc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-11-24T02:58:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-01T16:23:20.000Z", "max_issues_repo_path": "99.LA_sympy_tutorial.tex", "max_issues_repo_name": "ivanistheone/sympy_tutorial", "max_issues_repo_head_hexsha": "fa13b4d82c9bdbf4d2fc6083e603dace36a00fc2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "99.LA_sympy_tutorial.tex", "max_forks_repo_name": "ivanistheone/sympy_tutorial", "max_forks_repo_head_hexsha": "fa13b4d82c9bdbf4d2fc6083e603dace36a00fc2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-05-02T13:07:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T01:16:18.000Z", "avg_line_length": 29.5497835498, "max_line_length": 138, "alphanum_fraction": 0.6288455904, "num_tokens": 4614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9609517095103499, "lm_q2_score": 0.8902942275774318, "lm_q1q2_score": 0.8555297599577296}} {"text": "\n\\subsection{Definition}\n\nA sequence is an ordered list of terms.\n\nThese are commonly maps from natural numbers to real (or complex) numbers.\n\nWe can use \\(a_i=f(i)\\) to denote this.\n\nIf \\(f(i)\\) is defined on all \\(i\\in \\mathbb{N}\\) then the sequence is infinite. Otherwise it is finite.\n\nIf a sequence is defined on \\(n\\in \\mathbb{N}\\) and \\(n\\ne 0\\) then the sequence must be defined on \\(n-1\\).\n\nFor example \\(a_0, a_1, a_2,...\\) is a sequence, but \\(a_1,a_2,...\\) is not.\n\n\\subsection{Monotone sequence}\n\nA monotone sequence is one where each element is succeeded ordinally by the next entry.\n\nFor example:\n\n\\(<1,2,3,6,7>\\) is monotone\n\n\\(<1,2,3,3,4>\\) is not monotone\n\nAn increasing sequence is one where:\n\n\\(\\forall m \\in \\mathbb{N} \\forall n\\in \\mathbb{N} [m > n \\leftrightarrow a_m \\ge a_n]\\)\n\nA strictly increasing sequence is one where:\n\n\\(\\forall m \\in \\mathbb{N} \\forall n\\in \\mathbb{N} [m > n \\leftrightarrow a_m > a_n]\\)\n\nA decreasing sequence is one where:\n\n\\(\\forall m \\in \\mathbb{N} \\forall n\\in \\mathbb{N} [m > n \\leftrightarrow a_m \\le a_n]\\)\n\nA strictly decreasing sequence is one where:\n\n\\(\\forall m \\in \\mathbb{N} \\forall n\\in \\mathbb{N} [m > n \\leftrightarrow a_m < a_n]\\)\n\nAll strictly decreasing sequences are decreasing, and all strictly increasing sequences are increasing.\n\nA monotone sequence is one which is either increasing or decreasing.\n\n\\subsection{Subsequences}\n\nA subsequence of a sequence is the original sequence with some elements of the original removed, not changing the order.\n\nFor example:\n\n\\(<1,3,5>\\) is a subsequence of \\(<2,1,3,4,7,5>\\)\n\n", "meta": {"hexsha": "0b4cf279e626d97abd97e8ade7931925c0ed88cd", "size": 1587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sequences/01-01-Sequences.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sequences/01-01-Sequences.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sequences/01-01-Sequences.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3888888889, "max_line_length": 120, "alphanum_fraction": 0.7051039698, "num_tokens": 476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.9059898203834277, "lm_q1q2_score": 0.8554146270429949}} {"text": "\n\\subsection{Linear maps}\n\n\\subsubsection{Homomorphisms between vector spaces}\n\nHomomorphisms map between algebras, preserving the underlying structure.\n\nA homomorphism vetween vector space \\(V\\) and vector space \\(W\\) can be described as:\n\n\\(\\hom (V, W)\\)\n\nHomomorphism between vector spaces must preserve the group-like structure of the vector space.\n\n\\(f(u+v)=f(u)+f(v)\\)\n\nThe homomorphism must also preserve scalar multiplication.\n\n\\(f(\\alpha v)=\\alpha f(v)\\)\n\nA linear map (or function) is a map from one input to an output which preserves addition and scalar multiplication.\n\nThat is if function \\(f\\) is linear then:\n\n\\(f(aM+bN)=af(M)+bf(N)\\)\n\n\\subsubsection{Alternative names for homomorphisms}\n\nVector spaces homomorphisms are also called linear maps or linear functions.\n\n", "meta": {"hexsha": "fc32edb3d79265ea9cc0814a57b6da59d9cf951f", "size": 782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-01-morphisms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/maps/01-01-morphisms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/maps/01-01-morphisms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0666666667, "max_line_length": 115, "alphanum_fraction": 0.7557544757, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813501370537, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.8554020398815253}} {"text": "\\section{Directional Statistics}\n\n\\subsection{Mean Direction}\nThe mean direction of a collection of $i$ vectors $\\{\\mathbf{x}\\}_i$ is \\cite{damask2019consistently}:\n\n\\begin{equation}\n\\left<\\mathbf{x}\\right> = \\frac{\\mathbf{x_s}}{||\\mathbf{x_s}||_2}\n\\end{equation}\n\nWhere\n\n\\begin{equation}\n\\mathbf{x_s} = \\sum_i \\mathbf{x_i}\n\\end{equation}\n\nThe mean vector is not defined in case $||\\mathbf{x_s}||_2 = 0$. The alternative way to calculate the mean direction might make use of angles but apparently that creates ambiguity with respect to the choice of a \"zero\" angle (cf. footnote in \\citeasnoun{damask2019consistently}).\n\n\n\n\\subsection{Dispersion}\n\nDispersion is a measure of the variance on the direction of a set of vectors $\\{\\mathbf{x}\\}_i$. For a system of vectors, for example an eigenbasis, there are common and differential modes of dispersion. One way of measuring directional dispersion is to look at the \\textit{mean resultant length}:\n\n\\begin{equation}\n\\mu_r = \\frac{||\\mathbf{x_s}||}{N}\\ \\ \\ 0\\leq \\mu_r \\leq 1\n\\end{equation}\n\n\n\\textit{Circular variance} may be defined as $\\sigma_c = 1-\\mu_r$, but apparently there is an issue with generalization to higher dimensions. (TO DO)\n\nAn alternative is a model based approach, for example based on the von Mises - Fisher Distribution.\n\nIn the case of a basis, \\citeasnoun{damask2019consistently} states that, in order to understand the drivers for variation, dispersion parameters should be calculated for each descending subspace of the basis, first including all of the eigenvectors, then excluding the first eigenvector, etc.\n\t\n\n\n", "meta": {"hexsha": "e6bfdff68e768cd2165147e7fc6b865f5eea0d3d", "size": 1589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_directional.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_directional.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_directional.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9459459459, "max_line_length": 297, "alphanum_fraction": 0.7589679043, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741214369554, "lm_q2_score": 0.8976952832120991, "lm_q1q2_score": 0.8551212957238642}} {"text": "\n\\subsection{Hessian matrix}\n\nWe can take a function and make a matrix of its second order partial derivatives. This is the Hessian matrix, and it describes the local curvature of the function.\n\nIf the function \\(f\\) has \\(n\\) parameters, the Hessian matrix is \\(n\\times n\\), and is defined as:\n\n\\(H_{ij}=\\dfrac{\\delta^2 f}{\\delta x_i \\delta x_j}\\)\n\nIf the function is convex, then the Hessian matrix is positive semi-definite for all points, and vice versa.\n\nIf the function is concave, then the Hessian matrix is negative semi-definite for all points, and vice versa.\n\nWe can diagnose critical points by evaluating the Hessian matrix at those points.\n\nIf it is positive definite, it is a local minimum. If it is negative definite it is a local maximum. If there are both positive and negative eigenvalues it is a saddle point.\n\n", "meta": {"hexsha": "496e2217c9d70f0a1e46b86caef957c586247629", "size": 831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationUni/01-08-hessian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationUni/01-08-hessian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationUni/01-08-hessian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.1666666667, "max_line_length": 174, "alphanum_fraction": 0.7641395909, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377296574669, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.8548345430462079}} {"text": "\\section{Differentiability}\r\nAs we saw when looking at left and right hand derivatives, a derivative will fail to exist when the left and right hand derivatives differ.\r\nHowever, there are several other cases where a function might not be differentiable at a point.\r\n\\begin{enumerate}\r\n\t\\item \\textbf{Corner: } This is the simplest case where both the one sided derivatives exist, are finite, but are different.\r\n\t\tAn example would be $f(x)=\\abs{x}$ at $x=0$.\r\n\t\\item \\textbf{Cusp: } This is sort of an extreme example of a corner where the one of the one sides derivatives approaches $-\\infty$ and the other approaches $\\infty$.\r\n\t\tAn example would be $f(x)=\\sqrt[3]{x^2}$ at $x=0$.\r\n\t\\item \\textbf{Vertical Tangent: } This is where the one sided derivatives exist and agree, but approach $-\\infty$ or $\\infty$.\r\n\t\tAn example would be $f(x)=\\sqrt[3]{x}$ at $x = 0$.\r\n\t\\item \\textbf{Discontinuity: } This is where one of the one sided derivatives doesn't exist.\r\n\t\tAn example would be the unit step function at $x=0$, which is 1 for $x \\geq 0$ and -1 for $x < 0$.\r\n\\end{enumerate}\r\n\r\n\\subsection{Differentiability Implies Local Linearity}\r\nA function is locally linear at a point $a$ when it is differentiable at $a$ and closely resembles its own tangent line at $a$.\r\nVisually, what this means is that as you ``zoom in'' on a locally linear point, the curve will look more and more like a line.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{locally_linear}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.25\\textwidth]{./derivatives/cos1.png}\r\n\t\\includegraphics[width = 0.25\\textwidth]{./derivatives/cos2.png}\r\n\t\\includegraphics[width = 0.25\\textwidth]{./derivatives/cos3.png}\r\n\t\\caption{\\hyperref{}{}{}{Zooming in on a $\\cos$ curve}}\r\n\\end{figure}\r\n\r\n\\subsubsection{Numerical Approximation: Symmetric Difference Quotient}\r\nWe can use the derivative at a point and a very small value of $h$ to approximate the tangent slope.\r\nHowever, we can get a better estimate with the same value of $h$ by using the symmetric difference quotient.\r\n\\begin{equation*}\r\n\t\\frac{f(a+h)-f(a-h)}{2h}.\r\n\\end{equation*}\r\n\r\nA calculator might prefer this formula because it tends to give better approximations.\r\n\r\n\\subsection{Differentiability Implies Continuity}\r\n\\begin{theorem}\r\n\tIf $f^\\prime(a)$ exists, then $f$ is continuous at $a$.\r\n\\end{theorem}\r\n\r\nThe converse is not necessarily true: a function can be continuous but not differentiable.\r\n\r\n\\begin{example}\r\n\tDetermine whether or not the follow function is differentiable at $x=2$.\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\begin{cases}\r\n\t\t\tx^2 + 1 & x \\leq 2 \\\\\r\n\t\t\t4x-4 & x > 2\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLooking at the graph of this function, we see there is a jump discontinuity at $x=2$.\r\n\tIf the function was differentiable at $x=2$, it would be continuous at $x=2$.\r\n\tSince it is not continuous at $x=2$, it must not be differentiable at $x=2$.\r\n\\end{answer}", "meta": {"hexsha": "5328baacd66fd531a6246c6adbede2e4a472c2e1", "size": 2911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/differentiability.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/differentiability.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/differentiability.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 51.0701754386, "max_line_length": 169, "alphanum_fraction": 0.7203710065, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.950410972802222, "lm_q2_score": 0.8991213799730774, "lm_q1q2_score": 0.8545348254074887}} {"text": "\\section{General Covariance}\nLet $X \\in V$ be a random variable living in an inner product space V with $E\\left[ X\\right] = 0$\\newline\nDefine: The covariance of X is the quadratic form $\\operatorname{Cov}(X): V \\rightarrow R $ defined by\n$$\n\\operatorname{Cov}(X)(v)=E\\left[\\langle X, v\\rangle^{2}\\right]\n$$ \nIf V is finite dimensional and $e_{1}, \\dots, e_{n}$ is an orthonormal matrix then\n$$\n\\langle X, v\\rangle=X^{\\top} v=v^{\\top} X\n$$ and so \n$$\n\\operatorname{Cov}(X)(v)=\\mathbb{E}\\left[v^{\\top} X X^{\\top} v\\right]=v^{\\top} \\mathbb{E}\\left[X X^{\\top}\\right] v\n$$ \nSometimes, we may define a scalar variance \\newline\n$$\n\\operatorname{Var}(X)=\\mathbb{E}\\left[\\|X\\|^{2}\\right]=\\operatorname{tr}\\left(\\mathbb{E}\\left[X X^{\\top}\\right]\\right)\n$$\n\n\n\\subsection{Whitening}\nConsider transforming the random variable X with a linear transformation matrix A. Then \\newline\n$$\nCov(A X)=\\mathbb{E}\\left[AXX^{\\top} A^{\\top}\\right]=A \\mathbb{E}\\left[X X^{\\top}\\right] A^{\\top}=A V A^{T}\n$$\nwhere $V= \\mathbb{E}\\left[X X^{\\top}\\right]$ is the coveriance of $X$. \nSo if we choose A s.t. \\newline\n$$\nA VA^{\\top}=I \\Leftrightarrow V=A^{-1} A^{-T},\n$$\nthen \n$$\nCov(A X)= I,\n$$ \nso $AX$ is \"white noise\".\nClearly there are many choice for $A$. Namely given an $A$, $OA$ also works for any orthonormal $O$.\n\n\n\\subsection{Batch Normalization}\n\\begin{itemize}\n\\item Calculating an appropriate A is generally competationally too expensive. The most efficient way to do it is likely a Cholesky factorization.\n\\item In BN, we instead choose A diagonal so that \n$$\n\\operatorname{diag}\\left(A \\cup A^{T}\\right)=(1,1, \\ldots, 1)\n$$\n\\item Of course the off-diagonal entries of $A \\cup A^{T}$ will generally not be $O$.\n\\end{itemize}\n\n\n\\subsection{Central Limiting Theorem}\nLet $X_{1}, X_{2}, \\ldots, X_{n}$ be independent copies of $X\\in \\Omega$ with $E\\left[ X\\right] = 0$. Then $V=E\\left[ XX^T\\right] $.\nConsider \n$$\n\\bar{X}_{n}=\\frac{1}{\\sqrt{n}} \\sum\\limits_{i=1}^{n} X_{i}.\n$$ \nAs $n\\rightarrow \\infty$, $\\bar{X}_{n}$ converges to a Gaussian distribution, namely,\n$$\n\\lim_{n \\rightarrow \\infty} \\bar{X}_{n}= {\\rm Gaussian}(0, V)\n$$\nwith distribution\n$$\nP(X)=\\frac{1}{(\\sqrt{2 n}\\ {\\rm det}(V))^{d}} e^{\\frac{-x^{T}V^{-1}x}{2}}d x.\n$$ \n%$\\Omega \\stackrel{X}{\\longrightarrow} R^{d}$ pushforward measure\n% \\includepdf[pages=-,pagecommand={}]{497/handwritten_notes/MultidimensionalVariance.pdf}\n", "meta": {"hexsha": "a1b535458cbc32e409e9662d8d990e0156a74fe3", "size": 2372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/3 Probability/3.4-MultidimensionalVariance.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/3 Probability/3.4-MultidimensionalVariance.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/3 Probability/3.4-MultidimensionalVariance.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4923076923, "max_line_length": 146, "alphanum_fraction": 0.665682968, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.9124361521430956, "lm_q1q2_score": 0.8543002847096284}} {"text": "\n\\subsection{Frobenius norm}\n\nIf we have matrices \\(A\\) and \\(A\\) the distance is:\n\n\\(||A-B||=\\sqrt {\\sum_i \\sum_j |a_{ij}-b_{ij}|^2}\\)\n\nThis is a Euclidian norm.\n\n", "meta": {"hexsha": "b5cddaa7fd6d8f0d6d7f4d8fb7d840391cc75aa4", "size": 164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/02-01-frobenius.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/distance/02-01-frobenius.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/distance/02-01-frobenius.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4, "max_line_length": 52, "alphanum_fraction": 0.6219512195, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9697854138058638, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.854184152676757}} {"text": "\\subsection{Momentum method and Averaged Gradient} \n\nAnother way of thinking about the momentum method is that we are simply replacing our gradient direction by an average of the previously encountered gradients. Specifically, the momentum method can be rewritten\n\\begin{equation}\\label{Ave_grad1}\nx_{t+1} = x_t - \\frac{\\eta_t}{1-\\mu}[\\nabla f]_t,\n\\end{equation}\nwhere $[\\nabla f]_t$ is an average of the past gradients with exponentially decaying weights given by\n\\begin{equation}\\label{Ave_grad2}\n[\\nabla f]_t= (1-\\mu)\\sum_{i=0}^t \\mu^{t-i} \\nabla f(x_i).\n\\end{equation}\n(Note that this isn't quite exactly the average, since it isn't normalized correctly.)\nHere $\\mu$ is the momentum parameter which determines the time scale of the averaging, i.e. how many previous gradients are taken into account. A typical value used in deep learning is $\\mu = 0.9$, which corresponds to an average over around $10$ iterations.\n\nThe relationship between this formulation and the more standard formulation of momentum can be seen by noting the following recursive formula for $[\\nabla f]_t$,\n\\begin{equation}\n[\\nabla f]_t = \\mu[\\nabla f]_{t-1} + (1-\\mu)\\nabla f(x_t).\n\\end{equation}\n\n%Usually, the factor $(1-\\mu)$ is absorbed into the step size $s_t$ in implementations. \nIt is important in this context to note that pushing $\\mu$ closer to $1$ effectively increases the step size. This gives to PyTorch implementations below.\n\n\\begin{theorem}\n\tGiven $v_0=0$ and random initial value $x_0$, the averaged gradient (\\ref{Ave_grad1}) and (\\ref{Ave_grad2}) are equivalent to \n\t\\begin{align}\n\t&v_{t+1} = \\mu v_t + \\nabla f(x_t),\\\\\n\t&x_{t+1} = x_{t} - \\eta_t v_{t+1},\n\t\\end{align}\n\tfor any $t\\geq 0$.\n\\end{theorem}\n\n\n\\begin{algorithm}[H]\\caption{SGD with mini-batch and momentum}\n\t\\label{alg:batch-momentum-SGD}\n\t{\\bf Input}: initialization $x_0$, learning rate $\\eta_t$, momentum parameter $\\mu$, $v_0=0$.\n\t\n\t{\\bf For}: t = 0,1,2,$\\dots$ \n\t\n\t\\begin{center}\n\t\tRandomly pick $B_t \\subset \\{1, 2, \\cdots, N\\}$ independently \\\\\n\t\twith probability $\\frac{1}{\\tbinom{N}{m}}$ and $\\# B_t = m$.\n\t\\end{center}\n\t\\begin{align}\\label{equ:sgd-iteration-momentum}\n\t&v_{t+1} = \\mu v_t + g_t(x_t),\\\\\n\t&x_{t+1} = x_{t} - \\eta_t v_{t+1}.\n\t\\end{align}\n\t\\quad where \n\t$$\n\tg_{t}(x_t) = \\frac{1}{m} \\sum_{i \\in B_{t}} \\nabla f_i(x_t)\n\t$$\n\\end{algorithm}\n\n\n\\subsection{Derivation of momentum method} \n\n\nThe gradient descent method previously introduced can be viewed as a discretization of the gradient flow differential equation\n\\begin{equation}\\label{gradient_flow}\n x'(t) = -\\nabla f(x(t)).\n\\end{equation}\n\nGradient descent with momentum can be understood as a discretization of the damped Hamiltonian dynamics\n\\begin{equation}\\label{hamiltonian}\n \\begin{split}\n &v'(t) = -\\alpha v(t) - \\nabla f(x(t)) \\\\\n &x'(t) = v(t).\n \\end{split}\n\\end{equation}\nThis can be thought of as describing the motion of a particle in a potential well given by $f(x)$ which experiences friction, the strength of which is determined by $\\alpha$.\n\nThe relationship between this and the gradient flow dynamics can be seen by taking the high-friction limit $\\alpha\\rightarrow \\infty$. In fact, rewriting the Hamiltonian dynamics \\eqref{hamiltonian} as\n\\begin{equation}\n x''(t) = v'(t) = -\\alpha x'(t) - \\nabla f(x(t)),\n\\end{equation}\nwe make the time change $s = \\alpha t$ to get\n\\begin{equation}\n \\frac{1}{\\alpha^2}x''(s) + x'(s) +\\nabla f(x(s)) = 0. \n\\end{equation}\nTaking the limit as $\\alpha\\rightarrow \\infty$, we get the gradient flow equation \\eqref{gradient_flow}. So we see that the gradient flow is a high-friction limit of the damped Hamiltonian flow \\eqref{hamiltonian}.\n\nIt turns out that discretizing the Hamiltonian flow results in a method which converges much faster than gradient descent, provided we choose the friction parameter $\\alpha$ correctly. To see this, it is instructive to analyze a strongly convex quadratic objective, from which we see that\nthe dynamics \\eqref{gradient_flow} converges at an exponential rate\n\\begin{equation}\n f(x(t)) - f(x^*) = O(e^{-\\lambda_{min} t}),\n\\end{equation}\nwhere $\\lambda_{min}$ is the smallest eigenvalue of the quadratic objective.\n\nChoosing the optimal damping rate $\\alpha = 2\\sqrt{\\lambda_{min}}$ (note that this makes the lowest frequency modes critically damped), the dynamics \\eqref{hamiltonian} achieve an exponential convergence rate of\n\\begin{equation}\n f(x(t)) - f(x^*) = O(e^{-\\sqrt{\\lambda_{min}} t}).\n\\end{equation}\n\nCombined with the fact that \\eqref{hamiltonian} can be stably discretized with a step size $s = 0(\\lambda_{max}^{-\\frac{1}{2}})$, while \\eqref{gradient_flow} can only be stably discretized with a step size $s = O(\\lambda_{max}^{-1})$, shows that discretizing the Hamiltonian dynamics \\eqref{hamiltonian} results in a method which convergences much faster than gradient descent (the number of iterations scales with $\\sqrt{\\frac{\\lambda_{max}}{\\lambda_{min}}}$ vs $\\frac{\\lambda_{max}}{\\lambda_{min}}$.\n\nOnly certain special descretizations of \\eqref{hamiltonian} achieve this improved convergence rate globally for convex functions. The most famous of these is Nesterov's accelerated gradient descent\n\\begin{equation}\n \\begin{split}\n &x_{t+1} = y_t - \\frac{1}{\\lambda_{max}}\\nabla f(y_t) \\\\\n &y_{t+1} = x_{t+1} + \\frac{\\sqrt{\\lambda_{max}} - \\sqrt{\\lambda_{min}}}{\\sqrt{\\lambda_{max}} + \\sqrt{\\lambda_{min}}}(x_{t+1} - x_t).\n \\end{split}\n\\end{equation}\n\nHowever, for deep learning we often use the much simpler discretization\n\\begin{equation}\n \\begin{split}\n &v_{t+1} = (1 - s\\alpha) v_t + s\\nabla f(x_t)\\\\\n &x_{t+1} = x_t - sv_t.\n \\end{split}\n\\end{equation}\nThis often gives similar results since deep learning problems are non-convex and the theory of convex optimization doesn't apply anyway.\n\nHowever, there is work which analyzes different versions of momentum (i.e. different discretizations of the Hamiltonian dynamics \\eqref{hamiltonian}) for deep learning problems.\n\n\\includepdf{HandWrittenNotes/Momentum.pdf}\n", "meta": {"hexsha": "72ec25dc80b171f6308c74a37ac73b0378ff0ff1", "size": 5960, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/momentum.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/momentum.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/momentum.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.2807017544, "max_line_length": 501, "alphanum_fraction": 0.7260067114, "num_tokens": 1796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.9372107861416413, "lm_q1q2_score": 0.85396744329451}} {"text": "\n\\subsection{Sample covariance}\n\nWe previously defined the population covariance as \\(\\sigma_{XY}=E[(X-\\mu_X)^T(Y-\\mu_Y)]\\).\n\nWe define the sample covariance as \\(\\sigma_{XY}=\\dfrac{1}{n}\\sum_i(x_i-\\bar x)(y_i-\\bar y)\\).\n\nWe can calculate this using matrices:\n\n\\(M=X-\\bar x\\)\n\n\\(N=Y-\\bar y\\)\n\n\\(\\sigma_{XY}=\\dfrac{1}{n}M^TN\\).\n\n\\subsection{Sample correlation}\n\n\\(\\rho_{XY}=\\dfrac{\\sigma_{XY}}{\\sigma_X \\sigma_Y}\\)\n\n\\subsection{Covariance matrix}\n\nIf we have \\(n\\) variables we can have a \\(n\\times n \\) matrix \\(\\Sigma \\) where:\n\n\\(\\Sigma_{ij} = \\sigma_{ij}=\\dfrac{1}{n}(X_i-\\bar x_i)^T(X_j-\\bar x_j)\\)\n\n\\subsection{Centred covariance}\n\nIf \\(\\bar x = \\bar y = 0\\) then:\n\n\\(\\sigma_{XY}=\\dfrac{1}{n}X^TY\\)\n\n\\subsection{Correlation matrix}\n\nHere each entry is the correlation rather than the covariance.\n\n", "meta": {"hexsha": "2469af64bd011646a3fa592b6782369591a3d8d8", "size": 802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summaryMultiple/01-01-covariance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/summaryMultiple/01-01-covariance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/summaryMultiple/01-01-covariance.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2777777778, "max_line_length": 94, "alphanum_fraction": 0.6633416459, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9728307668889048, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.8536364036250387}} {"text": "\\section{Additional Exercises}\\label{sec:MoreFunctionExercises}\n\n\\Opensolutionfile{solutions}[ex]\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\nIf $f\\left( x\\right) =\\dfrac{1}{x-1},$ then which\nof the following is equal to $f\\left( \\dfrac{1}{x}\\right) ?$\n\\begin{enumerate}\n\t\\item\t$f(x)$\n\t\\item\t$-f(x)$\n\t\\item\t$xf(x)$\n\t\\item\t$-xf(x)$\n\t\\item\t$\\dfrac{f(x)}{x}$\n\t\\item\t$-\\dfrac{f(x)}{x}$\n\\end{enumerate}\n\\begin{sol}\n\t(d)\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nIf $f(x)=\\dfrac{x}{x+3}$, then find\nand simplify $\\dfrac{f(x)-f(2)}{x-2}$.\n\\begin{sol}\n\t$3/\\left[5(x+3)\\right]$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nIf $f(x)=x^2$, then find and\nsimplify $\\dfrac{f(3+h)-f(3)}{h}$.\n\\begin{sol}\n\t$6+h$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nWhat is the domain of\n\\begin{enumerate}\n\t\\item\t$f(x)=\\dfrac{\\sqrt{x-2}}{x^2-9}$?\n\t\\item\t$g(x)=\\dfrac{\\sqrt[3]{x-2}}{x^2-9}$?\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$[2,3)\\cup(3,\\infty)$\n\t\\item\t$(-\\infty,-3)\\cup(-3,3)\\cup(3,\\infty)$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSuppose that $f(x)=x^3$ and $g(x)=x$. What is the domain of $\\dfrac{f}{g}$?\n\\begin{sol}\n\t$\\left\\{x:x\\neq 0\\right\\}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSuppose that $f(x)=3x-4$. Find a\nfunction $g$ such that $(g\\circ f)(x)=5x+2$.\n\\begin{sol}\n\t$g(x)=(5x+26)/3$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nWhich of the following functions is one-to-one?\n\\begin{enumerate}\n\t\\item\t$f(x)=x^2+4x+3$\n\t\\item\t$g(x)=\\vert x\\vert+2$\n\t\\item\t$h(x)=\\sqrt[3]{x+1}$\n\t\\item\t$F(x)=\\cos x$, $-\\pi\\leq x\\leq\\pi$\n\t\\item\t$G(x)=e^x+e^{-x}$\n\\end{enumerate} \n\\begin{sol}\n\t(c)\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nWhat is the inverse of $f(x)=\\ln\\left(\\dfrac{e^x}{e^x-1}\\right)$? What is the domain of $f^{-1}$?\n\\begin{sol}\n\t$f^{-1}(x)=f(x)=\\ln\\left(\\dfrac{e^x}{e^x-1}\\right)$ and its domain is $(0,\\infty)$.\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSolve the following equations.\n\\begin{enumerate}\n\t\\item\t$e^{2-x}=3$\n\t\\item\t$e^{x^2}=e^{4x-3}$\n\t\\item\t$\\ln\\left(1+\\sqrt{x}\\right)=2$\n\t\\item\t$\\ln(x^2-3)=\\ln 2+\\ln x$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$2-\\ln 3$\n\t\\item\t1,3\n\t\\item\t$(e^2-1)^2$\n\t\\item\t3\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nFind the exact value of $\\sin^{-1}\\left(-\\sqrt{2}/2\\right)-\\cos^{-1}\\left(-\\sqrt{2}/2\\right)$.\n\\begin{sol}\n\t$-\\pi$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nFind $\\sin^{-1}\\left(\\sin(23\\pi/5)\\right)$.\n\\begin{sol}\n\t$2\\pi/5$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nIt can be proved that $f(x)=x^3+x+e^{x-1}$ is one-to-one. What is the value of $f^{-1}(3)$?\n\\begin{sol}\n\t1\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSketch the graph of $f(x)=\\left\\{ \n\\begin{array}{cc}\n-x & \\text{if }x\\leq 0 \\\\ \n\\tan ^{-1}x & \\text{if }x>0%\n\\end{array}%\n\\right. $\n\\end{ex}\n\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "67d8cba51f3c949199ec08b965f0cf5ca2b3f9e8", "size": 2802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-8-additional-exercises.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2-functions/2-8-additional-exercises.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2-functions/2-8-additional-exercises.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.1901840491, "max_line_length": 97, "alphanum_fraction": 0.562455389, "num_tokens": 1258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783527, "lm_q2_score": 0.9073122132152183, "lm_q1q2_score": 0.8535900250513714}} {"text": "\n\\subsection{Variance of OLS estimators}\n\n\\subsubsection{Variance-covariance matrix}\n\nWe know:\n\n\\(\\hat \\theta =(X^TX)^{-1}X^Ty\\)\n\n\\(y=X\\theta +\\epsilon\\)\n\nTherefore:\n\n\\(\\hat \\theta =(X^TX)^{-1}X^T(X\\theta +\\epsilon)\\)\n\n\\(\\hat \\theta =\\theta +(X^TX)^{-1}X^T\\epsilon\\)\n\n\\(\\hat \\theta -\\theta =(X^TX)^{-1}X^T\\epsilon\\)\n\n\\(Var [\\hat \\theta ]=E[(\\hat \\theta -\\theta)(\\hat \\theta -\\theta )^T]\\)\n\n\\(Var [\\hat \\theta ]=E[(X^TX)^{-1}X^T\\epsilon(X^TX^{-1}X^T\\epsilon )^T]\\)\n\n\\(Var [\\hat \\theta ]=E[(X^TX)^{-1}X^T\\epsilon \\epsilon^T X(X^TX)^{-1}]\\)\n\n\\(Var [\\hat \\theta ]=(X^TX)^{-1}X^TE[\\epsilon \\epsilon^T ]X(X^TX)^{-1}\\)\n\nWe write:\n\n\\(\\Omega=E[\\epsilon \\epsilon^T]\\)\n\n\\(Var [\\hat \\theta ]=(X^TX)^{-1}X^T\\Omega X(X^TX)^{-1}\\)\n\nDepending on how we estimate \\(\\Omega\\), we get different variance terms.\n\n\\subsubsection{Variance under IID}\n\nIf IID:\n\n\\(\\Omega = I\\sigma^2_{\\epsilon }\\)\n\n\\(Var [\\hat \\theta ]=(X^TX)^{-1}X^TI\\sigma^2_{\\epsilon } X(X^TX)^{-1}\\)\n\n\\(Var [\\hat \\theta ]=\\sigma^2_\\epsilon (X^TX)^{-1}\\)\n\n", "meta": {"hexsha": "75ba7e9f857fff1247e8d85e1020083b1a4805b1", "size": 1000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsInference/02-01-variance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsInference/02-01-variance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsInference/02-01-variance.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7391304348, "max_line_length": 73, "alphanum_fraction": 0.578, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611608990299, "lm_q2_score": 0.8887587883361618, "lm_q1q2_score": 0.8535294217257315}} {"text": "% -*- root: Main.tex -*-\n\\section{SVD}\n$\\mathbf{A} = \\mathbf{U} \\mathbf{D} \\mathbf{V}^\\top = \\sum_{k=1}^{\\operatorname{rank}(\\mathbf{A})} d_{k,k} u_k (v_k)^\\top$\\\\\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times P}, \\mathbf{U} \\in \\mathbb{R}^{N \\times N}, \\mathbf{D} \\in \\mathbb{R}^{N \\times P}, \\mathbf{V} \\in \\mathbb{R}^{P \\times P}$\\\\\n$\\mathbf{U}^\\top \\mathbf{U} = I = \\mathbf{V}^\\top \\mathbf{V}$ ($\\mathbf{U}, \\mathbf{V}$ orthogonal)\\\\\n$\\mathbf{U}$ columns are eigenvectors of $\\mathbf{A} \\mathbf{A}^\\top$, $\\mathbf{V}$ columns are eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$, $\\mathbf{D}$ diagonal elements are singular values.\\\\\n$(\\mathbf{D}^{-1})_{i,i} = \\frac{1}{\\mathbf{D}_{i, i}}$ (don't forget to transpose)\n\n1. calculate $\\mathbf{A}^\\top \\mathbf{A}$.\\\\\n2. calculate eigenvalues of $\\mathbf{A}^\\top \\mathbf{A}$, the square root of them, in descending order, are the diagonal elements of $\\mathbf{D}$.\\\\\n3. calculate eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$ using the eigenvalues resulting in the columns of $\\mathbf{V}$.\\\\\n4. calculate the missing matrix: $\\mathbf{U} = \\mathbf{A} \\mathbf{V} \\mathbf{D}^{-1}$.\\\\\n5. normalize each column of $\\mathbf{U}$ and $\\mathbf{V}$.\n\n\\subsection*{Low-Rank approximation}\nUsing only $K$ largest eigenvalues and corresponding eigenvectors. $\\tilde{\\mathbf{A}}_{i, j} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} \\mathbf{V}_{j, k} = \\sum_{k=1}^K \\mathbf{U}_{i, k} \\mathbf{D}_{k,k} (\\mathbf{V}^\\top)_{k, j}$.\n\n\\subsection*{Collaborative Filtering \\textendash\\ Prediction}\nFor $\\mathbf{U}, \\mathbf{V}$ (Movie-/User-embedding) use $k$-rank approx (fill up dimensions). Predict user preferences: $\\mathbf{U_k} \\mathbf{U_k^T} b$.\n\n\\subsection*{Echart-Young Theorem}\n$\\min_{rank(B)=K} ||A-B||_F^2 = ||A-A_k||_F^2 = \\sum_{r=k+1}^{rank(A)} \\sigma_r^2$\n$\\min_{rank(B)=K} ||A-B||_2 = ||A-A_k||_2 = \\sigma_{k+1}$\n", "meta": {"hexsha": "e33615337f33de1120e100191e243dc0a6153920", "size": 1847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SVD.tex", "max_stars_repo_name": "kalsan/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "ae93c61b8e7e88be725641d9580b37367c332458", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-07-31T11:12:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-02T09:35:54.000Z", "max_issues_repo_path": "SVD.tex", "max_issues_repo_name": "kalsan/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "ae93c61b8e7e88be725641d9580b37367c332458", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SVD.tex", "max_forks_repo_name": "kalsan/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "ae93c61b8e7e88be725641d9580b37367c332458", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-07-19T14:14:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-05T13:50:06.000Z", "avg_line_length": 76.9583333333, "max_line_length": 238, "alphanum_fraction": 0.639415268, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809826, "lm_q2_score": 0.9005297907896396, "lm_q1q2_score": 0.8531448530641057}} {"text": "\\lab{Public Key Cryptography}{RSA}\n\\label{lab:RSA}\n\n\\objective{Implement the RSA cryptosystem as an example of public key cryptography.}\n\nA \\emph{public key cryptosystem} uses separate keys for encryption and decryption.\nIf Alice wishes to send Bob a message, she encrypts it using Bob's \\emph{public key}, which is available to everyone.\nThen Bob decrypts it with his \\emph{private key}, which only he knows.\nAs long as it is difficult to find the private key from the public key, this is a secure system.\n\n%Public key cryptosystems are advantageous because for $n$ people to have secure communications with each other, they need exactly $n$ public-private key pairs.\n%A symmetric cryptosystem would require on the order of $n^2$ keys.\n%Also, they eliminate the need for secure key sharing algorithms like the Diffie-Hellman key exchange (see Lab \\ref{lab:DiffieHellman}).\n\nAs an analogy, consider a locked box with two kinds of keys.\nOne kind of key, called the public key, is available to anyone and can lock the box but not unlock it.\nThe other kind of key, called the private key, is only available to one person and can unlock the box.\nTo send a message to someone with the private key, the sender will put the message in the box and lock it.\nSince the only person that can unlock the box is the recipient, the message is safe until it arrives. This is how public key cryptography works.\n\nOne of the oldest and most popular public key cryptosystems is RSA cryptography.\n\n%All material in this lab through the section ``Security of RSA'' is required. \n%After that, all sections and subsections are independent of each other and may be covered as desired.\n\n\\section*{The RSA system}\nSuppose Alice wants to receive secret messages using RSA.\nTo do so, she first needs to generate a public key (for encryption) and a private key (for decryption).\nAlice does this by choosing two prime numbers, $p$ and $q$, and setting $n=pq$.\nThen she sets $\\phi(n) = (p-1)(q-1)$.\\footnote{\nThe function $\\phi: \\mathbb{Z} \\rightarrow \\mathbb{N}$ is called the \\emph{Euler phi function}. In general $\\phi(n)$ is the number of positive integers less than $n$ that are relatively prime to $n$.}\nAlice chooses her encryption exponent to be some integer $e$ that is relatively prime to $\\phi(n)$.\nThen she uses the Extended Euclidean Algorithm to find $d'$ such that $ed' + \\phi(n)x' = 1$, and adds or subtracts multiples of $\\phi(n)$ until $d = d'+k\\phi(n)$ is between 0 and $\\phi(n)$.\nAlice publishes her public key $(e, n)$ for the world to see and keeps her private key $(d,n)$ a secret ($e$ for encryption, $d$ for decryption).\n\nNow imagine Bob wants to send Alice a message, which he represents as an integer $m>> p = 1000003\n>>> q = 608609\n>>> n = p*q\n>>> phi_n = (p-1)*(q-1)\n\\end{lstlisting}\n\nNow we choose an encryption exponent $e = 1234567891$ and compute $d = 589492582555$ using the Extended Euclidean Algorithm.\n\\begin{lstlisting}\n>>> e = 1234567891\n>>> d = 589492582555\n\\end{lstlisting}\n\nFinally we are ready to encrypt the message. \nNote that $m>> m = long(190503180520)\n>>> c = pow(m, e, n)\n\\end{lstlisting}\n\nWe decrypt the message by raising $c$ to the $d^{th}$ power, modulo $n$.\n\\begin{lstlisting}\n>>> m == pow(c, d, n)\nTrue\n\\end{lstlisting}\n\n\\subsection*{Logistical considerations}\nThe cryptosystem described is not particularly easy to use, since the message must be converted to an integer and back again by hand.\nThe provided \\li{rsa_tools} module contains some functions to fix this problem.\nThe function \\li{string_to_int()} turns any string into an integer (using a mapping more complicated than $A=01, B=02$), and the function \\li{int_to_string()} changes it back again.\n\n\\begin{lstlisting}\n>>> import rsa_tools as r\n>>> r.string_to_int('SECRET')\n91556947314004\n>>> r.int_to_string(91556947314004)\n'SECRET'\n\\end{lstlisting}\n\nAt this point we have a problem, because the message 91556947314004 is larger than $n=608610825827$.\nWe can only use RSA to encrypt messages that are smaller than $n$.\nIn fact, the function \\li{string_size()} provided in \\li{rsa_tools} tells us the maximum number of characters we can encrypt with this choice of $n$.\n\n\\begin{lstlisting}\n>>> r.string_size(608610825827)\n4\n\\end{lstlisting}\n\nThe function \\li{partition()}, also in the \\li{rsa_tools} will break our message into pieces of length 4.\nWe specify the ``fill value'' \\li{x} that will be used to make all pieces the same length.\n\n\\begin{lstlisting}\n>>> r.partition('SECRET', 4, 'x')\n['SECR', 'ETxx']\n\\end{lstlisting}\nNow we can proceed to encrypt and decrypt the strings \\li{'SECR'} and \\li{'ETxx'} as before.\n\n% Problem 1: Implement the 'myRSA' class.\n\\begin{problem}\nWrite a class called \\li{myRSA} that can generate keys, encrypt messages, and decrypt messages.\nUse methods from the provided \\li{rsa_tools.py} module to convert strings to ints and vice-versa.\n\nWrite a method called \\li{generate_keys} that accepts a pair of primes and an encryption exponent and sets the \\li{public_key} and \\li{_private_key} attributes.\n(Starting \\li{_private_key} with an underscore hides the attribute from the user.)\nAlso include an \\li{encrypt} method that accepts a string and encrypts it, using \\li{public_key} as the default encryption key.\nIf a different public key is provided, then the message should be encrypted with the provided key.\nFinally, write a \\li{decrypt} method that decrypts an encrypted message with \\li{_private_key}.\n\nIn the next problem we will write a test function for this class.\n\\label{prob:rsa1}\n\\end{problem}\n\n\\subsection*{Security of RSA}\nSuppose an enemy Eve wants to read the message that Bob sent to Alice.\nLike Bob, she has access to Alice's public key $(e, n)$.\nLet's assume she has also intercepted the ciphertext $c$.\n\nOne way for Eve to read Bob's message is to directly find $m$ such that $m^e \\equiv c \\pmod{n}$.\nSuch a computation is known as taking a \\emph{discrete logarithm}.\nWhen $n$ is very large, this computation is essentially impossible.\n\nAnother option is for Eve to compute $(d, n)$ and then find $c^d$.\nHowever, computing $d$ means computing $\\phi(n)$.\nComputing $\\phi(n)$ from $n$ directly requires factoring $n$.\nWhen $n$ has hundreds of digits, finding its factors with known algorithms can take years.\n\nThus, the security of RSA depends on selecting large primes so that $n$ has many digits.\n\n\\section*{Exceptions}\n\nEvery programming language has a formal way of handling errors. In Python, we raise and handle \\emph{Exceptions}. There are different kinds of exceptions, each with its appropriate usage.\nIn Python, as in most languages, exceptions are organized into a class hierarchy.\nA complete list of Python exceptions can be found \\href{https://docs.python.org/2/library/exceptions.html}{here}.\nThe following code displays some examples of common exceptions:\n\n\\begin{lstlisting}\n# A 'NameError' exception indicates that a nonexistant name was used.\n>>> print(x)\nTraceback (most recent call last):\n File \"\", line 1, in \nNameError: name 'x' is not defined\n\n# An 'AttributeError' exception indicates that a nonexistant method or\n# attribute was called on some object.\n>>> x = list()\n>>> x.fly()\nTraceback (most recent call last):\n File \"\", line 1, in \nAttributeError: 'list' object has no attribute 'fly'\n\n# A 'SyntaxError' exception indicates bad coding syntax.\n>>> def myFunction(a, b)\n File \"\", line 1\n def myFunction(a, b)\n ^\nSyntaxError: invalid syntax\n\\end{lstlisting}\n\nMany exceptions, like the ones listed above, are due to coding mistakes and typos.\nExceptions can also be used programmatically to indicate a problem to the user.\nTo raise an exception, use the keyword \\li{raise}, followed by the name of the exception.\nAs soon as an exception is raised, the program stops running unless the exception is handled.\n\n\\begin{lstlisting}\n# raise a specific type of exception, with an error message included.\n>>> x = 7\n>>> if x > 5:\n... raise ValueError(\"'x' should not exceed 5.\")\n... \nTraceback (most recent call last):\n File \"\", line 2, in \nValueError: 'x' should not exceed 5.\n\\end{lstlisting}\n\nFor now we are only concerned with raising exceptions, but documentation on handling exceptions can be found \\href{https://docs.python.org/2/tutorial/errors.html}{here}.\n\n% Problem 2: Exceptions and testing my_RSA.\n\\begin{problem}\nWrite a \\li{test_myRSA} function that accepts a message, two primes, and an encryption exponent.\nIf the first argument is not a string, raise a \\li{TypeError} with error message ``message must be a string.''\nIf the final three arguments are not integers, raise a \\li{TypeError} with error message ``p, q, and e must be integers.''\n(Hint: use the built-in \\li{type} function.)\n\nCreate an instance of the \\li{myRSA} class.\nEncrypt and decrypt the message using the keys generated by the integer arguments.\nIf the original message and the decryption are not exacly the same, raise a \\li{ValueError} with error message ``decrypt(encrypt(message)) failed.''\nOtherwise, return \\li{True}.\n\\end{problem}\n\n\\section*{Making RSA Secure}\n\nSince the security of RSA depends on the use of large prime numbers for $p$ and $q$, we need a fast way to find such numbers for RSA to be a practical cryptosystem.\nIt is very slow to check that a large number is prime by finding its factors.\nIn fact, it is the difficulty of factoring that makes RSA secure.\n\nHowever, there exist fast algorithms that determine when a number is ``probably prime.''\nOne such algorithm comes from a special case of Theorem \\ref{thm:fermat} known as \\emph{Fermat's Little Theorem}:\n\\[\na^{p-1} \\equiv 1 \\pmod{p}\n\\]\nfor all primes $p$ and integers $a$ that are not divisible by $p$.\nTherefore, to check if a fixed number $p$ is likely a prime, we can compute $a^{p-1} \\pmod{p}$ for several values of $a$.\nIf we ever get something different than 1, then we know that $p$ is composite.\nThe value of $a$ that proved $p$ was composite is called a \\emph{witness number}.\nIn fact, the converse is true: if $a^{p-1} \\equiv 1 \\pmod{p}$ for every $a>> from Crypto.PublicKey import RSA\n\n# generate a 2048-bit RSA key\n>>> keypair = RSA.generate(2048)\n\n# Save the public key as a string for distribution.\n>>> public_key = keypair.publickey()\n>>> share_this = public_key.exportKey()\n\\end{lstlisting}\n\nThe \\li{share_this} variable may be distributed as a public key.\nAnother user may then import it and use it to encrypt a message.\n\n\\begin{lstlisting}\n>>> encrypter = RSA.importKey(share_this)\n>>> ciphertext = encrypter.encrypt('abcde', 2048)\n>>> ciphertext\n('\\xb1\\t\\xc6L\\xd1u\\x80.C@\\x07$#\\x8e\\xca\\x8a\\x05*\\xdf\\x1f.N\\xa9\\x80\n\\x08\\xcb*8~7\\x1d\\x87&&Ke\\xd5\\xed_H\\xb9\\xd0x\\xac!\\xf3\\xa9\\xdc\\xbfy5\ns\\x92\\x8d\\x15\\xf7vY\\x99G\\xb6\\x03j[\\xa3\\xc6\\x92a\\n\\x91\\x08N\\xbc\\xe4\n\\xcd\\xe2\\x9b\\xeb\\x1eT\\xe5\\xef\\x96\\x83\\x10\\xb7\\x0c\\xd1\\x9bK]z\\xa5!\\\nxcc\\xe0/\\xd3L\\xd4\\xa9xx?*\\xfb\\xf6\\xcaM8\\xe6\\x9d\\xd4u\\xbd\\xda\\xa8tf\nX\\x02\\xfa\\xff\\x99\\xff\\xbb\"\\xd1\\x87\\'\\xb9d\\x1c\\x1b\\x9fcWd\\x83\\xea}\\\nx1f\\xff\\xd3\\x9b0\\x8e\\x0f\\x91\\n\\x16\\r\\r\\xa5\\xa5S\\xafw\\x07N`$\\x9c]\\x\nac\\x96\\xe3\\x80l\\xc9\\xe5\\xe4Od\\xa5\\t>\\x16j\\xa1\\xb9\\x9c5\\xc0\\xfe\\xe3\n\\xe5i\\xcd\\xaf\\xdc\\xcad\\x82\\x10u\\x91\\xa0\"\\xcf\\xe3A\\x11\\x82\\x87\\xb9\\\nxdf\\xd7\\x86\\x87\\xff\\x11#-\\xb5!Q)\\xf7\\xf1a\\x94\\xb3e?\\xd0\\x96W4\\xb4\\\nxca\\xcf\\x18\\xd1I\\xcd\\x1dl\\xd7\\xe0Y\\xdf}F\\x93\\x92\\xe1(d\\xcc\\xdc\\xa7\n x\\xc5`',)\n>>> keypair.decrypt(ciphertext)\n'abcde'\n\\end{lstlisting}\n\nThe RSA encryption and decryption methods on these keys are textbook approaches.\n\n\\begin{comment}\nHowever, to increase security, we will want to pad the messages so every message encrypted with a particular key will become exactly as large (in bits) as the key itself.\nA commonly used padding algorithm is implemented in PyCrypto in the \\li{Crypto.Cipher.PKCS1_OAEP} module.\n\\begin{lstlisting}\n>>> from Crypto.Cipher import PKCS1_OAEP as oaep\n\n# generate a new key from the original RSA key.\n# This key can encrypt and decrypt\n>>> paddedkey = oaep.new(keypair)\n>>> encrypted = paddedkey.encrypt('hello world')\n>>> paddedkey.decrypt(encrypted)\n'hello world'\n\\end{lstlisting}\n\\end{comment}\n\n% Problem 4: Implement a PyCrypto-powered RSA system.\n\\begin{problem}\nWrite a new RSA class called \\li{PyCrypto} that acts like the \\li{myRSA} class, but implement it with methods from PyCrypto's \\li{RSA} package.\n\nStore both of your RSA keys in a single attribute called \\li{_keypair}, and store a sharable string representation of the public key in the \\li{public_key} attribute.\nInitialize \\li{_keypair} and \\li{public_key} in the constructor.\nThe \\li{encrypt} method accepts a string and encrypts it, using \\li{_keypair} as the default encryption key.\nIf the string representation of a different public key is provided, then the message should be encrypted with the provided key.\nThe \\li{decrypt} method decrypts an encrypted message using \\li{_keypair}.\n\nWith a partner, test your classes by exchanging public keys and sending secret messages.\n\\end{problem}\n\n\\begin{warn}\nThe following warning comes from the PyCrypto \\href{https://www.dlitz.net/software/pycrypto/}{website}:\n\n``The export of cryptography software is (still) governed by arms control regulations in Canada, the United States, and elsewhere.\nThe export or re-export of this software may be regulated by law in your country.''\n\\end{warn}\n\n% \t================ END OF LAB ================\t%\n\n% Group project problem from the old lab.\n% Assumes we did a problem on digital signatures.\n\\begin{comment}\n\\begin{problem}[Group Project]\nSplit into several groups of at least three individuals.\nEach group member should generate a private and public keypair using PyCrypto.\nShare your public keys with everyone in the group.\n\nYou might find it useful to transmit your messages as strings.\nHere are two functions that will read and write specially formatted strings for your messages.\n\\begin{lstlisting}\ndef print_msg(m_encrypted):\n #print the encrypted message as a specially formatted string\n out = (\"----BEGIN MESSAGE----\",\n m_encrypted[0],\n \"----END MESSAGE----\",\n \"----BEGIN SIGNATURE----\",\n m_encrypted[1],\n \"----END SIGNATURE----\")\n return '\\n'.join(out)\n\ndef read_msg(m_string):\n d1 = m_string.find('----BEGIN MESSAGE----') + 21\n d2 = m_string.find('----END MESSAGE----', d1)\n \n d3 = m_string.find('----BEGIN SIGNATURE----', d2) + 23\n d4 = m_string.find('----END SIGNATURE----', d3)\n message = m_string[d1:d2]\n sign = m_string[d3:d4]\n return message.strip(), sign.strip()\n\\end{lstlisting}\n\n\\begin{enumerate}\n\\item Encrypt and sign a message for someone in the group and send it to the entire group.\nAttach the sender's name to the encrypted message (a claim that the message came from a particular sender).\nIn this exercise we will verify that the actual origin of the message is indeed the claimed origin.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message addressed for you.\n\\item Attempt to decrypt and verify message addressed for someone else in the group.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\n\\item Encrypt and sign a different message for someone in the group and send it, anonymously, to the entire group.\nFor example, if Bob encrypts a message and sends it to Alice, he should claim the message came from another individual.\nEach group member should do the following:\n\\begin{enumerate}\n\\item Decrypt and verify the message address to you.\n\\item Report the message and verified signature.\n\\end{enumerate}\n\\end{enumerate}\n\\end{problem}\n \n\\end{comment}\n\n", "meta": {"hexsha": "5e07315e7853dd4f30cfb9f958d5292b2a051e10", "size": 18874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/RSA/Encryption.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/RSA/Encryption.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/RSA/Encryption.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.5415617128, "max_line_length": 200, "alphanum_fraction": 0.7445692487, "num_tokens": 4984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.9059898146721821, "lm_q1q2_score": 0.8531290743825998}} {"text": "\\textbf{Let $f(x)=\\sum_{n=-\\infty}^{\\infty}\\frac{1}{(1+i)(n+1/2)^6}e^{inx}$. Compute the Fourier coefficients of $f$ using a DFT or FFT on 11 points to obtain $\\hat{v}_k$ and verify the aliasing formula for the coefficients: \n\\begin{align*}\n\\hat{v}_k-\\hat{f}_k=\\sum_{m\\neq 0}\\hat{f}_{k+mN}\n\\end{align*}}\n\\newline\n\nFor this problem we inmediately have\n\\begin{align*}\n\\hat{f}_k=\\frac{1}{(1+i)(k+1/2)^6}.\n\\end{align*}\nTo compute $\\hat{v}_k=\\frac{1}{N}\\sum_0^{N-1}f(x_j)e^{-ikx_j}$ we need first $f(x_j)$. We can compute the values of the function using the information given by the problem, truncating the sum at $n=1000$ (because for higher values of $n$ we reach machine precision when calculating the remainder terms of the sum):\n\\begin{align*}\nf(x_j)=\\sum_{n=-1000}^{1000}\\frac{1}{(1+i)(n+1/2)^6}e^{inx_j}.\n\\end{align*}\nOnce we have these values it is easy to compute $\\hat{v}_k$. The right hand side of the equation is calculated for every value of $k$ in a loop in MATLAB, see code below. We have obtained an accuracy of $10^{-14}$ between the two sides of the equation. So the aliasing formula is verified.\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 2 \nx0=0;\nxf=2*pi;\nN=11;\nK=5;\nL=1e3;\nx=linspace(x0,xf,N+1);\nx(end)=[];\nk=-K:K;\nl=-L:L;\n\nfhat = 1./((1+1i)*(k+(1/2)).^6);\nfxj = 1./((1+1i)*(l+(1/2)).^6)*exp(1i*l'*x);\nvhat = (1/N)*fxj*exp(-1i*x'*k);\n\nlhs = vhat-fhat;\nm = l;\nm(1001) = [];\n\nrhs = zeros(1,11);\nfor l = 1:length(k)\n rhs(l) = sum(1./((1+1i)*((k(l)+m*N)+(1/2)).^6));\nend\ndiff = lhs-rhs\n\\end{verbatim}", "meta": {"hexsha": "e18a38092a61d0bcbbe702f9a109566dc3d28a07", "size": 1544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework2/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework2/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework2/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9069767442, "max_line_length": 314, "alphanum_fraction": 0.6522020725, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491107, "lm_q2_score": 0.9019206864156892, "lm_q1q2_score": 0.8530377294328356}} {"text": "\n\\subsection{Eigenvalues and eigenvectors}\n\nWhich vectors remain unchanged in direction after a transformation?\n\nThat is, for a matrix \\(A\\), what vectors \\(v\\) are equal to scalar multiplication by \\(\\lambda \\) following the operation of the matrix.\n\n$Av=\\lambda v$\n\n", "meta": {"hexsha": "b19e842e1b4cc01063d3af853a13ba4a14066a2b", "size": 268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-01-linearEigen.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-01-linearEigen.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/01-01-linearEigen.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8, "max_line_length": 137, "alphanum_fraction": 0.7537313433, "num_tokens": 60, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9702399043329856, "lm_q2_score": 0.8791467738423873, "lm_q1q2_score": 0.8529832817474907}} {"text": "\\subsection*{CFL conditions}\n\\subsubsection*{Problem 1-2}\nFor stability we need \n\\begin{align*}\n|g(w)|&\\leq 1,\\\\\n\\left|1+i\\frac{a\\Delta t}{ \\Delta x}\\sin\\left(\\Delta xw_{\\nu}\\right)-\\frac{4b\\Delta t}{\\Delta x^2}\\sin^2\\left(\\frac{\\Delta xw_{\\nu}}{2}\\right)\\right| &\\leq 1.\n\\end{align*}\nWe can use the identity $|g(w)|^2 = \\Re\\left[g\\right]^2+\\Im\\left[g\\right]^2$ to obtain\n\\begin{align*}\n\\left(1-4bcy^2\\right)^2+\\left(2ac\\Delta xy\\sqrt{1-y^2}\\right)^2 &\\leq 1,\n\\end{align*}\nwhere $c$ is the Courant Number and $y = \\sin\\left(w\\Delta x/2\\right)\\in[-1,1]$. We continue expanding the terms,\n\\begin{align*}\n1+16b^2c^2y^4-8bcy^2+4a^2c^2\\Delta x^2y^2(1-y^2) &\\leq 1,\\\\\n16b^2c^2y^4-8bcy^2+4a^2c^2\\Delta x^2y^2(1-y^2) &\\leq 0,\n\\end{align*}\nLet $z = y^2$,\n\\begin{align*}\n16b^2c^2z^2-8bcz+4a^2c^2\\Delta x^2z(1-z) &\\leq 0,\\\\\n16b^2c^2z-8bc+4a^2c^2\\Delta x^2(1-z) &\\leq 0,\n\\end{align*}\nThe previous equation represents a straight line on $z\\in[0,1]$. To guarantee that the entire line is negative, the endpoints must be.\n\\begin{itemize}\n\\item $z=1$:\n\\begin{align*}\n16b^2c^2-8bc &\\leq 0,\\\\\n2bc &\\leq 1,\\\\\n2b\\frac{\\Delta t}{\\Delta x^2} &\\leq 1,\\\\\n2b\\Delta t &\\leq \\Delta x^2.\n\\end{align*}\n\\item $z=0$:\n\\begin{align*}\n-8bc+4a^2c^2\\Delta x^2&\\leq 0,\\\\\na^2c\\Delta x^2&\\leq 2b,\\\\\na^2\\Delta t&\\leq 2b.\n\\end{align*}\n\\end{itemize}\nThus, the CFL conditions are\n\\begin{align}\n2b\\Delta t &\\leq \\Delta x^2,\\label{eq:CFL_1}\\\\\na^2\\Delta t&\\leq 2b.\\label{eq:CFL_2}\n\\end{align}\n\\subsubsection*{Problem 3}\nFor this problem the we have introduced an artificial diffusion by modifying the discrete PDE when adopting the Lax-Friedrichs scheme. We can obtain the desired CFL condition by removing $b$ from the 2 previous CFL conditions. From \\eqref{eq:CFL_1} and \\eqref{eq:CFL_2},\n\\begin{align*}\na^2\\Delta t&\\leq 2b,\\\\\n2b &\\leq \\frac{\\Delta x^2}{\\Delta t}.\n\\end{align*}\nJoining both together we get\n\\begin{align*}\na^2\\Delta t&\\leq 2b\\leq \\frac{\\Delta x^2}{\\Delta t},\\\\\na^2\\Delta t&\\leq \\frac{\\Delta x^2}{\\Delta t},\\\\\n\\Delta t^2&\\leq \\frac{\\Delta x^2}{a^2}.\n\\end{align*}\nWehre we have used the fact that the artificial diffusion introduced is $2b = \\Delta x^2/\\Delta t$. Finally, we obtain the desired CFL condition when $b=0$,\n\\begin{align*}\n\\Delta t&\\leq \\left|\\frac{\\Delta x}{a}\\right|.\n\\end{align*}\n\n\\subsubsection*{Problem 4}\nFor this problem the we have introduced an artificial diffusion by modifying the discrete PDE when adopting the Lax-Wendroff scheme. We can obtain the desired CFL condition by removing $b$ from the 2 previous CFL conditions. From \\eqref{eq:CFL_1} and \\eqref{eq:CFL_2},\n\\begin{align*}\na^2\\Delta t&\\leq 2b,\\\\\n2b &\\leq \\frac{\\Delta x^2}{\\Delta t}.\n\\end{align*}\nJoining both together we get\n\\begin{align*}\na^2\\Delta t&\\leq 2b\\leq \\frac{\\Delta x^2}{\\Delta t},\\\\\na^2\\Delta t&\\leq \\frac{\\Delta x^2}{\\Delta t},\\\\\n\\Delta t^2&\\leq \\frac{\\Delta x^2}{a^2}.\n\\end{align*}\nWhere we have used the fact that the artificial diffusion introduced is $2b = a^2\\Delta t$. Finally, we obtain the desired CFL condition when $b=0$,\n\\begin{align*}\n\\Delta t&\\leq \\left|\\frac{\\Delta x}{a}\\right|.\n\\end{align*}", "meta": {"hexsha": "792096cd1ab9ef32d2f77be20ab83876e89330f4", "size": 3075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AdvancedNumericalMethodsForPDEs/homework_1/tex/appendix.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AdvancedNumericalMethodsForPDEs/homework_1/tex/appendix.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AdvancedNumericalMethodsForPDEs/homework_1/tex/appendix.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0, "max_line_length": 270, "alphanum_fraction": 0.6809756098, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176863577751, "lm_q2_score": 0.9032942067038784, "lm_q1q2_score": 0.8528694909736206}} {"text": "\\section{Exponential family distributions}\n\nThe exponential family is a set of probability distributions with a common parametric form that lead to convenient mathematical properties when doing Bayesian inference\\cite{??}. \\\\\nThe exponential family distributions include many of the most common distributions, including the normal, exponential, gamma, beta, Dirichlet, Bernoulli and Poisson \\cite{???}.\\\\ \n\nThe parametrisations of the (multivariate) exponential family which we use in this thesis is:\n\\[\np(\\bfx|\\btheta) = h(\\bfx) \\exp \\{ \\eta(\\btheta) T(\\bfx) - A(\\btheta) \\}\n\\]\nwhere the functions that parametrise the distribution are:\n\\begin{itemize}\n\t\\item T(\\bfx): the sufficient statistics of the distribution.\n\t\\item $\\eta(\\btheta)$: the natural parameters.\n\t\\item $h(\\bfx)$: the base mesure.\n\t\\item $A(\\eta)$: the log-partition function.\n\\end{itemize}\n\nThe standard probability density (top) and the exponential family form (bottom) for the probability distributions frequently used in this thesis are the following:\\\\\n\n\\textbf{Univariate normal distribution}:\n\\beq \n\tp(x|\\mu,\\sigma^2) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\exp{-\\frac{(x-\\mu)^2}{2\\sigma^2}}\n\\eeq\n\\begin{equation}\n\\begin{split}\n\t& \\eta(\\mu,\\sigma^2) = \\bmat \\frac{\\mu}{\\sigma^2} & -\\frac{1}{2\\sigma^2} \\emat \\\\\n\t& h(x) = \\frac{1}{\\sqrt{2\\pi}}\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n\t& T(x) = \\bmat x & x^2 \\emat \\\\\n\t& A(\\eta) = -0.25\\frac{\\eta_1^2}{\\eta_2} - 0.5\\log(\\frac{1}{2\\eta_2}) % A(\\mu,\\sigma) = \\frac{\\mu^2}{2\\sigma^2} + \\log \\sigma\n\\end{split}\n\\end{equation}\n\n\\textbf{Multivariate normal distribution}:\n\\beq\n\tp(\\bfx|\\bmu,\\bSigma) = \\frac{1}{(2\\pi)^{D/2}} \\frac{1}{|\\bSigma|^{1/2}} \\exp{-\\frac{1}{2} (\\bfx - \\bmu)^T \\bSigma{-1} (\\bfx - \\bmu)} \\\\\n\\eeq\n\\begin{equation}\n\\begin{split}\n\t& \\eta(\\bmu,\\bSigma) = \\bmat \\Sigma^{-1} \\mu & -0.5\\Sigma^{-1} \\emat \\\\\n\t& h(x) = (2\\pi)^{-\\frac{k}{2}}\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n\t& T(x) = \\bmat x & xx^T \\emat \\\\\n\t& A(\\eta) = -0.25\\eta_1^T \\eta_2^{-1} \\eta_1 - 0.5\\log(|-2\\eta_2|)\n\\end{split}\n\\end{equation}\n\n\\textbf{Gamma distribution}:\n\\beq\np(x|\\alpha,\\beta) = \\frac{1}{\\Gamma(\\alpha)} \\beta^\\alpha x^{\\alpha-1} e^{-\\beta x}\n\\eeq\n\\begin{equation}\n\\begin{split}\n\t& \\eta(\\alpha,\\beta) = \\bmat \\alpha - 1 & -\\beta \\emat \\\\\n\t& h(x) = 1\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n\t& T(x) = \\bmat \\log x & x \\emat \\\\\n\t& A(\\eta) = \\log(\\Gamma(\\eta_1 + 1)) - (\\eta_1 + 1) \\log(-\\eta_2)\n\\end{split}\n\\end{equation}\n\n\\textbf{Beta distribution}:\n\\beq\np(x|a,b) = \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} x^{a-1} (1-x)^{b-1} \n\\eeq\n\\begin{equation}\n\\begin{split}\n\t& \\eta(a,b) = \\bmat a & b\\emat \\\\\n\t& h(x) = \\frac{1}{x(1-x)}\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n\t& T(x) = \\bmat \\log x & \\log (1-x) \\emat \\\\\n\t& A(\\eta) = \\log(\\Gamma(\\eta_1)) +\\log(\\Gamma(\\eta_2)) - \\log(\\Gamma(\\eta_1+\\eta_2))\n\\end{split}\n\\end{equation}\n\n\\textbf{Bernoulli distribution}:\n\\beq\n\tp(x|\\theta) = \\theta^x (1-\\theta)^{1-x}\n\\eeq\n\\begin{equation}\n\\begin{split}\n& \\eta(\\theta) = \\frac{\\theta}{1-\\theta} \\\\\n& h(x) = 1\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n& T(x) = x \\\\\n& A(\\eta) = \\log(1+\\exp^\\eta)\n\\end{split}\n\\end{equation}\n\n\\textbf{Poisson distribution}:\n\\beq\np(x|\\theta) = \\theta^x (1-\\theta)^{1-x}\n\\eeq\n\\begin{equation}\n\\begin{split}\n& \\eta(\\theta) = \\frac{\\theta}{1-\\theta} \\\\\n& h(x) = 1\n\\end{split}\n\\qquad \\qquad\n\\begin{split}\n& T(x) = x \\\\\n& A(\\eta) = \\log(1+\\exp^\\eta)\n\\end{split}\n\\end{equation}\n\nThe properties that all exponential family distributions share, and make it valuable for statistical modelling, are, among others: (1) The sufficient statistics can summarize arbitrary amounts of independent identically distributed data, and (2) The existence of conjugate priors within the same exponential family that guarantee a closed-form posterior distribution. \n\n• Products of exponential family distributions are exponential family distributions, but unnormalized.\n\nhttps://arxiv.org/pdf/0911.4863.pdf\n\nLet $\\bfx | \\btheta_x$ and $\\bfy | \\btheta_y$ be random variables with exponential family distributions:\n\\begin{align}\n\t\\bfx \\times \\bfy &= \n\th_x(\\bfx) \\exp \\{ \\eta_x(\\btheta_x) T_x(\\bfx) - A_x(\\btheta_x) \\} \\times h_y(\\bfy) \\exp \\{ \\eta_y(\\btheta_y) T_y(\\bfy) - A_y(\\btheta_y) \\} \\\\\n\t&= h_x(\\bfx) h_y(\\bfy) \\exp \\{ \\eta_x(\\btheta_x) T_x(\\bfx) + \\eta_y(\\theta_y) T_y(\\bfy) - A_x(\\btheta_x) A_y(\\btheta_y) \\} \\\\\n\t&= \\hat{h}(\\bfx,\\bfy) \\exp \\{ \\hat{\\eta}(\\btheta_x,\\btheta_y) \\hat{T}(\\bfx,\\bfy) - \\hat{A}(\\btheta_x, \\btheta_y) \\}\n\\end{align}\n% To exemplify the second property, consider the normally-distributed random variable with unknown mean and unknown variance:\n% \\baln\n% \tx \\sim \\mathcal{N}(\\mu, \\tau^{-1})\n% \\ealn\n\n\n", "meta": {"hexsha": "2f69d4f2f2900463745d5093ccfea116ae5bbbd6", "size": 4629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/old/exponential_family.tex", "max_stars_repo_name": "rargelaguet/thesis", "max_stars_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-01-08T13:01:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T07:24:40.000Z", "max_issues_repo_path": "Chapter2/old/exponential_family.tex", "max_issues_repo_name": "rargelaguet/thesis", "max_issues_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter2/old/exponential_family.tex", "max_forks_repo_name": "rargelaguet/thesis", "max_forks_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-09T04:47:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T08:25:50.000Z", "avg_line_length": 34.2888888889, "max_line_length": 368, "alphanum_fraction": 0.6517606394, "num_tokens": 1745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308128813471, "lm_q2_score": 0.9136765175373275, "lm_q1q2_score": 0.8528538144754659}} {"text": "\\section{Vectors}\n\\subsection*{Vectors}\n\\textbullet An ordered finite list of numbers.\\\\\n\\textbullet Block or stacked vectors($a = [b, c, d]$), Subvectors ($a_{r:s} = (a_r,...,a_s)$), Zero vectors (all elements equal to zero), Unit vectors(($e_i = 1$)), Ones vector($1_n$) \\& Sparsity($nnz(x)$)\n\n\\subsection*{Vector addition}\n\\textbullet \\textit{Commutative}: $a + b = b + a$\\\\\n\\textbullet \\textit{Associative}: $(a + b) + c = a + (b + c)$\\\\\n\\textbullet $a+0 = 0+a = a$\\\\\n\\textbullet $a - a = 0$\n\\subsection{Scalar-vector multiplication}\n$(-2)(1, 9, 6)=(-2, -18, -12)$\\\\\n\\textbullet \\textit{Commutative}: $\\alpha a = a \\alpha$\\\\\n\\textbullet \\textit{Left-distributive}: $(\\beta + \\gamma)a = \\beta a + \\gamma a$\\\\\n\\textbullet \\textit{Right-distributive}: $a(\\beta + \\gamma) = a\\beta + a\\gamma $ \\\\\n\nLinear combinations: $\\beta_1 a_1 + ... + \\beta_m a_m$\\\\\n\\textbullet With Unit vectors: $b = b_1 e_1 +...+ b_n e_n$ \\\\\n\\textbullet If $\\beta_1 +...+ \\beta_m = 1$, linear combination is said to be \\textit{affine combination}\n\n\\subsection{Inner product}\n$a^T b = a_1 b_1 +a_2 b_2 +...+ a_n b_n$\n\\textbf{Properties}:\\\\\n\\textbullet \\textit{Commutativity}:$a^T b = b^T a$\\\\\n\\textbullet \\textit{Scalar multiplication Associativity}:\\\\ $(\\gamma a)^T b = \\gamma(a^T b)$\\\\\n\\textbullet {Vector addition Distributivity}:\\\\\n$(a + b)^T c = a^T c + b^T c.$\n\n\\textbf{General examples}:\\\\\n\\textbullet Unit vector: $e_i^T a = a_i$ \\\\\n\\textbullet Sum: $\\textbf{1}^T a = a^1 + ... + a^n$ \\\\\n\\textbullet Average: $(\\textbf{1}/n)^T a=(a^1+...+a^n)/n$\\\\ \n\\textbullet Sum of squares: $a^Ta = a^2_1 +...+a^2_n$\\\\\n\\textbullet Selective sum: If $b_i = 1 or 0,$ \\textit{$b^Ta$} is the sum of elements for which $b_i = 1$,\n\n\\textbf{Block vectors}\\\\\n$a^T b = a_1^T b_1 + ... + a_k^T b_k$\n\n\\subsection{Complexity of vector computations}\n\\textit{Space}: 8n bytes\\\\\n\\textit{Complexity of vector operations}: $x^Ty=2n-1$ flops ($n$ scalar multiplications and $n-1$ scalar additions)\\\\\n\\textit{Complexity of sparse vector operations}: If x is sparse, then computing $ax$ requires \\textbf{nnz}(x) flops, If x and y are sparse, computing x + y requires no more than min{\\textbf{nnz}(x), \\textbf{nnz}(y)}. computing $x_T y$ requires no more than 2 min{\\textbf{nnz}(x), \\textbf{nnz}(y)} flops\n", "meta": {"hexsha": "0728ae60bcbcdce3b9b558357ba10a90ad22a968", "size": 2253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter1.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter1.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter1.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.3953488372, "max_line_length": 302, "alphanum_fraction": 0.6511318242, "num_tokens": 838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104943498961, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.852787561106764}} {"text": "\\section{$\\sigma$-Algebras, $\\sigma$-Fields}\n\n\\subsection{Definition}\nGiven a set $X$, a $\\sigma$-Algebra $\\mathscr{A}$ is a collection of subsets of a given set $X$, which has to satisfy the conditions:\n\n\n\\begin{itemize}\n\\item $\\emptyset, X \\in \\mathscr{A}$\n\\item If $A\\in\\mathscr{A}$, then $A^c := X\\setminus A \\in \\mathscr{A}$\n\\item $\\mathscr{A}$ has (possibly infinitely many) countable subsets $A_i \\in \\mathscr{A},\\ i \\in \\mathbb{N}$. Then $\\bigcup_{i=1}^{\\infty}A_i \\in \\mathscr{A}$. That is, the $\\sigma$-algebra is closed under \\textit{countable unions} of its subsets. \n\\end{itemize}\n\nAn element of the $\\sigma$-Algebra are $\\mathscr{A}$-measurable sets, or measurable with respect to the $\\sigma$-Algebra $\\mathscr{A}$. A $\\sigma$-algebra is a subset of the power set of $S$, i.e. $\\mathscr{A} \\subseteq P(X)$. \n\nThe difference to between an algebra and a $\\sigma$-algebra is that an algebra is closed under \\textit{finite} unions of subsets, i.e. $A,B\\in \\mathscr{A}$ then $A\\cup B \\in \\mathscr{A}$, while a $\\sigma$-algebra is closed under \\textit{countable} unions, i.e. for $\\{A_n: A_n \\in \\mathscr{A}, n\\in \\mathbb{N}\\}$, $\\bigcup_{n=1}^{\\infty} A_n \\in \\mathscr{A}$. Sometimes the terms \\textit{field} and \\textit{$\\sigma$-field} are used instead of \\textit{algebra} or \\textit{$\\sigma$-algebra}. Sometimes measure and integration theory are developed from $\\sigma$-rings instead o f $\\sigma$-algebras, which are slightly different animals.\n\n\\subsubsection{Example: The Smallest Possible $\\sigma$-Algebra}\n\n\\begin{equation}\n\\mathscr{A} = \\{\\emptyset, X\\}\n\\end{equation}\n\n\\subsubsection{Example: The Largest Possible $\\sigma$-Algebra} \nThe largest possible $\\sigma$-Algebra is the power set:\n\\begin{equation}\n\\mathscr{A} = P(X)\n\\end{equation}\n\nHowever, there are important examples where it is not possible to define a $\\sigma$-algebra on the full power set. \n\n\n\\subsection{Intersection Property}\nThe intersection of $\\sigma$ algebras is also a $\\sigma$-algebra. That way, a $\\sigma$-algebra with the desired properties can be constructed by creating individual $\\sigma$-algebras with the properties in question and forming their intersection.\n\n\\begin{equation}\n\\bigcap_i \\mathscr{A} \\ \\ \\mathrm{is\\ also\\ a\\ }\\sigma-\\mathrm{algebra}\n\\end{equation}\n\n\n\\subsection{Generated $\\sigma$-Algebras}\n\nFor a subset of the powerset $\\mathscr{M} \\subseteq P(X)$, that does not necessarily have to satisfy the properties of the $\\sigma$-Algebra, the \\textit{smallest} $\\sigma$-algebra that contains $\\mathscr{M}$ is the $\\sigma$-algebra \\textit{generated} by $\\mathscr{M}$. It can be constructed through the intersection of all $\\sigma$-algebras on $X$ that contain $\\mathscr{M}$. \n\n\\begin{equation}\n\\sigma(\\mathscr{M}) = \\bigcap_{\\mathscr{A}\\supseteq\\mathscr{M}}\\mathscr{A}\n\\end{equation}\n\n$\\sigma(\\mathscr{M})$ is the $\\sigma$-algebra \\textit{generated} by $\\mathscr{M}$. \n\n\\subsubsection{Example: Generated $\\sigma$-Algebra}\n\nTake $X = \\{a,b,c,d\\}$, and $\\mathscr{M} = \\{ \\{a\\}, \\{b\\}\\}$. Note that $\\mathscr{M}$ is not a $\\sigma$-algebra. To find the smallest $\\sigma$-algebra that contains $\\mathscr{M}$, one adds the elements necessary to fulfill the conditions on a $\\sigma$-algebra. These are the empty set $\\emptyset$ and the full set $X$, the union $\\{a,b\\}$, and the complements.\n\n\\begin{equation}\n\\sigma(\\mathscr{M}) = \\left\\{ \\emptyset, X, \\{a\\}, \\{b\\}, \\{a,b\\}, \\{b,c,d\\}, \\{a,c,d\\}, \\{c,d\\} \\right\\}\n\\end{equation}\n\n\n\\subsection{Borel $\\sigma$-Algebras ($\\mathscr{B}$)\t}\n\nBorel $\\sigma$-Algebras is the $\\sigma$-Algebra generated by \\textit{open sets}, for example $\\sigma(\\mathbb{R}^n)$ or $\\sigma(\\mathscr{M})$ with $\\mathscr{M} = (0,1)$.\n\n\n\\section{Measures, Measurable Spaces and Measure Spaces}\nA \\textit{measure} is a function that gives a volume measure for subsets of a $\\sigma$-algebra, where a $\\sigma$-algebra is a special sort of collection of subsets of some set $X$. \nThe combination $(X,\\mathscr{A})$ of a set $X$ and a $\\sigma$-Algebra that is defined on $X$ is called a \\textit{measurable space}. A measure is a function defined on the $\\sigma$-Algebra and maps to the positive real line (including $\\infty$!):\n\n\\begin{equation}\n\\mu: \\mathscr{A} \\rightarrow [0,\\infty)\\cup\\{\\infty\\} \n\\end{equation}\n\nIt has to satisfy the conditions:\n\n\\begin{itemize}\n\\item $\\mu(\\emptyset) = 0$\n\\item $\\mu(\\bigcup_i A_i) = \\sum_i \\mu(A_i)$ if $A_i \\cap A_j = \\emptyset$ when $i\\neq j$ (additive)\n\\item $\\mu(\\bigcup^{\\infty}_i A_i) = \\sum^{\\infty}_i \\mu(A_i)$ if $A_i \\cap A_j = \\emptyset$ when $i\\neq j$ ($\\sigma$-additive) \n\\end{itemize}\n\nWhere the infinite sum corresponds to gradually approximating the full volume by taking the union of countably infinitely many subsets. The collection $(X,\\mathscr{A},\\mu)$ is a \\textit{measure space}. \n\nThe reason why the $\\sigma$-algebra is included in the definition of a measurable space is because unless a $\\sigma$-algebra is defined on a set $X$, there is no guarantee that a measure exists on $X$.\n\n\\subsection{Example: Counting Measure}\n\n\\begin{equation}\n\\mu(A) = \\left\\{\\begin{array}{l} |A| \\mathrm{\\ if\\ }A\\mathrm{\\ has\\ finite\\ elements}\\\\ \\infty\\mathrm{\\ else}\\end{array}\\right.\n\\end{equation}\n\n\\subsection{Example: Dirac Measure}\n\\begin{equation}\n\\delta_p(A) = \\left\\{\\begin{array}{l} 1 \\mathrm{\\ if\\ }p\\in A\\\\ 0 \\mathrm{\\ else} \\end{array}\\right.\n\\end{equation}\n\n\\subsection{Example: Volume Measure}\nFor $X=\\mathbb{R}^n$, the conventional volume measure satisfies the properties of:\n\n\\begin{itemize}\n\\item $\\mu([0,1]^n) = 1$\n\\item $\\mu(x + A) = \\mu(A)$ for some $x\\in \\mathbb{R}^n$ (translation invariance)\n\\end{itemize}\n\n\n\n\\section{Measure Problem on $\\mathbb{R}$}\n\nThis is an important example of where it is not possible to define a measure on the whole powerset. This is why measure theory is founded on $\\sigma$-algebras.\\\\\n\nTake the following measure problem:\\\\\n\nWe search a measure $\\mu$ on $P(\\mathbb{R})$ with the properties:\n\n\\paragraph{}\n\\begin{enumerate}\n\\item $\\mu([a,b]) = b-a,\\ b>a$\n\\item $\\mu(x+A) = \\mu(A),\\ A\\in\\mathbb{R},\\ x\\in\\mathbb{R}$\t \n\\end{enumerate}\n\nThe only solution to this problem is the trivial map, $\\mu(\\mathbb{R}) = 0$. A proof goes as follows:\n\n\\paragraph{Claim}\nLet $\\mu$ be a measure on $P(\\mathbb{R})$ with $ \\mu ((0,1]) < \\infty $ and (2). The only measure that satisfies this condition is the zero measure, $\\mu = 0$, which violates (1).\n\nTake the interval $I:=(0,1]$ with equivalence relation $x\\sim y \\equiv x-y \\in \\mathbb{Q}$. That is, $x$ and $y$ are considered equivalent if they differ by a rational number. That is, we define sets of equivalent numbers, equivalence classes $ [x] := \\{ x+r: r \\in \\mathbb{Q}, x+r \\in I \\} $. The equivalence classes are a disjoint decomposition (a partition) of the unit interval $I$ in terms of possibly infinite, countable number of elements.\n\nTake a choice set $A\\subseteq I$ that consists of one number from each of the equivalence classes $[x]$ that make up $I$. (cf. sections \\ref{sec:choicesets}, \\ref{sec:axiomofchoice}). It has the property: \n\\begin{itemize}\n\\item For each $[x]$ there is an $a\\in A$ with $a \\in [x]$ \n\\item For all $a,b \\in A$, if $a,b \\in [x] \\implies a=b$ \n\\end{itemize}\n\nTake the translations of a set $A$, $A_n := r_n + A$ where $(r_n)_{n\\in\\mathbb{N}}$ are an enumeration of $\\mathbb{Q}\\cap(1,1]$. \n\n\\paragraph{Proof}\nThe axiom of choice guarantees that it is possible to form a choice set $A$ and the definition of equivalence classes guarantees that the translations of $A_n$ are still choice sets. \n\n\\paragraph{Claim}\n$A_n \\cap A_m = \\empty$ if $n\\neq m$.\n\n\\paragraph{Proof}\nTake $x \\in A_n \\cap A_m \\implies \\begin{array}{ll} x = r_n + a, & a_n \\in A\\\\ x = r_m + a_m, & a_m \\in A \\end{array}$\n\nThen, $r_n + a_n = r_m + a+m \\implies a_n - a_m = r_m - r_n \\in \\mathbb{Q} \\implies a_n \\sim a_m$ according to the definition of the equivalence classes. Also, $a_m, a_n \\in [a_m] \\implies a_n = a_m \\implies r_n = r_m \\implies n=m$.\n\n\\paragraph{Claim}\n$(0,1] \\subseteq \\bigcup_{n\\in\\mathbb{N}}A_n \\subseteq (-1,2]$ \n\n\\paragraph{Proof}\nGiven $r_n \\in \\mathbb{Q}\\cap (-1,1]$, $-1< r_n \\leq 1$ and $a_n \\in A,\\ 0\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nShow by induction that the number of degree-2 nodes (nodes with 2 children) in any non-empty binary tree is 1 fewer than the number of leaves.\nConclude that the number of internal nodes in a full binary tree is 1 fewer than the number of leaves.\n\n\\subsection*{Solution}\n\nLet $n(T)$ be the numebr of nodes, $d(T)$ be the number of nodes with 2 children and $l(T)$ be the number of leaves, in tree $T$.\nObjective is to prove $l(T) = d(T) + 1$ in any tree $T$.\nProof is given by induction on number of nodes $n$ in the binary tree $T$.\n\n\\begin{itemize}\\itemsep=0pt\n\\item[] \\textit{Base case:} The most trivial binary tree with $n(T)=1$ contains only the root node therefore $l(T) = 0 + 1 = d(T) + 1$.\n\\item[] \\textit{Inductive Hypothesis:} We form the inductive hypothesis as for any binary tree with $n(T) \\leq k$, $l(T) = d(T) + 1$.\n\\item[] \\textit{Induction Step:} Using the inductive hypothesis, we need to show $l(T) = d(T)+1$ holds true for any tree with $n(T) = k+1$ where $k > 0$.\nSince $n(T) > 1$, $T$ will have tree cases that follows.\n \\begin{itemize}\\itemsep=0pt\n \\item[] If root $r$ in tree $T$ ($n(T) = k+1$) has only a left subtree $T'$, since $r$ is neither a leaf nor a degree-2 node, $l(T) = l(T')$ and $d(T)=d(T')$.\nHowever, $n(T') = n(T) - 1 = k$.\nThus, using the inductive hypothesis, $l(T') = d(T') + 1$.\nTherefore, $l(T) = d(T) + 1$.\n \\item[] Similarly, if root $r$ in tree $T$ has only a right subtree $T'$, same reasoning will lead to $l(T') = d(T') + 1$.\n \\item[] In case both the left subtree ($T'$) and the right subtree ($T''$) of the binary tree $T$ ($n(T) = k+1$) are non-empty, the root $r$ of tree $T$ will be a degree-2 node.\nTherefore, $l(T) = l(T') + l(T'')$ and $d(T) = d(T') + d(T'') + 1$ will hold.\n Since both $n(T')$ and $n(T'')$ are less than $k$, using the inductive hypothesis, $l(T') = d(T') + 1$ and $l(T'') = d(T'') + 1$.\n Therefore, $l(T) = l(T') + l(T'') = d(T') + 1 + d(T'') + 1 = d(T) + 1$ and the induction is complete.\n \\end{itemize}\n Therefore number of leaves in tree $T$ is always 1 more than number of degree-2 nodes.\n\\end{itemize}\nThis prove would immediately lead to conclusion of the second part.\nSince all non-leaf nodes in a full binary tree are of second degree, number of internal nodes will be one less than the number of leaves.\n", "meta": {"hexsha": "020d97d3ce83f0710eada92cdfa3de98c04300bd", "size": 2688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q04.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q04.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q04.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 68.9230769231, "max_line_length": 181, "alphanum_fraction": 0.6235119048, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.9124361616674906, "lm_q1q2_score": 0.8525759422572633}} {"text": "\n\\subsection{Limits of real functions}\n\n\\subsubsection{Limit operator}\n\nFor a function \\(f(x)\\),\n\n\\(\\lim_{x\\rightarrow a}f(x)=L\\)\n\nWe can say that \\(L\\) is the limit if:\n\n\\(\\forall \\epsilon >0 \\exists \\delta >0 \\forall x[0<|x-p|<\\delta \\rightarrow |f(x)-L|<\\epsilon]\\)\n\n\n", "meta": {"hexsha": "35979351bf449d5ce1b1b5e746255ff0425c460b", "size": 271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/01-01-limit.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/01-01-limit.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/01-01-limit.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.0666666667, "max_line_length": 97, "alphanum_fraction": 0.6494464945, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992969868542, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.8525228831629951}} {"text": "\\section{Week 2}\n\\subsection{1/12/2020}\n\\begin{itemize}\n \\item For multiplication, the entry in row $i$ column $j$ is the dot of row $i$ of A and column $j$ of B.\n \\item Distributed from the left and right\n \\item Associative\n \\item Suppose A is a square matrix. $A^{-1}$ is a matrix of the same such that:\n \\item $AI = IA = A$\n \\item $A^{-1}A=AA^{-1}=I$\n \\item An inverse matrix may not exist if\n \\begin{itemize}\n \\item not square\n \\item if any row is a linear combination of other rows\n \\end{itemize}\n \\item If an inverse matrix exists, it is really helpful to solve a system of equations.\n \\item A $2\\times 2$ matrix is invertible if and only if $ad-bc$, the determinant, is not zero. In this case, we find the inverse of a 2x2 matrix.\n $$A=\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}$$\n $$A^{-1}=\\frac{1}{|A|}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix}=\\frac{1}{ad-bc}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix}$$\n \\item A diagonal matrix of any size is invertible when none of the diagonal entries are zero.\n \\item If they are invertible $(AB)^{-1} = B^{-1}A^{-1}$\n \\item Any matrix that causes a known change, should be easy to invert. We have to think of a matrix that would undo what is done.\n Ex. $$E=\\begin{bmatrix}1&0&0\\\\-5&1&0\\\\0&0&1\\end{bmatrix}$$ subtracts 5 times row1 from row2\n \\item So we would want something that adds 5 times row1 to row2\n Result:\n $$E=\\begin{bmatrix}1&0&0\\\\5&1&0\\\\0&0&1\\end{bmatrix}$$\n \\item $$P^{-1} = P^{12} = \\begin{bmatrix}0&1&0\\\\1&0&0\\\\0&0&1\\end{bmatrix}$$\n \\item When the inverse is not immediately obvious, one method of calculating it is called the Gauss-Jordan method. This is done by.\n \\begin{enumerate}\n \\item Putting the matrix you wish to invert next to the identity matrix\n \\item Use row transformations (elimination) to transform your matrix into the identity.\n \\item The identity will have been transformed into the inverse matrix.\n \\end{enumerate}\n \\item Ex. $$A=\\begin{bmatrix}2&-1&0&1&0&0\\\\-1&2&-1&0&1&0\\\\0&-1&2&0&0&1\\end{bmatrix}$$\n \\item $2R_2+R_1$\n $$A=\\begin{bmatrix}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&-1&2&0&0&1\\end{bmatrix}$$\n \\item $3R_3+R_2$\n $$A=\\begin{bmatrix}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&0&4&1&2&3\\end{bmatrix}$$\n \\item $2R_2+R_3$\n $$A=\\begin{bmatrix}2&-1&0&1&0&0\\\\0&6&0&3&6&3\\\\0&0&4&1&2&3\\end{bmatrix}$$\n \\item $6R_1+R_2$\n $$A=\\begin{bmatrix}12&0&0&9&6&3\\\\0&6&0&3&6&3\\\\0&0&4&1&2&3\\end{bmatrix}$$\n $$A=\\begin{bmatrix}12&0&0&9&6&3\\\\0&6&0&3&6&3\\\\0&0&4&1&2&3\\end{bmatrix}\\begin{bmatrix}\\frac{1}{12}\\\\\\frac{1}{6}\\\\\\frac{1}{4}\\end{bmatrix}=\\begin{bmatrix}1&0&0&3/4&1/2&1/4\\\\0&1&0&1/2&1&1/2\\\\0&0&1&1/4&1/2&3/4\\end{bmatrix}$$\n\\end{itemize}\n\n\\subsection{1/13/2021}\n\\begin{itemize}\n \\item We are trying to factorize for the lower and upper triangular matrices.\n \\item Ex. $\\begin{bmatrix}1&0\\\\-3&1\\end{bmatrix}\\begin{bmatrix}2&1\\\\6&8\\end{bmatrix}=\\begin{bmatrix}2&1\\\\0&5\\end{bmatrix}$\n \\item every $E^{-1}_{ij}$ matrix is lower triangular, with 1's on the main diagonal. The off diagonla entry is +k to undo the elimination done by the - k when multiplied from the left by $E_{ij}$\n \\item The product of several elimination matrices is still lower triangular.\n\\end{itemize}", "meta": {"hexsha": "8d51ae046848354ae4d6ab794c0c7931a32ef1bf", "size": 3259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/math/linear/content/week2.tex", "max_stars_repo_name": "WHS-Resources/WHS-Resources", "max_stars_repo_head_hexsha": "255306f11e159ee39d58f479b64935ecac792991", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/math/linear/content/week2.tex", "max_issues_repo_name": "WHS-Resources/WHS-Resources", "max_issues_repo_head_hexsha": "255306f11e159ee39d58f479b64935ecac792991", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-14T05:47:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-16T21:02:54.000Z", "max_forks_repo_path": "notes/math/linear/content/week2.tex", "max_forks_repo_name": "WHS-Resources/WHS-Resources", "max_forks_repo_head_hexsha": "255306f11e159ee39d58f479b64935ecac792991", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-13T20:58:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T20:58:04.000Z", "avg_line_length": 63.9019607843, "max_line_length": 224, "alphanum_fraction": 0.6508131329, "num_tokens": 1284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.9111797118207757, "lm_q1q2_score": 0.8522687715008314}} {"text": "\\section*{Ex.1.2}\n\\subsubsection*{Contract two nodes at random. Show min--cut is found with exponential small probability.}\n\nDefine a graph $G$ with $n$ nodes. Let the nodes $u_1,\\ldots,u_{u/2}$ be part of the set $S_1$ and let the nodes $u_{u/2+1},\\ldots,u_n$ be part of the set $S_2$. Let all nodes in $S_j, j=1,2$ have internal edges between them, and let there be an edge from $(u_1,u_n)$. Hence the min--cut would be $(u_1,u_n)$. It is easy to see that if the algorithm at any point contracts a node from $S_1$ and $S_2$ the min--cut is not found. Hence, we want to find the probability that at all steps, two nodes from either $S_{1i}$ or $S_{2i}$ is contracted, where $S_{ji}, j=1,2$ is the set of remaining nodes at $S_j$ after $i$ iterations.\n\nDefine $X_{ji} = \\{ 2 \\text{ nodes are picked from } S_{ji} \\}, j=1,2$. and note that $X_{1i}\\cap X_{2i}= \\emptyset$. Furthermore, note that \n$$\nP(X_{ji}) = \\frac{\\binom{\\abs{S_{ji}}}{2}}{\\binom{\\abs{S_{1i}} + \\abs{S_{2i}}}{2}}\n$$ \nwhich is simply all the ways you can pick two nodes from $S_{ji}$, out of all the ways you can pick two nodes in the remaining graph.\n\nDefine the event $E_i = \\{ S_{1i} \\text{ or } S_{2i}\\}$\n\nThen\n\\begin{align*}\nP(E_i) &= P(X_{1i} \\cup X_{2i}) = P(X_{1i}) + P(X_{2i}) - P(X_{1i} \\cap X_{2i}) = P(X_{1i}) + P(X_{2i})\\\\\n&= \\frac{\\binom{\\abs{S_{1i}}}{2}}{\\binom{\\abs{S_{1i}} + \\abs{S_{2i}}}{2}} + \\frac{\\binom{\\abs{S_{2i}}}{2}}{\\binom{\\abs{S_{1i}} + \\abs{S_{2i}}}{2}}\\\\\n&= \\frac{\\binom{\\abs{S_{1i}}}{2} + \\binom{\\abs{S_{2i}}}{2}}{\\binom{\\abs{S_{1i}} + \\abs{S_{2i}}}{2}}\n\\end{align*}\nwhere the last equation is strictly less than one as long as there are still elements in both of $S_{ji}$, which there for sure will be if no nodes from $S_{1i}$ and $S_{2i}$ have been contracted in the same iteration $i$.\n\nSet $p^* = \\max_{i} P(E_i)$ and note that because of the observation above $p^*<1$.\n\nHence\n\\begin{align*}\nP(\\bigcap_{i=1}^{n-2} E_i) = \\prod_{i=1}^{n-2}P(E_i) < \\prod_{i=1}^{n-2}p^* = (p^*)^{n-2}\n\\end{align*}\n\nwhich converges to 0 exponentially fast.", "meta": {"hexsha": "83752df9be3558668cca57352a7a0d8edf099689", "size": 2040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.1.2.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge2/Ex.1.2.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge2/Ex.1.2.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.3448275862, "max_line_length": 626, "alphanum_fraction": 0.6421568627, "num_tokens": 799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.9111797009670494, "lm_q1q2_score": 0.8522687531379767}} {"text": "\\subsection{De Morgan's Laws}\n\n\\begin{itemize}\n\\item \\(\\neg (A\\lor B)\\Leftrightarrow (\\neg A\\land \\neg B)\\)\n\\item \\(\\neg (A\\land B)\\Leftrightarrow (\\neg A\\lor \\neg B)\\)\n\\end{itemize}\n\nThis expresses the duality of normal form.\n\nDuality is the principle that binary operators have inverses, and when they are swapped with their inverse, the truth value of the statement is unaffected.\n\n", "meta": {"hexsha": "4dfd229c7f840b5c2c95be945c7551ab555120ab", "size": 385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/04-03-demorgan.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/04-03-demorgan.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/04-03-demorgan.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0833333333, "max_line_length": 155, "alphanum_fraction": 0.7376623377, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9669140187510509, "lm_q2_score": 0.8807970858005139, "lm_q1q2_score": 0.851655049935589}} {"text": "%!TEX root=report.tex\n\\subsection{SVD}\nSingular Value Decomposition (SVD) is a useful method for factorizing matrices.\n According to the SVD-theorem a matrix $X$ can be expressed as\n\\begin{equation}\nX=U \\Sigma V^{T}.\n\\label{eq:theory-svd}\n\\end{equation}\n\nIf the matrix $X$ has the size $m \\times n$, the factorized components have the following properties \\cite{introduction-to-data-mining}:\n\\begin{itemize}\n\\item The columns in $U$ are the eigenvectors of $X X^T$, with the size $m \\times m$.\n\\item The columns in $V$ are the eigenvectors of $X^T X$, with the size $n \\times n$.\n\\item $\\Sigma$ is a diagonal matrix, consisting of the square root of the corresponding eigenvalues to the eigenvectors in $U$ and $V$.\nIt has the size $m \\times n$. The square root eigenvalues are also called ``singular values''.\n\\end{itemize}\n\nIn the case where $X$ has many more rows than columns, the $U$ matrix will contain more eigenvectors than are strictly needed to reconstruct $X$ and the $\\Sigma$ matrix will have lots of zero-rows.\nA so called \\textit{economy-size} SVD is therefore often used.\nThe difference being that all the redundant eigenvectors in $U$ are removed, so it has the size $m \\times n$ and the zero-rows from $\\Sigma$ are also removed, so its size becomes $n \\times n$.\n\nAn important property of SVD is that the $V$ matrix contains all eigenvectors and is therefore an orthogonal matrix, for which it is known that\n\\begin{align}\nQ^T = Q^{-1} && Q Q^T = I && Q^T Q = I && \\text{, where Q is an orthogonal matrix.}\n\\end{align}\n\nIn the normal SVD (not \\textit{economy-size}) $U$ is also a complete orthogonal matrix.\nHowever in \\textit{economy-size} some of the columns have been removed, so it is only known that $U^T U = I$.\n\nIt is standard procedure to rearrange the matrices in $U \\Sigma V^T$, so the largest values in $\\Sigma$ appears first in the diagonal.\nThe reason being that $V$ is a change of basis matrix -- it transforms elements in the original space to a new orthogonal space.\nHere the first axis has the largest variance, the second axis has the second highest variance and so on.\nThe variance described by each axis, is given by the diagonal elements in $\\Sigma^2$.\nTypically one calculates a percentage called ``variance explained by principal components'' using\n\\begin{equation}\n\\rho_{jj} = \\frac{\\Sigma^2_{jj}}{\\sum_{i=1}^n \\Sigma^2_{ii}}.\n\\end{equation}\n\nIt is often seen that most of the variance in $X$ can be described using very few eigenvectors, thus one can reduce the dimensionality of a dataset to the most ``principal'' components.\nThe above mentioned analysis goes under the umbrella term ``Principal Component Analysis (PCA)'', where a ``principal component'' (loadings) should be understood as the axes in the transformed space (i.e., the eigenvectors).\n", "meta": {"hexsha": "cd5ed340cd1039534b449cfa22a84348750a941a", "size": 2795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-svd.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-svd.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-svd.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.1707317073, "max_line_length": 224, "alphanum_fraction": 0.7481216458, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.9173026494123034, "lm_q1q2_score": 0.851631857938295}} {"text": "\n\\subsection{Rectified Linear Unit (ReLU)}\n\n\\subsubsection{The function}\n\n\\(a(z)=\\max (0,z)\\)\n\n\\subsubsection{The derivative}\n\nIts differential is \\(1\\) for values of \\(z\\) above \\(0\\), and \\(0\\) for values of \\(z\\) below \\(0\\).\n\nThe differential is undefined at \\(z=0\\), however this is unlikely to occur in practice.\n\n\\subsubsection{Notes}\n\nThe ReLU activation function induces sparcity.\n\n", "meta": {"hexsha": "86ff4df5a46e5d7e236da43f59ff3f46aa235fe2", "size": 391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-02-ReLU.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-02-ReLU.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/neuralNetworksLink/01-02-ReLU.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7222222222, "max_line_length": 101, "alphanum_fraction": 0.7007672634, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305381464927, "lm_q2_score": 0.884039278690883, "lm_q1q2_score": 0.8515336301560564}} {"text": "\\subsection{Defining Image and Kernel}\n\n\\subsubsection{Image}\n\nOf a function, the set of vectors in the codomain hit by the domain.\nThe image of a function $f:\\;\\R^m\\rightarrow \\R^n$ is:\n\n\\[\\boxed{\n \\mathrm{Im}(f)=\\{\\tb{y}\\in \\R^n | \\exists\\;\\tb{x}\\in \\R^m\\text{ s.t. }f(\\tb{x})=\\tb{y}\\}\n}\\]\n\nSimilar in concept to the range of a function in non-linear context.\n\n\\subsubsection{Kernel}\n\nSet of vectors in the domain that are mapped to $\\tb{0}$ in the codomain.\nKernel of a function $f:\\;\\R^m\\rightarrow \\R^n$ is:\n\n\\[\\boxed{\n \\mathrm{Ker}(f)=\\{\\tb{x}\\in \\R^m | f(\\tb{x})=\\tb{0}\\}\n}\\]\n\nAnalogous to the roots/zeros of a polynomial.\n\n\\subsection{Examples}\n\nFollowing linear transformation's image lives in $\\R^2$:\n\n\\[T(\\tb{x})=\\left(\\begin{array}{cc}\n 1 & 1 \\\\\n -1 & 1\n \\end{array}\\right) \\tb{x}\\]\n\nFollowing linear transformation's image forms a plane that is\n$\\R^2$:\n\n\\[T(\\tb{x})=\\left(\\begin{array}{cc}\n 1 & -1 \\\\\n 0 & 2 \\\\\n 2 & 2\n \\end{array}\\right) \\tb{x}\\]\n\n\\subsection{Span}\n\nIf $A$ is an $n\\times m$ matrix, then image of $T(\\tb{x})=A\\tb{x}$ is set of all vectors in $\\R^n$\nthat are linear combinations of column vectors of $A$.\\\\\n\n\\noindent\nThus, the span of a set of $n$ vectors is all linear combinations of those vectors:\n\n\\[\\boxed{\n \\mathrm{span}(\\tb{v}_1,\\tb{v}_2,\\cdots,\\tb{v}_n)=\\{\\sum c_i\\tb{v}_i | c_i\\in\\R\\}\n}\\]\n\nSo the span of column vectors of $A$ is the image of the associated linear transformation.\n\n\\subsection{Kernel}\n\nKernel amounts to finding solutions to $A\\tb{x}=\\tb{0}$. Kernels are closed under linear combinations.\nKernel can never be empty set, it always holds true that $T(\\tb{0})=\\tb{0}$.\n\n\\subsection{Invertible Linear Transformations}\n\nMain conclusions about image and kernel:\n\n\\begin{itemize}\n \\item Kernel is always (trivially) $\\{\\tb{0}\\}$, else would imply dependance and therefore singularity in the associated matrix $A$\n so $\\boxed{\\mathrm{ker}(T)=\\{\\tb{0}\\}}$\n \\item Image is always the space $\\R^n$ if associated matrix $A$ is $n\\times n$, so $\\boxed{\\mathrm{Im}(T)=\\R^n}$\n\\end{itemize}", "meta": {"hexsha": "c02184188d1b29dc4063b1b95aa81d3d72acd6a9", "size": 2069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/11_image-kernel.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/11_image-kernel.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/11_image-kernel.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5571428571, "max_line_length": 135, "alphanum_fraction": 0.6578057032, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.9111796991580949, "lm_q1q2_score": 0.8514019080927473}} {"text": "%!TEX root=report.tex\n\\subsection{Least angular regression (LAR)}\nThe LAR model is almost equivalent to the linear regression, except that instead of only minimizing the sum of squares, an $\\ell^1$ norm penalty as added on the $\\hat{\\beta}$-vectors coefficients.\n\\begin{align}\n\\min_{\\hat{\\beta}}\\ (Y - \\hat{Y})^T (Y - \\hat{Y}) \\quad \\text{subject to} \\quad ||\\hat{\\beta}||_1 \\le s\n\\end{align}\n\nThe LAR algorithm \\cite{LAR-algorithm} solves this problem by initially letting all the $\\beta$ coefficients be zero.\nIt then finds the attribute, $b_1$, with the highest absolute correlation with the dependent variable Y and increases $b_1$ (or decreases depending on the sign of the correlation)\nuntil it reaches a point where another attribute $b_2$ has as much correlation with the residuals $R=Y-\\hat{Y}$ as $b_1$ has.\nAt this point the algorithm then increases/decreases both $b_1$ and $b_2$ in their joint direction until another attribute $b_i$ has the highest residual correlation.\nThis process can then be continued until there is no benefit in increasing any of the $b_i$s - that is, the full LAR solution is equivalent to the linear regression.\nIt should also be noted that if a coefficient crosses 0 in a iteration (step),\nthat coefficient should be set to 0, and the regression direction should subsequently be recomputed.\n\nSo why might one use LAR instead of for example the LASSO model? \nWhen using the LASSO one has to chose a specific value of $s$ to get one solution.\nHowever, in the LAR model you actually get the full solution path which means that you can find all the LASSO solutions instead of having to do multiple LASSO with different regularization parameters ($s$).\n", "meta": {"hexsha": "7b22610c09a6ef97a96a2b231b69640d2d38e345", "size": 1691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-lar.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-lar.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-lar.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.0, "max_line_length": 206, "alphanum_fraction": 0.7693672383, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.9407897434482925, "lm_q1q2_score": 0.851085954501831}} {"text": "\\label{problem_definition}\nClustering is the task of gathering items in a way that elements belonging\nto the same group (the \\emph{cluster}) are more similar to each other other than the ones\nassigned to the others.\\\\\nMore formally, given a input:\n\\begin{itemize}\n \\item $X = \\{x_0, \\dots ,x_n\\}$, the initial set of elements.\n \\item $d: X \\times X \\to \\mathbb{R}$, a \\emph{metric} measuring the similarity.\n\\end{itemize}\nThe final goal is to find the cluster configuration\n\\begin{equation*}\n C = \\left\\{ c_0, \\dots , c_m \\right\\} \\mid \\bigcup_{C} = X\n\\end{equation*}\npartitioning $X$ into $m$ clusters, maximizing the intra-cluster distance\n(dual problem of minimizing inter-cluter distance):\n\n\\begin{equation}\n \\underset{C}{\\mathrm{argmax}}\n \\sum_{c \\in C}\n \\sum_{i,j}^{|c|}\n d(c_i,c_j)\n\\end{equation}\n\n\n\\subsection*{Challenges}\nThe concept of clustering is simple and powerful; moreover, its versatility\nand generality are its greatness and at the same time source of many difficulties.\n%% Metrics identification\nGiven the only strict requirement to be the definition of a metric over the\ndomain of $X$, clustering is applied to a wide variety of problems.\nClearly, each domain offers different optimization opportunities and\nparticular challenges.\nIn particular, the choice of the metric heavily influences the final outcome quality.\nAs a result even the medical~\\cite{siless2013comparison}, the mechanical\nengineering~\\cite{wilding2011clustering} and the mobile networks~\\cite{cheng2009stability}\nliteratures features different studies that address this particular challenge\nsuggesting highly specialized distance functions.\n\n%% Inter/Intra cluster distance measure\nOnce the proper metric is identified, the following huge influencing factors\nare the mathematical definitions of ``intra-cluster'' and ``inter-cluster''\ndistances. They vary a lot in the different implementation leading to\ncompletely different clustering configurations.\nFor example, three methods are widely used when performing agglomerative\nclustering to define the distance between two clusters:\nthe average, the minimum, and the maximum distance.\nThe average approach uses the barycenters, while the minimum (maximum)\nrelies upon the minimal (maximal) distance between any two points\nbelonging to a different clusters.\n\n\n\\subsection*{Choosing the $k$ parameter}\nThe first main issue of the k-means described in Section \\ref{related} is the choice\nof the number of clusters the dataset has to be divided into.\n\nThe original k-means does not address this problem at all. Thus, some heuristic has to\nbe applied. One possibility is to have a deep knowledge of the structure underlying the\ndataset, having an idea of the target number of groups. On the other hand, especially\nin exploratory data analysis, this value cannot be known in advance.\nHence, the most common solution is to run the algorithm with increasing values of $k$ and\nfinally keeping the parameter that produces the best-quality clusters.\n\nChoosing the right value for this parameter is crucial, since a wrong one may\ninstruct the algorithm to collapse entities that are actually very far from each other\n(or vice versa).\n\n\n\\subsection*{Positioning the initial centroids}\nGiven that an optimal value for $k$ is found, the other big problem is how to position the $k$\ninitial centroids.\n\nGiven enough time, the k-means algorithm will always converge. However it may be to a local\nminimum. This is highly dependent on the initialization of the centroids. The boostrapping\nphase can be addressed in various ways. For example, the\n\\emph{scikit-learn}\\footnote{http://scikit-learn.org} Python library\nuses an approach that positions the initial centroids to be (generally) distant\nfrom each other by default. This procedure provides provably better results than using a random\none~\\cite{arthur2007k}.\n\nUsing a proper and efficient boostrapping heuristic is very important, since misplacing\nthe initial centroids does not allow the algorithm to find the real clusters underlying\nthe data.\n", "meta": {"hexsha": "a788832b9bf3d088a1e480a571c0199c6d20e188", "size": 4054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/problem.tex", "max_stars_repo_name": "GianlucaBortoli/enhanced-clustering", "max_stars_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections/problem.tex", "max_issues_repo_name": "GianlucaBortoli/enhanced-clustering", "max_issues_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/problem.tex", "max_forks_repo_name": "GianlucaBortoli/enhanced-clustering", "max_forks_repo_head_hexsha": "7ca4654fd72b2b279d77f803d35db9196b4a0a82", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.843373494, "max_line_length": 95, "alphanum_fraction": 0.7886038481, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574122783325, "lm_q2_score": 0.8933094003735664, "lm_q1q2_score": 0.8509434184349481}} {"text": "%!TEX root=report.tex\n\\subsection{The design matrix}\nIn OLS regression, a linear combination of the columns in the design matrix $X$, is used to predict $Y$.\nAs a starting point, the only values in $X$ are a column of ones (to fit an intercept) and a column containing the observed time $\\mathbf{t}$\n\n\\begin{equation}\nX = \\left[\\begin{matrix} \\mathbf{1} & \\mathbf{t} \\end{matrix}\\right].\n\\end{equation}\nIn the above case one would predict $\\hat{Y}$ as $\\beta_1 + \\beta_2 t$ where $\\beta_1$ will correspond to the intercept and $\\beta_2$ will correspond to the speed of mass gain.\nFrom this it follows naturally to include the acceleration by adding a column\n\n\\begin{equation}\nX = \\left[\\begin{matrix} \\mathbf{1} & \\mathbf{t} & \\frac{1}{2} \\mathbf{t}^2 \\end{matrix}\\right]\n\\end{equation} \nFrom Fourier analysis it is known that functions can be approximated by infinite sums of the trigonometric functions sines and cosines.\nTrigonometric functions are periodic in their behavior and thus are able to model periodic signals in the function that one wishes to approximate.\n\nIn the GRACE dataset, however, the measurements are recorded with a frequency of $\\frac{1}{10}$ days.\nThe Nyquist-Shannon sampling theorem states that one cannot find periodic signals above the Nyquist frequency which is given as half of the sample frequency. \nTherefore an infinite sum is not suited for approximating the function. \nInstead it is used, that the maximal frequency in the data has a period of a year ($T = 365.242$ days) while the minimal frequency will have 18 periods per year since $\\sfrac{365.242}{18} \\approx 20.29 \\text{ days}$. Hence it follows that the final design matrix will be given as\n\\begin{equation*}\n\\resizebox{\\textwidth}{!}{$\nX = \\left[\\begin{matrix}\n\t\\mathbf{1} &\n\t\\mathbf{t} &\n\t\\frac{1}{2} \\mathbf{t}^2 &\n\t\\cos\\left( \\dfrac{2 \\pi}{\\frac{365.242}{1}} \\mathbf{t} \\right) &\n\t\\sin\\left( \\dfrac{2 \\pi}{\\frac{365.242}{1}} \\mathbf{t} \\right) &\n\t\\cdots &\n\t\\cos\\left( \\dfrac{2 \\pi}{\\frac{365.242}{18}} \\mathbf{t} \\right) &\n\t\\sin\\left( \\dfrac{2 \\pi}{\\frac{365.242}{18}} \\mathbf{t} \\right)\n\\end{matrix}\\right].\n$}\n\\end{equation*}\n\nFrom this it's seen that the angular frequency is $\\omega_i = \\frac{2 \\pi}{\\sfrac{365.242}{i}} = \\frac{2 \\pi i}{T}$\n", "meta": {"hexsha": "df23e8da5ba52763ecd604c35e156e3187eba046", "size": 2246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-design.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-design.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-design.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.1052631579, "max_line_length": 280, "alphanum_fraction": 0.7217275156, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778061099871, "lm_q2_score": 0.8887588001219789, "lm_q1q2_score": 0.8507890743417126}} {"text": "\n\\subsection{Surface area}\nLet $S$ be a surface parameterized by $x$ and $y$.\nThat is, let $S=(x,y,z)$ where $z=f(x,y)$.\nThe tangent lines at a point on $S$ form a tiny parallelogram.\nThe area $a$ of the parallelogram is given by the magnitude of the cross product.\n$$a=\\left|\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}\\right|$$\nBy summing over all the parallelograms we obtain the total surface area $A$.\nHence\n$$A=\\int\\!\\!\\!\\int dA=\\int\\!\\!\\!\\int a\\,dx\\,dy$$\nThe following example computes the surface area of a unit disk\nparallel to the $xy$ plane.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nM1 = ((0,0,0),(0,0,-1),(0,1,0))\nM2 = ((0,0,1),(0,0,0),(-1,0,0))\nM3 = ((0,-1,0),(1,0,0),(0,0,0))\nM = (M1,M2,M3)\ncross(u,v) = dot(u,M,v)\nz = 2\nS = (x,y,z)\na = abs(cross(d(S,x),d(S,y)))\ndefint(a,y,-sqrt(1 - x^2),sqrt(1 - x^2),x,-1,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\pi$\n\n\\bigskip\n\\noindent\nThe result is $\\pi$, the area of a unit circle, which is what we expect.\nThe following example computes the surface area of $z=x^2+2y$ over\na unit square.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nM1 = ((0,0,0),(0,0,-1),(0,1,0))\nM2 = ((0,0,1),(0,0,0),(-1,0,0))\nM3 = ((0,-1,0),(1,0,0),(0,0,0))\nM = (M1,M2,M3)\ncross(u,v) = dot(u,M,v)\nz = x^2 + 2y\nS = (x,y,z)\na = abs(cross(d(S,x),d(S,y)))\ndefint(a,x,0,1,y,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{5}{8}\\log(5)+\\tfrac{3}{2}$\n\n\\bigskip\n\\noindent\nThe following exercise is from\n{\\it Multivariable Mathematics} by Williamson and Trotter, p. 598.\nFind the area of the spiral ramp defined by\n$$S=\\begin{bmatrix}u\\cos v\\\\\\ u\\sin v\\\\ v\\end{bmatrix},\\qquad 0\\le u\\le1,\\qquad 0\\le v\\le3\\pi$$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nM1 = ((0,0,0),(0,0,-1),(0,1,0))\nM2 = ((0,0,1),(0,0,0),(-1,0,0))\nM3 = ((0,-1,0),(1,0,0),(0,0,0))\nM = (M1,M2,M3)\ncross(u,v) = dot(u,M,v)\nx = u cos(v)\ny = u sin(v)\nz = v\nS = (x,y,z)\na = circexp(abs(cross(d(S,u),d(S,v))))\ndefint(a,u,0,1,v,0,3pi)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{3}{2}\\pi\\log(1+2^{1/2})+\\frac{3\\pi}{2^{1/2}}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfloat\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 10.8177$\n", "meta": {"hexsha": "557cc1d2fa5a73b1a13f3dc3cea64348c96b34a3", "size": 2186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/surface-area.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/surface-area.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/surface-area.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 27.325, "max_line_length": 95, "alphanum_fraction": 0.626715462, "num_tokens": 918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075690244281, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.8505408769343193}} {"text": "\n\\subsection{Probabilistic language models}\n\n\\subsubsection{Introduction}\n\nProbabilistic language models can predict future words given a history of words.\n\nThis can be used for predictive text. For example if a user types \"Did you call your\" we may want to estimate the probability that the next word is \"child\".\n\nWe can state this problem:\n\n\\(P(child|did\\ you\\ call\\ your)\\)\n\nBy definition this is:\n\n\\(P(child|did\\ you\\ call\\ your)= \\dfrac{P(did\\ you\\ call\\ your\\ child)}{P(did\\ you\\ call\\ your)}\\)\n\nWe can estimate each of these:\n\n\\(P(did\\ you\\ call\\ your\\ child)=\\dfrac{|did\\ you\\ call\\ your\\ child|}{|5\\ word\\ sentences|}\\)\n\n\\(P(did\\ you\\ call\\ your)=\\dfrac{|did\\ you\\ call\\ your|}{|4\\ word\\ sentences|}\\)\n\n\\subsubsection{Data requirements}\n\nThis needs a large corpus, which may not be practical.\n\nAdditionallly, the words must be indexed, and not simply stored as a bag of words.\n\n\\subsubsection{Decomposition}\n\nWe can decompose the probabilities using the chain rule.\n\n\\(P(did\\ you\\ call\\ your\\ child)=P(did)P(you|did)...P(child|did\\ you\\ call\\ your)\\)\n\n\\(P(w_1,...,w_k)= \\prod_k p(w_k|w_1,...,w_{k-1})\\)\n\n\\subsubsection{N-grams}\n\nWe can simplify the decomposition using the Markov assumption:\n\n\\(P(w_k|w_1,...,w_{k-1})=P(w_k|w_{k-1})\\)\n\nThis is a \\(1\\)-gram.\n\nWe can do this for \\(n\\) words back. This is an \\(n\\)-gram.\n\n\\subsubsection{Smoothing}\n\nWe can use smoothing to address small corpuses.\n\n\\(P(did\\ you\\ call\\ your\\ child)=\\dfrac{|did\\ you\\ call\\ your\\ child|+1}{|5\\ word\\ sentences|+V}\\)\n\n\\(P(did\\ you\\ call\\ your)=\\dfrac{|did\\ you\\ call\\ your|+1}{|4\\ word\\ sentences|+V}\\)\n\nFor some value \\(V\\).\n\n\\subsubsection{Perplexity}\n\nWe can compare probabilistic language models using perplexity.\n\nWe can then choose the model with the lowest perplexity.\n\n\\(perplexity(w_1, w_2, ..., w_n)=P(w_1, w_2, ..., w_n)^{-\\dfrac{1}{n}}\\)\n\nWe can expand this:\n\n\\(perplexity(w_1, w_2, ..., w_n)=\\prod_i P(w_i| w_1, ..., w_{i-1})^{-\\dfrac{1}{n}}\\)\n\nDepending on which n-gram we use we can then simplify this.\n\n", "meta": {"hexsha": "f2a564c8e94335d657e396844e5c6070a9903c29", "size": 2006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/NLP/01-01-language.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/NLP/01-01-language.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/NLP/01-01-language.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8611111111, "max_line_length": 156, "alphanum_fraction": 0.68444666, "num_tokens": 646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8976952907388474, "lm_q1q2_score": 0.8504595067823226}} {"text": "\n\\subsection{Avogadro's constant}\nThere is a proposal to define Avogadro's constant as exactly\n84446886 to the third power.\n(Fox, Ronald and Theodore Hill.\n``An Exact Value for Avogadro's Number.''\n{\\it American Scientist} 95 (2007): 104--107.)\nThe proposed number in the article is actually $(84446888)^3$.\nIn a subsequent addendum the authors reduced it to $84446886^3$ to make the\nnumber divisible by 12. (See {\\tt www.physorg.com/news109595312.html}.)\nThis number corresponds to an ideal cube of atoms with 84,446,886\natoms along each edge.\nLet us check the difference between the proposed value and the measured value\nof $(6.0221415\\pm0.0000010)\\times10^{23}$ atoms.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = 84446886^3\nB = 6.0221415*10^23\nA-B\n\\end{Verbatim}\n\n$\\displaystyle -5.17173\\times10^{16}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n0.0000010*10^23\n\\end{Verbatim}\n\n$\\displaystyle 1\\times10^{17}$\n\nWe see that the proposed value is within the experimental error.\nJust for the fun of it, let us factor the proposed value.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfactor(A)\n\\end{Verbatim}\n\n$\\displaystyle 2^3\\times3^3\\times1667^3\\times8443^3$\n", "meta": {"hexsha": "0f7cf7486e948037dc0df05eb8e1431cafc0e417", "size": 1199, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/avogadro.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/avogadro.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/avogadro.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5526315789, "max_line_length": 77, "alphanum_fraction": 0.7589658048, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8918110533454179, "lm_q1q2_score": 0.8501412175917292}}