Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
cpp_sisso
Commits
4e18d8e8
Commit
4e18d8e8
authored
Jun 02, 2020
by
Thomas Purcell
Browse files
Only storing primary features
Initial commit towards resizing temporary storage arrays
parent
77ab05f9
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/feature_creation/feature_space/FeatureSpace.cpp
View file @
4e18d8e8
...
...
@@ -24,6 +24,7 @@ FeatureSpace::FeatureSpace(
std
::
vector
<
std
::
string
>
allowed_ops
,
int
max_phi
,
int
n_sis_select
,
int
max_store_rung
,
double
max_abs_feat_val
)
:
_mpi_comm
(
mpi_comm
),
...
...
@@ -31,6 +32,7 @@ FeatureSpace::FeatureSpace(
_n_sis_select
(
n_sis_select
),
_n_samp
(
phi_0
[
0
]
->
n_samp
()),
_n_feat
(
phi_0
.
size
()),
_n_rung_store
(
max_store_rung
),
_max_abs_feat_val
(
max_abs_feat_val
),
_start_gen
(
1
,
0
),
_scores
(
phi_0
.
size
(),
0.0
),
...
...
@@ -55,7 +57,6 @@ FeatureSpace::FeatureSpace(
void
FeatureSpace
::
generate_feature_space
()
{
std
::
vector
<
double
>
scores
(
_phi
.
size
());
for
(
int
nn
=
1
;
nn
<=
_max_phi
;
++
nn
)
{
std
::
vector
<
node_ptr
>
next_phi
;
...
...
@@ -66,8 +67,6 @@ void FeatureSpace::generate_feature_space()
int
feat_ind
=
_n_feat
+
node_value_arrs
::
get_max_number_features
(
_allowed_ops
,
1
,
start_end
[
0
]);
next_phi
.
reserve
(
node_value_arrs
::
get_max_number_features
(
_allowed_ops
,
1
,
start_end
[
1
]
-
start_end
[
0
]));
scores
.
resize
(
node_value_arrs
::
get_max_number_features
(
_allowed_ops
,
1
,
_phi
.
size
()));
scores
.
reserve
(
node_value_arrs
::
get_max_number_features
(
_allowed_ops
,
1
,
_phi
.
size
()));
for
(
auto
feat_1
=
_phi
.
begin
()
+
start_end
[
0
];
feat_1
!=
_phi
.
begin
()
+
start_end
[
1
];
++
feat_1
)
{
...
...
@@ -135,19 +134,22 @@ void FeatureSpace::generate_feature_space()
{
_phi
.
reserve
(
_phi
.
size
()
+
next_phi_vec
.
size
());
for
(
auto
&
feat
:
next_phi_vec
)
{
if
(
nn
<=
node_value_arrs
::
N_RUNGS_STORED
)
{
feat
->
set_value
();
_phi
.
push_back
(
feat
);
}
else
{
_phi
.
push_back
(
feat
);
}
}
_phi
.
push_back
(
feat
);
}
}
// if(0 < _n_rung_store < _max_phi)
// {
// node_value_arrs::resize_values_arr(_n_rung_store, _start_gen[_n_rung_store+1], true);
// for(auto feat = _phi.begin(); feat != _phi.begin() + _start_gen[_n_rung_store+1]; ++feat)
// (*feat)->set_value();
// }
// else if(_n_rung_store > 0)
// {
// node_value_arrs::resize_values_arr(_max_phi, _phi.size(), false);
// for(auto feat = _phi.begin(); feat != _phi.end(); ++feat)
// (*feat)->set_value();
// }
_n_feat
=
_phi
.
size
();
}
...
...
src/feature_creation/feature_space/FeatureSpace.hpp
View file @
4e18d8e8
...
...
@@ -4,6 +4,7 @@
#include
<mpi_interface/MPI_Interface.hpp>
#include
<feature_creation/node/FeatureNode.hpp>
#include
<feature_creation/node/operator_nodes/allowed_ops.hpp>
#include
<feature_creation/node/value_storage/nodes_value_containers.hpp>
#include
<boost/serialization/shared_ptr.hpp>
...
...
@@ -22,6 +23,7 @@ class FeatureSpace
int
_n_sis_select
;
//!< Number of features to select for each dimensions
int
_n_samp
;
//!< Number of samples
int
_n_feat
;
//!< Total number of features
int
_n_rung_store
;
//!< Total rungs stored
double
_max_abs_feat_val
;
//!< Maximum absolute value for any feature
...
...
@@ -57,6 +59,7 @@ public:
std
::
vector
<
std
::
string
>
allowed_ops
,
int
max_phi
=
1
,
int
n_sis_select
=
1
,
int
max_store_rung
=
2
,
double
max_abs_feat_val
=
1e27
);
...
...
src/feature_creation/node/FeatureNode.hpp
View file @
4e18d8e8
...
...
@@ -57,7 +57,7 @@ public:
/**
* @brief Set the value for the feature
*/
inline
void
set_value
(
int
offset
=
-
1
){
return
;}
inline
void
set_value
(
int
offset
=
-
1
){
std
::
copy_n
(
node_value_arrs
::
PRIMARY_FEAT_ARR
.
get
()
+
_feat_ind
*
_n_samp
,
_n_samp
,
value_ptr
())
;}
/**
* @brief Check if the feature contains NaN
...
...
src/feature_creation/node/value_storage/nodes_value_containers.cpp
View file @
4e18d8e8
...
...
@@ -4,9 +4,11 @@ int node_value_arrs::N_SAMPLES;
int
node_value_arrs
::
N_STORE_FEATURES
;
int
node_value_arrs
::
N_RUNGS_STORED
;
std
::
unique_ptr
<
int
[]
>
node_value_arrs
::
TEMP_STORAGE_REG
;
std
::
unique_ptr
<
double
[]
>
node_value_arrs
::
VALUES_ARR
;
std
::
unique_ptr
<
double
[]
>
node_value_arrs
::
TEMP_STORAGE_ARR
;
std
::
unique_ptr
<
int
[]
>
node_value_arrs
::
TEMP_STORAGE_REG
=
nullptr
;
std
::
unique_ptr
<
double
[]
>
node_value_arrs
::
VALUES_ARR
=
nullptr
;
std
::
unique_ptr
<
double
[]
>
node_value_arrs
::
PRIMARY_FEAT_ARR
=
nullptr
;
std
::
unique_ptr
<
double
[]
>
node_value_arrs
::
TEMP_STORAGE_ARR
=
nullptr
;
int
node_value_arrs
::
get_number_new_features
(
std
::
string
new_op
,
int
n_current_features
)
{
...
...
@@ -48,15 +50,31 @@ int node_value_arrs::get_max_number_features(std::vector<std::string> allowed_op
return
n_feats
;
}
void
node_value_arrs
::
setup
_values_arr
(
int
n_samples
,
int
n_
rung
,
int
n_primary_feat
,
std
::
vector
<
std
::
string
>
allowed_operators
)
void
node_value_arrs
::
initialize
_values_arr
(
int
n_samples
,
int
n_
primary_feat
)
{
N_SAMPLES
=
n_samples
;
N_RUNGS_STORED
=
n_rung
;
N_STORE_FEATURES
=
get_max_number_features
(
allowed_operators
,
n_rung
,
n_primary_feat
)
;
N_RUNGS_STORED
=
0
;
N_STORE_FEATURES
=
n_primary_feat
;
PRIMARY_FEAT_ARR
=
std
::
unique_ptr
<
double
[]
>
(
new
double
[
N_STORE_FEATURES
*
N_SAMPLES
]);
VALUES_ARR
=
std
::
unique_ptr
<
double
[]
>
(
new
double
[
N_STORE_FEATURES
*
N_SAMPLES
]);
TEMP_STORAGE_ARR
=
std
::
unique_ptr
<
double
[]
>
(
new
double
[
3
*
N_STORE_FEATURES
*
N_SAMPLES
]);
TEMP_STORAGE_REG
=
std
::
unique_ptr
<
int
[]
>
(
new
int
[
3
*
N_STORE_FEATURES
]);
std
::
copy_n
(
std
::
vector
<
int
>
(
3
*
N_STORE_FEATURES
,
-
1
).
data
(),
3
*
N_STORE_FEATURES
,
TEMP_STORAGE_REG
.
get
());
}
void
node_value_arrs
::
resize_values_arr
(
int
n_dims
,
int
n_feat
,
bool
use_temp
)
{
N_RUNGS_STORED
=
n_dims
;
N_STORE_FEATURES
=
n_feat
;
VALUES_ARR
=
std
::
unique_ptr
<
double
[]
>
(
new
double
[
N_STORE_FEATURES
*
N_SAMPLES
]);
if
(
use_temp
)
{
TEMP_STORAGE_ARR
=
std
::
unique_ptr
<
double
[]
>
(
new
double
[
3
*
N_STORE_FEATURES
*
N_SAMPLES
]);
TEMP_STORAGE_REG
=
std
::
unique_ptr
<
int
[]
>
(
new
int
[
3
*
N_STORE_FEATURES
]);
std
::
copy_n
(
std
::
vector
<
int
>
(
3
*
N_STORE_FEATURES
,
-
1
).
data
(),
3
*
N_STORE_FEATURES
,
TEMP_STORAGE_REG
.
get
());
}
}
\ No newline at end of file
src/feature_creation/node/value_storage/nodes_value_containers.hpp
View file @
4e18d8e8
...
...
@@ -14,6 +14,7 @@ namespace node_value_arrs
extern
int
N_RUNGS_STORED
;
//!< Number of rungs with values stored
extern
std
::
unique_ptr
<
int
[]
>
TEMP_STORAGE_REG
;
//!< Register to see which feature is stored in each slot
extern
std
::
unique_ptr
<
double
[]
>
PRIMARY_FEAT_ARR
;
//!< Value of the stored features
extern
std
::
unique_ptr
<
double
[]
>
VALUES_ARR
;
//!< Value of the stored features
extern
std
::
unique_ptr
<
double
[]
>
TEMP_STORAGE_ARR
;
//!< Array to temporarily store feature values
...
...
@@ -42,11 +43,19 @@ namespace node_value_arrs
* @details Take initial parameters and construct the feature arraies
*
* @param n_samples number of samples per feature
* @param n_dims Number of dimensions to store
* @param n_primary_feat number of primary features
* @param allowed_operators list of allowed operators
*/
void
setup_values_arr
(
int
n_samples
,
int
n_dims
,
int
n_primary_feat
,
std
::
vector
<
std
::
string
>
allowed_operators
);
void
initialize_values_arr
(
int
n_samples
,
int
n_primary_feat
);
/**
* @brief set of the value arrays
* @details Take initial parameters and construct the feature arraies
*
* @param n_dims Number of dimensions to store
* @param n_feat number of features to store
* @param use_temp If true keep the temporary_storage
*/
void
resize_values_arr
(
int
n_dims
,
int
n_feat
,
bool
use_temp
);
/**
* @brief Get a reference slot/feature register
...
...
@@ -91,6 +100,11 @@ namespace node_value_arrs
temp_storage_reg
(
ind
,
offset
)
=
ind
;
return
access_temp_storage
((
ind
%
N_STORE_FEATURES
)
+
(
offset
%
3
)
*
N_STORE_FEATURES
);
}
inline
double
*
get_primary_feat_ptr
(
int
ind
)
{
return
PRIMARY_FEAT_ARR
.
get
()
+
ind
*
N_SAMPLES
;
}
}
#endif
\ No newline at end of file
src/inputs/InputParser.cpp
View file @
4e18d8e8
...
...
@@ -4,6 +4,7 @@ InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::sh
_n_dim
(
IP
.
get
<
int
>
(
"desc_dim"
)),
_n_sis_select
(
IP
.
get
<
int
>
(
"_n_sis_select"
)),
_max_rung
(
IP
.
get
<
int
>
(
"max_rung"
)),
_max_store_rung
(
IP
.
get
<
int
>
(
"n_rung_store"
,
2
)),
_n_samp
(
0
),
_filename
(
fn
),
_data_file
(
IP
.
get
<
std
::
string
>
(
"data_file"
,
"data.csv"
)),
...
...
@@ -131,12 +132,15 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm)
units
.
erase
(
units
.
begin
()
+
_propind
);
}
node_value_arrs
::
setup
_values_arr
(
_prop
.
size
(),
std
::
min
(
_max_rung
,
2
),
headers
.
size
()
,
_opset
);
node_value_arrs
::
initialize
_values_arr
(
_prop
.
size
(),
headers
.
size
());
std
::
vector
<
node_ptr
>
phi_0
;
for
(
int
ff
=
0
;
ff
<
headers
.
size
();
++
ff
)
{
phi_0
.
push_back
(
std
::
make_shared
<
FeatureNode
>
(
ff
,
headers
[
ff
],
data
[
ff
],
units
[
ff
]));
std
::
copy_n
(
data
[
ff
].
begin
(),
data
[
ff
].
size
(),
node_value_arrs
::
get_primary_feat_ptr
(
ff
));
}
_feat_space
=
std
::
make_shared
<
FeatureSpace
>
(
comm
,
phi_0
,
_opset
,
_max_rung
,
_n_sis_select
);
_feat_space
=
std
::
make_shared
<
FeatureSpace
>
(
comm
,
phi_0
,
_opset
,
_max_rung
,
_n_sis_select
,
_max_store_rung
);
}
void
stripComments
(
std
::
string
&
filename
)
...
...
src/inputs/InputParser.hpp
View file @
4e18d8e8
...
...
@@ -24,6 +24,7 @@ public:
std
::
shared_ptr
<
FeatureSpace
>
_feat_space
;
int
_n_dim
;
int
_max_rung
;
int
_max_store_rung
;
int
_n_sis_select
;
int
_n_samp
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment