function [ fit, z ] = chain_init ( chain_num, gen_num, par_num, ...
  problem_prior_sample, problem_sample_likelihood )

%*****************************************************************************80
%
%% chain_init() starts Markov chains from a prior distribution.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 January 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer CHAIN_NUM, the total number of chains.
%    3 <= CHAIN_NUM.
%
%    integer GEN_NUM, the total number of generations.
%    2 <= GEN_NUM.
%
%    integer PAR_NUM, the total number of parameters.
%    1 <= PAR_NUM.
%
%    function zp = problem_prior_sample ( par_num )
%
%    function value = problem_sample_likelihood ( par_num, zp )
%
%  Output:
%
%    real FIT(CHAIN_NUM,GEN_NUM), the likelihood of
%    each sample.
%
%    real Z(PAR_NUM,CHAIN_NUM,GEN_NUM), the Markov chain 
%    sample data.
%
  fit = zeros ( chain_num, gen_num );
  z = zeros ( par_num, chain_num, gen_num );

  for i = 1 : chain_num

    zp = problem_prior_sample ( par_num );

    z(1:par_num,i,1) = zp(1:par_num);

    fit(i,1) = problem_sample_likelihood ( par_num, zp );

  end

  return
end
