Skip to content
Snippets Groups Projects
Commit 7ed19eab authored by Anders Markvardsen's avatar Anders Markvardsen
Browse files

Upgrade ints with size_ts for the cost functions. re #2897

parent 79d665ac
No related branches found
No related tags found
No related merge requests found
......@@ -50,11 +50,11 @@ public:
/// Calculate value of cost function from observed
/// and calculated values
virtual double val(const double* yData, const double* inverseError, double* yCal, const int& n);
virtual double val(const double* yData, const double* inverseError, double* yCal, const size_t& n);
/// Calculate the derivatives of the cost function
virtual void deriv(const double* yData, const double* inverseError, const double* yCal,
const double* jacobian, double* outDerivs, const int& p, const int& n);
const double* jacobian, double* outDerivs, const size_t& p, const size_t& n);
private:
/// name of this minimizer
......
......@@ -49,11 +49,11 @@ public:
/// Calculate value of cost function from observed
/// and calculated values
virtual double val(const double* yData, const double* inverseError, double* yCal, const int& n);
virtual double val(const double* yData, const double* inverseError, double* yCal, const size_t& n);
/// Calculate the derivatives of the cost function
virtual void deriv(const double* yData, const double* inverseError, const double* yCal,
const double* jacobian, double* outDerivs, const int& p, const int& n);
const double* jacobian, double* outDerivs, const size_t& p, const size_t& n);
private:
/// name of this minimizer
......
......@@ -48,11 +48,11 @@ public:
/// Calculate value of cost function from observed
/// and calculated values
virtual double val(const double* yData, const double* inverseError, double* yCal, const int& n) = 0;
virtual double val(const double* yData, const double* inverseError, double* yCal, const size_t& n) = 0;
/// Calculate the derivatives of the cost function
virtual void deriv(const double* yData, const double* inverseError, const double* yCal,
const double* jacobian, double* outDerivs, const int& p, const int& n) = 0;
const double* jacobian, double* outDerivs, const size_t& p, const size_t& n) = 0;
};
/**
......
......@@ -20,16 +20,16 @@ DECLARE_COSTFUNCTION(CostFuncIgnorePosPeaks,Ignore positive peaks)
/// @param yCal :: Calculated y
/// @param n :: The number of points
/// @return The calculated cost value
double CostFuncIgnorePosPeaks::val(const double* yData, const double* inverseError, double* yCal, const int& n)
double CostFuncIgnorePosPeaks::val(const double* yData, const double* inverseError, double* yCal, const size_t& n)
{
for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
yCal[i] = ( yData[i] - yCal[i] ) * inverseError[i];
double retVal = 0.0;
double a = 2.0 / sqrt(M_PI);
double b = 1/sqrt(2.0);
for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
if ( yCal[i] <= 0.0 )
retVal += yCal[i]*yCal[i];
......@@ -41,16 +41,22 @@ DECLARE_COSTFUNCTION(CostFuncIgnorePosPeaks,Ignore positive peaks)
}
/// Calculate the derivatives of the cost function
/// @param yData :: Array of yData
/// @param inverseError :: Array of inverse error values
/// @param yCal :: Calculated y
/// @param jacobian :: Output jacobian
/// @param p :: The number of parameters
/// @param n :: The number of points
void CostFuncIgnorePosPeaks::deriv(const double* yData, const double* inverseError, const double* yCal,
const double* jacobian, double* outDerivs, const int& p, const int& n)
const double* jacobian, double* outDerivs, const size_t& p, const size_t& n)
{
double a = 2.0 / sqrt(M_PI);
double b = 1/sqrt(2.0);
for (int iP = 0; iP < p; iP++)
for (size_t iP = 0; iP < p; iP++)
{
outDerivs[iP] = 0.0;
for (int iY = 0; iY < n; iY++)
for (size_t iY = 0; iY < n; iY++)
{
if ( yCal[iY] >= yData[iY] )
outDerivs[iP] += 2.0*(yCal[iY]-yData[iY]) * jacobian[iY*p + iP]
......
......@@ -17,27 +17,33 @@ DECLARE_COSTFUNCTION(CostFuncLeastSquares,Least squares)
/// @param yCal :: Calculated y
/// @param n :: The number of points
/// @return The calculated cost value
double CostFuncLeastSquares::val(const double* yData, const double* inverseError, double* yCal, const int& n)
double CostFuncLeastSquares::val(const double* yData, const double* inverseError, double* yCal, const size_t& n)
{
for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
yCal[i] = ( yCal[i] - yData[i] ) * inverseError[i];
double retVal = 0.0;
for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
retVal += yCal[i]*yCal[i];
return retVal;
}
/// Calculate the derivatives of the cost function
/// @param yData :: Array of yData
/// @param inverseError :: Array of inverse error values
/// @param yCal :: Calculated y
/// @param jacobian :: Output jacobian
/// @param p :: The number of parameters
/// @param n :: The number of points
void CostFuncLeastSquares::deriv(const double* yData, const double* inverseError, const double* yCal,
const double* jacobian, double* outDerivs, const int& p, const int& n)
const double* jacobian, double* outDerivs, const size_t& p, const size_t& n)
{
for (int iP = 0; iP < p; iP++)
for (size_t iP = 0; iP < p; iP++)
{
outDerivs[iP] = 0.0;
for (int iY = 0; iY < n; iY++)
for (size_t iY = 0; iY < n; iY++)
{
outDerivs[iP] += 2.0*(yCal[iY]-yData[iY]) * jacobian[iY*p + iP]
* inverseError[iY]*inverseError[iY];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment