FeatureSpace.hpp 25.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
/** @file feature_creation/feature_space/FeatureSpace.hpp
 *  @brief Create a feature space from an initial set of features and algebraic operators
 *
 *  Use an initial set of features and combine them to generate more complicated algebraical features. SIS is also performed here
 *
 *  @author Thomas A. R. Purcell (tpurcell)
 *  @bug No known bugs.
 */

Thomas Purcell's avatar
Thomas Purcell committed
10
11
12
#ifndef FEATURE_SPACE
#define FEATURE_SPACE

Thomas Purcell's avatar
Thomas Purcell committed
13
#include <boost/serialization/shared_ptr.hpp>
14
#include <boost/filesystem.hpp>
Thomas Purcell's avatar
Thomas Purcell committed
15

Thomas Purcell's avatar
Thomas Purcell committed
16
#include <iostream>
Thomas Purcell's avatar
Thomas Purcell committed
17
#include <iomanip>
18
#include <utility>
Thomas Purcell's avatar
Thomas Purcell committed
19

Thomas Purcell's avatar
Thomas Purcell committed
20
21
22
23
24
25
26
27
28
29
#include "mpi_interface/MPI_Interface.hpp"
#include "mpi_interface/MPI_ops.hpp"
#include "mpi_interface/serialize_tuple.h"
#include "feature_creation/node/ModelNode.hpp"
#include "feature_creation/node/operator_nodes/allowed_ops.hpp"
#include "feature_creation/node/utils.hpp"
#include "feature_creation/node/value_storage/nodes_value_containers.hpp"
#include "utils/compare_features.hpp"
#include "utils/project.hpp"

30
31
32
33
#ifdef PY_BINDINGS
    namespace np = boost::python::numpy;
    namespace py = boost::python;
#endif
34

35
// DocString: cls_feat_space
36
37
38
39
40
/**
 * @brief Feature Space for SISSO calculations
 * @details Stores and performs all feature calculations for SIS
 *
 */
