Python numpy.polynomial.legendre.leg2poly() Examples

The following are 30 code examples of numpy.polynomial.legendre.leg2poly(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numpy.polynomial.legendre , or try the search function .
Example #1
Source File: test_legendre.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #2
Source File: test_legendre.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #3
Source File: test_legendre.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #4
Source File: test_legendre.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #5
Source File: test_legendre.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #6
Source File: test_legendre.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #7
Source File: test_legendre.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #8
Source File: test_legendre.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #9
Source File: test_legendre.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #10
Source File: test_legendre.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #11
Source File: test_legendre.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #12
Source File: ops.py    From learning-circuits with Apache License 2.0 5 votes vote down vote up
def legendre_transpose_mult_slow(v):
    """Naive multiplication P^T v where P is the matrix of coefficients of
    Legendre polynomials.
    Parameters:
        v: (batch_size, n)
    Return:
        P^T v: (batch_size, n)
    """
    n = v.shape[-1]
    # Construct the coefficient matrix P for Legendre polynomials
    P = np.zeros((n, n), dtype=np.float32)
    for i, coef in enumerate(np.eye(n)):
        P[i, :i + 1] = legendre.leg2poly(coef)
    P = torch.tensor(P)
    return v @ P 
Example #13
Source File: learning_ops.py    From learning-circuits with Apache License 2.0 5 votes vote down vote up
def _setup(self, config):
        torch.manual_seed(config['seed'])
        self.model = HstackDiagProduct(size=config['size'])
        self.optimizer = optim.Adam(self.model.parameters(), lr=config['lr'])
        self.n_steps_per_epoch = config['n_steps_per_epoch']
        size = config['size']
        # Target: Legendre polynomials
        P = np.zeros((size, size), dtype=np.float64)
        for i, coef in enumerate(np.eye(size)):
            P[i, :i + 1] = legendre.leg2poly(coef)
        self.target_matrix = torch.tensor(P)
        self.br_perm = bitreversal_permutation(size)
        self.input = (torch.eye(size)[:, :, None, None] * torch.eye(2)).unsqueeze(-1)
        self.input_permuted = self.input[:, self.br_perm] 
Example #14
Source File: test_legendre.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #15
Source File: test_legendre.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #16
Source File: test_legendre.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #17
Source File: test_legendre.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #18
Source File: test_legendre.py    From pySINDy with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #19
Source File: test_legendre.py    From pySINDy with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #20
Source File: test_legendre.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #21
Source File: test_legendre.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #22
Source File: test_legendre.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #23
Source File: test_legendre.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #24
Source File: test_legendre.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #25
Source File: test_legendre.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #26
Source File: test_legendre.py    From Computable with MIT License 5 votes vote down vote up
def test_leg2poly(self) :
        for i in range(10) :
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #27
Source File: test_legendre.py    From Computable with MIT License 5 votes vote down vote up
def test_legfromroots(self) :
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5) :
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #28
Source File: test_legendre.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) 
Example #29
Source File: test_legendre.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_legfromroots(self):
        res = leg.legfromroots([])
        assert_almost_equal(trim(res), [1])
        for i in range(1, 5):
            roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
            pol = leg.legfromroots(roots)
            res = leg.legval(roots, pol)
            tgt = 0
            assert_(len(pol) == i + 1)
            assert_almost_equal(leg.leg2poly(pol)[-1], 1)
            assert_almost_equal(res, tgt) 
Example #30
Source File: test_legendre.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_leg2poly(self):
        for i in range(10):
            assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i])