Tutorial on learning in canonical tensor format.

'''

import tensap

# %% Function to approximate
CHOICE = 2
if CHOICE == 1:
    ORDER = 5
    X = tensap.RandomVector(tensap.NormalRandomVariable(), ORDER)

    def fun(x):
        return 1 / (10 + x[:, 0] + 0.5 * x[:, 1])**2
elif CHOICE == 2:
    fun, X = tensap.multivariate_functions_benchmark('borehole')
    ORDER = X.size

# %% Approximation basis
DEGREE = 8
BASES = [
    tensap.PolynomialFunctionalBasis(X_TRAIN.orthonormal_polynomials(),
                                     range(DEGREE + 1))
    for X_TRAIN in X.random_variables
]
BASES = tensap.FunctionalBases(BASES)

# %% Training and test samples
NUM_TRAIN = 1000
X_TRAIN = X.random(NUM_TRAIN)
Y_TRAIN = fun(X_TRAIN)
コード例 #2
0
You should have received a copy of the GNU Lesser General Public License
along with tensap.  If not, see <https://www.gnu.org/licenses/>.

'''

import sys
import numpy as np
sys.path.insert(0, './../../../')
import tensap

# %% Choice of the function to approximate
CHOICE = 2
if CHOICE == 1:
    print('Henon-Heiles')
    D = 5
    FUN, X = tensap.multivariate_functions_benchmark('henon_heiles', D)

    DEGREE = 4
    BASES = [tensap.PolynomialFunctionalBasis(x.orthonormal_polynomials(),
                                              range(DEGREE+1)) for
             x in X.random_variables]

elif CHOICE == 2:
    print('Anisotropic function')
    D = 6
    X = tensap.RandomVector(tensap.UniformRandomVariable(-1, 1), D)

    def FUN(x):
        return 1/(10 + 2*x[:, 0] + x[:, 2] + 2*x[:, 3] - x[:, 4])**2

    DEGREE = 13