--------------------------------------------------- lines 6-59 of file: example/user/fix_constraint.cpp --------------------------------------------------- {xrst_begin fix_constraint.cpp} Using Constraints: Example and Test ################################### Model ***** .. math:: \B{p}( y_i | \theta , u ) \sim \B{N} ( u_i + \theta_i , 1 ) .. math:: \B{p}( u_i | \theta ) \sim \B{N} ( 0 , 1 ) .. math:: \B{p}( \theta ) \sim \B{U} ( - \infty , + \infty ) where :math:`\B{U} ( - \infty , + \infty )` is the improper uniform prior on :math:`[- \infty , + \infty ]`. It follows that the Laplace approximation is exact and .. math:: \B{p}( y_i | \theta ) \sim \B{N} ( \theta_i , 2 ) The corresponding objective for the fixed effects is equivalent to: .. math:: \frac{1}{2} \sum_{i=0}^{N-1} ( y_i - \theta_i )^2 For this problem we add the explicit constraint .. math:: \frac{1}{2} \sum_i \theta_i^2 = 1; The corresponding Lagrangian is .. math:: L( \theta , \lambda ) = \frac{1}{2} \sum_{i=0}^{N-1} ( y_i - \theta_i )^2 + \lambda \left( \frac{1}{2} \sum_i \theta_i^2 - 1 \right) {xrst_literal // BEGIN C++ // END C++ } {xrst_end fix_constraint.cpp}