Commit 2fc61650 authored by Hatim Djelassi's avatar Hatim Djelassi
Browse files

Release version v0.3

Add intrinsic functions
Extend symbol table interface
parent 647d9b1f
......@@ -160,6 +160,9 @@ struct covar_matern_1_node;
struct covar_matern_3_node;
struct covar_matern_5_node;
struct covar_sqrexp_node;
struct af_lcb_node;
struct af_ei_node;
struct af_pi_node;
struct gpdf_node;
struct regnormal_node;
struct squash_node;
......@@ -242,6 +245,9 @@ using real_node_types = typename combined_pack<
covar_matern_3_node*,
covar_matern_5_node*,
covar_sqrexp_node*,
af_lcb_node*,
af_ei_node*,
af_pi_node*,
gpdf_node*,
regnormal_node*
>,
......@@ -536,6 +542,9 @@ struct mid_node : derived_value_node<mid_node, real<0>>, ternary_node<real<0>, r
struct bounding_func_node : derived_value_node<bounding_func_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
struct squash_node : derived_value_node<squash_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
struct regnormal_node : derived_value_node<regnormal_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
struct af_lcb_node : derived_value_node<af_lcb_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
struct af_ei_node : derived_value_node<af_ei_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
struct af_pi_node : derived_value_node<af_pi_node, real<0>>, ternary_node<real<0>, real<0>, real<0>> {using kary_node::kary_node;};
// quaternary nodes
template <typename TType, typename UType, typename VType, typename WType>
......
......@@ -37,7 +37,8 @@ parser::parser(std::istream& input, symbol_table& symbols)
"erf", "erfc", "norm2", "sum_div", "xlog_sum",
"pos", "neg", "lb_func", "ub_func", "bounding_func", "squash", "regnormal",
"lmtd", "rlmtd", "cost_turton",
"covar_matern_1", "covar_matern_3", "covar_matern_5", "covar_sqrexp", "gpdf",
"covar_matern_1", "covar_matern_3", "covar_matern_5", "covar_sqrexp",
"af_lcb", "af_ei", "af_pi", "gpdf",
"nrtl_tau", "nrtl_dtau", "nrtl_g", "nrtl_gtau", "nrtl_gdtau", "nrtl_dgtau",
"antoine_psat", "ext_antoine_psat", "wagner_psat", "ik_cape_psat",
"antoine_tsat",
......@@ -531,7 +532,7 @@ bool parser::match_binary_function(std::unique_ptr<value_node<real<0>>>& result)
bool parser::match_ternary_function(std::unique_ptr<value_node<real<0>>>& result) {
init();
if (!check_any_keyword("mid", "bounding_func", "squash", "regnormal")) {
if (!check_any_keyword("mid", "bounding_func", "squash", "regnormal", "af_lcb", "af_ei", "af_pi")) {
return reject();
}
std::string type = current().lexeme;
......@@ -584,6 +585,24 @@ bool parser::match_ternary_function(std::unique_ptr<value_node<real<0>>>& result
third_child.release()));
return accept();
}
if (type == "af_lcb") {
result.reset(new regnormal_node(
first_child.release(), second_child.release(),
third_child.release()));
return accept();
}
if (type == "af_ei") {
result.reset(new regnormal_node(
first_child.release(), second_child.release(),
third_child.release()));
return accept();
}
if (type == "af_pi") {
result.reset(new regnormal_node(
first_child.release(), second_child.release(),
third_child.release()));
return accept();
}
return reject();
}
......
......@@ -18,6 +18,7 @@
#include <stack>
#include <set>
#include <unordered_map>
#include <list>
namespace ale {
......@@ -98,11 +99,25 @@ struct symbol_table {
template <typename TType>
void define(std::string name, value_symbol<TType>* sym) {
symbol_store[name].push(sym, &scope_stack.top());
auto it = symbol_store.find(name);
if (it != symbol_store.end()) {
it->second.push(sym, &scope_stack.top());
}
else {
symbol_names.push_back(name);
symbol_store[name].push(sym, &scope_stack.top());
}
}
void define(std::string name, base_symbol* sym) {
symbol_store[name].push(sym, &scope_stack.top());
auto it = symbol_store.find(name);
if (it != symbol_store.end()) {
it->second.push(sym, &scope_stack.top());
}
else {
symbol_names.push_back(name);
symbol_store[name].push(sym, &scope_stack.top());
}
}
template <typename TType>
......@@ -136,9 +151,14 @@ struct symbol_table {
it->second.print();
}
}
const std::list<std::string>& get_names() {
return symbol_names;
}
private:
std::unordered_map<std::string, symbol_stack> symbol_store;
std::stack<symbol_scope> scope_stack;
std::list<std::string> symbol_names;
};
......
......@@ -457,6 +457,37 @@ class evaluator {
double b = dispatch(node->get_child<2>());
return x / std::sqrt(a+b*std::pow(x,2));
}
double operator()(af_lcb_node* node) {
double mu = dispatch(node->get_child<0>());
double sigma = dispatch(node->get_child<1>());
double kappa = dispatch(node->get_child<2>());
return mu - kappa*sigma;
}
double operator()(af_ei_node* node) {
double mu = dispatch(node->get_child<0>());
double sigma = dispatch(node->get_child<1>());
double fmin = dispatch(node->get_child<2>());
if(sigma == 0){
return std::max(fmin-mu, 0.);
}
double x = mu - fmin;
double gcd = std::erf(1./std::sqrt(2)*(-x/sigma))/2.+0.5;
double gpd = 1./(std::sqrt(2*M_PI)) * std::exp(-std::pow(-x/sigma,2)/2.);
return (-x)*gcd + sigma*gpd;
}
double operator()(af_pi_node* node) {
double mu = dispatch(node->get_child<0>());
double sigma = dispatch(node->get_child<1>());
double fmin = dispatch(node->get_child<2>());
if(sigma == 0 && fmin <= mu){
return 0;
}
if(sigma == 0 && fmin > mu){
return 1;
}
double x = mu - fmin;
return std::erf(1./std::sqrt(2)*(-x/sigma))/2.+0.5;
}
double operator()(ext_antoine_psat_node* node) {
double t = dispatch(node->get_child<0>());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment