FeatureSpace.hpp 25.8 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
    int _max_param_depth; //!< Max depth to parameterize a feature (default=_max_rung)
88
    const bool _reparam_residual; //!< If True then reparameterize using the residuals of each model
89

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

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

172
173
174
175
176
177
178
179
    /**
     * @brief Uses _allowed_ops to set the operator lists
     */
    void set_op_lists();

    /**
     * @brief Initializes the output files for SIS
     */
180
    void initialize_fs_output_files() const;
181
182
183
184
    /**
     * @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
     */
185
    void generate_feature_space();
Thomas Purcell's avatar
Thomas Purcell committed
186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Purcell's avatar
Thomas Purcell committed
271
    #ifdef PARAMETERIZE
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
    /**
     * @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,
288
289
        const double l_bound=1e-50,
        const double u_bound=1e50
290
    );
Thomas Purcell's avatar
Thomas Purcell committed
291
    #else
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    /**
     * @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,
306
307
        const double l_bound=1e-50,
        const double u_bound=1e50
308
    );
Thomas Purcell's avatar
Thomas Purcell committed
309
    #endif
310

311
312
313
314
315
316
317
318
319
    /**
     * @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
     */
320
    void project_generated(const double* prop, const int size, std::vector<node_ptr>& phi_selected, std::vector<double>& scores_selected);
321

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

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

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

347
348
    // Python Interface Functions
    #ifdef PY_BINDINGS
349
    #ifdef PARAMETERIZE
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
    /**
     * @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
367
     * @param max_param_depth the maximum paremterization depths for features
368
     * @param reparam_residual If True then reparameterize using the residuals of each model
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
     */
    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,
384
385
        int max_param_depth = -1,
        bool reparam_residual=false
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    );

    /**
     * @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
404
     * @param reparam_residual If True then reparameterize using the residuals of each model
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
     */
    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,
420
421
        int max_param_depth = -1,
        bool reparam_residual=false
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
448
449
450
451
452
453
454
    #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
    );
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
481
482
483
484
485
486
487
    /**
     * @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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
    /**
     * @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
505
        std::string project_type="regression",
506
507
508
509
510
511
512
513
514
515
        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
516
     * @param prop The property to be learned (training data)
517
518
519
520
521
522
523
524
525
526
     * @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
527
        std::string project_type="regression",
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
605
606
607
608
609
610
611
        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
     */
612
    inline ModelNode get_feature(const int ind) const {return ModelNode(_phi[ind]);}
613
    #endif
Thomas Purcell's avatar
Thomas Purcell committed
614
615
};

616
#endif