How to use the splinter.BSplineBuilder function in splinter

To help you get started, we’ve selected a few splinter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bgrimstad / splinter / python / examples / bspline.py View on Github external
# Example with one variable
def f1(x):
    return -1. + 2*x + 0.1*(x**2) + 10*np.random.rand(1)[0]

x = np.arange(0, 11, 1)
y = np.zeros((len(x),))
for i in range(len(x)):
    y[i] = f1(x[i])

# Piecewise constant B-spline that interpolates the data
b0 = splinter.BSplineBuilder(x, y, degree=0).build()

# Linear B-spline that interpolates the data
b1 = splinter.BSplineBuilder(x, y, degree=1).build()

# Quadratic B-spline that interpolates the data
b2 = splinter.BSplineBuilder(x, y, degree=2).build()

# Cubic B-spline that interpolates the data
b3 = splinter.BSplineBuilder(x, y, degree=3).build()

xd = np.arange(0, 10, .01)
yd0 = b0.eval(xd)
yd1 = b1.eval(xd)
yd2 = b2.eval(xd)
yd3 = b3.eval(xd)

plt.plot(x, y, '*', label='Data points')
plt.plot(xd, yd0, label='Piecewise constant B-spline')
plt.plot(xd, yd1, label='Linear B-spline')
github bgrimstad / splinter / python / splinter / examples / bsplinebuilder.py View on Github external
#
# data = data.reshape([-1, 3])
# for row in data:
#     pass#print(row)

data = []
for x0 in range(10):
    for x1 in range(10):
        data.append([x0, x1, x0*x1])

df = pd.DataFrame(data=data, columns=["x0", "x1", "f(x0, x1)"])

builder = splinter.BSplineBuilder(df.values)


builder.degree([splinter.BSplineBuilder.Degree.LINEAR, splinter.BSplineBuilder.Degree.QUARTIC])
builder.numBasisFunctions([10 ** 3, 10 ** 2])
import math
builder.knotSpacing(splinter.BSplineBuilder.KnotSpacing.EQUIDISTANT)
builder.smoothing(splinter.BSplineBuilder.Smoothing.NONE)
builder.setLambda(math.pi)

bspline = builder.build()


for i in range(19):
    for j in range(19):
        x0 = (i * 9.)/19.
        x1 = (j * 9.)/19.
        print(str(bspline.eval([x0, x1])) + " ?= " + str(x0*x1))
github bgrimstad / splinter / python / splinter / examples / bsplinebuilder.py View on Github external
# for x0 in range(10):
#     for x1 in range(10):
#         data = np.append(data, [x0, x1, x0*x1])
#
# data = data.reshape([-1, 3])
# for row in data:
#     pass#print(row)

data = []
for x0 in range(10):
    for x1 in range(10):
        data.append([x0, x1, x0*x1])

df = pd.DataFrame(data=data, columns=["x0", "x1", "f(x0, x1)"])

builder = splinter.BSplineBuilder(df.values)


builder.degree([splinter.BSplineBuilder.Degree.LINEAR, splinter.BSplineBuilder.Degree.QUARTIC])
builder.numBasisFunctions([10 ** 3, 10 ** 2])
import math
builder.knotSpacing(splinter.BSplineBuilder.KnotSpacing.EQUIDISTANT)
builder.smoothing(splinter.BSplineBuilder.Smoothing.NONE)
builder.setLambda(math.pi)

bspline = builder.build()


for i in range(19):
    for j in range(19):
        x0 = (i * 9.)/19.
        x1 = (j * 9.)/19.
github bgrimstad / splinter / python / examples / bspline_multivariate.py View on Github external
X1, X2 = np.meshgrid(x1, x2)
Y = np.sqrt(X1 ** 2 + X2 ** 2)

data = []
x = []
y = []
for i in range(len(x1)):
    for j in range(len(x2)):
        x1_ij = X1[j, i]
        x2_ij = X2[j, i]

        x.append([x1_ij, x2_ij])
        y.append(Y[i, j])

