Layer_servo_system_sampler< RandNumberGenerator, ComputeLayerIndex >::
Layer_servo_system_sampler(
			   const  CategNonParamCdf& target,
			   double constraint,
			   ForwardIterator first, ForwardIterator last,
			   const RandNumberGenerator& rand,
			   const ComputeLayerIndex& getLayerIndex
			   ) : gen_(rand), getLayerIndex_(getLayerIndex)
{
	// constraint can vary from 0 to 1
	mu_ = constraint / ( 1.00001 - constraint);
	
	nb_of_categories_ = target[0].size();
	
	for (int i=0; i<target.size(); i++)
	{
		vector<double> local_pdf( target[i].p_begin(), target[i].p_end() );
		target_pdf_.push_back( local_pdf );

		vector<double> prob;
		nb_of_data_.push_back(0);
		
		for (int j=0; j<target[0].size(); j++)
			prob.push_back(0);
		
		current_histogram_.push_back(prob);
	}
	
	int z;
	// Compute the pdf of range [first, last)
	for( ; first != last ; ++first) 
	{
		if( ! first->is_informed() )	continue;

		z = getLayerIndex_( *first );
		current_histogram_[z][ int( first->property_value() ) ] ++;
		nb_of_data_[z] ++;

	}
}