Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90777516
sampling.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
Mon, Nov 4, 16:06
Size
2 KB
Mime Type
text/x-python
Expires
Wed, Nov 6, 16:06 (2 d)
Engine
blob
Format
Raw Data
Handle
22133119
Attached To
R6746 RationalROMPy
sampling.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
import
scipy.sparse
as
sp
from
rrompy.hfengines.base
import
MatrixEngineBase
from
rrompy.sampling.standard
import
(
SamplingEngineStandard
,
SamplingEngineStandardPOD
)
from
rrompy.parameter
import
parameterList
class
matrixEngine
(
MatrixEngineBase
):
def
__init__
(
self
):
super
()
.
__init__
(
verbosity
=
0
)
self
.
_affinePoly
=
True
N
=
100
self
.
npar
=
1
self
.
nAs
,
self
.
nbs
=
2
,
1
self
.
As
=
[
sp
.
spdiags
([
np
.
arange
(
1
,
1
+
N
)],
[
0
],
N
,
N
),
-
sp
.
eye
(
N
)]
self
.
bs
=
[
np
.
exp
(
1.j
*
np
.
linspace
(
0
,
-
np
.
pi
,
N
))]
self
.
thAs
=
self
.
getMonomialWeights
(
self
.
nAs
)
self
.
thbs
=
self
.
getMonomialWeights
(
self
.
nbs
)
def
test_krylov
():
mu
=
10.
+
.
5j
solver
=
matrixEngine
()
samplingEngine
=
SamplingEngineStandard
(
solver
,
verbosity
=
0
)
samples
=
samplingEngine
.
iterSample
([
mu
]
*
5
)
.
data
assert
samples
.
shape
==
(
100
,
5
)
assert
np
.
isclose
(
np
.
linalg
.
norm
(
samples
),
37.02294804524299
,
rtol
=
1e-5
)
def
test_distributed
():
mus
=
parameterList
(
np
.
linspace
(
5
,
15
,
11
)
+
.
5j
)
solver
=
matrixEngine
()
samplingEngine
=
SamplingEngineStandard
(
solver
,
verbosity
=
0
)
samples
=
samplingEngine
.
iterSample
(
mus
)
.
data
assert
samples
.
shape
==
(
100
,
11
)
assert
np
.
isclose
(
np
.
linalg
.
norm
(
samples
),
8.59778606421386
,
rtol
=
1e-5
)
def
test_distributed_pod
():
mus
=
np
.
linspace
(
5
,
15
,
11
)
+
.
5j
solver
=
matrixEngine
()
samplingEngine
=
SamplingEngineStandardPOD
(
solver
,
verbosity
=
0
)
samples
=
samplingEngine
.
iterSample
(
mus
)
.
data
assert
samples
.
shape
==
(
100
,
11
)
assert
np
.
isclose
(
np
.
linalg
.
norm
(
samples
),
3.3166247903553994
,
rtol
=
1e-5
)
assert
np
.
isclose
(
np
.
linalg
.
cond
(
samples
.
conj
()
.
T
.
dot
(
samples
)),
1.
,
rtol
=
1e-5
)
Event Timeline
Log In to Comment