OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MLModelMap Class Reference

#include <MLModel.h>

Public Member Functions

void addModel (const std::string &model_name, std::shared_ptr< AbstractMLModel > model)
 
bool modelExists (const std::string &model_name) const
 
std::shared_ptr< AbstractMLModelgetModel (const std::string &model_name) const
 
void deleteModel (const std::string &model_name)
 
std::vector< std::string > getModelNames () const
 
std::vector< MLModelMetadatagetModelMetadata () const
 
MLModelMetadata getModelMetadata (const std::string &model_name) const
 

Private Attributes

std::map< std::string,
std::shared_ptr
< AbstractMLModel > > 
model_map_
 
std::shared_mutex model_map_mutex_
 

Detailed Description

Definition at line 36 of file MLModel.h.

Member Function Documentation

void MLModelMap::addModel ( const std::string &  model_name,
std::shared_ptr< AbstractMLModel model 
)
inline

Definition at line 38 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by linear_reg_fit_impl(), and pca_fit_impl().

38  {
39  const auto upper_model_name = to_upper(model_name);
40  std::lock_guard<std::shared_mutex> model_map_write_lock(model_map_mutex_);
41  model_map_[upper_model_name] = model;
42  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MLModelMap::deleteModel ( const std::string &  model_name)
inline

Definition at line 62 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by Parser::DropModelStmt::execute().

62  {
63  const auto upper_model_name = to_upper(model_name);
64  std::lock_guard<std::shared_mutex> model_map_write_lock(model_map_mutex_);
65  auto const model_it = model_map_.find(upper_model_name);
66  if (model_it == model_map_.end()) {
67  std::ostringstream error_oss;
68  error_oss << "Cannot erase model " << upper_model_name
69  << ". No model by that name was found.";
70  throw std::runtime_error(error_oss.str());
71  }
72  model_map_.erase(model_it);
73  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<AbstractMLModel> MLModelMap::getModel ( const std::string &  model_name) const
inline

Definition at line 51 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by CodeGenerator::codegen(), ShowModelFeatureDetailsCommand::execute(), get_decision_trees__cpu_1(), linear_reg_coefs__cpu_1(), ml_reg_predict__cpu_template(), r2_score__cpu_template(), and random_forest_reg_var_importance__cpu_1().

51  {
52  const auto upper_model_name = to_upper(model_name);
53  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
54  auto model_map_itr = model_map_.find(upper_model_name);
55  if (model_map_itr != model_map_.end()) {
56  return model_map_itr->second;
57  }
58  const std::string error_str = "Model '" + upper_model_name + "' does not exist.";
59  throw std::runtime_error(error_str);
60  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<MLModelMetadata> MLModelMap::getModelMetadata ( ) const
inline

Definition at line 84 of file MLModel.h.

References model_map_, and model_map_mutex_.

Referenced by ShowModelDetailsCommand::execute(), EvaluateModelCommand::execute(), and foreign_storage::InternalMLModelMetadataDataWrapper::initializeObjectsForTable().

84  {
85  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
86  std::vector<MLModelMetadata> model_metadata;
87  for (auto const& model : model_map_) {
88  model_metadata.emplace_back(MLModelMetadata(
89  model.first,
90  model.second->getModelType(),
91  model.second->getModelTypeString(),
92  model.second->getNumLogicalFeatures(),
93  model.second->getNumFeatures(),
94  model.second->getNumCatFeatures(),
95  model.second->getNumLogicalFeatures() - model.second->getNumCatFeatures(),
96  model.second->getModelMetadataStr()));
97  }
98  return model_metadata;
99  }
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the caller graph for this function:

MLModelMetadata MLModelMap::getModelMetadata ( const std::string &  model_name) const
inline

Definition at line 101 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

101  {
102  const auto upper_model_name = to_upper(model_name);
103  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
104  auto model_map_itr = model_map_.find(upper_model_name);
105  if (model_map_itr != model_map_.end()) {
106  return MLModelMetadata(model_map_itr->first,
107  model_map_itr->second->getModelType(),
108  model_map_itr->second->getModelTypeString(),
109  model_map_itr->second->getNumLogicalFeatures(),
110  model_map_itr->second->getNumFeatures(),
111  model_map_itr->second->getNumCatFeatures(),
112  model_map_itr->second->getNumLogicalFeatures() -
113  model_map_itr->second->getNumCatFeatures(),
114  model_map_itr->second->getModelMetadataStr());
115  }
116  const std::string error_str = "Model '" + upper_model_name + "' does not exist.";
117  throw std::runtime_error(error_str);
118  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the call graph for this function:

std::vector<std::string> MLModelMap::getModelNames ( ) const
inline

Definition at line 75 of file MLModel.h.

References model_map_, and model_map_mutex_.

Referenced by ShowModelsCommand::execute(), and ShowModelDetailsCommand::getFilteredModelNames().

75  {
76  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
77  std::vector<std::string> model_names;
78  model_names.reserve(model_map_.size());
79  for (auto const& model : model_map_) {
80  model_names.emplace_back(model.first);
81  }
82  return model_names;
83  }
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the caller graph for this function:

bool MLModelMap::modelExists ( const std::string &  model_name) const
inline

Definition at line 44 of file MLModel.h.

References model_map_, model_map_mutex_, and to_upper().

Referenced by Parser::CreateModelStmt::check_model_exists().

44  {
45  const auto upper_model_name = to_upper(model_name);
46  std::shared_lock<std::shared_mutex> model_map_read_lock(model_map_mutex_);
47  auto model_map_itr = model_map_.find(upper_model_name);
48  return model_map_itr != model_map_.end();
49  }
std::string to_upper(const std::string &str)
std::shared_mutex model_map_mutex_
Definition: MLModel.h:122
std::map< std::string, std::shared_ptr< AbstractMLModel > > model_map_
Definition: MLModel.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::map<std::string, std::shared_ptr<AbstractMLModel> > MLModelMap::model_map_
private

Definition at line 121 of file MLModel.h.

Referenced by addModel(), deleteModel(), getModel(), getModelMetadata(), getModelNames(), and modelExists().

std::shared_mutex MLModelMap::model_map_mutex_
mutableprivate

Definition at line 122 of file MLModel.h.

Referenced by addModel(), deleteModel(), getModel(), getModelMetadata(), getModelNames(), and modelExists().


The documentation for this class was generated from the following file: