inline void gpu_train_batch(FeedForward_Network<activation, error>& network, arma::Mat<float> inputs, arma::Mat<float> targets, int batch_size, float learning_rate = 0.8f, float momentum = 0.8f) { network.resize_activation(batch_size); Raw_FeedForward_Network<activation, error> raw_net = convert_to_raw(network); Raw_FeedForward_Network<activation, error> * d_network = network_to_gpu(raw_net); int batches_in_train = targets.n_rows/batch_size - 1; for (int i = 0; i < batches_in_train; ++i) { arma::Mat<float> input_slice = inputs.rows(i*batch_size, (i+1) * batch_size - 1); Raw_Matrix raw_input = to_raw(input_slice); Raw_Matrix * d_input = matrix_to_gpu(raw_input); int num_trials = input_slice.n_rows; calculate_activation(num_trials, network.layer_sizes, d_network, d_input); //TODO make this memory shared as to not realloc free_gpu_matrix(d_input); arma::Mat<float> targets_slice = targets.rows(i*batch_size, (i+1) * batch_size - 1); Raw_Matrix raw_targets = to_raw(targets_slice); Raw_Matrix * d_targets = matrix_to_gpu(raw_targets); backprop(num_trials, network.layer_sizes, d_network, d_targets, learning_rate, momentum); free_gpu_matrix(d_targets); } network_to_cpu_free(d_network, raw_net); update_from_raw(network, raw_net); }
/** * Impute function searches through the input looking for mappedValue and * remove the whole row or column. The result is overwritten to the input. * * @param input Matrix that contains mappedValue. * @param mappedValue Value that the user wants to get rid of. * @param dimension Index of the dimension of the mappedValue. * @param columnMajor State of whether the input matrix is columnMajor or not. */ void Impute(arma::Mat<T>& input, const T& mappedValue, const size_t dimension, const bool columnMajor = true) { std::vector<arma::uword> colsToKeep; if (columnMajor) { for (size_t i = 0; i < input.n_cols; ++i) { if (!(input(dimension, i) == mappedValue || std::isnan(input(dimension, i)))) { colsToKeep.push_back(i); } } input = input.cols(arma::uvec(colsToKeep)); } else { for (size_t i = 0; i < input.n_rows; ++i) { if (!(input(i, dimension) == mappedValue || std::isnan(input(i, dimension)))) { colsToKeep.push_back(i); } } input = input.rows(arma::uvec(colsToKeep)); } }