Thomas Purcell's avatar
Thomas Purcell committed
41
42
class FeatureSpace
{
43
    std::vector<node_ptr> _phi_selected; //!< selected features
44
    std::vector<node_ptr> _phi; //!< all features
45
    const std::vector<node_ptr> _phi_0; //!< initial feature space
46

47
    #ifdef PARAMETERIZE
48
49
50
    std::vector<un_param_op_node_gen> _un_param_operators; //!< list of all parameterized unary operators with free parameters
    std::vector<bin_param_op_node_gen> _com_bin_param_operators; //!< list of all parameterized commutable binary operators with free parameters
    std::vector<bin_param_op_node_gen> _bin_param_operators; //!< list of all parameterized binary operators with free parameters
51
    std::vector<std::string> _allowed_param_ops; //!< Map of parameterization operator set (set of operators and non-linear parameters used for a non-linear least squares fit to property)
52
    #endif
53

54
55
56
57
58
    std::vector<std::string> _allowed_ops; //!< list of all allowed operators strings
    std::vector<un_op_node_gen> _un_operators; //!< list of all unary operators
    std::vector<bin_op_node_gen> _com_bin_operators; //!< list of all commutable binary operators
    std::vector<bin_op_node_gen> _bin_operators; //!< list of all binary operators

59
    std::vector<double> _prop; //!< The property to fit
60
61
    std::vector<double> _scores; //!< projection scores for each feature

62
    const std::vector<int> _task_sizes; //!< The number of elements in each task (training data)
63
    std::vector<int> _start_gen; //!< list of the indexes where each generation starts in _phi
Thomas Purcell's avatar
Thomas Purcell committed
64
    const std::string _project_type; //!< The type of projection that should be done during SIS
65
66
    const std::string _feature_space_file; //!< File to store information about the selected features
    const std::string _feature_space_summary_file; //!< File to store information about the selected features
67

68
69
70
71
    std::function<void(const double*, double*, const std::vector<node_ptr>&, const std::vector<int>&, const int)> _project; //!< Function used to calculate the scores for SIS
    std::function<void(const double*, double*, const std::vector<node_ptr>&, const std::vector<int>&, const int)> _project_no_omp; //!< Function used to calculate the scores for SIS without changing omp environment
    std::function<bool(const double*, const int, const double, const std::vector<double>&, const double, const int, const int)> _is_valid; //!< Function used to calculate the scores for SIS
    std::function<bool(const double*, const int, const double, const std::vector<node_ptr>&, const std::vector<double>&, const double)> _is_valid_feat_list; //!< Function used to calculate the scores for SIS without changing omp environment
72

73
    std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI communicator
74

75
76
77
    const double _cross_cor_max; //!< Maximum cross-correlation used for selecting features
    const double _l_bound; //!< lower bound for absolute value of the features
    const double _u_bound; //!< upper bound for absolute value of the features
78

Thomas Purcell's avatar
Thomas Purcell committed
79
    int _n_rung_store; //!< Total rungs stored
80
81
    int _n_feat; //!< Total number of features
    int _max_phi; //!< Maximum rung for the feature creation
82

83
84
85
    const int _n_sis_select; //!< Number of features to select for each dimensions
    const int _n_samp; //!< Number of samples (training data)
    const int _n_rung_generate; //!< Total number of rungs to generate on the fly
86

87
88
    int _max_param_depth; //!< Max depth to parameterize a feature (default=_max_rung)

Thomas Purcell's avatar
Thomas Purcell committed
89
public:
Thomas Purcell's avatar
Thomas Purcell committed
90

91
    #ifdef PARAMETERIZE
92
93
    /**
     * @brief Constructor for the feature space
94
     * @details constructs the feature space from an initial set of features and a list of allowed operators
95
96
     *
     * @param mpi_comm MPI communicator for the calculations
97
     * @param phi_0 The initial set of features to combine
98
     * @param allowed_ops list of allowed operators
99
     * @param allowed_param_ops dictionary of the parameterizable operators and their associated free parameters
100
     * @param prop The property to be learned (training data)
101
102
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
103
104
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
105
106
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
Thomas Purcell's avatar
Thomas Purcell committed
107
     * @param cross_corr_max Maximum cross-correlation used for selecting features
108
     * @param min_abs_feat_val minimum absolute feature value
109
     * @param max_abs_feat_val maximum absolute feature value
110
     * @param max_param_depth the maximum paremterization depths for features
111
     */
Thomas Purcell's avatar
Thomas Purcell committed
112
    FeatureSpace(
Thomas Purcell's avatar
Thomas Purcell committed
113
        std::shared_ptr<MPI_Interface> mpi_comm,
Thomas Purcell's avatar
Thomas Purcell committed
114
115
        std::vector<node_ptr> phi_0,
        std::vector<std::string> allowed_ops,
Thomas Purcell's avatar
Thomas Purcell committed
116
        std::vector<std::string> allowed_param_ops,
117
        std::vector<double> prop,
Thomas Purcell's avatar
Thomas Purcell committed
118
        std::vector<int> task_sizes,
119
        std::string project_type="regression",
Thomas Purcell's avatar
Thomas Purcell committed
120
121
        int max_phi=1,
        int n_sis_select=1,
122
123
        int max_store_rung=-1,
        int n_rung_generate=0,
Thomas Purcell's avatar
Thomas Purcell committed
124
        double cross_corr_max=1.0,
125
        double min_abs_feat_val=1e-50,
126
        double max_abs_feat_val=1e50,
Thomas Purcell's avatar
Thomas Purcell committed
127
        int max_param_depth = -1
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
    #else
    /**
     * @brief Constructor for the feature space
     * @details constructs the feature space from an initial set of features and a list of allowed operators
     *
     * @param mpi_comm MPI communicator for the calculations
     * @param phi_0 The initial set of features to combine
     * @param allowed_ops list of allowed operators
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     * @param min_abs_feat_val minimum absolute feature value
     * @param max_abs_feat_val maximum absolute feature value
     */
    FeatureSpace(
        std::shared_ptr<MPI_Interface> mpi_comm,
        std::vector<node_ptr> phi_0,
        std::vector<std::string> allowed_ops,
        std::vector<double> prop,
        std::vector<int> task_sizes,
        std::string project_type="regression",
        int max_phi=1,
        int n_sis_select=1,
        int max_store_rung=-1,
        int n_rung_generate=0,
        double cross_corr_max=1.0,
        double min_abs_feat_val=1e-50,
        double max_abs_feat_val=1e50
    );
    #endif
164
165
166
    /**
     * @brief Initialize the feature set given a property vector
     */
Thomas Purcell's avatar
Thomas Purcell committed
167
    void initialize_fs();
168

169
170
171
172
173
174
175
176
    /**
     * @brief Uses _allowed_ops to set the operator lists
     */
    void set_op_lists();

    /**
     * @brief Initializes the output files for SIS
     */
177
    void initialize_fs_output_files() const;
178
179
180
181
    /**
     * @brief Generate the full feature set from the allowed operators and initial feature set
     * @details populates phi with all features from an initial set and the allowed operators
     */
182
    void generate_feature_space();
Thomas Purcell's avatar
Thomas Purcell committed
183

184
    /**
185
     * @brief The selected feature space
186
     */
187
    inline std::vector<node_ptr> phi_selected() const {return _phi_selected;};
188
189

    /**
190
     * @brief The full feature space
191
     */
192
    inline std::vector<node_ptr> phi() const {return _phi;};
193
194

    /**
195
     * @brief The initial feature space
196
     */
197
    inline std::vector<node_ptr> phi0() const {return _phi_0;};
198
199

    /**
200
     * @brief The vector of projection scores for SIS
201
     */
202
    inline std::vector<double> scores() const {return _scores;}
203

204
    /**
205
     * @brief The MPI Communicator
206
     */
207
    inline std::shared_ptr<MPI_Interface> mpi_comm() const {return _mpi_comm;}
208

209
    /**
210
     * @brief The vector storing the number of samples in each task
211
     */
212
    inline std::vector<int> task_sizes() const {return _task_sizes;}
213

214
    // DocString: feat_space_feature_space_file
215
    /**
216
     * @brief The feature space filename
217
     */
218
    inline std::string feature_space_file() const {return _feature_space_file;}
219

220
    // DocString: feat_space_l_bound
221
    /**
222
     * @brief The minimum absolute value of the feature
223
     */
224
    inline double l_bound() const {return _l_bound;}
225

226
    // DocString: feat_space_u_bound
227
    /**
228
     * @brief The maximum absolute value of the feature
229
     */
230
    inline double u_bound() const {return _u_bound;}
231

232
    // DocString: feat_space_max_phi
233
    /**
234
     * @brief The maximum rung of the feature space
235
     */
236
    inline int max_phi() const {return _max_phi;}
237

238
    // DocString: feat_space_n_sis_select
239
    /**
240
     * @brief The number of features selected in each SIS step
241
     */
242
    inline int n_sis_select() const {return _n_sis_select;}
243

244
    // DocString: feat_space_n_samp
245
    /**
246
     * @brief The number of samples per feature
247
     */
248
    inline int n_samp() const {return _n_samp;}
249

250
    // DocString: feat_space_n_feat
251
    /**
252
     * @brief The number of features in the feature space
253
     */
254
    inline int n_feat() const {return _n_feat;}
255

256
    // DocString: feat_space_n_rung_store
257
    /**
258
     * @brief The number of rungs whose feature training data is stored in memory
259
     */
260
    inline int n_rung_store() const {return _n_rung_store;}
261

262
    // DocString: feat_space_n_rung_generate
263
    /**
264
     * @brief The number of rungs to be generated on the fly during SIS
265
     */
266
    inline int n_rung_generate() const {return _n_rung_generate;}
267

Thomas Purcell's avatar
Thomas Purcell committed
268
    #ifdef PARAMETERIZE
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
    /**
     * @brief Generate a new set of features from a single feature
     * @details Take in the feature and perform all valid algebraic operations on it.
     *
     * @param feat The feature to spawn new features from
     * @param feat_set The feature set to pull features from for combinations
     * @param feat_ind starting index for the next feature generated
     * @param optimizer The object used to optimize the parameterized features
     * @param l_bound lower bound for the absolute value of the feature
     * @param u_bound upper bound for the abosulte value of the feature
     */
    void generate_new_feats(
        std::vector<node_ptr>::iterator& feat,
        std::vector<node_ptr>& feat_set,
        unsigned long int& feat_ind,
        std::shared_ptr<NLOptimizer> optimizer,
285
286
        const double l_bound=1e-50,
        const double u_bound=1e50
287
    );
Thomas Purcell's avatar
Thomas Purcell committed
288
    #else
289
290
291
292
293
294
295
296
297
298
299
300
301
302
    /**
     * @brief Generate a new set of features from a single feature
     * @details Take in the feature and perform all valid algebraic operations on it.
     *
     * @param feat The feature to spawn new features from
     * @param feat_set The feature set to pull features from for combinations
     * @param feat_ind starting index for the next feature generated
     * @param l_bound lower bound for the absolute value of the feature
     * @param u_bound upper bound for the abosulte value of the feature
     */
    void generate_new_feats(
        std::vector<node_ptr>::iterator& feat,
        std::vector<node_ptr>& feat_set,
        unsigned long int& feat_ind,
303
304
        const double l_bound=1e-50,
        const double u_bound=1e50
305
    );
Thomas Purcell's avatar
Thomas Purcell committed
306
    #endif
307

308
309
310
311
312
313
314
315
316
    /**
     * @brief Calculate the SIS Scores for feature generated on the fly
     * @details Create the next rung of features and calculate their projection scores. Only keep those that can be selected by SIS.
     *
     * @param prop Pointer to the start of the vector storing the data to project the features onto
     * @param size The size of the data to project over
     * @param phi_selected The features that would be selected from the previous rungs
     * @param scores_selected The projection scores of the features that would be selected from the previous rungs
     */
317
    void project_generated(const double* prop, const int size, std::vector<node_ptr>& phi_selected, std::vector<double>& scores_selected);
318

319
320
    /**
     * @brief Perform SIS on a feature set with a specified property
321
     * @details Perform sure-independence screening with either the correct property or the error
322
     *
323
     * @param prop The property to perform SIS over
324
     */
325
    void sis(const std::vector<double>& prop);
326

327
    // DocString: feat_space_feat_in_phi
328
329
330
    /**
     * @brief Is a feature in this process' _phi?
     *
331
332
     * @param ind The index of the feature
     * @return True if feature is in this rank's _phi
333
     */
334
    inline bool feat_in_phi(int ind) const {return (ind >= _phi[0]->feat_ind()) && (ind <= _phi.back()->feat_ind());}
335

336
337
338
339
340
341
    // DocString: feat_space_remove_feature
    /**
     * @brief Remove a feature from phi
     *
     * @param ind index of feature to remove
     */
342
    void remove_feature(const int ind);
343

344
345
    // Python Interface Functions
    #ifdef PY_BINDINGS
346
    #ifdef PARAMETERIZE
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    /**
     * @brief Constructor for the feature space that takes in python objects
     * @details constructs the feature space from an initial set of features and a list of allowed operators (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param phi_0 The initial set of features to combine
     * @param allowed_ops list of allowed operators
     * @param allowed_param_ops dictionary of the parameterizable operators and their associated free parameters
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     * @param min_abs_feat_val minimum absolute feature value
     * @param max_abs_feat_val maximum absolute feature value
364
     * @param max_param_depth the maximum paremterization depths for features
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
     */
    FeatureSpace(
        py::list phi_0,
        py::list allowed_ops,
        py::list allowed_param_ops,
        py::list prop,
        py::list task_sizes,
        std::string project_type="regression",
        int max_phi=1,
        int n_sis_select=1,
        int max_store_rung=-1,
        int n_rung_generate=0,
        double cross_corr_max=1.0,
        double min_abs_feat_val=1e-50,
        double max_abs_feat_val=1e50,
        int max_param_depth = -1
    );

    /**
     * @brief Constructor for the feature space that takes in python and numpy objects
     * @details constructs the feature space from an initial set of features and a list of allowed operators (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param phi_0 The initial set of features to combine
     * @param allowed_ops list of allowed operators
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     * @param min_abs_feat_val minimum absolute feature value
     * @param max_abs_feat_val maximum absolute feature value
     */
    FeatureSpace(
        py::list phi_0,
        py::list allowed_ops,
        py::list allowed_param_ops,
        np::ndarray prop,
        py::list task_sizes,
        std::string project_type="regression",
        int max_phi=1,
        int n_sis_select=1,
        int max_store_rung=-1,
        int n_rung_generate=0,
        double cross_corr_max=1.0,
        double min_abs_feat_val=1e-50,
        double max_abs_feat_val=1e50,
        int max_param_depth = -1
    );
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
    #else
    /**
     * @brief Constructor for the feature space that takes in python objects
     * @details constructs the feature space from an initial set of features and a list of allowed operators (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param phi_0 The initial set of features to combine
     * @param allowed_ops list of allowed operators
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     * @param min_abs_feat_val minimum absolute feature value
     * @param max_abs_feat_val maximum absolute feature value
     */
    FeatureSpace(
        py::list phi_0,
        py::list allowed_ops,
        py::list prop,
        py::list task_sizes,
        std::string project_type="regression",
        int max_phi=1,
        int n_sis_select=1,
        int max_store_rung=-1,
        int n_rung_generate=0,
        double cross_corr_max=1.0,
        double min_abs_feat_val=1e-50,
        double max_abs_feat_val=1e50
    );
448

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
    /**
     * @brief Constructor for the feature space that takes in python and numpy objects
     * @details constructs the feature space from an initial set of features and a list of allowed operators (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param phi_0 The initial set of features to combine
     * @param allowed_ops list of allowed operators
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param max_phi highest rung value for the calculation
     * @param n_sis_select number of features to select during each SIS step
     * @param max_store_rung number of rungs to calculate and store the value of the features for all samples
     * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm)
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     * @param min_abs_feat_val minimum absolute feature value
     * @param max_abs_feat_val maximum absolute feature value
     */
    FeatureSpace(
        py::list phi_0,
        py::list allowed_ops,
        np::ndarray prop,
        py::list task_sizes,
        std::string project_type="regression",
        int max_phi=1,
        int n_sis_select=1,
        int max_store_rung=-1,
        int n_rung_generate=0,
        double cross_corr_max=1.0,
        double min_abs_feat_val=1e-50,
        double max_abs_feat_val=1e50
    );
    #endif
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
    /**
     * @brief Constructor for the feature space that takes in python and numpy objects
     * @details constructs the feature space from an initial set of features and a file containing postfix expressions for the features (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param feature_file The file with the postfix expressions for the feature space
     * @param phi_0 The initial set of features to combine
     * @param prop The property to be learned (training data)
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param n_sis_select number of features to select during each SIS step
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     */
    FeatureSpace(
        std::string feature_file,
        py::list phi_0,
        np::ndarray prop,
        py::list task_sizes,
Thomas Purcell's avatar
Thomas Purcell committed
498
        std::string project_type="regression",
499
500
501
502
503
504
505
506
507
508
        int n_sis_select=1,
        double cross_corr_max=1.0
    );

    /**
     * @brief Constructor for the feature space that takes in python and numpy objects
     * @details constructs the feature space from an initial set of features and a file containing postfix expressions for the features (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     *
     * @param feature_file The file with the postfix expressions for the feature space
     * @param phi_0 The initial set of features to combine
Thomas Purcell's avatar
Thomas Purcell committed
509
     * @param prop The property to be learned (training data)
510
511
512
513
514
515
516
517
518
519
     * @param task_sizes The number of samples per task
     * @param project_type The projection operator to use
     * @param n_sis_select number of features to select during each SIS step
     * @param cross_corr_max Maximum cross-correlation used for selecting features
     */
    FeatureSpace(
        std::string feature_file,
        py::list phi_0,
        py::list prop,
        py::list task_sizes,
Thomas Purcell's avatar
Thomas Purcell committed
520
        std::string project_type="regression",
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
        int n_sis_select=1,
        double cross_corr_max=1.0
    );

    // DocString: feat_space_sis_arr
    /**
     * @brief Wrapper function for SIS using a numpy array
     *
     * @param prop(np.ndarray) The property to perform SIS over as a numpy array
     */
    inline void sis(np::ndarray prop)
    {
        std::vector<double> prop_vec = python_conv_utils::from_ndarray<double>(prop);
        sis(prop_vec);
    }

    // DocString: feat_space_sis_list
    /**
     * @brief Wrapper function for SIS using a python list
     *
     * @param prop(list) The property to perform SIS over as a python list
     */
    inline void sis(py::list prop)
    {
        std::vector<double> prop_vec = python_conv_utils::from_list<double>(prop);
        sis(prop_vec);
    }

    // DocString: feat_space_phi_selected_py
    /**
     * @brief The selected feature space (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     * @return _phi_selected as a python list
     */
    py::list phi_selected_py();

    // DocString: feat_space_phi0_py
    /**
     * @brief The initial feature space (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     * @return _phi0 as a python list
     */
    py::list phi0_py();

    // DocString: feat_space_phi_py
    /**
     * @brief The feature space (cpp definition in <python/feature_creation/FeatureSpace.cpp>)
     * @return _phi as a python list
     */
    py::list phi_py();

    // DocString: feat_space_scores_py
    /**
     * @brief The vector of projection scores for SIS
     * @return _scores as a numpy array
     */
    inline np::ndarray scores_py(){return python_conv_utils::to_ndarray<double>(_scores);};

    // DocString: feat_space_task_sizes_py
    /**
     * @brief The vector storing the number of samples in each task
     * @return _task_sizes as a python list
     */
    inline py::list task_sizes_py(){return python_conv_utils::to_list<int>(_task_sizes);};

    // DocString: feat_space_allowed_ops_py
    /**
     * @brief The list of allowed operator nodes
     * @return _allowed_ops as a python list
     */
    inline py::list allowed_ops_py(){return python_conv_utils::to_list<std::string>(_allowed_ops);}

    // DocString: feat_space_start_gen_py
    /**
     * @brief The index in _phi where each generation starts
     * @return _start_gen as a python list
     */
    inline py::list start_gen_py(){return python_conv_utils::to_list<int>(_start_gen);}

    // DocString: feat_space_get_feature
    /**
     * @brief Return a feature at a specified index
     *
     * @param ind index of the feature to get
     * @return A ModelNode of the feature at index ind
     */
605
    inline ModelNode get_feature(const int ind) const {return ModelNode(_phi[ind]);}
606
    #endif
Thomas Purcell's avatar
Thomas Purcell committed
607
608
};

609
#endif