Mini Project 2

Watchanan Chantapakul (wcgzm)


A two-class dataset has gaussian likelihood functions and priors $P(\omega_1) = 4P(\omega_2)$. Let the parameters of the likelihoods be $\mu_1 = \begin{pmatrix} 7 \\ 1 \end{pmatrix}$, $\mu_2 = \begin{pmatrix} 1 \\ 7 \end{pmatrix}$ and $\Sigma_1 = \Sigma_2 = \begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}$

Question A

a) Write a generic Matlab function1 to compute the Mahalanobis distances between two arbitrary samples $\vec{x_1}$ and $\vec{x_2}$ or the distance between a sample $\vec{x_1}$ and the center of any given Gaussian distribution with covariance $\Sigma$, mean $\mu$, and dimension $d$.

1 you may use any computer language/package, but you may NOT use any function other than the basic operations: i.e. +, -, *, / (for scalars, vectors, or matrices)

Solution

$(i, j)$-Minor of a Matrix

$$ \mathbf{M}_{i, j} = \operatorname{det}((\mathbf{A}_{p, q})_{p \neq i, q \neq j}) = |(\mathbf{A}_{p, q})_{p \neq i, q \neq j}| $$

Determinant

$$ \operatorname{det}(A) = |\mathbf{A}| = \sum_{i=0, j} (-1)^{i+j} \cdot \mathbf{A}_{i, j} \cdot \mathbf{M}_{i, j} = \sum_{i=0, j} (-1)^{j} \cdot \mathbf{A}_{0, j} \cdot \mathbf{M}_{0, j} $$

Matrix of Cofactors

$$ \mathbf{C}_{i, j} = (–1)^{i+j} \mathbf{M}_{i, j} $$

Transpose

$$ \mathbf{A}^{\mathsf{T}}_{i, j} = \mathbf{A}_{j, i} $$

Adjugate Matrix

$$ \operatorname{adj}(\mathbf{A}) = \mathbf{C}^{\mathsf{T}} $$

Inverse Matrix

$$ \mathbf{A}^{-1} = |\mathbf{A}|^{-1} \cdot \operatorname{adj}(\mathbf{A}) = \frac{\operatorname{adj}(\mathbf{A})}{|\mathbf{A}|} $$

Identity matrix

$$ \mathbf{I}_{ij} = \begin{cases} 1 & i = j \\ 0 & \text{otherwise} \end{cases} $$

Mahalanobis Distance

$$ r^2 = (\vec{x} - \vec{y})^{\mathsf{T}} \mathbf{\Sigma}^{-1} (\vec{x} - \vec{y}) $$

Question B

b) Write another Matlab function1 to call the function above and compute the discriminant function with the following generic form $$ g_i(x) = -\frac{1}{2}(x-\mu_i)^t\Sigma_i^{-1}(x-\mu_i)-\frac{d}{2}\ln (2\pi) - \frac{1}{2} \ln |\Sigma_i| + \ln P(\omega_i) $$ also for any given $d$ dimensional data, mean, covariance matrix and prior probabilities.

1 you may use any computer language/package, but you may NOT use any function other than the basic operations: i.e. +, -, *, / (for scalars, vectors, or matrices)

Discriminant function $g_i(\cdot)$

Question C

c) write a Matlab program that generates (say, 1000) samples from the two classes with the parameters in part a); and plot the two classes in 3D. (your plot should be similar to figure 2.10 (b) in the textbook). The class samples above MUST be created from a Gaussian distribution with $N(~0, \mathbf{I})$ (ie. use the concept of whitening in an inverse manner).2

2 That is, do NOT use a Matlab Toolbox or any other library function, to generate the distributions above directly from the parameters in part a). You MUST do a “dewhitening” instead. In that case, the following Matlab functions can still be useful for this assignment: randn(), peaks(), meshgrid(), surf(), and mesh()

Eigenvalue $\lambda$

Eigenvector $\phi$

Cross-check with the example in the lecture note

Creating random samples

Now, we create 5,000 samples for each class.

Overlay all samples of all classes in the same figure.

Whitening Transformation

$$ \mathbf{Y} = \Lambda^{-\frac{1}{2}} \Phi^{\mathsf{T}} \mathbf{X} $$

Dewhitening Transformation

$$ \Lambda^{\frac{1}{2}} \mathbf{Y} = \Lambda^{\frac{1}{2}} \Lambda^{-\frac{1}{2}} \Phi^{\mathsf{T}} \mathbf{X} $$$$ \Lambda^{\frac{1}{2}} \mathbf{Y} = \mathbf{I} \Phi^{\mathsf{T}} \mathbf{X} $$$$ \Lambda^{\frac{1}{2}} \mathbf{Y} = \Phi^{\mathsf{T}} \mathbf{X} $$$$ (\Phi^{\mathsf{T}})^{-1} \Lambda^{\frac{1}{2}} \mathbf{Y} = (\Phi^{\mathsf{T}})^{-1} \Phi^{\mathsf{T}} \mathbf{X} $$$$ (\Phi^{\mathsf{T}})^{-1} \Lambda^{\frac{1}{2}} \mathbf{Y} = \mathbf{I} \mathbf{X} $$$$ (\Phi^{\mathsf{T}})^{-1} \Lambda^{\frac{1}{2}} \mathbf{Y} = \mathbf{X} $$$$ \Phi^{\mathsf{T}} \Lambda^{\frac{1}{2}} \mathbf{Y} = \mathbf{X} $$$$ \Phi \Lambda^{\frac{1}{2}} \mathbf{Y} = \mathbf{X} $$

Question D

d) derive the decision boundary and plot this boundary on top of the generated samples.

Discriminant function:

$$ g_i(x) = -\frac{1}{2}(x-\mu_i)^t\Sigma_i^{-1}(x-\mu_i)-\frac{d}{2}\ln (2\pi) - \frac{1}{2} \ln |\Sigma_i| + \ln P(\omega_i) $$

Decision boundary:

$$ g_i(x) = g_j(x) $$$$ -\frac{1}{2}(x-\mu_i)^t\Sigma_i^{-1}(x-\mu_i)-\frac{d}{2}\ln (2\pi) - \frac{1}{2} \ln |\Sigma_i| + \ln P(\omega_i) = -\frac{1}{2}(x-\mu_j)^t\Sigma_j^{-1}(x-\mu_j)-\frac{d}{2}\ln (2\pi) - \frac{1}{2} \ln |\Sigma_j| + \ln P(\omega_j) $$$$ -\frac{1}{2}(x-\mu_i)^t\Sigma_i^{-1}(x-\mu_i) - \frac{1}{2} \ln |\Sigma_i| + \ln P(\omega_i) = -\frac{1}{2}(x-\mu_j)^t\Sigma_j^{-1}(x-\mu_j) - \frac{1}{2} \ln |\Sigma_j| + \ln P(\omega_j) $$

From $\Sigma_1 = \Sigma_2$, $$ -\frac{1}{2}(x-\mu_i)^t\Sigma_i^{-1}(x-\mu_i) + \ln P(\omega_i) = -\frac{1}{2}(x-\mu_j)^t\Sigma_j^{-1}(x-\mu_j) + \ln P(\omega_j) $$ $$ -\frac{1}{2}\left[ x^{\mathsf{T}}\Sigma_i^{-1} x - 2\mu_i^{\mathsf{T}}\Sigma_i^{-1}x + \mu_i^{\mathsf{T}}\Sigma_i^{-1}\mu_i \right] + \ln P(\omega_i) = -\frac{1}{2}\left[ x^{\mathsf{T}}\Sigma_j^{-1} x - 2\mu_j^{\mathsf{T}}\Sigma_j^{-1}x + \mu_j^{\mathsf{T}}\Sigma_j^{-1}\mu_j \right] + \ln P(\omega_j) $$ $$ -\frac{1}{2} x^{\mathsf{T}}\Sigma_i^{-1} x +\frac{1}{2} 2\mu_i^{\mathsf{T}}\Sigma_i^{-1}x -\frac{1}{2}\mu_i^{\mathsf{T}}\Sigma_i^{-1}\mu_i + \ln P(\omega_i) = -\frac{1}{2} x^{\mathsf{T}}\Sigma_j^{-1} x + \frac{1}{2} 2\mu_j^{\mathsf{T}}\Sigma_j^{-1}x -\frac{1}{2} \mu_j^{\mathsf{T}}\Sigma_j^{-1}\mu_j + \ln P(\omega_j) $$ From $\Sigma_1 = \Sigma_2$, $$ \frac{1}{2} 2\mu_i^{\mathsf{T}}\Sigma_i^{-1}x -\frac{1}{2}\mu_i^{\mathsf{T}}\Sigma_i^{-1}\mu_i + \ln P(\omega_i) = \frac{1}{2} 2\mu_j^{\mathsf{T}}\Sigma_j^{-1}x -\frac{1}{2} \mu_j^{\mathsf{T}}\Sigma_j^{-1}\mu_j + \ln P(\omega_j) $$ $$ \mu_i^{\mathsf{T}}\Sigma_i^{-1}x -\frac{1}{2}\mu_i^{\mathsf{T}}\Sigma_i^{-1}\mu_i + \ln P(\omega_i) = \mu_j^{\mathsf{T}}\Sigma_j^{-1}x -\frac{1}{2} \mu_j^{\mathsf{T}}\Sigma_j^{-1}\mu_j + \ln P(\omega_j) $$ Let $i=1$ and $j=2$, and from $P(\omega_1) = 4P(\omega_2)$, we get $$ \mu_i^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 + \ln 4P(\omega_2) = \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 + \ln P(\omega_2) $$ $$ \mu_i^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 + \ln 4P(\omega_2) - \ln P(\omega_2) = \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 $$ $$ \mu_i^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 + \ln \frac{4P(\omega_2)}{P(\omega_2)} = \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 $$ $$ \mu_i^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 + \ln 4 = \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 $$ From $\mu_1 = \begin{bmatrix} 7 \\ 1 \end{bmatrix}$, $\mu_2 = \begin{bmatrix} 1 \\ 7 \end{bmatrix}$, From $\Sigma_1 = \Sigma_2 = \begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}$, $$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}^{-1}\vec{x} -\frac{1}{2}\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}^{-1}\begin{bmatrix} 7 \\ 1 \end{bmatrix} + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}^{-1}\vec{x} -\frac{1}{2} \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 3.1 & 0 \\ 0 & 2.6 \end{bmatrix}^{-1}\begin{bmatrix} 1 \\ 7 \end{bmatrix} $$

$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\vec{x} -\frac{1}{2}\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} 7 \\ 1 \end{bmatrix} + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\vec{x} -\frac{1}{2} \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} 1 \\ 7 \end{bmatrix} $$$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2}\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} 7 \\ 1 \end{bmatrix} + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2} \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} 1 \\ 7 \end{bmatrix} $$$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2}\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{7}{3.1} \\ \frac{1}{2.6} \end{bmatrix} + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2} \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} \\ \frac{7}{2.6} \end{bmatrix} $$$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2} (\frac{7 \cdot 7}{3.1} + \frac{1 \cdot 1}{2.6}) + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2} (\frac{1 \cdot 1}{3.1} + \frac{7 \cdot 7}{2.6}) $$
$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - 8.0955 + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - 9.5844 $$
$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2.8751 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{1}{3.1} & 0 \\ 0 & \frac{1}{2.6} \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} $$$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} \frac{x_1}{3.1} \\ \frac{x_2}{2.6} \end{bmatrix} + 2.8751 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} \frac{x_1}{3.1} \\ \frac{x_2}{2.6} \end{bmatrix} $$$$ \frac{7 \cdot x_1}{3.1} + \frac{x_2}{2.6} + 2.8751 = \frac{x_1}{3.1} + \frac{7 \cdot x_2}{2.6} $$

Multiply both sides by $3.1 \times 2.6 = 8.06$, $$ (2.6 \cdot 7 \cdot x_1) + (3.1 \cdot x_2) + (8.06 \cdot 2.8751) = (2.6 \cdot x_1) + (3.1 \cdot 7 \cdot x_2) $$

$$ 18.2 x_1 + 3.1x_2 + 23.1733 = 2.6 x_1 + 21.7 x_2 $$$$ 15.6 x_1 + 23.1733 = 18.6 x_2 $$
$$ 0.8387x_1 + 1.2459 = x_2 $$

Likelihood

3D Plot

The way I do this plot is to take the maximum likelihood of all classes at a point $(x_1, x_2)$. So, instead of plotting two surfaces separately, I combine them into one single surface. It is then colored based on the values of discriminant function.

Note that I intentionally do not put the scatter plot of all samples on the $z=0$ plane as it looks too messy.

Let's take a look at the 3D plot from the bottom.

Here is the view when we look at $z=0$ plane as a line.

Question E

e) plot the posterior probabilities.

Posterior probability

$$ P(\omega_i | \vec{x}) = \frac{p(\vec{x} | \omega_i) P(\omega_i)}{p(\vec{x})} $$

where the evidence is defined as:

$$ p(\vec{x}) = \sum_{j=1}^{C} p(\vec{x} | \omega_i) P(\omega_i) $$

