bindings_docstring_keyed.hpp 10.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
/** @file python/bindings.hpp
 *  @brief Definitions to convert C++ classes into python classes
 *
 *  @author Thomas A. R. Purcell (tpurcell)
 *  @bug No known bugs.
 */
#ifndef PYTHON_BINDING
#define PYTHON_BINDINGS

10
11
#include <descriptor_identifier/SISSO_DI/SISSO_DI.hpp>
#include <descriptor_identifier/SISSO_DI/SISSORegressor.hpp>
12
#include <descriptor_identifier/SISSO_DI/SISSOLogRegressor.hpp>
13
#include <descriptor_identifier/SISSO_DI/SISSOClassifier.hpp>
14
#include <feature_creation/feature_space/FeatureSpace.hpp>
15
#include <python/feature_creation/node_utils.hpp>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

namespace py = boost::python;
namespace np = boost::python::numpy;

namespace sisso
{
    /**
     * @brief Register all C++ classes as python classes
     * @details [long description]
     */
    void register_all();

    namespace feature_creation
    {
        static void registerFeatureSpace();
        static void registerUnit();
        namespace node
        {
            /**
             * @brief struct used wrap a Node object for conversion
             */
            struct NodeWrap :  Node, py::wrapper<Node>
            {
            public:
                inline std::string expr(){return this->get_override("expr")();}
41
                inline std::string get_latex_expr(std::string cap){return this->get_override("latex_expr")();}
42
43
44
                inline Unit unit(){return this->get_override("unit")();}
                inline std::vector<double> value(){return this->get_override("value")();}
                inline std::vector<double> test_value(){return this->get_override("test_value")();}
45
46
47
48
                inline void set_value(int offset=0){this->get_override("set_value")();}
                inline double* value_ptr(int offset=0){return this->get_override("value_ptr")();}
                inline void set_test_value(int offset=0){this->get_override("set_test_value")();}
                inline double* test_value_ptr(int offset=0){return this->get_override("test_value_ptr")();}
49
50
51
52
                inline bool is_nan(){return this->get_override("is_nan")();}
                inline bool is_const(){return this->get_override("is_const")();}
                inline NODE_TYPE type(){return this->get_override("type")();}
                inline int rung(int cur_rung = 0){return this->get_override("rung")();}
53
                inline std::map<int, int> primary_feature_decomp(){return this->get_override("primary_feature_decomp")();}
54
55
                void update_primary_feature_decomp(std::map<int, int>& pf_decomp){this->get_override("update_primary_feature_decomp")();}
                void update_postfix(std::string& cur_expr){this->get_override("update_postfix")();}
56
                inline std::string get_postfix_term(){return this->get_override("get_postfix_term")();}
57
58
                inline void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, int pl_mn, int& expected_abs_tot){this->get_override("update_add_sub_leaves");}
                inline void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot){this->get_override("update_div_mult_leaves");}
Thomas Purcell's avatar
Bug fix    
Thomas Purcell committed
59
60
                inline int n_feats(){return this->get_override("n_feats")();}
                inline std::shared_ptr<Node> feat(int ind){return this->get_override("feat")();}
61
62
63
64
65
66
67
            };
            /**
             * @brief struct used wrap an OperatorNode object for conversion
             */
            template<int N>
            struct OperatorNodeWrap : OperatorNode<N>, py::wrapper<OperatorNode<N>>
            {
68
69
                inline void set_value(int offset=0){this->get_override("set_value")();}
                inline void set_test_value(int offset=0){this->get_override("set_test_value")();}
70
71
72
                inline NODE_TYPE type(){return this->get_override("type")();}
                inline int rung(int cur_rung = 0){return this->get_override("rung")();}
                inline std::string expr(){return this->get_override("expr")();}
73
                inline std::string get_latex_expr(std::string cap){return this->get_override("latex_expr")();}
74
                inline Unit unit(){return this->get_override("unit")();}
75
                inline std::string get_postfix_term(){return this->get_override("get_postfix_term")();}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
                inline void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, int pl_mn, int& expected_abs_tot){this->get_override("update_add_sub_leaves")();}
                inline void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot){this->get_override("update_div_mult_leaves")();}
            };

            /**
             * @brief Register the Node for accessing the object via python
             */
            static void registerNode();

            /**
             * @brief Register the FeatureNode for accessing the object via python
             */
            static void registerFeatureNode();

            /**
             * @brief Register the ModelNode for accessing the object via python
             */
            static void registerModelNode();

            /**
             * @brief Register the OperatorNode for accessing the object via python
             */
            template<int N>
            static void registerOperatorNode()
            {
                py::class_<OperatorNodeWrap<N>, py::bases<Node>, boost::noncopyable>("OperatorNode")
                    .def("is_nan", &OperatorNode<N>::is_nan, "@DocString_op_node_is_nan@")
                    .def("is_const", &OperatorNode<N>::is_const, "@DocString_op_node_is_const@")
                    .def("set_value", py::pure_virtual(&OperatorNode<N>::set_value), "@DocString_op_node_set_value@")
                    .def("set_test_value", py::pure_virtual(&OperatorNode<N>::set_test_value), "@DocString_op_node_set_test_value@")
                    .def("rung", py::pure_virtual(&OperatorNode<N>::rung), "@DocString_op_node_rung@")
                    .def("expr", py::pure_virtual(&OperatorNode<N>::expr), "@DocString_op_node_expr@")
108
                    .def("latex_expr", py::pure_virtual(&OperatorNode<N>::latex_expr), "@DocString_op_node_latex_expr@")
109
                    .def("unit", py::pure_virtual(&OperatorNode<N>::unit), "@DocString_op_node_unit@")
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
110
111
                    .add_property("n_feats", &OperatorNode<N>::n_feats, "@DocString_op_node_n_feats@")
                    .add_property("feat", &OperatorNode<N>::feat, "@DocString_op_node_feat@")
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
                ;
            }

            /**
             * @brief Register the AddNode object for conversion to a python object
             */
            static void registerAddNode();

            /**
             * @brief Register the SubNode object for conversion to a python object
             */
            static void registerSubNode();

            /**
             * @brief Register the DivNode object for conversion to a python object
             */
            static void registerDivNode();

            /**
             * @brief Register the MultNode object for conversion to a python object
             */
            static void registerMultNode();

            /**
             * @brief Register the AbsDiffNode object for conversion to a python object
             */
            static void registerAbsDiffNode();

            /**
             * @brief Register the AbsNode object for conversion to a python object
             */
            static void registerAbsNode();

            /**
             * @brief Register the InvNode object for conversion to a python object
             */
            static void registerInvNode();

            /**
             * @brief Register the LogNode object for conversion to a python object
             */
            static void registerLogNode();

            /**
             * @brief Register the ExpNode object for conversion to a python object
             */
            static void registerExpNode();

            /**
             * @brief Register the NegExpNode object for conversion to a python object
             */
            static void registerNegExpNode();

            /**
             * @brief Register the SinNode object for conversion to a python object
             */
            static void registerSinNode();

            /**
             * @brief Register the CosNode object for conversion to a python object
             */
            static void registerCosNode();

            /**
             * @brief Register the CbNode object for conversion to a python object
             */
            static void registerCbNode();

            /**
             * @brief Register the CbrtNode object for conversion to a python object
             */
            static void registerCbrtNode();

            /**
             * @brief Register the SqNode object for conversion to a python object
             */
            static void registerSqNode();

            /**
             * @brief Register the SqrtNode object for conversion to a python object
             */
            static void registerSqrtNode();

            /**
             * @brief Register the SixPowNode object for conversion to a python object
             */
            static void registerSixPowNode();

        }
    }

    namespace descriptor_identifier
    {
205
206
207
        struct SISSO_DI_Wrap : SISSO_DI, py::wrapper<SISSO_DI>
        {
            inline void l0_norm(){this->get_override("l0_norm")();}
208
209
210
211
212
213
            inline void fit(){this->get_override("fit")();}
        };

        struct Model_Wrap : Model, py::wrapper<Model>
        {
            inline void to_file(std::string filename, bool train = true, std::vector<int> test_inds = {}){this->get_override("to_file")();}
214
        };
215
216
217
218
219
220

        /**
         * @brief Register the Model object for conversion to a python object
         */
        static void registerModel();

221
222
223
224
225
        /**
         * @brief Register the Model object for conversion to a python object
         */
        static void registerModelRegressor();

226
227
228
229
230
        /**
         * @brief Register the Model object for conversion to a python object
         */
        static void registerModelLogRegressor();

231
232
233
234
235
        /**
         * @brief Register the Model object for conversion to a python object
         */
        static void registerModelClassifier();

236
237
238
239
240
        /**
         * @brief Register the SISSORegressor object for conversion to a python object
         */
        static void registerSISSO_DI();

241
242
243
244
        /**
         * @brief Register the SISSORegressor object for conversion to a python object
         */
        static void registerSISSORegressor();
245

246
247
248
249
        /**
         * @brief Register the SISSORegressor object for conversion to a python object
         */
        static void registerSISSOLogRegressor();
250
251
252
253
254

        /**
         * @brief Register the SISSORegressor object for conversion to a python object
         */
        static void registerSISSOClassifier();
255
256
257
    }
}

258
#endif