Computes the \(\boldsymbol{\Gamma}\) matrix and the \(\boldsymbol{g}\) vector for generalized score matching.
Here, \(\boldsymbol{\Gamma}\) is block-diagonal, and in the non-profiled non-centered setting, the \(j\)-th block is composed of \(\boldsymbol{\Gamma}_{\mathbf{KK},j}\), \(\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta},j}\) and its transpose, and finally \(\boldsymbol{\Gamma}_{\boldsymbol{\eta\eta},j}\). In the centered case, only \(\boldsymbol{\Gamma}_{\mathbf{KK},j}\) is computed. In the profiled non-centered case, $$\boldsymbol{\Gamma}_{j}\equiv\boldsymbol{\Gamma}_{\mathbf{KK},j}-\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta},j}\boldsymbol{\Gamma}_{\boldsymbol{\eta}\boldsymbol{\eta},j}^{-1}\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta}}^{\top}.$$
Similarly, in the non-profiled non-centered setting, \(\boldsymbol{g}\) can be partitioned \(p\) parts, each with a \(p\)-vector \(\boldsymbol{g}_{\mathbf{K},j}\) and a scalar \(g_{\boldsymbol{\eta},j}\). In the centered setting, only \(\boldsymbol{g}_{\mathbf{K},j}\) is needed. In the profiled non-centered case, $$\boldsymbol{g}_j\equiv\boldsymbol{g}_{\mathbf{K},j}-\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta},j}\boldsymbol{\Gamma}_{\boldsymbol{\eta\eta},j}^{-1}g_{\boldsymbol{\eta},j}.$$
The formulae for the pieces above are
$$\boldsymbol{\Gamma}_{\mathbf{KK},j}\equiv\frac{1}{n}\sum_{i=1}^nh\left(X_j^{(i)}\right){X_j^{(i)}}^{2a-2}{\boldsymbol{X}^{(i)}}^a{{\boldsymbol{X}^{(i)}}^a}^{\top},$$
$$\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta},j}\equiv-\frac{1}{n}\sum_{i=1}^nh\left(X_j^{(i)}\right){X_j^{(i)}}^{a+b-2}{\boldsymbol{X}^{(i)}}^a,$$
$$\boldsymbol{\Gamma}_{\boldsymbol{\eta\eta},j}\equiv\frac{1}{n}\sum_{i=1}^nh\left(X_j^{(i)}\right){X_j^{(i)}}^{2b-2},$$
$$\boldsymbol{g}_{\mathbf{K},j}\equiv\frac{1}{n}\sum_{i=1}^n\left(h'\left(X_j^{(i)}\right){X_j^{(i)}}^{a-1}+(a-1)h\left(X_j^{(i)}\right){X_j^{(i)}}^{a-2}\right){\boldsymbol{X}^{(i)}}^a+ah\left(X_j^{(i)}\right){X_j^{(i)}}^{2a-2}\boldsymbol{e}_{j,p},$$
$$\boldsymbol{g}_{\boldsymbol{\eta},j}\equiv\frac{1}{n}\sum_{i=1}^n-h'\left(X_j^{(i)}\right){X_j^{(i)}}^{b-1}-(b-1)h\left(X_j^{(i)}\right){X_j^{(i)}}^{b-2},$$
where \(\boldsymbol{e}_{j,p}\) is the \(p\)-vector with 1 at the \(j\)-th position and 0 elsewhere.
In the profiled non-centered setting, the function also returns \(t_1\) and \(t_2\) defined as
$$\boldsymbol{t}_1\equiv\boldsymbol{\Gamma}_{\boldsymbol{\eta\eta}}^{-1}\boldsymbol{g}_{\boldsymbol{\eta}},\quad\boldsymbol{t}_2\equiv\boldsymbol{\Gamma}_{\boldsymbol{\eta\eta}}^{-1}\boldsymbol{\Gamma}_{\mathbf{K}\boldsymbol{\eta}}^{\top},$$
so that \(\hat{\boldsymbol{\eta}}=\boldsymbol{t}_1-\boldsymbol{t}_2\mathrm{vec}(\hat{\mathbf{K}}).\)