Page MenuHomec4science

convert_trained_model_pivoted.py
No OneTemporary

File Metadata

Created
Sun, Jun 9, 00:00

convert_trained_model_pivoted.py

# 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