scidart icon indicating copy to clipboard operation
scidart copied to clipboard

Finding root of a function

Open saroad2 opened this issue 2 years ago • 1 comments

Description

There should be a way to caclulate the root of a function using scidart. That function should generaly be from n dimentional space to m dimentional space.

Suggested API

Taking inspiration from scipy, the API should look like:


OptimizeResult root(   // calculating root for multidimentional functions
    Array Function(Array) func, // function to find root of
    Array x0,  // initial guess for the root
    {
        RootAlgorithm method = RootAlgorithm.hybr, // optiomization algorithm
        Array2d Function(Array)? jac, // possible jacobian method
        double tolerance = 1e-5,  // chosen tolerance
    }
) {
    ...
}

OptimizeResult rootScalar(   // calculating root for scalar functions
    double Function(double) func, // function to find root of
    double x0,  // initial guess for the root
    {
        RootAlgorithm method = RootAlgorithm.hybr, // optiomization algorithm
        double Function(double)? jac, // possible jacobian method
        double tolerance = 1e-5,  // chosen tolerance
    }
) {
    ...
}

Where OptimizeResult is a class from the following form:

class OptimizeResult {
    Array result;  // the result of the optiomization
    bool success;  // is the optimzation was successful
    int iterations; // number of iterations until stopping
    String message;  // explanatory message for the reason of termination
    OptimizeResult({
        required this.result, 
        required this.success, 
        required this.iterations,
        required this.message,  
    });
}

And the RootAlgorithm enum should look like:

enum RootAlgorithm {
    hybr,
    lm,
    broyden,
    anderson,
    linearmixing,
    diagbroyden,
    excitingmixing,
    krylov,
    dfSane,
}

Possible Roadmap

In my opinion, the best option to start with is the implimentation of the RootAlgorithm.brodyden method. It is quite simple, relies havily on Newton–Raphson method, and is well documented.

After that, we can continue to implement the other methods.

Summary

Finding functions' roots is a very important ability in order to make scidart a legitimate alternative for other scientific libraries.

Please let know if you approve my approach and I'll go ahead and implement it.

saroad2 avatar Jan 31 '23 08:01 saroad2

Hey @polotto ,

What do you think about the API suggestion? Is it good to go?

saroad2 avatar Feb 10 '23 19:02 saroad2