Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F75797457
kernel.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
Sun, Aug 4, 08:28
Size
2 KB
Mime Type
text/x-python
Expires
Tue, Aug 6, 08:28 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
19612160
Attached To
R6746 RationalROMPy
kernel.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
.base
import
sparseMap
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
,
paramList
from
rrompy.utilities.exception_manager
import
RROMPyException
from
rrompy.parameter
import
checkParameterList
__all__
=
[
'hatFunction'
,
'val'
,
'vander'
]
def
hatFunctionRef
(
x
:
Np1D
,
supp
:
float
,
depth
:
int
,
kind
:
str
)
->
Np1D
:
if
depth
<
0
:
y
=
np
.
zeros_like
(
x
)
elif
depth
==
0
:
y
=
np
.
ones_like
(
x
)
elif
depth
==
1
:
if
not
np
.
isclose
(
np
.
abs
(
supp
),
1.
):
raise
RROMPyException
((
"Wrong depth. Depth 1 points must be on "
"boundary."
))
y
=
np
.
array
(
np
.
sign
(
supp
)
*
x
)
else
:
width
=
.
5
**
(
depth
-
1.
)
if
np
.
abs
(
supp
)
+
width
>
1.
+
.
25
*
width
:
raise
RROMPyException
((
"Wrong depth or support point. Support "
"point too close to boundary."
))
y
=
np
.
array
(
1.
-
np
.
abs
(
x
-
supp
)
/
width
)
return
np
.
clip
(
y
,
0.
,
1.
,
y
)
def
hatFunction
(
x
:
paramList
,
supportPoints
:
paramList
,
depths
:
Np2D
,
kind
:
str
,
lims
:
paramList
)
->
Np2D
:
x
=
checkParameterList
(
x
)[
0
]
supportPoints
=
checkParameterList
(
supportPoints
,
x
.
shape
[
1
])[
0
]
lims
=
checkParameterList
(
lims
,
x
.
shape
[
1
])[
0
]
res
=
np
.
ones
((
len
(
supportPoints
),
len
(
x
)))
for
d
in
range
(
x
.
shape
[
1
]):
x0
=
sparseMap
(
x
(
d
),
lims
(
d
),
kind
,
False
)
for
j
in
range
(
len
(
supportPoints
)):
supp
=
sparseMap
(
supportPoints
(
j
,
d
),
lims
(
d
),
kind
,
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
(
van
,
c
,
1
)
Event Timeline
Log In to Comment