Ejemplo n.º 1
0
 def test_error(self):
     """
     Error if chebfun is called with another type.
     """
     class C(object):
         pass
     with self.assertRaises(TypeError):
         chebfun(C())
Ejemplo n.º 2
0
    def test_error(self):
        """
        Error if chebfun is called with another type.
        """
        class C(object):
            pass

        with self.assertRaises(TypeError):
            chebfun(C())
Ejemplo n.º 3
0
def __chebydiff__(x, dt, params, options=None):
    """
    Fit the timeseries with chebyshev polynomials, and differentiate this model.

    :param x: (np.array of floats, 1xN) time series to differentiate
    :param dt: (float) time step
    :param params: (list) [N] : (int) order of the polynomial
    :param options:
    :return: x_hat    : estimated (smoothed) x
             dxdt_hat : estimated derivative of x
    """

    if isinstance(params, list):
        n = params[0]
    else:
        n = params

    mean = np.mean(x)
    x = x - mean

    def f(y):
        t = np.linspace(-1, 1, len(x))
        return np.interp(y, t, x)

    # Chebychev polynomial
    poly = pychebfun.chebfun(f, N=n, domain=[-1, 1])
    ts = np.linspace(poly.domain()[0], poly.domain()[-1], len(x))

    x_hat = poly(ts) + mean
    dxdt_hat = poly.differentiate()(ts) * (2 / len(x)) / dt

    return x_hat, dxdt_hat
Ejemplo n.º 4
0
 def __setstate__(self, dict):
     self.lower = dict["lower"]
     self.upper = dict["upper"]
     self.name = dict["name"]
     self.interp_points = dict["interp_points"]
     if 'interp_err_typ' not in dict:
         self.interp_err_typ = chebfun(self.getTypical, domain=[self.lower, self.upper], N=self.interp_points)
         dict['interp_err_typ'] = self.interp_err_typ
     self.__dict__ = dict  # make dict our attribute dictionary
Ejemplo n.º 5
0
def mergeSegments(f, i, j):
    if i is j:
        return f.segments[i]
    else:
        # Range of the new segment
        a = f.segments[i].a
        b = f.segments[j].b
        interp = cheb.chebfun(f, domain=[a, b], N=100)
        tmp = pacal.segments.InterpolatedSegment(a, b, interp)
        return tmp
Ejemplo n.º 6
0
def __chebydiff__(x, dt, params, options={}):
    '''
    Fit the timeseries with chebyshev polynomials, and differentiate this model.
    
    Inputs
    ------
    x       : (np.array of floats, 1xN) time series to differentiate
    dt      : (float) time step

    Parameters
    ----------
    params  : (list) [N] : (int) order of the polynomial
    options : (dict) {}

    Outputs
    -------
    x_hat    : estimated (smoothed) x
    dxdt_hat : estimated derivative of x

    '''

    if type(params) is list:
        N = params[0]
    else:
        N = params

    mean = np.mean(x)
    x = x - mean

    def f(y):
        t = np.linspace(-1, 1, len(x))
        return np.interp(y, t, x)

    # Chebychev polynomial
    poly = pychebfun.chebfun(f, N=N, domain=[-1, 1])
    ts = np.linspace(poly.domain()[0], poly.domain()[-1], len(x))

    x_hat = poly(ts) + mean
    dxdt_hat = poly.differentiate()(ts) * (2 / len(x)) / dt

    return x_hat, dxdt_hat
Ejemplo n.º 7
0
 def test_from_scalar(self):
     val = np.random.rand()
     cr = chebfun(val)
     ce = Chebfun.from_data([val])
     tools.assert_close(cr, ce)
Ejemplo n.º 8
0
 def test_from_values(self):
     values = np.random.randn(10)
     cr = chebfun(values)
     ce = Chebfun.from_data(values)
     tools.assert_close(cr, ce)
Ejemplo n.º 9
0
 def test_from_chebfun(self):
     ce = Chebfun.from_function(tools.f)
     cr = chebfun(ce)
     tools.assert_close(cr, ce)
Ejemplo n.º 10
0
 def test_from_chebcoeffs(self):
     coeffs = np.random.randn(10)
     cr = chebfun(chebcoeff=coeffs)
     ce = Chebfun.from_coeff(coeffs)
     tools.assert_close(cr, ce)
Ejemplo n.º 11
0
 def __init__(self, lower, upper, interp_points):
     self.lower=lower
     self.upper=upper
     self.interp_points=interp_points
     self.name="TypErrorInterpolator"
     self.interp_err_typ=chebfun(self.getTypical, domain=[self.lower, self.upper], N=self.interp_points)
Ejemplo n.º 12
0
 def test_from_scalar(self):
     val = np.random.rand()
     cr = chebfun(val)
     ce = Chebfun.from_data([val])
     tools.assert_close(cr, ce)
Ejemplo n.º 13
0
 def test_from_values(self):
     values = np.random.randn(10)
     cr = chebfun(values)
     ce = Chebfun.from_data(values)
     tools.assert_close(cr, ce)
Ejemplo n.º 14
0
 def test_from_chebfun(self):
     ce = Chebfun.from_function(tools.f)
     cr = chebfun(ce)
     tools.assert_close(cr, ce)
Ejemplo n.º 15
0
 def test_from_chebcoeffs(self):
     coeffs = np.random.randn(10)
     cr = chebfun(chebcoeff=coeffs)
     ce = Chebfun.from_coeff(coeffs)
     tools.assert_close(cr, ce)