Project: s41467-024-53352-9 | Function: auxiliary_forward_backward (cpp)

system: You are an expert C++ programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow C++ best practices and maintain consistent code style.
Return **only** the complete C++ function code.

user: Complete this C++ function:

**DESCRIPTION:** Implements forward and backward pass for auxiliary predictor in split learning, calculating predictions and gradients with combined loss from labels and main predictor

**KEY TERMS:** {
  "mu": "weight for true label loss (0.5)",
  "gamma": "weight for consistency loss (0.5)",
  "Extractor_activation": "activations from feature extractor",
  "Auxiliary_weight": "auxiliary predictor weights",
  "Prediction_auxiliary": "auxiliary predictor output",
  "Prediction": "main predictor output",
  "Loss": "combined loss function",
  "Extractor_activation_gradient": "gradients for extractor"
}

**CONTEXT CODE:**
		
				 //**Calculate gradient	of regressor
				 for(int i=0; i<Output_dimension; i++ ) 
				 {    
						Regression_bias_gradient[i] += Loss[i] / Batch_size;
						for(int j=0; j < Hidden_dimension ; j++ ) 
						{
								Regression_weight_gradient[j*Output_dimension + i] += Processor_activation[k*Hidden_dimension+j] * Loss[i] / Batch_size;
						}
				}
				
				 //**Calculate activation gradient of processor
				 for(int i=0; i<Hidden_dimension; i++) 
				 {    
							Accumb = 0.0;
							for(int j=0; j<Output_dimension; j++) 
							{
									Accumb += Regression_weight[i*Output_dimension+j] * Loss[j];
							}
							Processor_activation_gradient[k*Hidden_dimension+i] = Accumb;
					}
		}
}

/******************************************************************
* Forward and backward pass of auxiliary regressor
******************************************************************/
/******************************************************************
* Forward and backward pass of auxiliary regressor
******************************************************************/
void auxiliary_forward_backward(void){
    float Accumf = 0.0;
    float Accumb = 0.0;
    const float mu = 0.5f;
    const float gamma = 0.5f;

    for(int k=0; k<Batch_size; k++)
    {
        //**Forward pass: Calculate auxiliary prediction
        for(int i=0; i<Output_dimension; i++) 
        {
            Accumf = Auxiliary_bias[i];
            for(int j=0; j<Hidden_dimension; j++) 
            {
                Accumf += Extractor_activation[k*Hidden_dimension + j] * Auxiliary_weight[j*Output_dimension + i];
            }
            Prediction_auxiliary[i] = Accumf;
        }

        //**Calculate combined loss derivative (dL/dPrediction_auxiliary)
        float auxiliary_loss[Output_dimension];
        for(int i=0; i<Output_dimension; i++) 
        {
            float label_diff = Prediction_auxiliary[i] - Label[k*Output_dimension + i];
            float consistency_diff = Prediction_auxiliary[i] - Prediction[k*Output_dimension + i];
            auxiliary_loss[i] = mu * label_diff + gamma * consistency_diff;
        }

        //**Backward pass: Update auxiliary predictor gradients
        for(int i=0; i<Output_dimension; i++ ) 
        {    
            // Accumulate bias gradient
            Auxiliary_bias_gradient[i] += auxiliary_loss[i] / Batch_size;

            // Accumulate weight gradient
            for(int j=0; j < Hidden_dimension ; j++ ) 
            {
                Auxiliary_weight_gradient[j*Output_dimension + i] += Extractor_activation[k*Hidden_dimension + j] * auxiliary_loss[i] / Batch_size;
            }
        }

        //**Calculate extractor activation gradient
        for(int j=0; j<Hidden_dimension; j++) 
        {    
            Accumb = 0.0;
            for(int i=0; i<Output_dimension; i++) 
            {
                Accumb += Auxiliary_weight[j*Output_dimension + i] * auxiliary_loss[i];
            }
            Extractor_activation_gradient[k*Hidden_dimension + j] = Accumb;
        }
    }
}

/******************************************************************
* Backward pass of extractor in federated round
******************************************************************/
void extractor_backward(void){
		
		float HiddenDelta [Hidden_dimension] = {0};
		for(int k=0; k<Batch_size; k++)
		{				 
				 //**Calculate gradient of extractor
				 for(int i=0 ; i<Hidden_dimension; i++ ) 
				 {   
						HiddenDelta[i] = (Extractor_activation[k*Hidden_dimension+i]>0)?Extractor_activation_gradient[k*Hidden_dimension+i]:0;
						Extractor_bias_gradient[i] += HiddenDelta[i]/Batch_size;
						for(int j=0; j<Input_dimension; j++)
						{ 
								Extractor_weight_gradient[j*Hidden_dimension+i] += Input[k][j] * HiddenDelta[i]/Batch_size;           
						}
				}
				
		}
}

/******************************************************************
* Backward pass of extractor in fine-tuning round
******************************************************************/
void extractor_backward_finetune(void){
		
		float HiddenDelta [Hidden_dimension] = {0};
		for(int k=0; k<Batch_size; k++)
		{				 
				 //**Calculate gradient of extractor
				 for(int i=0 ; i<Hidden_dimension; i++ ) 
				 {   
						HiddenDelta[i] = (Extractor_activation[k*Hidden_dimension+i]>0)?Extractor_activation_gradient[k*Hidden_dimension+i]:0;
						Extractor_bias_gradient[i] += HiddenDelta[i]/Batch_size;
						for(int j=0; j<Input_dimension; j++)
						{ 
								Extractor_weight_gradient[j*Hidden_dimension+i] += Input[k][j] * HiddenDelta[i]/Batch_size;           
						}
				}
				
		}
}

/******************************************************************
* Model test of extractor
******************************************************************/
void extractor_test(void)
{
    float Accum=0;
		for (int i = 0; i < Hidden_dimension; i++) 
		{
					Accum = Extractor_bias[i];
					for (int j = 0; j < Input_dimension; j++) 
					{
							Accum += Input_single[j] * Extractor_weight[j*Hidden_dimension + i];
					}
					Extractor_activation_test[i] = (Accum>0)?Accum:0;
		}
}					 
	
/******************************************************************
* Model test of regressor
******************************************************************/
void regressor_test(void)
{