Skip to content

Use standard time series convention for markov() input data #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions control/modelsimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def era(YY, m, n, nin, nout, r):
raise NotImplementedError('This function is not implemented yet.')


def markov(Y, U, m=None, transpose=None):
def markov(Y, U, m=None, transpose=False):
"""Calculate the first `m` Markov parameters [D CB CAB ...]
from input `U`, output `Y`.

Expand Down Expand Up @@ -424,8 +424,7 @@ def markov(Y, U, m=None, transpose=None):
Number of Markov parameters to output. Defaults to len(U).
transpose : bool, optional
Assume that input data is transposed relative to the standard
:ref:`time-series-convention`. The default value is true for
backward compatibility with legacy code.
:ref:`time-series-convention`. Default value is False.

Returns
-------
Expand Down Expand Up @@ -456,15 +455,6 @@ def markov(Y, U, m=None, transpose=None):
>>> H = markov(Y, U, 3, transpose=False)

"""
# Check on the specified format of the input
if transpose is None:
# For backwards compatibility, assume time series in rows but warn user
warnings.warn(
"Time-series data assumed to be in rows. This will change in a "
"future release. Use `transpose=True` to preserve current "
"behavior.")
transpose = True

# Convert input parameters to 2D arrays (if they aren't already)
Umat = np.array(U, ndmin=2)
Ymat = np.array(Y, ndmin=2)
Expand Down
17 changes: 6 additions & 11 deletions control/tests/modelsimp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ def testMarkovSignature(self, matarrayout, matarrayin):
H = markov(np.transpose(Y), np.transpose(U), m, transpose=True)
np.testing.assert_array_almost_equal(H, np.transpose(Htrue))

# Default (in v0.8.4 and below) should be transpose=True (w/ warning)
with pytest.warns(UserWarning, match="assumed to be in rows.*"
"change in a future release"):
# Generate Markov parameters without any arguments
H = markov(np.transpose(Y), np.transpose(U), m)
np.testing.assert_array_almost_equal(H, np.transpose(Htrue))

# Generate Markov parameters without any arguments
H = markov(Y, U, m)
np.testing.assert_array_almost_equal(H, Htrue)

# Test example from docstring
T = np.linspace(0, 10, 100)
Expand All @@ -65,9 +61,8 @@ def testMarkovSignature(self, matarrayout, matarrayin):

# Make sure MIMO generates an error
U = np.ones((2, 100)) # 2 inputs (Y unchanged, with 1 output)
with pytest.warns(UserWarning):
with pytest.raises(ControlMIMONotImplemented):
markov(Y, U, m)
with pytest.raises(ControlMIMONotImplemented):
markov(Y, U, m)

# Make sure markov() returns the right answer
@pytest.mark.parametrize("k, m, n",
Expand Down Expand Up @@ -108,7 +103,7 @@ def testMarkovResults(self, k, m, n):
T = np.array(range(n)) * Ts
U = np.cos(T) + np.sin(T/np.pi)
_, Y, _ = forced_response(Hd, T, U, squeeze=True)
Mcomp = markov(Y, U, m, transpose=False)
Mcomp = markov(Y, U, m)

# Compare to results from markov()
np.testing.assert_array_almost_equal(Mtrue, Mcomp)
Expand Down