示例#1
0
 def testSinReturnSaveSpaces(self):
     space = self.workspace(self.n)
     table = self.wavetable(self.n)
     x = numx.arange(self.n) * ((2 + 0j) * numx.pi / self.n)
     for i in range(1, self.n / 2):
         y = numx.sin(x * i)
         tmp = self.convert(y)
         f = self.transform(tmp, space, table, tmp)
         self._CheckSinResult(f, i)
示例#2
0
 def testSinReturnSaveSpaces(self):
     space = self.workspace(self.n)
     table = self.wavetable(self.n)
     x = numx.arange(self.n) * ((2+0j) * numx.pi / self.n)
     for i in range(1,self.n/2):
         y = numx.sin(x * i)
         tmp = self.convert(y)
         f = self.transform(tmp, space, table, tmp)
         self._CheckSinResult(f, i)
示例#3
0
 def EFunc(self):
     x = self._data
     t = x-1.0
     t2 = t*t
     # Necessary as my python does not handle the exp of big numbers
     # correctly
     if t2 > 700:
         tmp = 0
     else:
         tmp = numx.exp(-t2)
     return tmp*numx.sin(8*x)
示例#4
0
文件: bspline2.py 项目: pygsl/pygsl
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)

    b = bspline(10, nbreak)
    b.knots_uniform(x[0], x[-1])
    X = numx.zeros((N, ncoeffs))
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)

    res_x = x[::N / 64]
    X = b.eval_vector(res_x)
    res_y, res_y_err = multifit.linear_est_matrix(X, c, cov)

    pylab.plot(x, y, '-')
    pylab.errorbar(res_x, res_y, fmt='g-', xerr=res_y_err)
示例#5
0
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)


    b = bspline(10, nbreak)
    b.knots_uniform(x[0], x[-1])
    X = numx.zeros((N, ncoeffs))
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)


    res_x = x[::N/64]
    X = b.eval_vector(res_x)
    res_y, res_y_err = multifit.linear_est_matrix(X, c, cov)

    pylab.plot(x,y, '-')
    pylab.errorbar(res_x, res_y, fmt='g-', xerr=res_y_err)    
示例#6
0
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)

    b = bspline(4, nbreak)
    k = b.get_internal_knots()
    pygsl.set_debug_level(10)
    b.knots(k)
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)

    b.set_coefficients_and_covariance_matrix(c, cov)

    res_x = x[:: N / 64]
    res_y, res_y_err = b.eval_dep_yerr_vector(res_x)
    # res_y = b.eval_dep_vector(res_x)

    print res_y
    pylab.plot(x, y, "-")
    pylab.errorbar(res_x, res_y, fmt="g-", xerr=res_y_err)
示例#7
0
文件: bspline3.py 项目: pygsl/pygsl
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)

    b = bspline(4, nbreak)
    k = b.get_internal_knots()
    pygsl.set_debug_level(10)
    b.knots(k)
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)

    b.set_coefficients_and_covariance_matrix(c, cov)

    res_x = x[::N / 64]
    res_y, res_y_err = b.eval_dep_yerr_vector(res_x)
    #res_y = b.eval_dep_vector(res_x)

    print(res_y)
    pylab.plot(x, y, '-')
    pylab.errorbar(res_x, res_y, fmt='g-', xerr=res_y_err)
示例#8
0
'graph' program. e.g

     $ python ./interpolation.py > interp.dat
     $ graph -T ps < interp.dat > interp.ps

The result shows a smooth interpolation of the original points.  The
interpolation method can changed simply by varing spline. .

"""
from pygsl import spline, errors, init
from pygsl import _numobj as numx

print ("#m=0,S=2")
n = 10
a = numx.arange(n)
x = a + 0.5 * numx.sin(a)
y = a + numx.cos(a**2)
for i in a:
    print (x[i], y[i])

print ("#m=1,S=0")
# Generation of the spline object ...  Acceleration is handled internally
myspline = spline.cspline(n)
myspline = spline.linear(n)
#acc = myspline._object.get_accel_object()
#print "Accel object", dir(acc)
# initalise with the vector of the independent and the dependent
init.add_c_traceback_frames(1)
#init.set_debug_level(10)
myspline.init(x, y[:3])
#print("Saved error state", init.error_handler_state_get())
示例#9
0
def polydd():
    xa = numx.arange(100) / 100.0 * 2. * numx.pi
    ya = numx.sin(xa)
    dd = poly.poly_dd(xa, ya)
    dd.eval(0)        
    c = dd.taylor(0.0)
示例#10
0
import pygsl

def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))
    
    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices  = numx.argsort(abscoeff) # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i] # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)

    #print result2
    #print result2 - array
    
if __name__ == '__main__':
    a = numx.arange(256)
    b = numx.sin(a*(2*numx.pi / 16.))
    #b = a * 0.0
    run(b)
示例#11
0
def polydd():
    xa = numx.arange(100) / 100.0 * 2. * numx.pi
    ya = numx.sin(xa)
    dd = poly.poly_dd(xa, ya)
    dd.eval(0)
    c = dd.taylor(0.0)
示例#12
0
 def f2(x,y):
     return numx.sin(x) / x
示例#13
0
 def SinOne(self, x, l, args=()):
     y = numx.sin(x * l)
     tmp = self.convert(y)
     f = self.transform(*((tmp,) + args))
     self._CheckSinResult(f, l)
示例#14
0
 def setUp(self):
     xa = Numeric.arange(100) / 100.0 * 2. * Numeric.pi
     ya = Numeric.sin(xa)
     self.dd = poly.poly_dd(xa, ya)
示例#15
0
 def setUp(self):
     xa = Numeric.arange(100) / 100.0 * 2. * Numeric.pi
     ya = Numeric.sin(xa)
     self.dd = poly.poly_dd(xa, ya)
示例#16
0
 def SinOne(self, x, l, args=()):
     y = numx.sin(x * l)
     tmp = self.convert(y)
     f = self.transform(*((tmp, ) + args))
     self._CheckSinResult(f, l)
示例#17
0
 def f1(x,y):
     return Numeric.sin(x)
示例#18
0
 def f1(x, y):
     return Numeric.sin(x)
示例#19
0
 def f2(x, y):
     return numx.sin(x) / x
示例#20
0
'graph' program. e.g

     $ python ./interpolation.py > interp.dat
     $ graph -T ps < interp.dat > interp.ps

The result shows a smooth interpolation of the original points.  The
interpolation method can changed simply by varing spline. .

"""
from pygsl import spline, errors
from pygsl import _numobj as numx

print "#m=0,S=2"
n = 10
a = numx.arange(n)
x = a + 0.5 * numx.sin(a)
y = a + numx.cos(a**2)
for i in a:
    print x[i], y[i]

print "#m=1,S=0"
# Generation of the spline object ...  Acceleration is handled internally
myspline = spline.cspline(n)
myspline = spline.linear(n)
acc = myspline._object.get_accel_object()
#print "Accel object", dir(acc)
# initalise with the vector of the independent and the dependent
myspline.init(x,y)
x1 = numx.arange(n * 20) / 20.
for xi in x1:
    #print xi, myspline.eval(xi)
示例#21
0
 def f2(x,y):
     return Numeric.sin(x) / x
示例#22
0
 def f2(x, y):
     return Numeric.sin(x) / x
示例#23
0

def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))

    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices = numx.argsort(abscoeff)  # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i]  # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)

    #print result2
    #print result2 - array


if __name__ == '__main__':
    a = numx.arange(256)
    b = numx.sin(a * (2 * numx.pi / 16.))
    #b = a * 0.0
    run(b)