Page MenuHomec4science

kernel.py
No OneTemporary

File Metadata

Created
Tue, May 7, 10:38

kernel.py

# Copyright (C) 2018-2020 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 .base import centerNormalize, sparseMap
from rrompy.utilities.base.types import Np1D, Np2D, paramList
from rrompy.parameter import checkParameterList
__all__ = ['hatFunction', 'val', 'vander']
def hatFunctionRef(x:Np1D, supp:float, depth:int, kind:str) -> Np1D:
noBdr = "HAAR" in kind.upper()
if depth < noBdr: return np.zeros_like(x)
if depth == noBdr: return np.ones_like(x)
suppEff = sparseMap(supp, [-1., 1.], kind, False)
suppLREff = suppEff + .5 ** (depth - 1) * np.array([-1., 1.])
widthL, widthR = sparseMap(suppLREff, [-1., 1.], kind) - supp
xC = np.array(x - supp)
if (np.isclose(widthL, 0., atol = 1e-12)
or supp + (.95 + .1 * noBdr) * widthL < - 1.):
isleft, isright = 0, 1
elif (np.isclose(widthR, 0., atol = 1e-12)
or supp + (.95 + .1 * noBdr) * widthR > 1.):
isleft, isright = 1, 0
else:
isleft, isright = xC < 0., xC >= 0.
y = 1. - xC / (widthL * isleft + widthR * isright)
return np.clip(y, 0., 1., y)
def hatFunction(x:paramList, supportPoints:paramList, depths:Np2D,
kind:str, lims:paramList) -> Np2D:
x = checkParameterList(x)
supportPoints = checkParameterList(supportPoints, x.shape[1])
lims = checkParameterList(lims, x.shape[1])
res = np.ones((len(supportPoints), len(x)))
for d in range(x.shape[1]):
x0 = centerNormalize(x(d), lims(d), False)
for j in range(len(supportPoints)):
supp = centerNormalize(supportPoints(j, d), lims(d), False)
res[j] *= hatFunctionRef(x0, supp, depths[j, d], kind)
return res.T
def vander(supportPoints:paramList, depths:Np2D, kind:str,
lims:paramList) -> Np2D:
return hatFunction(supportPoints, supportPoints, depths, kind, lims)
def val(x:paramList, c:Np2D, supportPoints:paramList, depths:Np2D,
kind:str, lims:paramList) -> Np2D:
van = hatFunction(x, supportPoints, depths, kind, lims)
return np.tensordot(c, van, (0, -1))

Event Timeline