Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79332187
sampling_engine_linear.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, Aug 25, 21:16
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Aug 27, 21:16 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20176369
Attached To
R6746 RationalROMPy
sampling_engine_linear.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
from
rrompy.sampling.base.sampling_engine_base
import
SamplingEngineBase
from
rrompy.utilities.base.types
import
Np1D
,
paramVal
,
paramList
,
sampList
from
rrompy.utilities.base
import
verbosityDepth
from
rrompy.utilities.exception_manager
import
RROMPyException
from
rrompy.parameter
import
checkParameter
,
checkParameterList
from
rrompy.sampling
import
sampleList
__all__
=
[
'SamplingEngineLinear'
]
class
SamplingEngineLinear
(
SamplingEngineBase
):
"""HERE"""
def
preprocesssamples
(
self
,
idxs
:
Np1D
)
->
sampList
:
if
self
.
samples
is
None
or
len
(
self
.
samples
)
==
0
:
return
return
self
.
samples
(
idxs
)
def
postprocessu
(
self
,
u
:
sampList
,
overwrite
:
bool
=
False
)
->
Np1D
:
return
u
def
_getSampleConcurrence
(
self
,
mu
:
paramVal
,
previous
:
Np1D
,
homogeneized
:
bool
=
False
)
->
sampList
:
mu
=
checkParameter
(
mu
,
1
)
samplesOld
=
self
.
preprocesssamples
(
previous
)
RHS
=
self
.
HFEngine
.
b
(
mu
,
len
(
previous
),
homogeneized
=
homogeneized
)
for
i
in
range
(
1
,
len
(
previous
)
+
1
):
RHS
-=
self
.
HFEngine
.
A
(
mu
,
i
)
.
dot
(
samplesOld
[
-
i
])
return
self
.
solveLS
(
mu
,
RHS
=
RHS
,
homogeneized
=
homogeneized
)
def
nextSample
(
self
,
mu
:
paramVal
,
overwrite
:
bool
=
False
,
homogeneized
:
bool
=
False
)
->
Np1D
:
mu
=
checkParameter
(
mu
,
self
.
HFEngine
.
npar
)
ns
=
self
.
nsamples
muidxs
=
self
.
mus
.
findall
(
mu
)
if
len
(
muidxs
)
>
0
:
u
=
self
.
_getSampleConcurrence
(
mu
,
np
.
sort
(
muidxs
),
homogeneized
)
else
:
u
=
self
.
solveLS
(
mu
,
homogeneized
=
homogeneized
)
u
=
self
.
postprocessu
(
u
,
overwrite
=
overwrite
)
if
overwrite
:
self
.
samples
[
ns
]
=
u
self
.
mus
[
ns
]
=
mu
else
:
if
ns
==
0
:
self
.
samples
=
sampleList
([
u
])
else
:
self
.
samples
.
append
(
u
)
self
.
mus
.
append
(
mu
)
self
.
nsamples
+=
1
return
u
def
iterSample
(
self
,
mus
:
paramList
,
homogeneized
:
bool
=
False
)
->
sampList
:
mus
,
_
=
checkParameterList
(
mus
,
self
.
HFEngine
.
npar
)
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"INIT"
,
"Starting sampling iterations."
,
timestamp
=
self
.
timestamp
)
n
=
len
(
mus
)
if
n
<=
0
:
raise
RROMPyException
((
"Number of samples must be positive."
))
self
.
resetHistory
()
if
self
.
verbosity
>=
7
:
verbosityDepth
(
"MAIN"
,
"Computing sample {}/{}."
.
format
(
1
,
n
),
timestamp
=
self
.
timestamp
)
u
=
self
.
nextSample
(
mus
[
0
],
homogeneized
=
homogeneized
)
if
n
>
1
:
self
.
preallocateSamples
(
u
,
mus
[
0
],
n
)
for
j
in
range
(
1
,
n
):
if
self
.
verbosity
>=
7
:
verbosityDepth
(
"MAIN"
,
"Computing sample {}/{}."
.
format
(
j
+
1
,
n
),
timestamp
=
self
.
timestamp
)
self
.
nextSample
(
mus
[
j
],
overwrite
=
True
,
homogeneized
=
homogeneized
)
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"DEL"
,
"Finished sampling iterations."
,
timestamp
=
self
.
timestamp
)
return
self
.
samples
Event Timeline
Log In to Comment