Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ScannerBit/include/gambit/ScannerBit/base_prior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Gambit {
/**
* @brief Abstract base class for priors
*/
class BasePrior
class BasePrior
{
private:
unsigned int param_size;
Expand All @@ -67,13 +67,13 @@ namespace Gambit {
virtual void transform(hyper_cube_ref<double> unit, std::unordered_map<std::string, double> &physical) const = 0;

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

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

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

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

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

virtual std::vector<std::string> getSetParameters() const { return param_names; }

inline unsigned int size() const { return param_size; }

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

} // namespace Priors

} // namespace Gambit

#endif // __BASE_PRIORS_HPP__
39 changes: 21 additions & 18 deletions ScannerBit/include/gambit/ScannerBit/priors/composite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
///
/// Combine several priors to a prior for
/// e.g. an entire model
///
///
///
/// *********************************************
///
/// Authors (add name and date if you modify):
///
///
/// \author Ben Farmer
/// (benjamin.farmer@monash.edu.au)
/// \date 2013 Dec
Expand All @@ -36,9 +36,9 @@
#include "gambit/ScannerBit/scanner_utils.hpp"


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

class CompositePrior : public BasePrior
{

private:
// References to component prior objects
std::vector<BasePrior*> my_subpriors;
std::vector<std::string> shown_param_names;

std::set<std::string> set_param_names;

public:

// Constructors defined in composite.cpp
CompositePrior(const Options &model_options, const Options &prior_options);

CompositePrior(const std::vector<std::string> &params, const Options &options);
double log_prior_density(const std::unordered_map<std::string, double> &physical) const override

double log_prior_density(const std::unordered_map<std::string, double> &physical) const override
{
double log_pdf_density = 0.0;
for (auto it = my_subpriors.begin(), end = my_subpriors.end(); it != end; ++it)
{
log_pdf_density += (*it)->log_prior_density(physical);
}

return log_pdf_density;
}

inline std::vector<std::string> getShownParameters() const override { return shown_param_names; }


inline std::vector<std::string> getSetParameters() const override { return std::vector<std::string>(set_param_names.begin(), set_param_names.end()); }

// Transformation from unit hypercube to physical parameters
void transform(hyper_cube_ref<double> unitPars, std::unordered_map<std::string,double> &outputMap) const override
{
Expand Down Expand Up @@ -108,7 +111,7 @@ namespace Gambit
auto round_trip = physical;
transform(unit, round_trip);
const double rtol = 1e-4;
for (const auto &s : physical)
for (const auto &s : physical)
{
const double a = round_trip.at(s.first);
const double b = s.second;
Expand All @@ -119,19 +122,19 @@ namespace Gambit
}
}
}

//~CompositePrior() noexcept
~CompositePrior()
{
// Need to destroy all the prior objects that we created using 'new'
for (auto it = my_subpriors.begin(), end = my_subpriors.end(); it != end; it++)
{
{
// Delete prior object
delete *it;
}
}
}
};

LOAD_PRIOR(composite, CompositePrior)
} // end namespace Priors
} // end namespace Gambit
Expand Down
6 changes: 6 additions & 0 deletions ScannerBit/include/gambit/ScannerBit/py_module_scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,12 @@ PYBIND11_EMBEDDED_MODULE(scanner_plugin, m)

return names;
})
.def_property_readonly_static("set_parameter_names", [](py::object)
{
static py::list names = scanner_base::to_list<std::string>(get_prior().getSetParameters());

return names;
})
.def_property_readonly_static("mpi_rank", [](py::object)
{
static int my_rank = scanner_base::rank();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// GAMBIT: Global and Modular BSM Inference Tool
// *********************************************
/// \file
///
/// ScannerBit interface to Diver 1.3.0
///
/// Header file
///
/// *********************************************
///
/// Authors (add name and date if you modify):
///
/// \author Pat Scott
/// (patrickcolinscott@gmail.com)
/// \date 2025 Apr
///
/// *********************************************

#pragma once

#include "gambit/ScannerBit/scanner_plugin.hpp"

// C++ prototype of the main run_de function for Diver.
extern "C" double cdiver(double (*)(double[], const int, int&, bool&, const bool, void*&), int, const double[], const double[],
const char[], int, double[], double[], int, const int[], bool, int, int, int, const double[], double, double, bool,
bool, int, bool, bool, double, int, bool, int, bool, bool, bool, bool, int, int, const double[], bool, int, double, int,
void*&, int);

namespace Gambit
{

namespace Diver_1_3_0
{

/// Structure for passing likelihood and printer data through Diver to the objective function.
struct diverScanData
{
Scanner::like_ptr likelihood_function;
Scanner::printer_interface* printer;
};

/// Function to be minimised by Diver
double objective(double params[], const int param_dim, int &fcall, bool &quit, const bool validvector, void*& context);

}

}
Loading
Loading