BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FitObjectiveBuilder Class Reference

Description

Definition at line 32 of file FitObjectiveBuilder.h.

Collaboration diagram for FitObjectiveBuilder:
[legend]

Public Member Functions

 FitObjectiveBuilder (JobItem *jobItem)
 
 ~FitObjectiveBuilder ()
 
void attachObserver (std::shared_ptr< GUIFitObserver > observer)
 
std::unique_ptr< IChiSquaredModule > createChiSquaredModule () const
 
std::unique_ptr< FitObjective > createFitObjective () const
 
std::unique_ptr< IMinimizer > createMinimizer () const
 
mumufit::Parameters createParameters () const
 
void interruptFitting ()
 
void runFit ()
 

Private Member Functions

std::unique_ptr< ISimulation > buildSimulation (const mumufit::Parameters &params) const
 
void update_fit_parameters (const mumufit::Parameters &params) const
 

Private Attributes

std::unique_ptr< FitObjective > m_fit_objective
 
JobItemm_jobItem
 
std::shared_ptr< GUIFitObserverm_observer
 

Constructor & Destructor Documentation

◆ FitObjectiveBuilder()

FitObjectiveBuilder::FitObjectiveBuilder ( JobItem jobItem)

Definition at line 31 of file FitObjectiveBuilder.cpp.

32  : m_jobItem(jobItem)
33 {
34  ASSERT(m_jobItem->fitSuiteItem());
35 }
FitSuiteItem * fitSuiteItem()
Definition: JobItem.cpp:257

References JobItem::fitSuiteItem(), and m_jobItem.

Here is the call graph for this function:

◆ ~FitObjectiveBuilder()

FitObjectiveBuilder::~FitObjectiveBuilder ( )
default

Member Function Documentation

◆ attachObserver()

void FitObjectiveBuilder::attachObserver ( std::shared_ptr< GUIFitObserver observer)

Definition at line 102 of file FitObjectiveBuilder.cpp.

103 {
104  m_observer = observer;
105 }
std::shared_ptr< GUIFitObserver > m_observer

References m_observer.

◆ buildSimulation()

std::unique_ptr< ISimulation > FitObjectiveBuilder::buildSimulation ( const mumufit::Parameters &  params) const
private

Definition at line 113 of file FitObjectiveBuilder.cpp.

114 {
115  static std::mutex build_simulation_mutex;
116  std::unique_lock<std::mutex> lock(build_simulation_mutex);
117 
118  update_fit_parameters(params);
121 }
void update_fit_parameters(const mumufit::Parameters &params) const
const SimulationOptionsItem & simulationOptionsItem() const
Definition: JobItem.cpp:415
MultiLayerItem * sampleItem()
Definition: JobItem.cpp:222
InstrumentItem * instrumentItem() const
Definition: JobItem.cpp:233
std::unique_ptr< ISimulation > itemsToSimulation(const MultiLayerItem *sampleItem, const InstrumentItem *instrumentItem, const SimulationOptionsItem &optionsItem)
Creates domain simulation from sample and instrument items.

References JobItem::instrumentItem(), GUI::Transform::ToCore::itemsToSimulation(), m_jobItem, JobItem::sampleItem(), JobItem::simulationOptionsItem(), and update_fit_parameters().

Referenced by createFitObjective().

Here is the call graph for this function:

◆ createChiSquaredModule()

std::unique_ptr<IChiSquaredModule> FitObjectiveBuilder::createChiSquaredModule ( ) const

◆ createFitObjective()

std::unique_ptr< FitObjective > FitObjectiveBuilder::createFitObjective ( ) const

Definition at line 70 of file FitObjectiveBuilder.cpp.

71 {
72  auto result = std::make_unique<FitObjective>();
73 
74  simulation_builder_t builder = [&](const mumufit::Parameters& params) {
75  return buildSimulation(params);
76  };
77 
78  auto* realDataItem = m_jobItem->realDataItem();
79  ASSERT(realDataItem);
80 
81  const DataItem* intensity_item = realDataItem->dataItem();
82  ASSERT(intensity_item);
83  ASSERT(intensity_item->getDatafield());
84 
85  std::unique_ptr<Datafield> data(intensity_item->getDatafield()->clone());
86 
87  result->execAddSimulationAndData(builder, *data, nullptr, 1.0);
88 
89  return result;
90 }
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
Datafield * getDatafield()
Definition: DataItem.h:41
std::unique_ptr< ISimulation > buildSimulation(const mumufit::Parameters &params) const
RealDataItem * realDataItem()
Definition: JobItem.cpp:290

References buildSimulation(), DataItem::getDatafield(), m_jobItem, and JobItem::realDataItem().

Referenced by runFit().

Here is the call graph for this function:

◆ createMinimizer()

std::unique_ptr< IMinimizer > FitObjectiveBuilder::createMinimizer ( ) const

Definition at line 92 of file FitObjectiveBuilder.cpp.

93 {
95 }
MinimizerContainerItem * minimizerContainerItem()
std::unique_ptr< IMinimizer > createMinimizer() const override

References MinimizerContainerItem::createMinimizer(), JobItem::fitSuiteItem(), m_jobItem, and FitSuiteItem::minimizerContainerItem().

Referenced by runFit().

Here is the call graph for this function:

◆ createParameters()

mumufit::Parameters FitObjectiveBuilder::createParameters ( ) const

Definition at line 97 of file FitObjectiveBuilder.cpp.

98 {
100 }
mumufit::Parameters createParameters() const
FitParameterContainerItem * fitParameterContainerItem()

References FitParameterContainerItem::createParameters(), FitSuiteItem::fitParameterContainerItem(), JobItem::fitSuiteItem(), and m_jobItem.

Referenced by runFit().

Here is the call graph for this function:

◆ interruptFitting()

void FitObjectiveBuilder::interruptFitting ( )

Definition at line 107 of file FitObjectiveBuilder.cpp.

108 {
109  m_fit_objective->interruptFitting();
110 }
std::unique_ptr< FitObjective > m_fit_objective

References m_fit_objective.

◆ runFit()

void FitObjectiveBuilder::runFit ( )

Definition at line 39 of file FitObjectiveBuilder.cpp.

40 {
42 
44  m_fit_objective->setObjectiveMetric(std::move(module));
45 
46  if (m_observer) {
47  fit_observer_t plot_observer = [&](const FitObjective& obj) { m_observer->update(&obj); };
48  m_fit_objective->initPlot(1, std::move(plot_observer));
49  }
50 
51  auto minimizer_impl = createMinimizer();
52  const bool requires_residuals = minimizer_impl->requiresResiduals();
53 
54  mumufit::Minimizer minimizer;
55  minimizer.setMinimizer(minimizer_impl.release());
56 
57  auto result = requires_residuals ? minimizer.minimize(
58  [&](const mumufit::Parameters& params) {
59  return m_fit_objective->evaluate_residuals(params);
60  },
62  : minimizer.minimize(
63  [&](const mumufit::Parameters& params) {
64  return m_fit_objective->evaluate(params);
65  },
67  m_fit_objective->finalize(result);
68 }
std::unique_ptr< IMinimizer > createMinimizer() const
std::unique_ptr< FitObjective > createFitObjective() const
mumufit::Parameters createParameters() const
std::unique_ptr< ObjectiveMetric > createMetric() const

References createFitObjective(), MinimizerContainerItem::createMetric(), createMinimizer(), createParameters(), JobItem::fitSuiteItem(), m_fit_objective, m_jobItem, m_observer, and FitSuiteItem::minimizerContainerItem().

Here is the call graph for this function:

◆ update_fit_parameters()

void FitObjectiveBuilder::update_fit_parameters ( const mumufit::Parameters &  params) const
private

Definition at line 123 of file FitObjectiveBuilder.cpp.

124 {
125  QVector<double> values = QVector<double>::fromStdVector(params.values());
126 
127  auto* fitParContainer = m_jobItem->fitParameterContainerItem();
129 }
void setValuesInParameterContainer(const QVector< double > &values, class ParameterContainerItem *parameterContainer)
Propagate values to the corresponding parameter tree items of parameterContainer.
FitParameterContainerItem * fitParameterContainerItem()
Definition: JobItem.cpp:282
ParameterContainerItem * parameterContainerItem()
Definition: JobItem.cpp:271

References JobItem::fitParameterContainerItem(), m_jobItem, JobItem::parameterContainerItem(), and FitParameterContainerItem::setValuesInParameterContainer().

Referenced by buildSimulation().

Here is the call graph for this function:

Member Data Documentation

◆ m_fit_objective

std::unique_ptr<FitObjective> FitObjectiveBuilder::m_fit_objective
private

Definition at line 57 of file FitObjectiveBuilder.h.

Referenced by interruptFitting(), and runFit().

◆ m_jobItem

JobItem* FitObjectiveBuilder::m_jobItem
private

◆ m_observer

std::shared_ptr<GUIFitObserver> FitObjectiveBuilder::m_observer
private

Definition at line 56 of file FitObjectiveBuilder.h.

Referenced by attachObserver(), and runFit().


The documentation for this class was generated from the following files: