Skip to content

Commit

Permalink
updated Cpufit
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianjp88 committed Oct 18, 2017
1 parent c5ca798 commit fb4b277
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions Cpufit/lm_fit_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,32 @@ void LMFitCPP::calc_derivatives_gauss2drotated(
void LMFitCPP::calc_derivatives_gauss1d(
std::vector<float> & derivatives)
{
for (std::size_t x = 0; x < info_.n_points_; x++)
float * user_info_float = (float*)user_info_;
float x = 0.f;

for (std::size_t point_index = 0; point_index < info_.n_points_; point_index++)
{
if (!user_info_float)
{
x = float(point_index);
}
else if (info_.user_info_size_ / sizeof(float) == info_.n_points_)
{
x = user_info_float[point_index];
}
else if (info_.user_info_size_ / sizeof(float) > info_.n_points_)
{
std::size_t const fit_begin = fit_index_ * info_.n_points_;
x = user_info_float[fit_begin + point_index];
}

float argx = ((x - parameters_[1])*(x - parameters_[1])) / (2 * parameters_[2] * parameters_[2]);
float ex = exp(-argx);

derivatives[0 * info_.n_points_ + x] = ex;
derivatives[1 * info_.n_points_ + x] = (parameters_[0] * (x - parameters_[1])*ex) / (parameters_[2] * parameters_[2]);
derivatives[2 * info_.n_points_ + x] = (parameters_[0] * (x - parameters_[1])*(x - parameters_[1])*ex) / (parameters_[2] * parameters_[2] * parameters_[2]);
derivatives[3 * info_.n_points_ + x] = 1;
derivatives[0 * info_.n_points_ + point_index] = ex;
derivatives[1 * info_.n_points_ + point_index] = (parameters_[0] * (x - parameters_[1])*ex) / (parameters_[2] * parameters_[2]);
derivatives[2 * info_.n_points_ + point_index] = (parameters_[0] * (x - parameters_[1])*(x - parameters_[1])*ex) / (parameters_[2] * parameters_[2] * parameters_[2]);
derivatives[3 * info_.n_points_ + point_index] = 1;
}
}

Expand Down Expand Up @@ -302,13 +319,29 @@ void LMFitCPP::calc_values_gauss2drotated(std::vector<float>& gaussian)

void LMFitCPP::calc_values_gauss1d(std::vector<float>& gaussian)
{
for (std::size_t ix = 0; ix < info_.n_points_; ix++)
float * user_info_float = (float*)user_info_;
float x = 0.f;
for (std::size_t point_index = 0; point_index < info_.n_points_; point_index++)
{
if (!user_info_float)
{
x = float(point_index);
}
else if (info_.user_info_size_ / sizeof(float) == info_.n_points_)
{
x = user_info_float[point_index];
}
else if (info_.user_info_size_ / sizeof(float) > info_.n_points_)
{
std::size_t const fit_begin = fit_index_ * info_.n_points_;
x = user_info_float[fit_begin + point_index];
}

float argx
= ((ix - parameters_[1])*(ix - parameters_[1]))
= ((x - parameters_[1])*(x - parameters_[1]))
/ (2 * parameters_[2] * parameters_[2]);
float ex = exp(-argx);
gaussian[ix] = parameters_[0] * ex + parameters_[3];
gaussian[point_index] = parameters_[0] * ex + parameters_[3];
}
}

Expand Down

0 comments on commit fb4b277

Please sign in to comment.