8 const auto& existingNames = handle.getNames();
9 auto nameExists = [&](
const std::string& name) {
10 return std::find(existingNames.begin(), existingNames.end(), name) != existingNames.end();
14 if (!nameExists(
"uniform")) {
15 handle.add(
"uniform", [](
const std::vector<double>& args) ->
double {
16 if (args.size() != 2) {
17 throw std::runtime_error(
"uniform requires 2 arguments: min, max");
19 return (args[0] + args[1]) / 2.0;
24 if (!nameExists(
"uniform_int")) {
25 handle.add(
"uniform_int", [](
const std::vector<double>& args) ->
double {
26 if (args.size() != 2) {
27 throw std::runtime_error(
"uniform_int requires 2 arguments: min, max");
29 return (args[0] + args[1]) / 2.0;
34 if (!nameExists(
"normal")) {
35 handle.add(
"normal", [](
const std::vector<double>& args) ->
double {
36 if (args.size() != 2) {
37 throw std::runtime_error(
"normal requires 2 arguments: mean, stddev");
44 if (!nameExists(
"exponential")) {
45 handle.add(
"exponential", [](
const std::vector<double>& args) ->
double {
46 if (args.size() != 1) {
47 throw std::runtime_error(
"exponential requires 1 argument: rate");
54 if (!nameExists(
"poisson")) {
55 handle.add(
"poisson", [](
const std::vector<double>& args) ->
double {
56 if (args.size() != 1) {
57 throw std::runtime_error(
"poisson requires 1 argument: mean");
64 if (!nameExists(
"bernoulli")) {
65 handle.add(
"bernoulli", [](
const std::vector<double>& args) ->
double {
66 if (args.size() != 1) {
67 throw std::runtime_error(
"bernoulli requires 1 argument: probability");
74 if (!nameExists(
"binomial")) {
75 handle.add(
"binomial", [](
const std::vector<double>& args) ->
double {
76 if (args.size() != 2) {
77 throw std::runtime_error(
"binomial requires 2 arguments: trials, probability");
79 return args[0] * args[1];
84 if (!nameExists(
"gamma")) {
85 handle.add(
"gamma", [](
const std::vector<double>& args) ->
double {
86 if (args.size() != 2) {
87 throw std::runtime_error(
"gamma requires 2 arguments: shape, scale");
89 return args[0] * args[1];
94 if (!nameExists(
"lognormal")) {
95 handle.add(
"lognormal", [](
const std::vector<double>& args) ->
double {
96 if (args.size() != 2) {
97 throw std::runtime_error(
"lognormal requires 2 arguments: logscale, shape");
99 return std::exp(args[0] + args[1] * args[1] / 2.0);
104 if (!nameExists(
"geometric")) {
105 handle.add(
"geometric", [](
const std::vector<double>& args) ->
double {
106 if (args.size() != 1) {
107 throw std::runtime_error(
"geometric requires 1 argument: probability");
109 return (1.0 - args[0]) / args[0];