Least squares in java.

A small library for using least squres fitting in java. Build using the JAMA matrix library

Лицензия

Лицензия

Категории

Категории

Ant Компиляция и сборка Square Прикладные библиотеки Financial
Группа

Группа

org.orangepalantir
Идентификатор

Идентификатор

leastsquares
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Least squares in java.
A small library for using least squres fitting in java. Build using the JAMA matrix library
Ссылка на сайт

Ссылка на сайт

https://github.com/odinsbane/least-squares-in-java
Система контроля версий

Система контроля версий

https://github.com/odinsbane/least-squares-in-java

Скачать leastsquares

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.orangepalantir/leastsquares/ -->
<dependency>
    <groupId>org.orangepalantir</groupId>
    <artifactId>leastsquares</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.orangepalantir/leastsquares/
implementation 'org.orangepalantir:leastsquares:1.0.0'
// https://jarcasting.com/artifacts/org.orangepalantir/leastsquares/
implementation ("org.orangepalantir:leastsquares:1.0.0")
'org.orangepalantir:leastsquares:jar:1.0.0'
<dependency org="org.orangepalantir" name="leastsquares" rev="1.0.0">
  <artifact name="leastsquares" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.orangepalantir', module='leastsquares', version='1.0.0')
)
libraryDependencies += "org.orangepalantir" % "leastsquares" % "1.0.0"
[org.orangepalantir/leastsquares "1.0.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
gov.nist.math : jama jar 1.0.3

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.8.2

Модули Проекта

Данный проект не имеет модулей.

least-squares-in-java

Java Least Squares fitting library.

This is a small least squares fitting library made in java. It was originally used in the development of an image analysis tool SpeckleTrackerJ. http://athena.physics.lehigh.edu/speckletrackerj/ It uses methods described in "Numerical Recipes in C", Second Edition (1992).

The outline of using this library is you have a set of data that you would like fit a function to. Define the Function, how it evaluates the input and paramters. Create a Fitter (three types currently) initialized to the function. Set the fitter with the data and make an initial guess of the parameters. Tell the fitter to find the best set of parameters which minimizes the sum of squares of error.

Example

Lets say we have some data.

double[][] xs = {
    {0}, {1}, {2}, {3}, {4}, {5}
};
double[] z = {1.1, 0.9, 1.0, 1.35, 1.82, 2.5};

And we want to fit a quadratic function f(x) = Axx + B*x + C. The parameters are A, B, C and the input is x. So we have 3 parameters and 1 input.

Function fun = new Function(){
    @Override
    public double evaluate(double[] values, double[] parameters) {
        double A = parameters[0];
        double B = parameters[1];
        double C = parameters[2];
        double x = values[0];
        return A*x*x + B*x + C;
    }
    @Override
    public int getNParameters() {
        return 3;
    }

    @Override
    public int getNInputs() {
        return 1;
    }
};

The next step is to create a fitter.

Fitter fit = new LinearFitter(fun);

Set the data, and make a guess at the initial parameters.

fit.setData(xs, zs);
fit.setParameters(new double[]{0,0,0});

fit.fitData();

The results can be obtained by using getParameters.

System.out.println(Arrays.toString(fit.getParameters()));
#[0.10000000000000023, -0.20000000000000123, 1.000000000000001]

This example is included in the examples package.

Fitter implementations

LinearFitter: for use with equations that are linearly dependent on the input parameters. Standard linear regression where derivatives are taken by setting all of the parameters to zero, except for the one of interest.

NonLinearSolver: Similar to the LinearSolver, except it will run multiple iterations, there is a damping factor, and the derivatives are calculated by taken by varying the parameters a small amount from the previous guess.

MarquardtFitter: Similar to the NonLinearSolver except the damping is adaptive.

Версии библиотеки

Версия
1.0.0