How to use the splinter.load 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 / splinter / examples / polynomial.py View on Github external
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))


##### Start of the example #####
import splinter
import numpy as np

# Must be done if splinter was unable to locate the shared library by itself
splinter.load("/home/anders/SPLINTER/build/release/libsplinter-2-0.so")


def f(x):
    return x[0]*x[1]

# Create a numpy array and populate it with samples
d = np.empty((10*10, 3))
idx = 0
for i in range(10):
    for j in range(10):
        d[idx] = [i, j, f([i, j])]
        idx += 1

# powers should be a matrix with the number of terms rows and number of variables columns
# If you want a Polynomial of the form f(x, y) = c1*x**2*y + c2*x*y**2, then powers should be [[2, 1], [1, 2]]
# This is because the first term is of degree 2 in x, degree 1 in y. The second term is of degree 1 in x, degree 2 in y.
github bgrimstad / splinter / python / examples / bspline_multivariate.py View on Github external
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import splinter

# 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 two variables
def f(x):
    return x[0]*x[1]

x1 = np.arange(-5, 5, 0.25)
x2 = np.arange(-5, 5, 0.25)
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)):
github bgrimstad / splinter / python / examples / bspline.py View on Github external
# Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
import numpy as np
import matplotlib.pyplot as plt
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import splinter

# 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()
github bgrimstad / splinter / python / examples / bspline_regularization.py View on Github external
# Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
import numpy as np
import matplotlib.pyplot as plt
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import splinter

# 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 = [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
github bgrimstad / splinter / python / splinter / examples / rbfnetwork.py View on Github external
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))


##### Start of the example #####
import splinter
import pandas as pd

# Must be done if splinter was unable to locate the shared library by itself
splinter.load("/home/anders/SPLINTER/build/release/libsplinter-2-0.so")


def f(x0, x1):
    import math
    return x1 * (x0 - math.log(x0))

# Create a Pandas DataFrame and populate it with samples
d = []
for x0 in range(1, 10):
    for x1 in range(1, 10):
        d.append([x0, x1, f(x0, x1)])
df = pd.DataFrame(data=d, columns=["x0", "x1", "f(x0, x1)"])

# Create a RBFNetwork of type Thin plate spline
rbf = splinter.RBFNetworkBuilder(df.values).build()
github bgrimstad / splinter / python / examples / datatable.py View on Github external
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))


##### Start of the example #####
import splinter

# This must be done if splinter could not locate the shared library
splinter.load("/home/anders/SPLINTER/build/debug/libsplinter-2-0.so")

# Create a new, empty DataTable
d = splinter.DataTable()

# Populate it with samples
for i in range(10):
    for j in range(10):
        d.addSample([i,j], i*j)

# Save the samples for use later
d.save("test.datatable")

# Create DataTable from saved
d2 = splinter.DataTable("test.datatable")

print("Original:")
github bgrimstad / splinter / python / splinter / examples / bsplinebuilder.py View on Github external
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))


##### Start of the example #####
import splinter
import numpy as np
import pandas as pd

splinter.load("/home/anders/SPLINTER/build/release/libsplinter-2-0.so")


#d = splinter.DataTable()
# data = np.array([])
# 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])