(in this case $C = 2$)


Question F

f) redo part c), d) and e) using the same parameters except for $\Sigma_1 = \Sigma_2 = \begin{bmatrix} 3.1 & 0.35 \\ 0.35 & 2.6 \end{bmatrix}$

Decision boundary

Just like the equation of the previous question, but with different covariance matrix:

$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2}\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} 7 \\ 1 \end{bmatrix} + \ln 4 \\ = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -\frac{1}{2} \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} 1 \\ 7 \end{bmatrix} $$
$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -7.9118 + \ln 4 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - 9.4236 $$
$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2.8981 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.3276 & -0.0441 \\ -0.0441 & 0.3906 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} $$$$ \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.3276x_1 -0.0441x_2 \\ -0.0441x_1 + 0.3906x_2 \end{bmatrix} + 2.8981 = \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.3276x_1 -0.0441x_2 \\ -0.0441x_1 + 0.3906x_2 \end{bmatrix} $$$$ 7(0.3276x_1 -0.0441x_2) + 1(-0.0441x_1 + 0.3906x_2) + 2.8981 = 1(0.3276x_1 -0.0441x_2) + 7(-0.0441x_1 + 0.3906x_2)$$
$$ 2.2932x_1 - 0.3087x_2 -0.0441x_1 + 0.3906x_2 + 2.8981 = 0.3276x_1 - 0.0441x_2 -0.3087x_1 + 2.7342x_2 $$$$ - 0.3087x_2 + 0.3906x_2 + 0.0441x_2 - 2.7342x_2 + 2.8981 = 0.3276x_1 -0.3087x_1 - 2.2932x_1 + 0.0441x_1 $$$$ (- 0.3087 + 0.3906 + 0.0441 - 2.7342)x_2 = (0.3276 + -0.3087 - 2.2932 + 0.0441)x_1 - 2.8981 $$
$$ -2.6082x_2 = -2.2302x_1 - 2.8981 $$
$$ x_2 = 0.8551x_1 + 1.1111 $$

Question G

g) redo part c), d) and e) for $\Sigma_1 = \begin{bmatrix} 2.1 & 1.5 \\ 1.5 & 3.8 \end{bmatrix}$, $\Sigma_2 = \begin{bmatrix} 3.1 & 0.35 \\ 0.35 & 2.6 \end{bmatrix}$ and $P(\omega_1) = 2 \times P(\omega_2)$

Decision boundary

$$ g_i(x) = g_j(x) $$$$ -\frac{1}{2} x^{\mathsf{T}}\Sigma_i^{-1} x +\frac{1}{2} 2\mu_i^{\mathsf{T}}\Sigma_i^{-1}x -\frac{1}{2}\mu_i^{\mathsf{T}}\Sigma_i^{-1}\mu_i - \frac{1}{2} \ln|\Sigma_i| + \ln P(\omega_i) = -\frac{1}{2} x^{\mathsf{T}}\Sigma_j^{-1} x + \frac{1}{2} 2\mu_j^{\mathsf{T}}\Sigma_j^{-1}x -\frac{1}{2} \mu_j^{\mathsf{T}}\Sigma_j^{-1}\mu_j - \frac{1}{2} \ln|\Sigma_j| + \ln P(\omega_j) $$$$ -\frac{1}{2} x^{\mathsf{T}}\Sigma_1^{-1} x + \mu_1^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 - \frac{1}{2} \ln|\Sigma_1| + \ln \frac{2P(\omega_2)}{P(\omega_2)} = -\frac{1}{2} x^{\mathsf{T}}\Sigma_2^{-1} x + \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 - \frac{1}{2} \ln|\Sigma_2| $$$$ -\frac{1}{2} x^{\mathsf{T}}\Sigma_1^{-1} x + \mu_1^{\mathsf{T}}\Sigma_1^{-1}x -\frac{1}{2}\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 - \frac{1}{2} \ln|\Sigma_1| + \ln 2 = -\frac{1}{2} x^{\mathsf{T}}\Sigma_2^{-1} x + \mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\frac{1}{2} \mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 - \frac{1}{2} \ln|\Sigma_2|$$$$ -x^{\mathsf{T}}\Sigma_1^{-1} x + 2\mu_1^{\mathsf{T}}\Sigma_1^{-1}x -\mu_1^{\mathsf{T}}\Sigma_1^{-1}\mu_1 - \ln|\Sigma_1| + 2\ln 2 = -x^{\mathsf{T}}\Sigma_2^{-1} x + 2\mu_2^{\mathsf{T}}\Sigma_2^{-1}x -\mu_2^{\mathsf{T}}\Sigma_2^{-1}\mu_2 - \ln|\Sigma_2|$$
$$ -\begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.66317627 & -0.2617801 \\ -0.2617801 & 0.36649215 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.66317627 & -0.2617801 \\ -0.2617801 & 0.36649215 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - \begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.66317627 & -0.2617801 \\ -0.2617801 & 0.36649215 \end{bmatrix}\begin{bmatrix} 7 \\ 1 \end{bmatrix} - 1.7457 + 2\ln 2 \\ = - \begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.32755906 & -0.04409449 \\ -0.04409449 & 0.39055118 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2\begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.32755906 & -0.04409449 \\ -0.04409449 & 0.39055118 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - \begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.32755906 & -0.04409449 \\ -0.04409449 & 0.39055118 \end{bmatrix}\begin{bmatrix} 1 \\ 7 \end{bmatrix} - 2.0716 $$
$$ -\begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.66317627 & -0.2617801 \\ -0.2617801 & 0.36649215 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.66317627 & -0.2617801 \\ -0.2617801 & 0.36649215 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - 29.1972 - 1.7457 + 2\ln 2 \\ = - \begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.32755906 & -0.04409449 \\ -0.04409449 & 0.39055118 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 2\begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.32755906 & -0.04409449 \\ -0.04409449 & 0.39055118 \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - 18.8472 - 2.0716 $$
$$ -\begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.66317627x_1 -0.2617801x_2 \\ -0.2617801x_1 + 0.36649215x_2 \end{bmatrix} + 2\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.66317627x_1 -0.2617801x_2 \\ -0.2617801x_1 + 0.36649215x_2 \end{bmatrix} - 8.6378 \\ = - \begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} 0.32755906x_1 & -0.04409449x_2 \\ -0.04409449x_1 & 0.39055118x_2 \end{bmatrix} + 2\begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.32755906x_1 -0.04409449x_2 \\ -0.04409449x_1 + 0.39055118x_2 \end{bmatrix} $$

$$ -(0.66317627x_1^2 -0.2617801x_2^2 + -0.2617801x_1^2 + 0.36649215x_2^2) + 2\begin{bmatrix} 7 & 1 \end{bmatrix}\begin{bmatrix} 0.66317627x_1 -0.2617801x_2 \\ -0.2617801x_1 + 0.36649215x_2 \end{bmatrix} - 8.6378 \\ = -(0.32755906x_1^2 -0.04409449x_2^2 + -0.04409449x_1^2 + 0.39055118x_2^2) + 2\begin{bmatrix} 1 & 7 \end{bmatrix}\begin{bmatrix} 0.32755906x_1 -0.04409449x_2 \\ -0.04409449x_1 + 0.39055118x_2 \end{bmatrix} $$

$$ -(0.66317627x_1^2 -0.2617801x_2^2 -0.2617801x_1^2 + 0.36649215x_2^2) + 14(0.66317627x_1 -0.2617801x_2) + 2(-0.2617801x_1 + 0.36649215x_2) - 8.6378 \\ = -(0.32755906x_1^2 -0.04409449x_2^2 -0.04409449x_1^2 + 0.39055118x_2^2) + 2(0.32755906x_1 -0.04409449x_2) + 14(-0.04409449x_1 + 0.39055118x_2) $$
$$ -0.66317627x_1^2 + 0.2617801x_2^2 + 0.2617801x_1^2 - 0.36649215x_2^2 + 9.2845x_1 - 3.6649x_2 - 0.5236x_1 + 0.7330x_2 - 8.6378 \\ = -0.32755906x_1^2 + 0.04409449x_2^2 + 0.04409449x_1^2 - 0.39055118x_2^2 + 0.6551x_1 -0.0882x_2 -0.6173x_1 + 5.4677x_2 $$
$$ -0.1179x_1^2 + 0.2417x_2^2 + 8.7231x_1 - 8.3114x_2 - 8.6378 = 0 $$

Solution y:

  1. $ x_2 \approx 0.000413736 \left(41557 - \sqrt{2849643 x_1^2 - 210837327 x_1 + 1935759875}\right) $

  2. $ x_2 \approx 0.000413736 \left(\sqrt{2849643 x_1^2 - 210837327 x_1 + 1935759875} + 41557\right) $