4
4
5
5
from __future__ import annotations
6
6
7
- from numpy import empty , ndarray
7
+ import numpy
8
+ from numpy import empty
8
9
from numpy .linalg import inv
9
10
10
11
from linearmodels .iv .covariance import (
11
12
KERNEL_LOOKUP ,
12
13
cov_kernel ,
13
14
kernel_optimal_bandwidth ,
14
15
)
15
- from linearmodels .typing import Float64Array
16
+ import linearmodels .typing . data
16
17
17
18
18
19
class _HACMixin :
19
20
def __init__ (self , kernel : str , bandwidth : float | None ) -> None :
20
21
self ._kernel : str | None = None
21
22
self ._bandwidth : float | None = None # pragma: no cover
22
- self ._moments : ndarray = empty ((0 ,)) # pragma: no cover
23
+ self ._moments : numpy . ndarray = empty ((0 ,)) # pragma: no cover
23
24
self ._check_kernel (kernel )
24
25
self ._check_bandwidth (bandwidth )
25
26
@@ -60,7 +61,9 @@ def _check_bandwidth(self, bandwidth: float | None) -> None:
60
61
if bandwidth < 0 :
61
62
raise ValueError ("bandwidth must be non-negative." )
62
63
63
- def _kernel_cov (self , z : Float64Array ) -> Float64Array :
64
+ def _kernel_cov (
65
+ self , z : linearmodels .typing .data .Float64Array
66
+ ) -> linearmodels .typing .data .Float64Array :
64
67
nobs = z .shape [0 ]
65
68
bw = self .bandwidth
66
69
kernel = self ._kernel
@@ -96,10 +99,10 @@ class HeteroskedasticCovariance:
96
99
97
100
def __init__ (
98
101
self ,
99
- xe : Float64Array ,
102
+ xe : linearmodels . typing . data . Float64Array ,
100
103
* ,
101
- jacobian : ndarray | None = None ,
102
- inv_jacobian : ndarray | None = None ,
104
+ jacobian : numpy . ndarray | None = None ,
105
+ inv_jacobian : numpy . ndarray | None = None ,
103
106
center : bool = True ,
104
107
debiased : bool = False ,
105
108
df : int = 0 ,
@@ -131,7 +134,7 @@ def config(self) -> dict[str, str | float]:
131
134
return {"type" : self .__class__ .__name__ }
132
135
133
136
@property
134
- def s (self ) -> Float64Array :
137
+ def s (self ) -> linearmodels . typing . data . Float64Array :
135
138
"""
136
139
Score/moment condition covariance
137
140
@@ -149,7 +152,7 @@ def s(self) -> Float64Array:
149
152
return (out + out .T ) / 2
150
153
151
154
@property
152
- def jacobian (self ) -> Float64Array :
155
+ def jacobian (self ) -> linearmodels . typing . data . Float64Array :
153
156
"""The Jacobian"""
154
157
if self ._jac is None :
155
158
assert self ._inv_jac is not None
@@ -158,7 +161,7 @@ def jacobian(self) -> Float64Array:
158
161
return self ._jac
159
162
160
163
@property
161
- def inv_jacobian (self ) -> Float64Array :
164
+ def inv_jacobian (self ) -> linearmodels . typing . data . Float64Array :
162
165
"""Inverse Jacobian"""
163
166
if self ._inv_jac is None :
164
167
assert self ._jac is not None
@@ -172,7 +175,7 @@ def square(self) -> bool:
172
175
return self ._square
173
176
174
177
@property
175
- def cov (self ) -> Float64Array :
178
+ def cov (self ) -> linearmodels . typing . data . Float64Array :
176
179
"""
177
180
Compute parameter covariance
178
181
@@ -229,10 +232,10 @@ class KernelCovariance(HeteroskedasticCovariance, _HACMixin):
229
232
230
233
def __init__ (
231
234
self ,
232
- xe : Float64Array ,
235
+ xe : linearmodels . typing . data . Float64Array ,
233
236
* ,
234
- jacobian : ndarray | None = None ,
235
- inv_jacobian : ndarray | None = None ,
237
+ jacobian : numpy . ndarray | None = None ,
238
+ inv_jacobian : numpy . ndarray | None = None ,
236
239
kernel : str | None = None ,
237
240
bandwidth : float | None = None ,
238
241
center : bool = True ,
@@ -262,7 +265,7 @@ def config(self) -> dict[str, str | float]:
262
265
return out
263
266
264
267
@property
265
- def s (self ) -> Float64Array :
268
+ def s (self ) -> linearmodels . typing . data . Float64Array :
266
269
"""
267
270
Score/moment condition covariance
268
271
@@ -289,11 +292,15 @@ class HeteroskedasticWeight:
289
292
Flag indicating to center the moments when computing the weights
290
293
"""
291
294
292
- def __init__ (self , moments : Float64Array , center : bool = True ) -> None :
295
+ def __init__ (
296
+ self , moments : linearmodels .typing .data .Float64Array , center : bool = True
297
+ ) -> None :
293
298
self ._moments = moments
294
299
self ._center = center
295
300
296
- def w (self , moments : Float64Array ) -> Float64Array :
301
+ def w (
302
+ self , moments : linearmodels .typing .data .Float64Array
303
+ ) -> linearmodels .typing .data .Float64Array :
297
304
"""
298
305
Score/moment condition weighting matrix
299
306
@@ -335,7 +342,7 @@ class KernelWeight(HeteroskedasticWeight, _HACMixin):
335
342
336
343
def __init__ (
337
344
self ,
338
- moments : Float64Array ,
345
+ moments : linearmodels . typing . data . Float64Array ,
339
346
center : bool = True ,
340
347
kernel : str | None = None ,
341
348
bandwidth : float | None = None ,
@@ -344,7 +351,9 @@ def __init__(
344
351
_HACMixin .__init__ (self , kernel , bandwidth )
345
352
super ().__init__ (moments , center = center )
346
353
347
- def w (self , moments : Float64Array ) -> Float64Array :
354
+ def w (
355
+ self , moments : linearmodels .typing .data .Float64Array
356
+ ) -> linearmodels .typing .data .Float64Array :
348
357
"""
349
358
Score/moment condition weighting matrix
350
359
0 commit comments