This repository implements optimization calculations for multivariate functions and statistical optimization.
- Implementation of Simplex Method
- Implementing Class Classification by Unsupervised Learning
- Python Implementation of Levenberg–Marquardt Algorithm
- Python Implementation of Gauss Newton Method
- Python Implementation of Newton’s Method
- Python Implementation of Gradient Method
The function
- Repeat following calculation until
$f(X)\geqq f(X\prime)$
- Update following variables
- Repeat following calculation until
$f(X)\leqq f(X\prime)$
- Update following variables
You can try gradient method by runngin below command. In this example, we want to find the maximum value of
python3 gradient_method.py
The gradient method for finding the maximum value of the bivariate function
Putting
3. Let $\triangle x \leftarrow t\triangledown f(x),x \leftarrow x+\triangle x$ using $t$ obtained in step 2
At a point determined by a gradient method linear search for the function
You can try gradient method in the multivariable case by runngin below command. In this example, we want to find the maximum value of
python3 hill_climbing.py
If you can compute not only the first-order derivative
The terms above the third order of
Since this solution is
This iterative method is called the Newton's method. The algorithm is as follows.
The geometric meaning of Newton's method is as follows. The higher order terms in Eq(1) ... is to approximate the function
The above equation is called the second-order approximation of the function
You can try Newton's method by runngin below command. In this example, we want to find the minimum value of
python3 newton.py
The value of the function
The bar represents the value at the point
Let
Eq(6) can be rewritten as
A better approximation of the solution
You can try multivariable Newton's method by running below command. In this example, we want to find the minimum value of
python3 newton_multi_var.py
Suppose that the following equation is theoretically known to hold for an m-dimensional vector
However, when
A typical method for obtaining this is the nonlinear least-squares method, in which
If each
In this case, whether the Newton's or conjugate gradient method is used, the Hesse matrix, whose elements are second-order derivatives, must be calculated. However, this is difficult when
If
Eq(6) is called the Gauss-Newton approximation. If we denote by the symbol
The Newton method using the Hesse matrix approximated by the above equation is called the Gauss Newton method. Applying Eq(7) to Newton's method, we obtain the following iterative formula.
The symbol
You can try Gauss Newton method by running below command. In this example, we want to find coefficients of a function(
python3 gauss_newton.py
We can find approximate coefficients by gauss newton method.
The Gauss Newton method does not require a second-order derivative, but this is an approximation that consists only of an approximation of the solution. If a good approximation of the solution is not available, it is advisable to first perform a coarse search, such as the gradient method, and then switch to the Gauss Newton method when the solution is somewhat closer. This is systematically done by the Levenberg-Marquardt method.
First, consider the case of minimization of one variable
This approximates the function
However,
Written in vector and matrix symbols, it looks like this
The idea of the Levenberg-Marquardt method is to use Eq(4) when the current value
where
You can try Levenberg–Marquardt algorithm by running below command. In this example, we want to find coefficients of a function(
python3 levenberg_marquardt.py
Suppose we observe
Unsupervised learning considers each data
This is estimated by iteration.
Given the affiliation probability
Since the expected number of data
From these, the probability densities
The algorithm for classification into any
5. If $w_\alpha^{(k)}$ is convergent, classify $x_\alpha$ into class $k$ where $w_\alpha^{(k)}$ is maximal. Otherwise, return to step 2.
You can try this unsurpervised learing algorithm by running below command.
python3 unsupervised_learning.py
The graph on the right side shows how unsupervised learning is used to classify classes.
Consider an optimization problem of the following form
This problem is characterized by the following points:
- The
$n$ variables$x_1,...,x_n$ are all non-negative. - The
$m$ constraints are linear inequalities in the variable$x_1,...,x_n$ . - The function
$f$ to be maximized is a linear inequality in variables$x_1,...,x_n$ .
A problem with these three characteristics is called linear programming. And the representation of it as Eq(1) is called the standard form of linear programming. The method of solving a linear program is called linear programming. A concrete example of linear programming is the following problem.
Two machines M_1 and M_2 are used to make two different containers A and B. It takes 2 minutes to use machine M_1 and 4 minutes to use machine M_2 to make one container A. On the other hand, it takes 8 minutes for machine M_1 and 4 minutes for machine M_2 to make one container B. The profit from making containers A and B is 29 yen and 45 yen per container, respectively. How should we plan to maximize the profit?
If only
Inequalities can be equated by adding non-negative numbers to the smaller side. Eq(2) can be rewritten as
If the variables
Putting all variables on the right side as
These are all non-negative. However, this is not an optimal solution. This is because if we increase
First, consider increasing
Next, consider increasing
Substituting this into (1) and (3) in Eq. (5) and eliminating
In summary, the above is as follows
Putting all variables on the right side as
However, this is not the optimal solution. This is because even if
Substituting this into (5) and (6) and eliminating
Putting all variables on the right side as
This is the optimal solution. This is because the coefficients of
You can try simplex method by running below command.
python3 simplex_method.py