When I call a function, get_split(), the Arduino restarts. I have tried to find what is causing this, but I have had no luck. Here is my code:
std::vector<std::vector<std::vector<std::vector<float>>>> get_split(std::vector< std::vector< float > >& dataset) {
std::vector<int> class_values; // declares vector 'class_values'
for (int i = 0; i < dataset.size(); i++) { // loops through each value in dataset (the dataset contains vectors) and appends the last value in each vector to class_values
class_values.push_back(dataset[i][dataset.size()]);
}
std::vector<std::vector<std::vector<float>>> b_index;
b_index.push_back(std::vector<std::vector<float>>(999));
std::vector<std::vector<std::vector<float>>> b_value;
b_value.push_back(std::vector<std::vector<float>>(999));
std::vector<std::vector<std::vector<float>>> b_score;
b_score.push_back(std::vector<std::vector<float>>(999));
std::vector<std::vector<std::vector<float>>> b_groups;
for (int i = 0; i < dataset[0].size(); i++) {
for (int j = 0; j < dataset.size(); j++) {
std::vector<std::vector<std::vector<float>>> groups = test_split(i, dataset[j][i], dataset); // gets the split of the dataset (assigns each vector in the dataset to either 'left' or 'right')
float gini = gini_index(class_values, groups); // calculates the gini
if (gini < b_score[0][0][0]) {
b_index[0][0][0] = i;
b_value[0][0][0] = dataset[j][i];
b_score[0][0][0] = gini;
b_groups = groups;
}
}
}
std::vector<std::vector<std::vector<std::vector<float>>>> vals;
vals.push_back(b_index);
vals.push_back(b_value);
vals.push_back(b_groups);
return vals; // returns the values.
}
This code is meant to check the gini of splitting a certain function (the gini_index() function works fine). Then it calls test_split which assigns the vector values into two sub-vectors in the vector groups, left and right. Then I just choose the split with the lowest gini.
When I delete everything in the function it doesn't restart, but I have deleted the first for loop, and also the part where it returns a vector, but still no luck. Also when deleting the for loop underneath the declaration of b_groups, it still doesn't work. I don't think it is a memory/storage issue because the Arduino IDE says that I'm only using 3% of that.
PS: I have used the library StandardCplusplus library to include vectors.