Ejemplo n.º 1
0
/**
 * @brief Computes an array of the exponentials in the transport equation,
 *        \f$ exp(-\frac{\Sigma_t * l}{sin(\theta)}) \f$, for each energy group
 *        and polar angle for a given Track segment.
 * @param curr_segment pointer to the Track segment of interest
 * @param exponentials the array to store the exponential values
 */
void VectorizedSolver::computeExponentials(segment* curr_segment,
                                           FP_PRECISION* exponentials) {

  FP_PRECISION length = curr_segment->_length;
  FP_PRECISION* sigma_t = curr_segment->_material->getSigmaT();

  /* Evaluate the exponentials using the linear interpolation table */
  if (_interpolate_exponential) {
    FP_PRECISION tau;
    int index;

    for (int e=0; e < _num_groups; e++) {
      for (int p=0; p < _num_polar; p++) {
        tau = sigma_t[e] * length;
        index = round_to_int(tau * _inverse_exp_table_spacing);
        index *= _two_times_num_polar;
        exponentials(p,e) = (1. - (_exp_table[index+2 * p] * tau +
                             _exp_table[index + 2 * p +1]));
      }
    }
  }

  /* Evalute the exponentials using the intrinsic exp(...) function */
  else {

    int tid = omp_get_thread_num();

    FP_PRECISION* sinthetas = _quad->getSinThetas();
    FP_PRECISION* taus = &_thread_taus[tid*_polar_times_groups];

    /* Initialize the tau argument for the exponentials */
    for (int p=0; p < _num_polar; p++) {

      for (int v=0; v < _num_vector_lengths; v++) {

        #pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          taus(p,e) = -sigma_t[e] * length / sinthetas[p];
      }
    }

    /* Evaluate the negative of the exponentials using Intel's MKL */
    #ifdef SINGLE
    vsExp(_polar_times_groups, taus, exponentials);
    #else
    vdExp(_polar_times_groups, taus, exponentials);
    #endif

    /* Compute one minus the exponentials */
    for (int p=0; p < _num_polar; p++) {

      for (int v=0; v < _num_vector_lengths; v++) {

        #pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          exponentials(p,e) = 1.0 - exponentials(p,e);
      }
    }
  }
}
Ejemplo n.º 2
0
/**
 * @brief Computes an array of the exponentials in the transport equation,
 *        \f$ exp(-\frac{\Sigma_t * l}{sin(\theta)}) \f$, for each energy group
 *        and polar angle for a given Track segment.
 * @param curr_segment pointer to the Track segment of interest
 * @param exponentials the array to store the exponential values
 */
void VectorizedSolver::computeExponentials(segment* curr_segment,
                                           FP_PRECISION* exponentials) {

  FP_PRECISION length = curr_segment->_length;
  FP_PRECISION* sigma_t = curr_segment->_material->getSigmaT();

  /* Evaluate the exponentials using the linear interpolation table */
  if (_exp_evaluator->isUsingInterpolation()) {
    FP_PRECISION tau;

    for (int e=0; e < _num_groups; e++) {
      tau = length * sigma_t[e];
      for (int p=0; p < _num_polar; p++)
        exponentials(p,e) = _exp_evaluator->computeExponential(tau, p);
    }
  }

  /* Evalute the exponentials using the intrinsic exp(...) function */
  else {

    int tid = omp_get_thread_num();
    FP_PRECISION* sin_thetas = _polar_quad->getSinThetas();
    FP_PRECISION* taus = &_thread_taus[tid*_polar_times_groups];

    /* Initialize the tau argument for the exponentials */
    for (int p=0; p < _num_polar; p++) {

      for (int v=0; v < _num_vector_lengths; v++) {

#pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          taus(p,e) = -sigma_t[e] * length;

#pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          taus(p,e) /= sin_thetas[p];
      }
    }

    /* Evaluate the negative of the exponentials using Intel's MKL */
#ifdef SINGLE
    vsExp(_polar_times_groups, taus, exponentials);
#else
    vdExp(_polar_times_groups, taus, exponentials);
#endif

    /* Compute one minus the exponentials */
    for (int p=0; p < _num_polar; p++) {

      for (int v=0; v < _num_vector_lengths; v++) {

#pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          exponentials(p,e) = 1.0 - exponentials(p,e);
      }
    }
  }
}
Ejemplo n.º 3
0
void NeuralNetwork::predictHelper(Mat &V, vector<float> &predictions)
{
	vector<float> exponentials(LABEL_SIZE);
	float exponentialSum = 0;

	// Compute softmax values
	//#pragma omp parallel for reduction(+:exponentialSum)
	for (int i = 0; i < LABEL_SIZE; i++)
	{
		exponentials[i] = expf(V.at<float>(i, 0));
		if (isinf(exponentials[i]))
			exponentials[i] = INFINITY;
		exponentialSum += exponentials[i];
	}

	if (exponentialSum == 0)
	{
		exponentialSum = 0.0000001;
	}

	// Compute predictions
	//#pragma omp parallel for
	for (int i = 0; i < LABEL_SIZE; i++)
	{
		//predictions.push_back(exponentials[i] / exponentialSum);
		predictions[i] = exponentials[i] / exponentialSum;
		if (isinf(predictions[i]) || predictions[i] > 1)
			predictions[i] = 1;
		else if (predictions[i] < 0)
			predictions[i] = 0;
	}
}