Exemplo n.º 1
0
/**
 * Calculates the gradient of chi-square using the experimental data, calculated
 * data and errors
 * @return : The gradient of chi-square as a vector
 */
std::vector<double> MaxentCalculator::calculateChiGrad() const {

  // Calculates the gradient of Chi
  // CGrad_i = -2 * [ data_i - dataCalc_i ] / [ error_i ]^2

  if ((m_data.size() != m_errors.size()) ||
      (m_dataCalc.size() % m_data.size())) {
    // Data and errors must have the same number of data points
    // but the reconstructed (calculated) data may contain more points
    throw std::runtime_error("Cannot compute gradient of Chi");
  }

  // We only consider the experimental data points to calculate chi grad
  size_t sizeDat = m_data.size();
  // The number of calculated data points can be bigger than the number of
  // experimental data points I am not sure how we should deal with this
  // situation. On the one hand one can only consider real data and errors to
  // calculate chi-square, but on the other hand this method should return a
  // vector of size equal to the size of the calculated data, so I am just
  // setting the 'leftovers' to zero. This is what is done in the original
  // muon code.
  size_t sizeDatCalc = m_dataCalc.size();
  std::vector<double> cgrad(sizeDatCalc, 0.);
  auto dpoints = static_cast<double>(sizeDat);
  for (size_t i = 0; i < sizeDat; i++) {
    if (m_errors[i] != 0)
      cgrad[i] = -2. * (m_data[i] - m_dataCalc[i]) / m_errors[i] / m_errors[i] /
                 dpoints;
  }

  return cgrad;
}
Exemplo n.º 2
0
void MainWindow::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    QLinearGradient lgrad(25,100,150,175);
    QRadialGradient rgrad(QPoint(100,100),100);
    QConicalGradient cgrad(QPoint(100,100),100);

    lgrad.setColorAt(0.0,Qt::red);
    lgrad.setColorAt(0.5,Qt::green);
    lgrad.setColorAt(1.0,Qt::blue);


    QRect rect(10,10,200,200);
    painter.fillRect(rect,lgrad);
    painter.fillRect(rect,rgrad);
    painter.fillRect(rect,cgrad);
}
Exemplo n.º 3
0
void F77_SUB(cgrad)(int *n, double x[], double grval[]) { 
  cgrad(n, x, grval) ;    
}