Skip to content

Commit 250c448

Browse files
committed
Fix few docstring things, change name to eigensys_realization
1 parent 614a080 commit 250c448

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

control/modelsimp.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from .statefbk import gram
5151
from .timeresp import TimeResponseData
5252

53-
__all__ = ['hsvd', 'balred', 'modred', 'era', 'markov', 'minreal']
53+
__all__ = ['hsvd', 'balred', 'modred', 'eigensys_realization', 'markov', 'minreal', 'era']
5454

5555

5656
# Hankel Singular Value Decomposition
@@ -369,10 +369,11 @@ def minreal(sys, tol=None, verbose=True):
369369
return sysr
370370

371371

372-
def era(arg, r, m=None, n=None, dt=True, transpose=False):
373-
r"""era(YY, r)
372+
def eigensys_realization(arg, r, m=None, n=None, dt=True, transpose=False):
373+
r"""eigensys_realization(YY, r)
374374
375-
Calculate an ERA model of order `r` based on the impulse-response data.
375+
Calculate an ERA model of order `r` based on the impulse-response data
376+
`YY`.
376377
377378
This function computes a discrete time system
378379
@@ -385,73 +386,68 @@ def era(arg, r, m=None, n=None, dt=True, transpose=False):
385386
386387
The function can be called with 2 arguments:
387388
388-
* ``sysd, S = era(data, r)``
389-
* ``sysd, S = era(YY, r)``
389+
* ``sysd, S = eigensys_realization(data, r)``
390+
* ``sysd, S = eigensys_realization(YY, r)``
390391
391392
where `response` is an `TimeResponseData` object, and `YY` is 1D or 3D
392393
array and r is an integer.
393394
394395
Parameters
395396
----------
396397
YY : array_like
397-
impulse-response data from which the StateSpace model is estimated,
398-
1D or 3D array.
398+
Impulse-response from which the StateSpace model is estimated, 1D
399+
or 3D array.
399400
data : TimeResponseData
400-
impulse-response data from which the StateSpace model is estimated.
401+
Impulse-response from which the StateSpace model is estimated.
401402
r : integer
402403
Order of model.
403404
m : integer, optional
404-
Number of rows in Hankel matrix.
405-
Default is 2*r.
405+
Number of rows in Hankel matrix. Default is 2*r.
406406
n : integer, optional
407-
Number of columns in Hankel matrix.
408-
Default is 2*r.
407+
Number of columns in Hankel matrix. Default is 2*r.
409408
dt : True or float, optional
410409
True indicates discrete time with unspecified sampling time,
411-
positive number is discrete time with specified sampling time.
412-
It can be used to scale the StateSpace model in order to match
413-
the impulse response of this library.
414-
Default values is True.
410+
positive number is discrete time with specified sampling time. It
411+
can be used to scale the StateSpace model in order to match the
412+
impulse response of this library. Default is True.
415413
transpose : bool, optional
416414
Assume that input data is transposed relative to the standard
417415
:ref:`time-series-convention`. For TimeResponseData this parameter
418-
is ignored.
419-
Default value is False.
416+
is ignored. Default is False.
420417
421418
Returns
422419
-------
423420
sys : StateSpace
424421
A reduced order model sys=StateSpace(Ar,Br,Cr,Dr,dt).
425422
S : array
426-
Singular values of Hankel matrix.
427-
Can be used to choose a good r value.
423+
Singular values of Hankel matrix. Can be used to choose a good r
424+
value.
428425
429426
References
430427
----------
431-
.. [1] Samet Oymak and Necmiye Ozay
432-
Non-asymptotic Identification of LTI Systems
433-
from a Single Trajectory.
428+
.. [1] Samet Oymak and Necmiye Ozay, Non-asymptotic Identification of
429+
LTI Systems from a Single Trajectory.
434430
https://arxiv.org/abs/1806.05722
435431
436432
Examples
437433
--------
438434
>>> T = np.linspace(0, 10, 100)
439435
>>> _, YY = ct.impulse_response(ct.tf([1], [1, 0.5], True), T)
440-
>>> sysd, _ = ct.era(YY, r=1)
436+
>>> sysd, _ = ct.eigensys_realization(YY, r=1)
441437
442438
>>> T = np.linspace(0, 10, 100)
443439
>>> response = ct.impulse_response(ct.tf([1], [1, 0.5], True), T)
444-
>>> sysd, _ = ct.era(response, r=1)
440+
>>> sysd, _ = ct.eigensys_realization(response, r=1)
445441
"""
446442
def block_hankel_matrix(Y, m, n):
447-
443+
"""Create a block Hankel matrix from Impulse response"""
448444
q, p, _ = Y.shape
449445
YY = Y.transpose(0,2,1) # transpose for reshape
450446

451447
H = np.zeros((q*m,p*n))
452448

453449
for r in range(m):
454-
# shift and add row to hankel matrix
450+
# shift and add row to Hankel matrix
455451
new_row = YY[:,r:r+n,:]
456452
H[q*r:q*(r+1),:] = new_row.reshape((q,p*n))
457453

@@ -477,7 +473,7 @@ def block_hankel_matrix(Y, m, n):
477473
raise ValueError("Hankel parameters are to small")
478474

479475
if (l-1) < m+n:
480-
raise ValueError("Not enough data for requested number of parameters")
476+
raise ValueError("not enough data for requested number of parameters")
481477

482478
H = block_hankel_matrix(YY[:,:,1:], m, n+1) # Hankel matrix (q*m, p*(n+1))
483479
Hf = H[:,:-p] # first p*n columns of H
@@ -651,3 +647,6 @@ def markov(Y, U, m=None, transpose=False):
651647

652648
# Return the first m Markov parameters
653649
return H if transpose else np.transpose(H)
650+
651+
# Function aliases
652+
era = eigensys_realization

control/tests/modelsimp_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from control import StateSpace, impulse_response, step_response, forced_response, tf, rss, c2d
1111
from control.exception import ControlMIMONotImplemented
1212
from control.tests.conftest import slycotonly
13-
from control.modelsimp import balred, hsvd, markov, modred, era
13+
from control.modelsimp import balred, hsvd, markov, modred, eigensys_realization
1414

1515

1616
class TestModelsimp:
@@ -129,15 +129,15 @@ def testERASignature(self):
129129
ir_true = impulse_response(sysd_true,T=T)
130130

131131
# test TimeResponseData
132-
sysd_est, _ = era(ir_true,r=2)
132+
sysd_est, _ = eigensys_realization(ir_true,r=2)
133133
ir_est = impulse_response(sysd_est, T=T)
134134
_, H_est = ir_est
135135

136136
np.testing.assert_allclose(H_true, H_est, rtol=1e-6, atol=1e-8)
137137

138138
# test ndarray
139139
_, YY_true = ir_true
140-
sysd_est, _ = era(YY_true,r=2)
140+
sysd_est, _ = eigensys_realization(YY_true,r=2)
141141
ir_est = impulse_response(sysd_est, T=T)
142142
_, H_est = ir_est
143143

@@ -169,7 +169,7 @@ def testERASignature(self):
169169
ir_true = impulse_response(sysd_true, T=T)
170170

171171
# test TimeResponseData
172-
sysd_est, _ = era(ir_true,r=4,dt=dt)
172+
sysd_est, _ = eigensys_realization(ir_true,r=4,dt=dt)
173173

174174
step_true = step_response(sysd_true)
175175
step_est = step_response(sysd_est)
@@ -180,7 +180,7 @@ def testERASignature(self):
180180

181181
# test ndarray
182182
_, YY_true = ir_true
183-
sysd_est, _ = era(YY_true,r=4,dt=dt)
183+
sysd_est, _ = eigensys_realization(YY_true,r=4,dt=dt)
184184

185185
step_true = step_response(sysd_true, T=T)
186186
step_est = step_response(sysd_est, T=T)

doc/control.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Model simplification tools
137137
balred
138138
hsvd
139139
modred
140-
era
140+
eigensys_realization
141141
markov
142142

143143
Nonlinear system support

examples/era_msd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
response.plot()
4848
plt.show()
4949

50-
sysd_est, _ = ct.era(response,r=4,dt=dt)
50+
sysd_est, _ = ct.eigensys_realization(response,r=4,dt=dt)
5151

5252
step_true = ct.step_response(sysd)
5353
step_true.sysname="H_true"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy