Commit ef7d3bf0 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Merge branch 'refiner' into 'main'

Minimizer: rm unused member function, make getter functions const, correct typos

See merge request !504
parents 2ffc98b4 b5ea2d50
Pipeline #72294 passed with stage
in 3 minutes and 42 seconds
......@@ -190,7 +190,6 @@ void Minimizer::cleanup()
}
if (_gsl->jacobian) {
// jacobian is part of the workspace, doesnt need to be freed
gsl_matrix_free(_gsl->jacobian);
_gsl->jacobian = nullptr;
}
......
......@@ -197,9 +197,6 @@ bool RefinementBatch::refine(unsigned int max_iter)
if (!_constraints.empty())
_params.setKernel(constraintKernel(_params.nparams(), _constraints));
_cost_function.clear();
_cost_function.shrink_to_fit();
min.initialize(_params, _peaks.size() * 3);
min.set_f([&](Eigen::VectorXd& fvec) { return residuals(fvec); });
bool success = min.fit(max_iter);
......@@ -212,7 +209,7 @@ bool RefinementBatch::refine(unsigned int max_iter)
return success;
}
int RefinementBatch::residuals(Eigen::VectorXd& fvec)
int RefinementBatch::residuals(Eigen::VectorXd& fvec) const
{
if (_residual_type == ResidualType::QSpace) {
return qSpaceResiduals(fvec);
......@@ -223,7 +220,7 @@ int RefinementBatch::residuals(Eigen::VectorXd& fvec)
}
}
int RefinementBatch::qSpaceResiduals(Eigen::VectorXd& fvec)
int RefinementBatch::qSpaceResiduals(Eigen::VectorXd& fvec) const
{
UnitCell uc = _cell->fromParameters(_u0, _uOffsets, _cellParameters);
const Eigen::Matrix3d& UB = uc.reciprocalBasis();
......@@ -245,12 +242,10 @@ int RefinementBatch::qSpaceResiduals(Eigen::VectorXd& fvec)
}
}
_cost_function.push_back(0.5 * fvec.norm());
return 0;
}
int RefinementBatch::realSpaceResiduals(Eigen::VectorXd& fvec)
int RefinementBatch::realSpaceResiduals(Eigen::VectorXd& fvec) const
{
UnitCell uc = _cell->fromParameters(_u0, _uOffsets, _cellParameters);
const Eigen::Matrix3d& UB = uc.reciprocalBasis();
......@@ -292,8 +287,6 @@ int RefinementBatch::realSpaceResiduals(Eigen::VectorXd& fvec)
}
}
_cost_function.push_back(0.5 * fvec.norm());
return 0;
}
......
......@@ -52,13 +52,13 @@ class RefinementBatch {
bool refine(unsigned int max_iter = 100);
//! Compute the residual vector for the current set of parameters.
int residuals(Eigen::VectorXd& fvec);
int residuals(Eigen::VectorXd& fvec) const;
//! Compute reciprocal space residual
int qSpaceResiduals(Eigen::VectorXd& fvec);
int qSpaceResiduals(Eigen::VectorXd& fvec) const;
//! Compute real (detector) space residuals
int realSpaceResiduals(Eigen::VectorXd& fvec);
int realSpaceResiduals(Eigen::VectorXd& fvec) const;
//! Returns the list of peaks used for refinement.
std::vector<ohkl::Peak3D*> peaks() const;
......@@ -112,7 +112,6 @@ class RefinementBatch {
std::vector<std::vector<int>> _constraints;
std::vector<Eigen::Matrix3d> _wts;
std::vector<std::reference_wrapper<InstrumentState>> _states;
std::vector<double> _cost_function;
};
} // namespace ohkl
......
......@@ -354,17 +354,17 @@ int Refiner::updatePredictions(std::vector<Peak3D*> peaks)
return updated;
}
UnitCell* Refiner::unrefinedCell()
const UnitCell* Refiner::unrefinedCell() const
{
return &_unrefined_cell;
}
InstrumentStateList* Refiner::refinedStates()
const InstrumentStateList* Refiner::refinedStates() const
{
return _states;
}
InstrumentStateList* Refiner::unrefinedStates()
const InstrumentStateList* Refiner::unrefinedStates() const
{
return &_unrefined_states;
}
......
......@@ -98,24 +98,26 @@ class Refiner {
void refineKi();
//! Perform the refinement with the maximum number of iterations as given. N.B. the four
//! previous funcitons set the number of free parameters and at least one must be run
//! previous functions set the number of free parameters and at least one must be run
//! *before* refine
bool refine();
//! Update the centers of predicted peaks, after refinement.
//! Updates the centers of predicted peaks, after refinement.
//! Returns the number of remaining peaks
//! (some peaks may be rejected with flag PredictionUpdateFailure).
int updatePredictions(std::vector<Peak3D*> peaks);
//! Returns the individual peak/frame batches used during refinement.
const std::vector<RefinementBatch>& batches() const;
//! Return the unrefined cell
UnitCell* unrefinedCell();
const UnitCell* unrefinedCell() const;
//! Return the refined states
InstrumentStateList* refinedStates();
const InstrumentStateList* refinedStates() const;
//! Return the unrefined states
InstrumentStateList* unrefinedStates();
const InstrumentStateList* unrefinedStates() const;
//! Return number of frames
int nframes() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment