Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F67921245
trained_model_pivoted_rational.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, Jun 25, 01:49
Size
4 KB
Mime Type
text/x-python
Expires
Thu, Jun 27, 01:49 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18493093
Attached To
R6746 RationalROMPy
trained_model_pivoted_rational.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/>.
#
from
.trained_model_pivoted_general
import
TrainedModelPivotedGeneral
from
.trained_model_rational
import
TrainedModelRational
from
rrompy.utilities.base.types
import
Np1D
,
List
,
paramList
,
sampList
,
HFEng
from
rrompy.utilities.base
import
verbosityManager
as
vbMng
from
rrompy.utilities.poly_fitting.heaviside
import
rational2heaviside
from
rrompy.utilities.exception_manager
import
RROMPyAssert
from
rrompy.parameter
import
checkParameterList
from
rrompy.sampling
import
sampleList
__all__
=
[
'TrainedModelPivotedRational'
]
class
TrainedModelPivotedRational
(
TrainedModelPivotedGeneral
,
TrainedModelRational
):
"""
ROM approximant evaluation for pivoted Rational approximant (with pole
matching).
Attributes:
Data: dictionary with all that can be pickled.
"""
def
initializeFromRational
(
self
,
HFEngine
:
HFEng
,
matchingWeight
:
float
=
1.
,
POD
:
bool
=
True
):
"""Initialize Heaviside representation."""
RROMPyAssert
(
self
.
data
.
nparPivot
,
1
,
"Number of pivot parameters"
)
poles
,
coeffs
=
[],
[]
for
Q
,
P
in
zip
(
self
.
data
.
Qs
,
self
.
data
.
Ps
):
cfs
,
pls
,
basis
=
rational2heaviside
(
P
,
Q
)
poles
+=
[
pls
]
coeffs
+=
[
cfs
]
self
.
initializeFromLists
(
poles
,
coeffs
,
basis
,
HFEngine
,
matchingWeight
,
POD
)
self
.
data
.
_temporary
=
False
def
getPVal
(
self
,
mu
:
paramList
=
[])
->
sampList
:
"""
Evaluate rational numerator at arbitrary parameter.
Args:
mu: Target parameter.
"""
RROMPyAssert
(
self
.
data
.
nparPivot
,
1
,
"Number of pivot parameters"
)
if
not
self
.
data
.
_temporary
:
return
super
()
.
getPVal
(
mu
)
mu
=
checkParameterList
(
mu
,
self
.
data
.
npar
)[
0
]
muP
=
checkParameterList
(
mu
.
data
[:,
self
.
data
.
directionPivot
],
self
.
data
.
nparPivot
)[
0
]
muM
=
checkParameterList
(
mu
.
data
[:,
self
.
data
.
directionMarginal
],
self
.
data
.
nparMarginal
)[
0
]
muP
=
checkParameterList
(
muP
,
self
.
data
.
nparPivot
)[
0
]
vbMng
(
self
,
"INIT"
,
"Evaluating numerator at mu = {}."
.
format
(
muP
),
17
)
muPC
=
self
.
centerNormalizePivot
(
muP
)
pP
=
[
sampleList
(
P
(
muPC
))
for
P
in
self
.
data
.
Ps
]
vbMng
(
self
,
"DEL"
,
"Done evaluating numerator."
,
17
)
return
self
.
interpolateMarginal
(
muM
,
pP
)
def
getQVal
(
self
,
mu
:
Np1D
,
der
:
List
[
int
]
=
None
,
scl
:
Np1D
=
None
)
->
Np1D
:
"""
Evaluate rational denominator at arbitrary parameter.
Args:
mu: Target parameter.
der(optional): Derivatives to take before evaluation.
"""
RROMPyAssert
(
self
.
data
.
nparPivot
,
1
,
"Number of pivot parameters"
)
if
not
self
.
data
.
_temporary
:
return
super
()
.
getQVal
(
mu
,
der
,
scl
)
mu
=
checkParameterList
(
mu
,
self
.
data
.
npar
)[
0
]
muP
=
checkParameterList
(
mu
.
data
[:,
self
.
data
.
directionPivot
],
self
.
data
.
nparPivot
)[
0
]
muM
=
checkParameterList
(
mu
.
data
[:,
self
.
data
.
directionMarginal
],
self
.
data
.
nparMarginal
)[
0
]
if
der
is
None
:
derP
,
derM
=
None
,
None
else
:
derP
=
[
der
[
x
]
for
x
in
self
.
data
.
directionPivot
]
derM
=
[
der
[
x
]
for
x
in
self
.
data
.
directionMarginal
]
if
scl
is
None
:
sclP
,
sclM
=
None
,
None
else
:
sclP
=
[
scl
[
x
]
for
x
in
self
.
data
.
directionPivot
]
sclM
=
[
scl
[
x
]
for
x
in
self
.
data
.
directionMarginal
]
muP
=
checkParameterList
(
muP
,
self
.
data
.
nparPivot
)[
0
]
vbMng
(
self
,
"INIT"
,
"Evaluating denominator at mu = {}."
.
format
(
muP
),
17
)
muPC
=
self
.
centerNormalizePivot
(
muP
)
qP
=
[
Q
(
muPC
,
derP
,
sclP
)
.
reshape
(
1
,
-
1
)
for
Q
in
self
.
data
.
Qs
]
vbMng
(
self
,
"DEL"
,
"Done evaluating denominator."
,
17
)
return
self
.
interpolateMarginal
(
muM
,
qP
,
derM
,
sclM
)
Event Timeline
Log In to Comment