本文整理汇总了C++中additional_buffer_smart_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ additional_buffer_smart_ptr类的具体用法?C++ additional_buffer_smart_ptr怎么用?C++ additional_buffer_smart_ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了additional_buffer_smart_ptr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test
void dropout_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id,
bool force_deterministic) const
{
if (offset_input_entry_id > 0)
throw neural_network_exception("dropout_layer_updater_plain is not able to run using offset");
if (force_deterministic)
{
memcpy(&(output_buffer->at(0)), &(input_buffer->at(0)), input_configuration_specific.get_neuron_count() * updater_count * sizeof(float));
}
else
{
const std::vector<float>::const_iterator in_it_global = input_buffer->begin();
const std::vector<float>::iterator out_it_global = output_buffer->begin();
unsigned char * keep_elem_ptr = reinterpret_cast<unsigned char *>(&(additional_buffers[0]->at(0)));
nnforge_shared_ptr<const dropout_layer> layer_derived = nnforge_dynamic_pointer_cast<const dropout_layer>(layer_schema);
const float dropout_rate = layer_derived->dropout_rate;
const float keep_rate = 1.0F - dropout_rate;
const float mult = 1.0F / keep_rate;
const int total_workload = input_configuration_specific.get_neuron_count() * updater_count;
nnforge_uniform_real_distribution<float> dist(0.0F, 1.0F);
for(int i = 0; i < total_workload; ++i)
keep_elem_ptr[i] = (dist(gen) <= keep_rate ? (unsigned char)1 : (unsigned char)0);
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count) shared(keep_elem_ptr)
{
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int elem_id = workload_id;
*(out_it_global + elem_id) = *(in_it_global + elem_id) * (keep_elem_ptr[elem_id] ? mult : 0.0F);
}
}
}
}
开发者ID:anshumang,项目名称:nnForgeINST,代码行数:50,代码来源:dropout_layer_updater_plain.cpp
示例2: test
void hyperbolic_tangent_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id) const
{
if (offset_input_entry_id > 0)
throw neural_network_exception("hyperbolic_tangent_layer_updater_plain is not able to run using offset");
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::const_iterator in_it = input_buffer->begin();
const std::vector<float>::iterator out_it = output_buffer->begin();
nnforge_shared_ptr<const hyperbolic_tangent_layer> layer_derived = nnforge_dynamic_pointer_cast<const hyperbolic_tangent_layer>(layer_schema);
const float hyperbolic_tangent_steepness2 = layer_derived->steepness * 2.0F;
const float hyperbolic_tangent_major_multiplier = layer_derived->major_multiplier;
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float inp = *(in_it + i);
float inp2 = expf(inp * hyperbolic_tangent_steepness2);
float res = (inp2 - 1.0F) / (inp2 + 1.0F) * hyperbolic_tangent_major_multiplier;
*(out_it + i) = res;
}
}
开发者ID:Alienfeel,项目名称:nnForge,代码行数:33,代码来源:hyperbolic_tangent_layer_updater_plain.cpp
示例3: backprop
void hyperbolic_tangent_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count) const
{
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::iterator in_err_it = input_errors->begin();
const std::vector<float>::const_iterator out_it = output_neurons->begin();
nnforge_shared_ptr<const hyperbolic_tangent_layer> layer_derived = nnforge_dynamic_pointer_cast<const hyperbolic_tangent_layer>(layer_schema);
const float hyperbolic_tangent_major_multiplier_reverse = 1.0F / layer_derived->major_multiplier;
const float hyperbolic_tangent_steepness3 = layer_derived->steepness * layer_derived->major_multiplier;
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float out_neuron = *(out_it + i);
float normalized_value = out_neuron * hyperbolic_tangent_major_multiplier_reverse;
float der1st = hyperbolic_tangent_steepness3 * (1.0F - (normalized_value * normalized_value));
*(in_err_it + i) *= der1st;
}
}
开发者ID:Alienfeel,项目名称:nnForge,代码行数:30,代码来源:hyperbolic_tangent_layer_updater_plain.cpp
示例4: test
void sigmoid_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const layer_data_list& data,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
int offset_input_entry_id) const
{
if (offset_input_entry_id >= 0)
throw neural_network_exception("sigmoid_layer_updater_plain is not able to run using the same input");
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::const_iterator in_it = input_buffer->begin();
const std::vector<float>::iterator out_it = output_buffer->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float inp = *(in_it + i);
float res = 1.0F / (expf(-inp) + 1.0F);
*(out_it + i) = res;
}
}
开发者ID:jmp84,项目名称:nnForge,代码行数:27,代码来源:sigmoid_layer_updater_plain.cpp
示例5: backprop
void soft_rectified_linear_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count) const
{
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::iterator in_err_it = input_errors->begin();
const std::vector<float>::const_iterator out_it = output_neurons->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float out_neuron = *(out_it + i);
float val = expf(out_neuron);
float der1st = (val - 1.0F) / val;
*(in_err_it + i) *= der1st;
}
}
开发者ID:bluelzx,项目名称:nnForge,代码行数:27,代码来源:soft_rectified_linear_layer_updater_plain.cpp
示例6: test
void softmax_layer_hessian_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int feature_map_count = static_cast<unsigned int>(input_configuration_specific.feature_map_count);
const std::vector<float>::const_iterator input_buffer_it = input_buffer->begin();
const std::vector<float>::iterator output_buffer_it = output_buffer->begin();
const int total_workload = entry_count * input_neuron_count_per_feature_map;
const int openmp_thread_count = plain_config->openmp_thread_count;
#pragma omp parallel default(none) shared(additional_buffers) num_threads(openmp_thread_count)
{
int thread_id = 0;
#ifdef _OPENMP
thread_id = omp_get_thread_num();
#endif
std::vector<float>& local_additional_buffer = *(additional_buffers[thread_id]);
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / input_neuron_count_per_feature_map;
int neuron_id = workload_id - (entry_id * input_neuron_count_per_feature_map);
const std::vector<float>::const_iterator in_it = input_buffer_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::iterator out_it = output_buffer_it + (entry_id * input_neuron_count) + neuron_id;
float max_val = -1.0e+37F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
float val = *(in_it + (feature_map_id * input_neuron_count_per_feature_map));
max_val = std::max(max_val, val);
}
float sum = 0.0F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
float val = expf((*(in_it + (feature_map_id * input_neuron_count_per_feature_map))) - max_val);
sum += val;
local_additional_buffer[feature_map_id] = val;
}
float mult = 1.0F / sum;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
*(out_it + (feature_map_id * input_neuron_count_per_feature_map)) = local_additional_buffer[feature_map_id] * mult;
} // for(int workload_id
} // #pragma parallel
}
开发者ID:bluelzx,项目名称:nnForge,代码行数:60,代码来源:softmax_layer_hessian_plain.cpp
示例7: backprop
void absolute_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count) const
{
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::const_iterator in_it = input_neurons->begin();
const std::vector<float>::iterator in_err_it = input_errors->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float val = *(in_it + i);
if (val < 0.0F)
{
*(in_err_it + i) = - *(in_err_it + i);
}
}
}
开发者ID:dreadlord1984,项目名称:nnForge,代码行数:27,代码来源:absolute_layer_updater_plain.cpp
示例8: test
void absolute_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id,
bool force_deterministic) const
{
if (offset_input_entry_id > 0)
throw neural_network_exception("absolute_layer_updater_plain is not able to run using offset");
const int elem_count = static_cast<int>(updater_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::const_iterator in_it = input_buffer->begin();
const std::vector<float>::iterator out_it = output_buffer->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
*(out_it + i) = fabs(*(in_it + i));
}
开发者ID:anshumang,项目名称:nnForgeINST,代码行数:25,代码来源:absolute_layer_updater_plain.cpp
示例9: backprop
void softmax_layer_hessian_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int feature_map_count = static_cast<unsigned int>(input_configuration_specific.feature_map_count);
const std::vector<float>::iterator input_errors_it = input_errors->begin();
const std::vector<float>::const_iterator output_errors_it = output_errors->begin();
const std::vector<float>::const_iterator output_neurons_it = output_neurons->begin();
const int total_workload = entry_count * input_neuron_count_per_feature_map;
const int openmp_thread_count = plain_config->openmp_thread_count;
#pragma omp parallel default(none) shared(additional_buffers) num_threads(openmp_thread_count)
{
int thread_id = 0;
#ifdef _OPENMP
thread_id = omp_get_thread_num();
#endif
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / input_neuron_count_per_feature_map;
int neuron_id = workload_id - (entry_id * input_neuron_count_per_feature_map);
const std::vector<float>::iterator in_errors_it = input_errors_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::const_iterator out_errors_it = output_errors_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::const_iterator out_neurons_it = output_neurons_it + (entry_id * input_neuron_count) + neuron_id;
float sum = 0.0F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
unsigned int offset = feature_map_id * input_neuron_count_per_feature_map;
float val = (*(out_neurons_it + offset));
sum += val * val * (*(out_errors_it + offset));
}
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
unsigned int offset = feature_map_id * input_neuron_count_per_feature_map;
float y = *(out_neurons_it + offset);
float y2 = y * y;
*(in_errors_it + offset) = y2 * ((*(out_errors_it + offset)) * (2.0F * (y2 - y) + 1.0F) - sum);
}
} // for(int workload_id
} // #pragma parallel
}
开发者ID:bluelzx,项目名称:nnForge,代码行数:59,代码来源:softmax_layer_hessian_plain.cpp
示例10: backprop
void dropout_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
bool force_deterministic) const
{
if (force_deterministic)
return;
const std::vector<float>::iterator in_err_it_global = input_errors->begin();
unsigned char * keep_elem_ptr = reinterpret_cast<unsigned char *>(&(additional_buffers[0]->at(0)));
nnforge_shared_ptr<const dropout_layer> layer_derived = nnforge_dynamic_pointer_cast<const dropout_layer>(layer_schema);
const float dropout_rate = layer_derived->dropout_rate;
const float keep_rate = 1.0F - dropout_rate;
const float mult = 1.0F / keep_rate;
const int total_workload = input_configuration_specific.get_neuron_count() * updater_count;
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count) shared(keep_elem_ptr)
{
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int elem_id = workload_id;
*(in_err_it_global + elem_id) *= (keep_elem_ptr[elem_id] ? mult : 0.0F);
}
}
}
开发者ID:anshumang,项目名称:nnForgeINST,代码行数:38,代码来源:dropout_layer_updater_plain.cpp
示例11: test
void sigmoid_layer_hessian_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const int elem_count = static_cast<int>(entry_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::const_iterator in_it = input_buffer->begin();
const std::vector<float>::iterator out_it = output_buffer->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float inp = *(in_it + i);
float res = 1.0F / (expf(-inp) + 1.0F);
*(out_it + i) = res;
}
}
开发者ID:dreadlord1984,项目名称:nnForge,代码行数:23,代码来源:sigmoid_layer_hessian_plain.cpp
示例12: backprop
void max_subsampling_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
bool force_deterministic) const
{
const std::vector<float>::iterator in_err_it_global = input_errors->begin();
const std::vector<float>::const_iterator out_err_it_global = output_errors->begin();
const std::vector<float>::const_iterator max_indexes_it_global = additional_buffers[0]->begin();
const int total_clean_workload = updater_count * input_configuration_specific.get_neuron_count();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int workload_id = 0; workload_id < total_clean_workload; ++workload_id)
{
*(in_err_it_global + workload_id) = 0.0F;
}
const int total_workload = updater_count * output_configuration_specific.get_neuron_count();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
unsigned int max_index = *(((unsigned int *)(&(*max_indexes_it_global))) + workload_id);
float err = *(out_err_it_global + workload_id);
*(in_err_it_global + max_index) = err;
}
}
开发者ID:anshumang,项目名称:nnForgeINST,代码行数:37,代码来源:max_subsampling_layer_updater_plain.cpp
示例13: backprop
void sigmoid_layer_hessian_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const int elem_count = static_cast<int>(entry_count * input_configuration_specific.get_neuron_count());
const std::vector<float>::iterator in_err_it = input_errors->begin();
const std::vector<float>::const_iterator out_it = output_neurons->begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int i = 0; i < elem_count; ++i)
{
float out_neuron = *(out_it + i);
float der1st = out_neuron * (1.0F - out_neuron);
*(in_err_it + i) *= (der1st * der1st);
}
}
开发者ID:dreadlord1984,项目名称:nnForge,代码行数:24,代码来源:sigmoid_layer_hessian_plain.cpp
示例14: test
void untile_layer_tester_plain::test(
additional_buffer_smart_ptr input_buffer,
additional_buffer_set& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const std::vector<float>::const_iterator in_it_global = input_buffer->begin();
const std::vector<float>::iterator out_it_global = additional_buffers[0]->begin();
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
nnforge_shared_ptr<const untile_layer> layer_derived = nnforge_dynamic_pointer_cast<const untile_layer>(layer_schema);
const std::vector<std::vector<unsigned int> >& upsampling_sizes_list = layer_derived->upsampling_sizes_list;
const int total_tiling_factor = layer_derived->get_tiling_factor().get_inverse();
if (entry_count % total_tiling_factor != 0)
throw neural_network_exception((boost::format("untile_layer_tester_plain: entry_count (%1%) is not evenly divisible by total_tiling_factor (%2%)") % entry_count % total_tiling_factor).str());
std::vector<int> position_list(input_neuron_count_per_feature_map);
{
std::vector<unsigned int> tiling_sizes(input_configuration_specific.dimension_sizes.size(), 1);
for(int i = 0; i < upsampling_sizes_list.size(); ++i)
{
const std::vector<unsigned int>& upsampling_sizes = upsampling_sizes_list[i];
for(int j = 0; j < upsampling_sizes.size(); ++j)
tiling_sizes[j] *= upsampling_sizes[j];
}
std::vector<unsigned int> spatial_pos(input_configuration_specific.dimension_sizes.size(), 0);
for(unsigned int i = 0; i < input_neuron_count_per_feature_map; ++i)
{
unsigned int pos = spatial_pos.back() * tiling_sizes.back();
for(int j = static_cast<int>(spatial_pos.size() - 2); j >= 0; --j)
pos = pos * output_configuration_specific.dimension_sizes[j] + spatial_pos[j] * tiling_sizes[j];
position_list[i] = pos;
for(int j = 0; j < spatial_pos.size(); ++j)
{
if ((++spatial_pos[j]) < input_configuration_specific.dimension_sizes[j])
break;
spatial_pos[j] = 0;
}
}
} // position_list
std::vector<int> offset_list(total_tiling_factor);
{
std::vector<std::vector<unsigned int> > positions_list;
positions_list.push_back(std::vector<unsigned int>(output_configuration_specific.dimension_sizes.size(), 0));
std::vector<unsigned int> total_upsampling_sizes(upsampling_sizes_list.front().size(), 1);
for(int level = static_cast<unsigned int>(upsampling_sizes_list.size()) - 1; level >= 0; --level)
{
std::vector<std::vector<unsigned int> > new_positions_list;
const std::vector<unsigned int>& upsampling_sizes = upsampling_sizes_list[level];
unsigned int local_tiling_count = 1;
for(std::vector<unsigned int>::const_iterator it = upsampling_sizes.begin(); it != upsampling_sizes.end(); ++it)
local_tiling_count *= *it;
for(std::vector<std::vector<unsigned int> >::const_iterator it = positions_list.begin(); it != positions_list.end(); ++it)
{
const std::vector<unsigned int>& current_positions = *it;
std::vector<unsigned int> local_pos(upsampling_sizes.size(), 0);
for(unsigned int i = 0; i < local_tiling_count; ++i)
{
std::vector<unsigned int> new_untiled_positions(current_positions);
for(unsigned int j = 0; i < static_cast<unsigned int>(upsampling_sizes.size()); ++j)
new_untiled_positions[j] += local_pos[j] * total_upsampling_sizes[j];
new_positions_list.push_back(new_untiled_positions);
for(int j = 0; j < local_pos.size(); ++j)
{
if ((++local_pos[j]) < upsampling_sizes[j])
break;
local_pos[j] = 0;
}
}
}
for(unsigned int i = 0; i < static_cast<unsigned int>(total_upsampling_sizes.size()); ++i)
total_upsampling_sizes[i] *= upsampling_sizes[i];
positions_list = new_positions_list;
}
for(int i = 0; i < total_tiling_factor; ++i)
{
const std::vector<unsigned int>& positions = positions_list[i];
int pos = positions.back();
for(int j = static_cast<int>(positions.size() - 2); j >= 0; --j)
//.........这里部分代码省略.........
开发者ID:anshumang,项目名称:nnForgeINST,代码行数:101,代码来源:untile_layer_tester_plain.cpp
示例15: test
void average_subsampling_layer_hessian_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const std::vector<float>::const_iterator in_it_global = input_buffer->begin();
const std::vector<float>::iterator out_it_global = output_buffer->begin();
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
std::tr1::shared_ptr<const average_subsampling_layer> layer_derived = std::tr1::dynamic_pointer_cast<const average_subsampling_layer>(layer_schema);
const std::vector<unsigned int>& subsampling_sizes = layer_derived->subsampling_sizes;
const unsigned int dimension_count = static_cast<unsigned int>(layer_derived->subsampling_sizes.size());
std::vector<unsigned int> input_slices(input_configuration_specific.dimension_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i < dimension_count - 1; ++i)
input_slices[i + 1] = input_slices[i] * input_configuration_specific.dimension_sizes[i];
unsigned int subsampling_elem_count = 1;
for(unsigned int i = 0; i < dimension_count; ++i)
subsampling_elem_count *= subsampling_sizes[i];
const unsigned int const_subsampling_elem_count = subsampling_elem_count;
const float mult = 1.0F / static_cast<float>(subsampling_elem_count);
const unsigned int feature_map_count = output_configuration_specific.feature_map_count;
std::vector<unsigned int> current_local_input_position(dimension_count, 0);
std::vector<unsigned int> offset_list(subsampling_elem_count);
for(unsigned int i = 1; i < subsampling_elem_count; ++i)
{
int offset = 0;
for(unsigned int j = 0; j < dimension_count; ++j)
{
offset += static_cast<int>(input_slices[j]);
if ((++current_local_input_position[j]) < subsampling_sizes[j])
{
offset_list[i] = offset_list[i-1] + offset;
break;
}
current_local_input_position[j] = 0;
offset -= static_cast<int>(subsampling_sizes[j] * input_slices[j]);
}
}
const int total_workload = entry_count * output_configuration_specific.feature_map_count;
const std::vector<unsigned int>::const_iterator dimension_sizes_it = output_configuration_specific.dimension_sizes.begin();
const std::vector<unsigned int>::const_iterator subsampling_sizes_it = subsampling_sizes.begin();
const std::vector<unsigned int>::const_iterator input_slices_it = input_slices.begin();
const std::vector<unsigned int>::const_iterator offset_list_it = offset_list.begin();
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
std::tr1::array<unsigned int, max_dimension_count> current_output_position;
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / feature_map_count;
int feature_map_id = workload_id - (entry_id * feature_map_count);
std::vector<float>::const_iterator in_it_base = in_it_global + (entry_id * input_neuron_count) + (feature_map_id * input_neuron_count_per_feature_map);
std::vector<float>::iterator out_it_base = out_it_global + (entry_id * output_neuron_count) + (feature_map_id * output_neuron_count_per_feature_map);
std::fill_n(current_output_position.begin(), dimension_count, 0);
for(std::vector<float>::iterator out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it)
{
// Define the starting position of the first input elem
std::vector<float>::const_iterator in_it = in_it_base;
for(unsigned int i = 0; i < dimension_count; ++i)
in_it += current_output_position[i] * (*(subsampling_sizes_it + i)) * (*(input_slices_it + i));
float sum = 0.0F;
for(unsigned int i = 0; i < const_subsampling_elem_count; ++i)
{
sum += *(in_it + (*(offset_list_it + i)));
}
*out_it = sum * mult;
// Go to the next output element
for(unsigned int i = 0; i < dimension_count; ++i)
{
if ((++current_output_position[i]) < *( dimension_sizes_it + i))
break;
current_output_position[i] = 0;
}
}
}
}
}
开发者ID:ChenglongChen,项目名称:nnForge,代码行数:94,代码来源:average_subsampling_layer_hessian_plain.cpp
示例16: test
void sparse_convolution_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
const std::vector<float>::const_iterator in_it_global = input_buffer->begin() + input_neuron_count * offset_input_entry_id;
const std::vector<float>::iterator out_it_global = output_buffer->begin();
nnforge_shared_ptr<const sparse_convolution_layer> layer_derived = nnforge_dynamic_pointer_cast<const sparse_convolution_layer>(layer_schema);
const std::vector<unsigned int>& window_sizes = layer_derived->window_sizes;
const unsigned int dimension_count = static_cast<unsigned int>(window_sizes.size());
std::vector<unsigned int> input_slices(input_configuration_specific.dimension_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i < dimension_count - 1; ++i)
input_slices[i + 1] = input_slices[i] * input_configuration_specific.dimension_sizes[i];
unsigned int window_elem_count = 1;
for(unsigned int i = 0; i < dimension_count; ++i)
window_elem_count *= window_sizes[i];
const unsigned int const_window_elem_count = window_elem_count;
const std::vector<float>::const_iterator weights = (*data)[0].begin();
const std::vector<float>::const_iterator biases = (*data)[1].begin();
const std::vector<int>::const_iterator column_indices = (*data_custom)[0].begin();
const std::vector<int>::const_iterator row_indices = (*data_custom)[1].begin();
std::vector<unsigned int> current_local_input_position(dimension_count, 0);
std::vector<unsigned int> offset_list(window_elem_count);
for(unsigned int i = 1; i < window_elem_count; ++i)
{
int offset = 0;
for(unsigned int j = 0; j < dimension_count; ++j)
{
offset += static_cast<int>(input_slices[j]);
if ((++current_local_input_position[j]) < window_sizes[j])
{
offset_list[i] = offset_list[i-1] + offset;
break;
}
current_local_input_position[j] = 0;
offset -= static_cast<int>(window_sizes[j] * input_slices[j]);
}
}
const unsigned int output_feature_map_count = output_configuration_specific.feature_map_count;
const unsigned int input_feature_map_count = input_configuration_specific.feature_map_count;
const int total_workload = updater_count * output_feature_map_count;
const std::vector<unsigned int>::const_iterator output_dimension_sizes_it = output_configuration_specific.dimension_sizes.begin();
const std::vector<unsigned int>::const_iterator input_slices_it = input_slices.begin();
const std::vector<unsigned int>::const_iterator offset_list_it = offset_list.begin();
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
nnforge_array<unsigned int, max_dimension_count> current_output_position;
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / output_feature_map_count;
int output_feature_map_id = workload_id - (entry_id * output_feature_map_count);
std::vector<float>::iterator out_it_base = out_it_global + (entry_id * output_neuron_count) + (output_feature_map_id * output_neuron_count_per_feature_map);
std::vector<float>::const_iterator in_it_base = in_it_global + entry_id * input_neuron_count;
const int start_column_index = row_indices[output_feature_map_id];
const int end_column_index = row_indices[output_feature_map_id + 1];
std::fill_n(current_output_position.begin(), dimension_count, 0);
for(std::vector<float>::iterator out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it)
{
float sum = *(biases + output_feature_map_id);
std::vector<float>::const_iterator weights_it = weights + start_column_index * const_window_elem_count;
std::vector<float>::const_iterator in_it_base2 = in_it_base;
for(unsigned int i = 0; i < dimension_count; ++i)
in_it_base2 += current_output_position[i] * (*(input_slices_it + i));
for(int column_index = start_column_index; column_index < end_column_index; ++column_index)
{
int input_feature_map_id = column_indices[column_index];
// Define the starting position of the first input elem
std::vector<float>::const_iterator in_it = in_it_base2 + (input_feature_map_id * input_neuron_count_per_feature_map);
for(unsigned int i = 0; i < const_window_elem_count; ++i)
{
sum += (*(in_it + *(offset_list_it + i))) * (*weights_it);
++weights_it;
}
}
//.........这里部分代码省略.........
开发者ID:bluelzx,项目名称:nnForge,代码行数:101,代码来源:sparse_convolution_layer_updater_plain.cpp
示例17: backprop
void sparse_convolution_layer_updater_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr input_neurons,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count) const
{
const std::vector<float>::iterator in_err_it_global = input_errors->begin();
const std::vector<float>::const_iterator out_err_it_global = output_errors->begin();
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
nnforge_shared_ptr<const sparse_convolution_layer> layer_derived = nnforge_dynamic_pointer_cast<const sparse_convolution_layer>(layer_schema);
const std::vector<unsigned int>& window_sizes = layer_derived->window_sizes;
const unsigned int dimension_count = static_cast<unsigned int>(window_sizes.size());
std::vector<unsigned int> input_slices(input_configuration_specific.dimension_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i &l
|
请发表评论