An open API service indexing awesome lists of open source software.

https://github.com/paescebu/polynomialregressionswift

Swift function for calculation of the polynomial regression (least squares fitting) of a given set of points.
https://github.com/paescebu/polynomialregressionswift

ios ipados iphone macosx math polynomial polynomial-regression polynomials swift swift4 swift5

Last synced: 5 months ago
JSON representation

Swift function for calculation of the polynomial regression (least squares fitting) of a given set of points.

Awesome Lists containing this project

README

        

# PolynomialRegressionSwift
Swift function for calculation of the polynomial regression of a given set of points in a 2D coordinate system.

You have to give an array of CGPoint and the desired degree of polynomial you would like to aquire. The function will return an Array containing the polynomial coefficients.

## Overview
* [Features](#features)
* [Example](#example)
* [Implementation](#implementation)
* [Warranty](#warranty)

## Features
- **Uses Apple's Accelerate framework on Matrix operations and solving of linear systems for increased performance**
- Can calculate any degree of polynomial
- Easy to use
- Also contains a custom matrix class which allows to transpose a matrix or multiply two matrices
- runs on iOS and macOS

## Example

let points:[CGPoint] = [
CGPoint(x: 0, y: 1),
CGPoint(x: 9, y: -7),
CGPoint(x: 13, y: 6),
CGPoint(x: 15, y: 12),
CGPoint(x: 19, y: -4),
CGPoint(x: 20, y: -12),
CGPoint(x: 26, y: -2),
CGPoint(x: 26, y: 13),
CGPoint(x: 29, y: 23),
CGPoint(x: 30, y: 30),
]

let regression = PolynomialRegression.regression(withPoints: points, degree: 6)

print("The result is the sum of")
for i in 0..