radialEvaluate

Evaluates a radial-basis fit.

Synopsis

radialEvaluate (x, radialFit)

Required Arguments

float x[[]] (Input)
Array of size (radialFit[0].dimension) × n containing the abscissae of the data points at which the fit will be evaluated. The argument x[i][j] is the abscissa value of the (i+1)-th data point in the (j+1)-th dimension.
structure radialFit (Input)
A radial-basis structure to be used for the evaluation. (Input).

Return Value

An array of length n containing the values of the radial-basis fit at the desired values. If no value can be computed, then None is returned.

Description

The function radialEvaluate evaluates a radial-basis fit from data generated by radialScatteredFit.

Example

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.radialEvaluate import radialEvaluate
from pyimsl.math.radialScatteredFit import radialScatteredFit
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.randomUniform import randomUniform


def F(x):
    return sin(2.0 * pi * x)


ndata = 10
num_centers = 5
noise_size = 0.25
fdata = empty(ndata)
xdata = empty(ndata)
xdata2 = empty((ndata * 2, 1), dtype=double)
pi = constant("pi")
randomSeedSet(234579)
noise = randomUniform(ndata)

# Set up the sampled data points with noise.
for i in range(0, ndata):
    xdata[i] = float(i) / (ndata - 1)
    fdata[i] = F(xdata[i]) + noise_size * (1.0 - 2.0 * noise[i])

# Compute the radial fit.
radial_fit = radialScatteredFit(xdata, fdata, num_centers)

# Compare result to the original function at twice as many values as
# there were original data points.
for i in range(0, ndata * 2):
    xdata2[i, 0] = float(i) / (2 * (ndata - 1))

# Evaluate the fit at these new points.
fdata2 = radialEvaluate(xdata2, radial_fit)
print("    I     TRUE       APPROX     ERROR")
for i in range(0, 2 * ndata):
    print("%5d %10.5f %10.5f %10.5f"
          % (i + 1, F(xdata2[i, 0]), fdata2[i], F(xdata2[i, 0]) - fdata2[i]))

Output

    I     TRUE       APPROX     ERROR
    1    0.00000   -0.12821    0.12821
    2    0.34202    0.40184   -0.05982
    3    0.64279    0.79627   -0.15348
    4    0.86603    1.04735   -0.18132
    5    0.98481    1.15482   -0.17001
    6    0.98481    1.12662   -0.14181
    7    0.86603    0.97878   -0.11275
    8    0.64279    0.73465   -0.09187
    9    0.34202    0.42350   -0.08148
   10    0.00000    0.07850   -0.07850
   11   -0.34202   -0.26554   -0.07648
   12   -0.64279   -0.57454   -0.06825
   13   -0.86603   -0.81744   -0.04858
   14   -0.98481   -0.96821   -0.01660
   15   -0.98481   -1.00729    0.02249
   16   -0.86603   -0.92258    0.05655
   17   -0.64279   -0.70962    0.06684
   18   -0.34202   -0.37134    0.02932
   19   -0.00000    0.08297   -0.08297
   20    0.34202    0.63895   -0.29693