function [ log_post0, log_post1, log_lkld0, log_lkld1 ] = compute_log_post_cbig( x, cbigObject )

  % Goes with "train_cbig_on_hist.m" and "compute_post_cbig"
  
  if nargin < 2
    error( [ mfilename '.compute_log_post_cbig() needs 5 input arguments.' ] );
  end

  mean_v = cbigObject.mean_v;
  std_v  = cbigObject.std_v;
  prior0     = cbigObject.prior_v( 1 );
  prior1     = cbigObject.prior_v( 2 );
  
  % Remember the size
  siz = size( x );
  x = x(:);
  
  % Normalization constants so that the integral of each likelihood function
  % over the whole space is 1
  Z0 = normcdf( mean_v( 2 ), mean_v( 1 ), std_v( 1 ) );
  Z1 = normcdf( 2 * mean_v( 2 ) - mean_v( 1 ), mean_v( 2 ), std_v( 2 ) );
  
  % first get the likelihoods of each data point
  swarn = warning; warning off;
  log_lkld0 = -log( Z0 ) + log_normpdf( x, mean_v( 1 ), std_v( 1 ) ) + log( double( x < mean_v( 2 ) ) );
  log_lkld1 = -log( Z1 ) + log_normpdf( x, mean_v( 2 ), std_v( 2 ) ) + log( double( x > mean_v( 1 ) ) );
  warning( swarn );
  
  % second compute the posteriors of each data point
  log_post0 = log_lkld0 + log( prior0 );
  log_post1 = log_lkld1 + log( prior1 );
  tmp = logsum( log_post0, log_post1 );
  log_post0 = log_post0 - tmp;
  log_post1 = log_post1 - tmp;
  
  % sanity check
  if any( abs( logsum( log_post0, log_post1 ) ) > 1e-10 )
    error( 'insane' )
  end
  
  % Reset the size correctly
  
  log_post0 = reshape( log_post0, siz );
  log_post1 = reshape( log_post1, siz );
  log_lkld0 = reshape( log_lkld0, siz );
  log_lkld1 = reshape( log_lkld1, siz );
  