0.1.4-dev-4 #86
@ -3,6 +3,8 @@ package scientifik.kmath.interpolation
|
||||
import scientifik.kmath.functions.PiecewisePolynomial
|
||||
import scientifik.kmath.functions.value
|
||||
import scientifik.kmath.operations.Ring
|
||||
import scientifik.kmath.structures.Buffer
|
||||
import scientifik.kmath.structures.asBuffer
|
||||
|
||||
interface Interpolator<X, Y> {
|
||||
fun interpolate(points: XYPointSet<X, Y>): (X) -> Y
|
||||
@ -18,4 +20,26 @@ interface PolynomialInterpolator<T : Comparable<T>> : Interpolator<T, T> {
|
||||
override fun interpolate(points: XYPointSet<T, T>): (T) -> T = { x ->
|
||||
interpolatePolynomials(points).value(algebra, x) ?: getDefaultValue()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
x: Buffer<T>,
|
||||
y: Buffer<T>
|
||||
): PiecewisePolynomial<T> {
|
||||
val pointSet = BufferXYPointSet(x, y)
|
||||
return interpolatePolynomials(pointSet)
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
data: Map<T, T>
|
||||
): PiecewisePolynomial<T> {
|
||||
val pointSet = BufferXYPointSet(data.keys.toList().asBuffer(), data.values.toList().asBuffer())
|
||||
return interpolatePolynomials(pointSet)
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
data: List<Pair<T, T>>
|
||||
): PiecewisePolynomial<T> {
|
||||
val pointSet = BufferXYPointSet(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer())
|
||||
return interpolatePolynomials(pointSet)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
//package scientifik.kmath.interpolation
|
||||
package scientifik.kmath.interpolation
|
||||
//
|
||||
//import scientifik.kmath.functions.PiecewisePolynomial
|
||||
//import scientifik.kmath.operations.Ring
|
||||
|
Loading…
Reference in New Issue
Block a user