matrix1d sum(matrix2d myVector) { matrix1d mySum(myVector.size(),0.0); for (int i=0; i<myVector.size(); i++) { for (int j=0; j<myVector[i].size(); j++) { mySum[i]+=myVector[i][j]; } } return mySum; }
matrix1d mean2(matrix2d myVector) { matrix1d myMean(myVector[0].size(),0.0); for (int i=0; i<myVector.size(); i++) { for (int j=0; j<myVector[i].size(); j++) { myMean[j]+=myVector[i][j]/double(myVector.size()); } } return myMean; }
matrix1d mean1(matrix2d myVector) { matrix1d myMean(myVector.size(),0.0); for (int i=0; i<myVector.size(); i++) { for (int j=0; j<myVector[i].size(); j++) { myMean[i]+=myVector[i][j]; } myMean[i]/=double(myVector[i].size()); } return myMean; }
void matrix2dio<T>::m2dToText(std::ostream & os, const matrix2d<T> & m) { size_t i = 0, j = 0; for (i = 0; i < m.rows(); i++) { std::valarray<T> r = m.row(i); os << r[0]; for (j = 1; j < m.cols(); j++) std::cout << ' ' << r[j]; os << '\n'; } os << std::flush; }
matrix1d NeuroEvo::getAction(matrix2d state) { matrix1d stateSum(state[0].size(), 0.0); // state[type][state_element] -- specifies combination for state for (size_t i = 0; i < state.size(); i++) { for (size_t j = 0; j < state[i].size(); j++) { stateSum[j] += state[i][j]; } } return getAction(stateSum); }