Page MenuHomec4science

eigenproblem_engine.py
No OneTemporary

File Metadata

Created
Thu, Nov 28, 13:03

eigenproblem_engine.py

# 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 numbers import Number
from rrompy.hfengines.base.linear_affine_engine import LinearAffineEngine
from rrompy.hfengines.base.scipy_engine_base import (ScipyEngineBase,
ScipyEngineBaseTensorized)
from rrompy.utilities.base.types import List, Np1D, Np2D
from rrompy.utilities.base import verbosityManager as vbMng
from rrompy.parameter import checkParameter
__all__ = ['EigenproblemEngine', 'TensorizedEigenproblemEngine']
class EigenproblemEngine(LinearAffineEngine, ScipyEngineBase):
"""
Solver for generic eigenvalue-like problems.
(A_0 + \mu_1 A_1 + ... + \mu_N A_N) u(\mu) = f
"""
def __init__(self, As:List[Np2D], f : Np1D = 420, verbosity : int = 10,
timestamp : bool = True):
super().__init__(verbosity = verbosity, timestamp = timestamp)
self._affinePoly = True
self.npar, self.nAs, self.nbs = len(As) - 1, len(As), 1
self.As = As
if np.any([isinstance(A, (np.ndarray,)) for A in As]):
for j in range(self.nAs):
if not isinstance(self.As[j], (np.ndarray,)):
self.As[j] = self.As[j].todense()
self.setSolver("SOLVE")
if isinstance(f, (Number,)):
np.random.seed(f)
f = np.random.randn(self.As[0].shape[0])
f /= np.linalg.norm(f)
else:
f = np.array(f).flatten()
self.bs = [f]
class TensorizedEigenproblemEngine(EigenproblemEngine,
ScipyEngineBaseTensorized):
"""
Solver for generic eigenvalue-like problems.
(A_0 + \mu_1 A_1 + ... + \mu_N A_N) U(\mu) = U
"""
def __init__(self, As:List[Np2D], f : Np1D = 420, ncol : int = 1,
verbosity : int = 10, timestamp : bool = True):
if isinstance(f, (Number,)):
np.random.seed(f)
f = np.random.randn(As[0].shape[0], ncol)
f = (f / np.linalg.norm(f, axis = 0))
else:
f = np.array(f).reshape(-1, ncol)
self.nports = f.shape[1]
super().__init__(As = As, f = f, verbosity = verbosity,
timestamp = timestamp)

Event Timeline