1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
require 'test_helper'
class BsplineTest < GSL::TestCase
N = 100
NMAX = 10
BMAX = 10 # 100
def _test_bspline(bw)
ncoeffs, order = bw.ncoeffs, bw.order
a = bw.breakpoint(0)
b = bw.breakpoint(bw.nbreak - 1)
N.times { |i|
xi, sum = a + (b - a) * (i / (N - 1)), 0.0
bb = bw.eval(xi)
ncoeffs.times { |j|
bj = bb[j]
refute bj < 0 || bj > 1,
"basis-spline coefficient #{j} is in range [0,1] for x=#{xi}"
sum += bj
}
assert_rel sum, 1.0, order * GSL::DBL_EPSILON,
"basis-spline coefficient #{order} is in range [0,1] for x=#{xi}"
}
end
def test_bspline_knots_uniform
1.upto(NMAX) { |order|
2.upto(BMAX) { |breakpoints|
bw = GSL::BSpline.alloc(order, breakpoints)
bw.knots_uniform(-1.23 * order, 45.6 * order)
_test_bspline(bw)
}
}
end
def test_bspline_knots
1.upto(NMAX) do |order|
2.upto(BMAX) do |breakpoints|
a, b = -1.23 * order, 45.6 * order
bw = GSL::BSpline.alloc(order, breakpoints)
test_data = [GSL::Vector.alloc(breakpoints)]
test_data << NMatrix.new([breakpoints], dtype: :float64) if ENV['NMATRIX']
test_data.each do |k|
breakpoints.times do |i|
f = GSL.sqrt(i.to_f / (breakpoints - 1.0))
k[i] = (1 - f) * a + f * b
end
bw.knots(k)
_test_bspline(bw)
end
end
end
end
end
|