Skip to content

Commit 3739ce6

Browse files
Florian WilhelmFlorian Wilhelm
Florian Wilhelm
authored and
Florian Wilhelm
committed
Cleanups of masked arrays
1 parent 6fb35cd commit 3739ce6

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

pydse/arma.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ARMA(object):
3333
u: (mxt) matrix of input variables
3434
TREND: (pxt) matrix like y or a p-dim vector
3535
"""
36-
def __init__(self, A=None, B=None, C=None, TREND=None, rand_state=None):
36+
def __init__(self, A, B=None, C=None, TREND=None, rand_state=None):
3737
self.A = np.asarray(A[0]).reshape(A[1], order='F')
3838
if B is not None:
3939
self.B = np.asarray(B[0]).reshape(B[1], order='F')
@@ -58,14 +58,6 @@ def __init__(self, A=None, B=None, C=None, TREND=None, rand_state=None):
5858
else:
5959
self.rand = np.random.RandomState()
6060

61-
def _set_array_by_mask(self, arr, mask, values):
62-
mask = np.where(~mask)
63-
arr[mask] = values
64-
65-
def _get_array_by_mask(self, arr, mask):
66-
mask = np.where(~mask)
67-
return arr[mask]
68-
6961
def _get_num_non_consts(self):
7062
a = np.sum(~self.Aconst)
7163
b = np.sum(~self.Bconst)
@@ -74,10 +66,9 @@ def _get_num_non_consts(self):
7466

7567
@property
7668
def non_consts(self):
77-
a, b, c = self._get_num_non_consts()
78-
A = self._get_array_by_mask(self.A, self.Aconst)
79-
B = self._get_array_by_mask(self.B, self.Bconst)
80-
C = self._get_array_by_mask(self.C, self.Cconst)
69+
A = self.A[~self.Aconst]
70+
B = self.B[~self.Bconst]
71+
C = self.C[~self.Cconst]
8172
return np.hstack([A, B, C])
8273

8374
@non_consts.setter
@@ -89,9 +80,9 @@ def non_consts(self, values):
8980
A_values = values[:a]
9081
B_values = values[a:a + b]
9182
C_values = values[a + b:a + b + c]
92-
self._set_array_by_mask(self.A, self.Aconst, A_values)
93-
self._set_array_by_mask(self.B, self.Bconst, B_values)
94-
self._set_array_by_mask(self.C, self.Cconst, C_values)
83+
self.A[~self.Aconst] = A_values
84+
self.B[~self.Bconst] = B_values
85+
self.C[~self.Cconst] = C_values
9586

9687
def _check_consistency(self, A, B, C, TREND):
9788
if A is None:
@@ -141,7 +132,7 @@ def simulate(self, y0=None, u0=None, sampleT=100, noise=None):
141132
u0 = u0 if u0 is not None else np.zeros((c, m))
142133

143134
# generate white noise if necessary
144-
if not noise:
135+
if noise is None:
145136
noise = self._get_noise(sampleT, p, b)
146137
w0, w = noise
147138

@@ -182,7 +173,7 @@ def forecast(self, y, u=None):
182173
m = self.C.shape[2] if self.C else 0
183174
TREND = self.TREND
184175

185-
# ToDo: Let these be parameters and do consistensy check
176+
# ToDo: Let these be parameters and do consistency check
186177
sampleT = predictT = y.shape[0]
187178
pred_err = np.zeros((sampleT, p))
188179

0 commit comments

Comments
 (0)