function value = p2_sample_likelihood ( par_num, zp )

%*****************************************************************************80
%
%% P2_SAMPLE_LIKELIHOOD computes the log likelihood function.
%
%  Discussion:
%
%    "A 10-dimensional twisted Gaussian density function, given by the
%    unnormalized density
%      pi_b(x) proportional to pi(phi_b(x)),
%    with
%      phi_b(x) = (x1, x2+bx1^2-100b,x3,...,x10).
%    Here, pi signifies the density of a multivariate normal distribution,
%    Nd(0,Sigma), with Sigma=diag(100,1,...,1), and phi_b is a function that
%    is used to transform pi to a twisted distribution."
%
%    The value b = 0.01 corresponds to a mildly nonlinear problem,
%    and b = 0.1 to a highly nonlinear problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    25 January 2018
%
%  Author:
%
%    John Burkardt
%
%  Input parameters:
%
%    Input, integer PAR_NUM, the total number of parameters.
%    1 <= PAR_NUM.
%
%    Input, real ZP(PAR_NUM), a sample.
%
%  Output parameters:
%
%    Output, real VALUE, the log likelihood function 
%    for the sample.
%
  b = 0.01;

  y2 = zp(2) + b * zp(1) * zp(1) - 100.0 * b;

  xcx = zp(1) * zp(1) / 100.0 + y2 * y2;
  for i = 3 : par_num
    xcx = xcx + zp(i) * zp(i);
  end

  value = ...
    - 0.5 * par_num * log ( 2.0 * pi ) ...
    - 0.5 * log ( 100.0 ) ...
    - 0.5 * xcx;

  return
end

