You can define your problem in JavaScript and paste the url or code in the following area, then click the Minimize button, the minimzed point of defined function will be found.
Optimization log and result will be showed here.
The JavaScript will be evaluated with jQuery available. Please define
optimization.func, optimization.grad, etc in that JavaScript code.
You can follow an example in this gist, and paste the RAW url in the URLs input area, or, paste the JavaScript code directly in the code area.
optimization.start. For example,
optimization.start = [2, 2];
optimization.func. For example,
optimization.func = function(p) {
return .5 * Math.pow(1 - p[0], 2) + Math.pow(p[1] - p[0]*p[0], 2);
};
optimization.grad, like:
optimization.grad = function (p) {
return [(p[0] - 1) + 2 * (p[0]*p[0] - p[1]) * 2 * p[0], 2 * (p[1] - p[0] * p[0])];
};
The solving algorithm should be specfied through optimization.solver. Currently,
only three gradient solvers have been adapted, they are LmBFGSSolver, ConjugateGradientSolver and GradientDescentSolver.
TODO: Add some global searching optimization algorithms.
As a full example of logisitc regression, we can paste the following two URLs(from this gist) to the above, and click minimize to get the result.
https://gist.githubusercontent.com/zuoyan/81b1b5ab764efe5d9112/raw/0a4c3c53756d6a19c1d444209f8244bb67021bfd/logistic_regression.js https://gist.githubusercontent.com/zuoyan/81b1b5ab764efe5d9112/raw/7c0495bd14a6c243fe026bee9e543f8b02b97f9e/lr_lowbwt.js
In logistic regression, we assume every feature has some contribution to the clustering, and the final posibility of positive clustering is dertermined by their weight sum:
$$P(X, Y=1) = Logistic\left(\prod_{f\in{features}} w_f \times x_f\right).$$ $$P(X, Y=-1) = 1 - Logistic\left(\prod_{f\in{features}} w_f \times x_f\right).$$Where Logisitc is a map from real value to posibility range \([0, 1]\), it is defined as:
Due to floating precision problem, the maximize probability problem is usually turned to maximize log-likelihood problem:
$$\ln P(samples) = \sum_{(X, Y) \in samples} \ln P(X, Y).$$In order to get robust logistic regression, we usually need to normalize the input value. This code use another trick to avoid floating range problems.
$$-\ln \dfrac{1}{1 + e^{-x}} = \ln(1 + e^{-x}).$$When \(x\) is negative, we use the following formula:
$$\ln (1 + e^{-x}) = \ln(1 + e^x) - x.$$ In the calculation of gradient, we also choose \(\dfrac{-e^{-x}}{1 + e^{-x}}\) for positive values, and \(\dfrac{-1}{1 + e^x}\) for negative values.