Skip to content

Commit c19d1a1

Browse files
authored
Merge pull request #44 from GambitBSM/repo-sync/gambit/gambit_light_sync
🔄 synced file(s) with GambitBSM/gambit
2 parents a6294f5 + c0ba511 commit c19d1a1

File tree

9 files changed

+268
-171
lines changed

9 files changed

+268
-171
lines changed

ScannerBit/include/gambit/ScannerBit/base_prior.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Gambit {
4242
/**
4343
* @brief Abstract base class for priors
4444
*/
45-
class BasePrior
45+
class BasePrior
4646
{
4747
private:
4848
unsigned int param_size;
@@ -67,13 +67,13 @@ namespace Gambit {
6767
virtual void transform(hyper_cube_ref<double> unit, std::unordered_map<std::string, double> &physical) const = 0;
6868

6969
/** @overload in place STL containers */
70-
void transform(const std::vector<double> &unit, std::unordered_map<std::string, double> &physical) const
70+
void transform(const std::vector<double> &unit, std::unordered_map<std::string, double> &physical) const
7171
{
7272
transform(map_vector<double>(const_cast<double *>(&unit[0]), unit.size()), physical);
7373
}
7474

7575
/** @overload return STL containers */
76-
std::unordered_map<std::string, double> transform(const std::vector<double> &unit) const
76+
std::unordered_map<std::string, double> transform(const std::vector<double> &unit) const
7777
{
7878
std::unordered_map<std::string, double> physical;
7979
transform(unit, physical);
@@ -84,13 +84,13 @@ namespace Gambit {
8484
virtual void inverse_transform(const std::unordered_map<std::string, double> &physical, hyper_cube_ref<double> unit) const = 0;
8585

8686
/** @overload in place STL containers */
87-
void inverse_transform(const std::unordered_map<std::string, double> &physical, std::vector<double> &unit) const
87+
void inverse_transform(const std::unordered_map<std::string, double> &physical, std::vector<double> &unit) const
8888
{
8989
inverse_transform(physical, map_vector<double>(const_cast<double *>(&unit[0]), unit.size()));
9090
}
9191

9292
/** @overload return STL containers */
93-
std::vector<double> inverse_transform(const std::unordered_map<std::string, double> &physical) const
93+
std::vector<double> inverse_transform(const std::unordered_map<std::string, double> &physical) const
9494
{
9595
std::vector<double> unit(param_size);
9696
inverse_transform(physical, unit);
@@ -102,6 +102,8 @@ namespace Gambit {
102102

103103
virtual std::vector<std::string> getShownParameters() const { return param_names; }
104104

105+
virtual std::vector<std::string> getSetParameters() const { return param_names; }
106+
105107
inline unsigned int size() const { return param_size; }
106108

107109
inline void setSize(const unsigned int size) { param_size = size; }
@@ -112,7 +114,7 @@ namespace Gambit {
112114
};
113115

114116
} // namespace Priors
115-
117+
116118
} // namespace Gambit
117119

118120
#endif // __BASE_PRIORS_HPP__

ScannerBit/include/gambit/ScannerBit/priors/composite.hpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
///
55
/// Combine several priors to a prior for
66
/// e.g. an entire model
7-
///
7+
///
88
///
99
/// *********************************************
1010
///
1111
/// Authors (add name and date if you modify):
12-
///
12+
///
1313
/// \author Ben Farmer
1414
/// (benjamin.farmer@monash.edu.au)
1515
/// \date 2013 Dec
@@ -36,9 +36,9 @@
3636
#include "gambit/ScannerBit/scanner_utils.hpp"
3737

3838

39-
namespace Gambit
39+
namespace Gambit
4040
{
41-
namespace Priors
41+
namespace Priors
4242
{
4343
/// Special "build-a-prior" class
4444
/// This is the class to use for setting simple 1D priors (from the library above) on individual parameters.
@@ -47,32 +47,35 @@ namespace Gambit
4747

4848
class CompositePrior : public BasePrior
4949
{
50-
50+
5151
private:
5252
// References to component prior objects
5353
std::vector<BasePrior*> my_subpriors;
5454
std::vector<std::string> shown_param_names;
55-
55+
std::set<std::string> set_param_names;
56+
5657
public:
57-
58+
5859
// Constructors defined in composite.cpp
5960
CompositePrior(const Options &model_options, const Options &prior_options);
60-
61+
6162
CompositePrior(const std::vector<std::string> &params, const Options &options);
62-
63-
double log_prior_density(const std::unordered_map<std::string, double> &physical) const override
63+
64+
double log_prior_density(const std::unordered_map<std::string, double> &physical) const override
6465
{
6566
double log_pdf_density = 0.0;
6667
for (auto it = my_subpriors.begin(), end = my_subpriors.end(); it != end; ++it)
6768
{
6869
log_pdf_density += (*it)->log_prior_density(physical);
6970
}
70-
71+
7172
return log_pdf_density;
7273
}
73-
74+
7475
inline std::vector<std::string> getShownParameters() const override { return shown_param_names; }
75-
76+
77+
inline std::vector<std::string> getSetParameters() const override { return std::vector<std::string>(set_param_names.begin(), set_param_names.end()); }
78+
7679
// Transformation from unit hypercube to physical parameters
7780
void transform(hyper_cube_ref<double> unitPars, std::unordered_map<std::string,double> &outputMap) const override
7881
{
@@ -108,7 +111,7 @@ namespace Gambit
108111
auto round_trip = physical;
109112
transform(unit, round_trip);
110113
const double rtol = 1e-4;
111-
for (const auto &s : physical)
114+
for (const auto &s : physical)
112115
{
113116
const double a = round_trip.at(s.first);
114117
const double b = s.second;
@@ -119,19 +122,19 @@ namespace Gambit
119122
}
120123
}
121124
}
122-
125+
123126
//~CompositePrior() noexcept
124127
~CompositePrior()
125128
{
126129
// Need to destroy all the prior objects that we created using 'new'
127130
for (auto it = my_subpriors.begin(), end = my_subpriors.end(); it != end; it++)
128-
{
131+
{
129132
// Delete prior object
130133
delete *it;
131134
}
132-
}
135+
}
133136
};
134-
137+
135138
LOAD_PRIOR(composite, CompositePrior)
136139
} // end namespace Priors
137140
} // end namespace Gambit

ScannerBit/include/gambit/ScannerBit/py_module_scan.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ PYBIND11_EMBEDDED_MODULE(scanner_plugin, m)
862862

863863
return names;
864864
})
865+
.def_property_readonly_static("set_parameter_names", [](py::object)
866+
{
867+
static py::list names = scanner_base::to_list<std::string>(get_prior().getSetParameters());
868+
869+
return names;
870+
})
865871
.def_property_readonly_static("mpi_rank", [](py::object)
866872
{
867873
static int my_rank = scanner_base::rank();

ScannerBit/include/gambit/ScannerBit/scanners/diver_1.0.5/diver.hpp renamed to ScannerBit/include/gambit/ScannerBit/scanners/diver_1.3.0/diver.hpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// *********************************************
33
/// \file
44
///
5-
/// ScannerBit interface to Diver 1.0.5
5+
/// ScannerBit interface to Diver 1.3.0
66
///
77
/// Header file
88
///
@@ -11,26 +11,25 @@
1111
/// Authors (add name and date if you modify):
1212
///
1313
/// \author Pat Scott
14-
/// (p.scott@imperial.ac.uk)
15-
/// \date 2019 Dec
14+
/// (patrickcolinscott@gmail.com)
15+
/// \date 2025 Apr
1616
///
1717
/// *********************************************
1818

19-
#ifndef __diver_hpp__
20-
#define __diver_hpp__
19+
#pragma once
2120

2221
#include "gambit/ScannerBit/scanner_plugin.hpp"
2322

2423
// C++ prototype of the main run_de function for Diver.
25-
extern "C" void cdiver(double (*)(double[], const int, int&, bool&, const bool, void*&), int, const double[], const double[],
26-
const char[], int, int, const int[], bool, const int, const int, int, int, const double[], double,
27-
double, bool, bool, int, bool, bool, double, int, bool, bool, double(*)(const double[], const int, void*&),
28-
double, double, int, bool, bool, int, bool, int, double, int, void*&, int);
24+
extern "C" double cdiver(double (*)(double[], const int, int&, bool&, const bool, void*&), int, const double[], const double[],
25+
const char[], int, double[], double[], int, const int[], bool, int, int, int, const double[], double, double, bool,
26+
bool, int, bool, bool, double, int, bool, int, bool, bool, bool, bool, int, int, const double[], bool, int, double, int,
27+
void*&, int);
2928

3029
namespace Gambit
3130
{
3231

33-
namespace Diver_1_0_5
32+
namespace Diver_1_3_0
3433
{
3534

3635
/// Structure for passing likelihood and printer data through Diver to the objective function.
@@ -46,5 +45,3 @@ namespace Gambit
4645
}
4746

4847
}
49-
50-
#endif // #defined __diver_hpp__

0 commit comments

Comments
 (0)