Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66203985
convert_trained_model_pivoted.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, Jun 9, 00:00
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Jun 11, 00:00 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18185808
Attached To
R6746 RationalROMPy
convert_trained_model_pivoted.py
View Options
# 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/>.
#
from
.trained_model_pivoted_rational_nomatch
import
(
TrainedModelPivotedRationalNoMatch
)
from
.trained_model_pivoted_rational_polematch
import
(
TrainedModelPivotedRationalPoleMatch
)
from
rrompy.utilities.base
import
verbosityManager
as
vbMng
from
rrompy.utilities.exception_manager
import
RROMPyException
,
RROMPyWarning
__all__
=
[
'convertTrainedModelPivoted'
]
def
convertTrainedModelPivoted
(
model
,
outType
,
verbObj
=
None
,
muteWarnings
:
bool
=
False
):
if
isinstance
(
model
,
outType
):
return
model
if
((
isinstance
(
model
,
TrainedModelPivotedRationalNoMatch
)
and
outType
==
TrainedModelPivotedRationalPoleMatch
)
or
(
isinstance
(
model
,
TrainedModelPivotedRationalPoleMatch
)
and
outType
==
TrainedModelPivotedRationalNoMatch
)):
return
convertTrainedModelPivotedMatchUnmatch
(
model
,
outType
,
verbObj
,
muteWarnings
)
raise
RROMPyException
((
"Model type or conversion output type not "
"recognized."
))
def
convertTrainedModelPivotedMatchUnmatch
(
model
,
outType
,
verbObj
=
None
,
muteWarnings
:
bool
=
False
):
if
verbObj
is
not
None
:
sf
,
st
=
[
"NoMatch"
,
"PoleMatch"
]
if
outType
==
TrainedModelPivotedRationalPoleMatch
:
msgw
=
"match poles, set up marginalInterp,"
else
:
#if outType == TrainedModelPivotedRationalNoMatch:
st
,
sf
=
sf
,
st
msgw
=
"set up marginalInterp"
vbMng
(
verbObj
,
"INIT"
,
"Starting model conversion from {} to {} model."
.
format
(
sf
,
st
),
10
)
excludeDataKey
=
[
"marginalInterp"
,
"approxParameters"
]
if
outType
==
TrainedModelPivotedRationalPoleMatch
:
modelC
=
TrainedModelPivotedRationalPoleMatch
()
msgw
=
"match poles, set up marginalInterp,"
else
:
#if outType == TrainedModelPivotedRationalNoMatch:
modelC
=
TrainedModelPivotedRationalNoMatch
()
msgw
=
"set up marginalInterp"
excludeDataKey
+=
[
"HIs"
,
"suppEffPts"
,
"suppEffIdx"
,
"coeffsEff"
,
"polesEff"
,
"projGramian"
]
for
key
in
model
.
__dict__
.
keys
():
setattr
(
modelC
,
key
,
model
.
__dict__
[
key
])
for
key
in
excludeDataKey
:
delattr
(
modelC
.
data
,
key
)
if
verbObj
is
not
None
:
vbMng
(
verbObj
,
"DEL"
,
"Finished model conversion."
,
10
)
if
not
muteWarnings
:
RROMPyWarning
((
"Model conversion result not yet fuctional: must stil "
"{} and assign approxParameters."
)
.
format
(
msgw
))
return
modelC
Event Timeline
Log In to Comment