I have a function $s^Tx_ix_j^Ts$ where $s \in \mathbf{R^d}$ and $x \in \mathbf{R^d}$ which is computed at every index of matrix which means $K_{ij}=s^Tx_ix_j^Ts$ with $K_{ij} \in \mathbf{R^{n \ x \ n}}$. Now if i take any vector $v \in \mathbf{R^n}$ then how to multiply that vector with matrix with matrix in this form $v^T.K.v$. What I have done so far is
$\sum_{i,j} z_i.(s_i.x_i.x_j.s_j).z_j$
Is it possible to complete the square of the above term with the one given below?
$\sum_{i} ||z_i.s_i.x_i||^2$.
$\def\e{\varepsilon} \def\E{\cal E}$ Let $\{\e_i\}$ denote the standard basis vectors, and collect the $\{x_i\}$ into the columns of a matrix $X$ such that $$X = \big[x_1\;x_2\;\ldots\;x_n\big]\quad\iff\quad x_i=X\e_i$$ Then the $K$ matrix can be written as $$\eqalign{ K_{ij} &= s^T(X\e_i)(X\e_j)^Ts \\ &= s^T\!X\e_i\;\e_j^TX^T\!s \\ &= \e_i^T X^T\!s\;s^T\!X\e_j &\doteq\; \e_i^T\,K\,\e_j \\ K &= X^Tss^TX \\ &= kk^T \qquad\qquad\Big(k &\doteq X^Ts\Big) \\ }$$ The scalar product in question is therefore $$\eqalign{ v^TKv &= v^Tkk^Tv = \|k^Tv\|^2 = \|s^TXv\|^2 \\ }$$