Page MenuHomec4science

degree.py
No OneTemporary

File Metadata

Created
Fri, May 3, 21:07

degree.py

# 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.base.types import Np2D, Tuple, List
from .kroneckerer import kroneckerer
__all__ = ['fullDegreeN', 'totalDegreeN', 'fullDegreeSet', 'totalDegreeSet',
'degreeTotalToFull', 'fullDegreeMaxMask', 'totalDegreeMaxMask']
def fullDegreeN(deg:int, npar:int) -> int:
return (1 + deg) ** npar
def totalDegreeN(deg:int, npar:int) -> int:
return int(binom(deg + npar, npar))
def fullDegreeSet(deg:int, npar:int) -> List[List[int]]:
idxs = np.empty((fullDegreeN(deg, npar), npar), dtype = int)
for j in range(npar):
idxs[:, j] = kroneckerer(np.arange(deg + 1), fullDegreeN(deg, j),
fullDegreeN(deg, npar - j - 1))
return idxs
def totalDegreeSet(deg:int, npar:int,
return_mask : bool = False) -> List[List[int]]:
remN = fullDegreeSet(deg, npar)
mask = np.sum(remN, axis = 1) <= deg
if return_mask: return remN[mask], mask
return remN[mask]
def degreeTotalToFull(shapeFull:Tuple[int], dim:int, coeffs:Np2D) -> Np2D:
from .hash_derivative import hashIdxToDerivative as hashI
full = np.zeros(shapeFull, dtype = coeffs.dtype)
for j in range(len(coeffs)):
full[tuple(hashI(j, dim))] = coeffs[j]
return full
def fullDegreeMaxMask(deg:int, npar:int) -> List[int]:
return np.where(np.any(fullDegreeSet(deg, npar) == deg, axis = 1))[0]
def totalDegreeMaxMask(deg:int, npar:int) -> List[int]:
if deg == 0: return np.zeros(1, dtype = int)
return np.arange(totalDegreeN(deg - 1, npar), totalDegreeN(deg, npar))

Event Timeline