Page MenuHomec4science

base.py
No OneTemporary

File Metadata

Created
Sat, Jun 29, 07:50
# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import numpy as np
from scipy.special import binom
from rrompy.utilities.exception_manager import RROMPyException
__all__ = ['polybases', 'polyfitname', 'polydomcoeff']
polybases = ["CHEBYSHEV", "LEGENDRE", "MONOMIAL"]
def polyfitname(basis:str) -> str:
fitnames = {"CHEBYSHEV" : "chebfit", "LEGENDRE" : "legfit",
"MONOMIAL" : "polyfit"}
try:
return fitnames[basis.upper()]
except:
raise RROMPyException("Polynomial basis not recognized.")
def polydomcoeff(n:int, basis:str) -> float:
basis = basis.upper()
if isinstance(n, (list, tuple, np.ndarray,)):
nv = np.array(n)
else:
nv = np.array([n])
if basis == "CHEBYSHEV":
x = np.ones_like(nv, dtype = float)
x[nv > 0] = np.power(2., nv[nv > 0] - 1)
elif basis == "LEGENDRE":
x = np.ones_like(nv, dtype = float)
x[nv > 10] = (np.power(2., nv[nv > 10])
* np.power(np.pi * nv[nv > 10], -.5))
x[nv <= 10] = (np.power(.5, nv[nv <= 10])
* binom(2 * nv[nv <= 10], nv[nv <= 10]))
elif basis == "MONOMIAL":
x = np.ones_like(nv, dtype = float)
else:
raise RROMPyException("Polynomial basis not recognized.")
if isinstance(n, (list,)):
return list(x)
if isinstance(n, (tuple,)):
return tuple(x)
if isinstance(n, (np.ndarray,)):
return x
return x[0]

Event Timeline