# Cubic B-spline
bspline = splinter.BSplineBuilder(x, y, degree=[1, 3], smoothing=splinter.BSplineBuilder.Smoothing.NONE).build()

Zbs = Y

for i in range(len(x1)):
    for j in range(len(x2)):
        x1_ij = X1[i, j]
        x2_ij = X2[i, j]
        Zbs[i, j] = bspline.eval([x1_ij, x2_ij])[0]

# Plot f
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X1, X2, Y, rstride=1, cstride=1, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)
# ax.set_zlim(-1.01, 1.01)
github bgrimstad / splinter / python / examples / bspline_regularization.py View on Github external
return -1. + 2*x + 0.1*(x**2) + 10*np.random.rand(1)[0]

x = [0.]*11
y = [0.]*11
for i in range(11):
    x[i] = i
    y[i] = f1(i)

# Cubic B-spline that interpolates the data (note that NONE is the default smoothing setting)
b1 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.NONE).build()

# Cubic B-spline with regularization
b2 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.IDENTITY, alpha=0.1).build()

# Cubic P-spline
b3 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.PSPLINE, alpha=0.1).build()

n = 1000
xd = [0.]*n
yd1 = [0.]*n
yd2 = [0.]*n
yd3 = [0.]*n
for i in range(n):
    val = i/100.
    xd[i] = val
    yd1[i] = b1.eval([val])
    yd2[i] = b2.eval([val])
    yd3[i] = b3.eval([val])


plt.plot(x, y, '*', label='Data points')
plt.plot(xd, yd1, label='Interpolating B-spline')
github bgrimstad / splinter / python / examples / bspline_regularization.py View on Github external
# splinter.load("/home/bjarne/Code/C++/splinter4/splinter/bin/Release/libsplinter-3-0.so")
splinter.load("/home/anders/SPLINTER/build/debug/libsplinter-3-0.so")


# Example with one variable
def f1(x):
    return -1. + 2*x + 0.1*(x**2) + 10*np.random.rand(1)[0]

x = [0.]*11
y = [0.]*11
for i in range(11):
    x[i] = i
    y[i] = f1(i)

# Cubic B-spline that interpolates the data (note that NONE is the default smoothing setting)
b1 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.NONE).build()

# Cubic B-spline with regularization
b2 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.IDENTITY, alpha=0.1).build()

# Cubic P-spline
b3 = splinter.BSplineBuilder(x, y, smoothing=splinter.BSplineBuilder.Smoothing.PSPLINE, alpha=0.1).build()

n = 1000
xd = [0.]*n
yd1 = [0.]*n
yd2 = [0.]*n
yd3 = [0.]*n
for i in range(n):
    val = i/100.
    xd[i] = val
    yd1[i] = b1.eval([val])
github bgrimstad / splinter / python / examples / bspline.py View on Github external
# Only for dev purposes
# splinter.load("/home/bjarne/Code/C++/splinter4/splinter/bin/Release/libsplinter-3-0.so")
splinter.load("/home/anders/SPLINTER/build/debug/libsplinter-3-0.so")


# Example with one variable
def f1(x):
    return -1. + 2*x + 0.1*(x**2) + 10*np.random.rand(1)[0]

x = np.arange(0, 11, 1)
y = np.zeros((len(x),))
for i in range(len(x)):
    y[i] = f1(x[i])

# Piecewise constant B-spline that interpolates the data
b0 = splinter.BSplineBuilder(x, y, degree=0).build()

# Linear B-spline that interpolates the data
b1 = splinter.BSplineBuilder(x, y, degree=1).build()

# Quadratic B-spline that interpolates the data
b2 = splinter.BSplineBuilder(x, y, degree=2).build()

# Cubic B-spline that interpolates the data
b3 = splinter.BSplineBuilder(x, y, degree=3).build()

xd = np.arange(0, 10, .01)
yd0 = b0.eval(xd)
yd1 = b1.eval(xd)
yd2 = b2.eval(xd)
yd3 = b3.eval(xd)