コード例 #1
0
    def _get_integration_limits(self, omega, args, kwds):
        a, b = self.a, self.b
        M = 30
        ab = [a]
        scale = (b - a) / 2
        n = 30
        x = np.linspace(a, b, n + 1)
        dg_x = np.asarray([scale * omega * self.dg(xi, *args, **kwds)
                           for xi in x])
        i10 = findcross(dg_x, M)
        i1 = findcross(dg_x, 1)
        i0 = findcross(dg_x, 0)
        im1 = findcross(dg_x, -1)
        im10 = findcross(dg_x, -M)
        x10 = ecross(x, dg_x, i10, M) if len(i10) else ()
        x1 = ecross(x, dg_x, i1, 1) if len(i1) else ()
        x0 = ecross(x, dg_x, i0, 0) if len(i0) else ()
        xm1 = ecross(x, dg_x, im1, -1) if len(im1) else ()
        xm10 = ecross(x, dg_x, im10, -M) if len(im10) else ()

        for i in np.unique(np.hstack((x10, x1, x0, xm1, xm10))):
            if x[0] < i < x[n]:
                ab.append(i)
        ab.append(b)
        return ab
コード例 #2
0
    def _get_integration_limits(self, omega, args, kwds):
        a, b = self.a, self.b
        M = 30
        ab = [a]
        scale = (b - a) / 2
        n = 30
        x = np.linspace(a, b, n + 1)
        dg_x = np.asarray([scale * omega * self.dg(xi, *args, **kwds)
                           for xi in x])
        i10 = findcross(dg_x, M)
        i1 = findcross(dg_x, 1)
        i0 = findcross(dg_x, 0)
        im1 = findcross(dg_x, -1)
        im10 = findcross(dg_x, -M)
        x10 = ecross(x, dg_x, i10, M) if len(i10) else ()
        x1 = ecross(x, dg_x, i1, 1) if len(i1) else ()
        x0 = ecross(x, dg_x, i0, 0) if len(i0) else ()
        xm1 = ecross(x, dg_x, im1, -1) if len(im1) else ()
        xm10 = ecross(x, dg_x, im10, -M) if len(im10) else ()

        for i in np.unique(np.hstack((x10, x1, x0, xm1, xm10))):
            if x[0] < i < x[n]:
                ab.append(i)
        ab.append(b)
        return ab
コード例 #3
0
def test_findcross_and_ecross():
    assert_allclose(findcross([0, 0, 1, -1, 1], 0), [1, 2, 3])
    assert_allclose(findcross([0, 1, -1, 1], 0), [0, 1, 2])

    t = linspace(0, 7 * pi, 250)
    x = sin(t)
    ind = findcross(x, 0.75)
    assert_allclose(ind, [9, 25, 80, 97, 151, 168, 223, 239])
    t0 = ecross(t, x, ind, 0.75)
    assert_allclose(t0, [0.84910514, 2.2933879, 7.13205663,
                         8.57630119, 13.41484739, 14.85909194,
                         19.69776067, 21.14204343])
コード例 #4
0
ファイル: test_misc.py プロジェクト: wafo-project/pywafo
def test_findcross_and_ecross():
    assert_array_equal(findcross([0, 0, 1, -1, 1], 0), np.array([1, 2, 3]))
    assert_array_equal(findcross([0, 1, -1, 1], 0), np.array([0, 1, 2]))

    t = linspace(0, 7 * pi, 250)
    x = sin(t)
    ind = findcross(x, 0.75)
    assert_array_equal(ind, np.array([9, 25, 80, 97, 151, 168, 223, 239]))
    t0 = ecross(t, x, ind, 0.75)
    assert_array_almost_equal(t0, np.array([0.84910514, 2.2933879, 7.13205663,
                                            8.57630119, 13.41484739,
                                            14.85909194,
                                            19.69776067, 21.14204343]))
コード例 #5
0
ファイル: estimation.py プロジェクト: eelcovv/pywafo
    def get_bounds(self, alpha=0.05):
        """Return confidence interval for profiled parameter
        """
        if alpha < self.alpha:
            warnings.warn("Might not be able to return CI with alpha less than %g" % self.alpha)
        cross_level = self.Lmax - 0.5 * chi2isf(alpha, 1)
        ind = findcross(self.data, cross_level)
        N = len(ind)
        if N == 0:
            warnings.warn(
                """Number of crossings is zero, i.e.,
            upper and lower bound is not found!"""
            )
            CI = (self.pmin, self.pmax)

        elif N == 1:
            x0 = ecross(self.args, self.data, ind, cross_level)
            isUpcrossing = self.data[ind] > self.data[ind + 1]
            if isUpcrossing:
                CI = (x0, self.pmax)
                warnings.warn("Upper bound is larger")
            else:
                CI = (self.pmin, x0)
                warnings.warn("Lower bound is smaller")

        elif N == 2:
            CI = ecross(self.args, self.data, ind, cross_level)
        else:
            warnings.warn("Number of crossings too large! Something is wrong!")
            CI = ecross(self.args, self.data, ind[[0, -1]], cross_level)
        return CI
コード例 #6
0
ファイル: estimation.py プロジェクト: mikemt/pywafo-1
    def get_bounds(self, alpha=0.05):
        '''Return confidence interval for profiled parameter
        '''
        if alpha < self.alpha:
            warnings.warn(
                'Might not be able to return CI with alpha less than %g' %
                self.alpha)
        cross_level = self.Lmax - 0.5 * chi2isf(alpha, 1)
        ind = findcross(self.data, cross_level)
        N = len(ind)
        if N == 0:
            warnings.warn('''Number of crossings is zero, i.e.,
            upper and lower bound is not found!''')
            CI = (self.pmin, self.pmax)

        elif N == 1:
            x0 = ecross(self.args, self.data, ind, cross_level)
            isUpcrossing = self.data[ind] > self.data[ind + 1]
            if isUpcrossing:
                CI = (x0, self.pmax)
                warnings.warn('Upper bound is larger')
            else:
                CI = (self.pmin, x0)
                warnings.warn('Lower bound is smaller')

        elif N == 2:
            CI = ecross(self.args, self.data, ind, cross_level)
        else:
            warnings.warn('Number of crossings too large! Something is wrong!')
            CI = ecross(self.args, self.data, ind[[0, -1]], cross_level)
        return CI