Estimate a response function from instrument restrictions rather than prediction error.
Why not regress the outcome on the treatment?
Consider Y=h_0(T)+U, with E[U\mid Z]=0 but potentially E[U\mid T]\ne0. Ordinary prediction learns E[Y\mid T], not necessarily h_0. An instrument restriction instead asks whether the fitted residual is orthogonal to every function of Z. Identification still requires enough variation in the instruments: a flexible optimizer cannot supply completeness or instrument validity.
Trex connects a differentiable torch.nn.Module for h_\theta to a moment callback \rho_\theta=\rho(h_\theta(T),Y). For an IV regression, use \rho_\theta=h_\theta(T)-Y. Both estimators below operate on the complete sample; they are not stochastic-minibatch IV estimators.
Two finite-sample objectives
Maximum moment restriction (MMR) uses a positive-definite kernel:
Trex uses an RBF kernel, with a median-distance bandwidth when none is given. This is the nonnegative, diagonal-including quadratic criterion, not an unbiased off-diagonal U-statistic. The kernel matrix costs O(n^2) memory. For vector-valued moments the objective sums the componentwise quadratic forms. Instrument scaling and bandwidth affect the criterion’s geometry.
Sieve minimum distance (SMD) replaces all instrument functions by a finite polynomial basis B_i=b(Z_i):
Trex standardizes instruments before constructing the polynomial sieve. degree, interactions, and the ridge r determine the approximation. Increasing the degree can add weak or nearly redundant moments; it is not a free improvement in identification.
Worked example: an endogenous nonlinear regressor
Here T=0.9Z+V and U=0.7V+\varepsilon. We know the response is quadratic and estimate its coefficients. This deliberately separates the instrument problem from neural-network approximation and local minima.
Figure 1: The structural curve and fits. OLS targets a different conditional expectation because treatment is endogenous.
Diagnostics and scope
Inspect the fitted criterion and loss history, and evaluate moments on new observations. A small training loss can mean overfitting the instrument sample. Compare sensitivity to bandwidth or sieve degree on validation moments rather than selecting by in-sample loss alone. The hsic helper is a dependence diagnostic, not a replacement for an identification argument.
These classes do not supply a complete inferential procedure for learned functions. Their interfaces accept neural modules, but neither automatic standard errors nor causal validity follows from that flexibility. Account for regularization, approximation, weak instruments, and tuning in any inferential extension. For finite-dimensional unconditional moments and sandwich covariances, see GMM.