atomicrex  0.1
An advanced atomistic model building tool
SpaMinimizer.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include "../Atomicrex.h"
25 #include "../job/FitJob.h"
26 #include "Minimizer.h"
27 
28 #include <random>
29 
30 namespace atomicrex {
31 
36 class SpaMinimizer : public Minimizer
37 {
38 public:
39 
42 
56  virtual void prepare(
57  std::vector<double>&& x0,
58  const std::function<double(const std::vector<double>&)>& func,
59  const std::function<double(const std::vector<double>&, std::vector<double>&)>& gradient = std::function<double(const std::vector<double>&, std::vector<double>&)>()) override;
60 
65  virtual void setConstraints(
66  std::vector<BoundConstraints>&& constraintTypes,
67  std::vector<double>&& lowerBounds,
68  std::vector<double>&& upperBounds) override;
69 
71  virtual MinimizerResult iterate() override;
72 
74  virtual void parse(XML::Element minimizerElement) override;
75 
76 private:
77 
79  std::vector<double> randomParameters();
80 
81 private:
82 
84  std::vector<BoundConstraints> _constraintTypes;
85  std::vector<double> _lowerBounds;
86  std::vector<double> _upperBounds;
87 
89  std::shared_ptr<Minimizer> _submin;
90 
92  std::vector<double>_bestParameters;
93  double _bestResidual;
94 
96  std::default_random_engine _gen;
98  std::uniform_real_distribution<> _dis;
99 
100 };
101 
102 } // End of namespace
virtual void setConstraints(std::vector< BoundConstraints > &&constraintTypes, std::vector< double > &&lowerBounds, std::vector< double > &&upperBounds) override
Definition: SpaMinimizer.cpp:49
SpaMinimizer(FitJob *job)
Constructor.
Definition: SpaMinimizer.h:41
FitJob * job() const
Returns the job to which this object belongs.
Definition: Minimizer.h:68
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
virtual void parse(XML::Element minimizerElement) override
Parses the minimizer&#39;s parameters from the XML file.
Definition: SpaMinimizer.cpp:65
Definition: XMLUtilities.h:69
Definition: FitJob.h:37
Abstract base class for minimization algorithms.
Definition: Minimizer.h:34
Definition: SpaMinimizer.h:36
virtual void prepare(std::vector< double > &&x0, const std::function< double(const std::vector< double > &)> &func, const std::function< double(const std::vector< double > &, std::vector< double > &)> &gradient=std::function< double(const std::vector< double > &, std::vector< double > &)>()) override
Definition: SpaMinimizer.cpp:33
virtual MinimizerResult iterate() override
Performs one iteration of the Spa Minimizer.
Definition: SpaMinimizer.cpp:84