ModErn Text Analysis
META Enumerates Textual Applications
loss_function_factory.h
Go to the documentation of this file.
1 
9 #ifndef META_CLASSIFY_LOSS_FUNCTION_FACTORY_H_
10 #define META_CLASSIFY_LOSS_FUNCTION_FACTORY_H_
11 
12 #include <functional>
13 #include <memory>
14 #include <unordered_map>
15 
17 #include "util/factory.h"
18 #include "util/shim.h"
19 
20 namespace meta
21 {
22 namespace classify
23 {
24 namespace loss
25 {
26 
33  : public util::factory<loss_function_factory, loss_function>
34 {
35  friend base_factory;
36 
37  private:
42 
46  template <class Loss>
47  void reg();
48 };
49 
55 std::unique_ptr<loss_function>
56  make_loss_function(const std::string& identifier);
57 
62 template <class Loss>
63 std::unique_ptr<loss_function> make_loss_function()
64 {
65  return make_unique<Loss>();
66 }
67 
72 template <class Loss>
74 {
75  loss_function_factory::get().add(Loss::id, make_loss_function<Loss>);
76 }
77 }
78 }
79 }
80 
81 #endif
loss_function_factory()
Constructs the loss_function_factory singleton.
Definition: loss_function_factory.cpp:22
Factory that is responsible for creating loss functions from strings.
Definition: loss_function_factory.h:32
void add(const std::string &identifier, Function &&fn)
Associates the given identifier with the given factory method.
Definition: factory.h:61
void reg()
Registers a loss function.
Definition: loss_function_factory.cpp:17
Generic factory that can be subclassed to create factories for specific types.
Definition: factory.h:27
static loss_function_factory & get()
Obtains the singleton.
Definition: factory.h:48
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
std::unique_ptr< loss_function > make_loss_function(const std::string &identifier)
Convenience method for making a loss function using the factory.
Definition: loss_function_factory.cpp:35
void register_loss_function()
Registration method for loss functions.
Definition: loss_function_factory.h:73