Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79646153
vander.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Aug 27, 13:15
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Aug 29, 13:15 (2 d)
Engine
blob
Format
Raw Data
Handle
20214212
Attached To
R6746 RationalROMPy
vander.py
View Options
# 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
rrompy.utilities.poly_fitting.polynomial.vander
import
(
polyvander
as
pvP
,
polyvanderTotal
as
pvTP
)
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
,
Tuple
,
List
,
paramList
from
rrompy.parameter
import
checkParameterList
from
rrompy.utilities.exception_manager
import
RROMPyException
__all__
=
[
'heavisidevander'
,
'polyvander'
,
'polyvanderTotal'
]
def
heavisidevander
(
x
:
paramList
,
poles
:
Np1D
,
reorder
:
List
[
int
]
=
None
)
->
Np2D
:
"""Compute Heaviside-Vandermonde matrix."""
x
=
checkParameterList
(
x
,
1
)[
0
]
x_un
,
idx_un
=
x
.
unique
(
return_inverse
=
True
)
nx
=
len
(
x
)
if
len
(
x_un
)
<
nx
:
raise
RROMPyException
(
"Sample points must be distinct."
)
del
x_un
x
=
x
.
data
.
flatten
()
if
reorder
is
not
None
:
x
=
x
[
reorder
]
poles
=
poles
.
flatten
()
Van
=
np
.
empty
((
len
(
x
),
len
(
poles
)),
dtype
=
np
.
complex
)
for
j
in
range
(
len
(
x
)):
Van
[
j
,
:]
=
1.
/
(
x
[
j
]
-
poles
)
return
Van
def
polyvander
(
x
:
paramList
,
poles
:
Np1D
,
degs
:
List
[
int
]
=
None
,
basis
:
str
=
"MONOMIAL_HEAVISIDE"
,
derIdxs
:
List
[
List
[
List
[
int
]]]
=
None
,
reorder
:
List
[
int
]
=
None
,
scl
:
Np1D
=
None
)
->
Np2D
:
"""
Compute full Hermite-Vandermonde matrix with specified derivative
directions.
"""
if
derIdxs
is
not
None
and
np
.
sum
(
np
.
sum
(
derIdxs
))
>
0
:
raise
RROMPyException
((
"Cannot take derivatives of heaviside "
"function."
))
basisp
=
basis
.
split
(
"_"
)[
0
]
VanH
=
heavisidevander
(
x
,
poles
,
reorder
=
reorder
)
if
degs
is
None
or
np
.
sum
(
degs
)
<
0
:
VanP
=
np
.
empty
((
len
(
x
),
0
))
else
:
VanP
=
pvP
(
x
,
degs
,
basisp
,
derIdxs
=
derIdxs
,
reorder
=
reorder
,
scl
=
scl
)
return
np
.
block
([[
VanH
,
VanP
]])
def
polyvanderTotal
(
x
:
paramList
,
poles
:
Np1D
,
deg
:
int
=
None
,
basis
:
str
=
"MONOMIAL_HEAVISIDE"
,
derIdxs
:
List
[
List
[
List
[
int
]]]
=
None
,
reorder
:
List
[
int
]
=
None
,
scl
:
Np1D
=
None
)
->
Np2D
:
"""
Compute full total degree Hermite-Vandermonde matrix with specified
derivative directions.
"""
if
derIdxs
is
not
None
and
np
.
sum
(
np
.
sum
(
derIdxs
))
>
0
:
raise
RROMPyException
((
"Cannot take derivatives of radial basis "
"function."
))
basisp
=
basis
.
split
(
"_"
)[
0
]
VanR
=
heavisidevander
(
x
,
poles
,
reorder
=
reorder
)
if
deg
is
None
or
deg
<
0
:
VanP
=
np
.
empty
((
len
(
x
),
0
))
derIdxs
,
ordIdxs
=
np
.
zeros
(
0
,
dtype
=
int
),
np
.
zeros
(
0
,
dtype
=
int
)
else
:
VanP
=
pvTP
(
x
,
deg
,
basisp
,
derIdxs
=
derIdxs
,
reorder
=
reorder
,
scl
=
scl
)
ordIdxsEff
=
np
.
concatenate
((
np
.
arange
(
len
(
VanR
)),
ordIdxs
+
len
(
VanR
)))
return
np
.
block
([[
VanR
,
VanP
],
[
VanP
.
T
.
conj
(),
np
.
zeros
(
tuple
([
VanP
.
shape
[
1
]]
*
2
))]])
Event Timeline
Log In to Comment