Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swharden/swarmfit
A .NET package for fitting curves to data using particle swarm optimization
https://github.com/swharden/swarmfit
curve curve-fitting math mathmatics particle-swarm-optimization
Last synced: about 2 months ago
JSON representation
A .NET package for fitting curves to data using particle swarm optimization
- Host: GitHub
- URL: https://github.com/swharden/swarmfit
- Owner: swharden
- License: mit
- Created: 2024-08-14T16:20:10.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-25T02:04:19.000Z (3 months ago)
- Last Synced: 2024-11-04T15:06:27.041Z (about 2 months ago)
- Topics: curve, curve-fitting, math, mathmatics, particle-swarm-optimization
- Language: C#
- Homepage: https://www.nuget.org/packages/SwarmFit/
- Size: 730 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwarmFit
[![CI](https://github.com/swharden/SwarmFit/actions/workflows/ci.yaml/badge.svg)](https://github.com/swharden/SwarmFit/actions/workflows/ci.yaml)
**SwarmFit is a .NET package for fitting curves to X/Y data** points using [particle swarm optimization](https://en.wikipedia.org/wiki/Particle_swarm_optimization). Unlike other gradient decent strategies, finding the derivative of the error function is not required. SwarmFit can be used to calculate best fit curves for arbitrary equations that use any number of parameters.
![](dev/fit2.gif)
## Quickstart
```cs
// data points to fit
double[] xs = [1, 2, 3, 4, 5];
double[] ys = [304, 229, 174, 134, 111];// a custom function to fit to the data using any number of parameters
static double MyFitFunc(double x, double[] parameters)
{
double a = parameters[0];
double b = parameters[1];
double c = parameters[2];
return a + b * Math.Exp(x * c);
}// the minimum and maximum value for each parameter
double[] minVars = [-100, -5000, -10];
double[] maxVars = [100, 5000, 10];// perform the fit with general purpose settings
double[] solution = QuickFit.Solve(xs, ys, MyFitFunc, minVars, maxVars);// display the solution
double a = solution[0];
double b = solution[1];
double c = solution[2];
Console.WriteLine($"Y = {a} + {b} * e^(x * {c})");
```## Graphical Demo
A sample application is included with this repository which generates random data and fits it using common curve functions. This application demonstrates advanced features such as fitter fine-tuning, iterative error logging, charting, etc.
![](dev/example3.png)