本文整理汇总了C++中NeuralNetwork类的典型用法代码示例。如果您正苦于以下问题:C++ NeuralNetwork类的具体用法?C++ NeuralNetwork怎么用?C++ NeuralNetwork使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NeuralNetwork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_calculate_terms_Jacobian
void PerformanceFunctionalTest::test_calculate_terms_Jacobian(void) {
message += "test_calculate_terms_Jacobian\n";
DataSet ds;
NeuralNetwork nn;
PerformanceFunctional pf(&nn, &ds);
pf.set_objective_type(PerformanceFunctional::SUM_SQUARED_ERROR_OBJECTIVE);
Matrix<double> terms_Jacobian;
// Test
ds.set(1, 1, 3);
ds.initialize_data(0.0);
nn.set(1, 1);
nn.initialize_parameters(0.0);
terms_Jacobian = pf.calculate_terms_Jacobian();
assert_true(terms_Jacobian.get_rows_number() == 3, LOG);
assert_true(terms_Jacobian.get_columns_number() == 2, LOG);
assert_true(terms_Jacobian == 0.0, LOG);
}
示例2: TEST
TEST(TestNeuralNetwork, getWeights)
{
NeuralNetwork nn {400, 25, 10};
EXPECT_EQ(401*25 + 26 * 10, nn.getWeights().size());
for (auto w : nn.getWeights()) {
EXPECT_FLOAT_EQ(0.0f, w);
}
}
示例3: test_video
void test_video() {
VideoCapture cap(CV_CAP_ANY);
ImageProcessor processor;
ImageLoader loader;
NeuralNetwork net;
net.load(NET_FILE_NAME);
//net.visualize_hidden_units(1, 50);
if (!cap.isOpened()) {
cout << "Failed to initialize camera\n";
return;
}
namedWindow("CameraCapture");
namedWindow("ProcessedCapture");
cv::Mat frame;
while (true) {
cap >> frame;
cv::Mat processedFrame = processor.process_image(frame);
if(processedFrame.rows * processedFrame.cols == INPUT_LAYER_SIZE) {
mat input = loader.to_arma_mat(processedFrame);
int label = net.predict(input);
if(label == 0)
putText(frame, "A", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8);
else if(label == 1)
putText(frame, "E", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8);
else if(label == 2)
putText(frame, "I", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8);
else if(label == 3)
putText(frame, "O", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8);
else if(label == 4)
putText(frame, "U", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8);
}
imshow("CameraCapture", frame);
imshow("ProcessedCapture", processedFrame);
int key = waitKey(5);
if(key == 13) {
imwrite("captura.jpg", frame);
}
if (key == 27)
break;
}
destroyAllWindows();
}
示例4: TRACE
void NeuralNetworkManager::resetNeuralNetworks() {
TRACE("NeuralNetworkManager::resetNeuralNetworks");
QMutexLocker locker(&mNetworkExecutionMutex);
for(QListIterator<NeuralNetwork*> i(mNeuralNetworks); i.hasNext();) {
NeuralNetwork *net = i.next();
net->reset();
}
}
示例5: test_get_multilayer_perceptron_pointer
void NeuralNetworkTest::test_get_multilayer_perceptron_pointer(void) {
message += "test_get_multilayer_perceptron_pointer\n";
NeuralNetwork nn;
// Test
nn.set(1, 1);
assert_true(nn.get_multilayer_perceptron_pointer() != NULL, LOG);
}
示例6: test_get_conditions_layer_pointer
void NeuralNetworkTest::test_get_conditions_layer_pointer(void) {
message += "test_get_conditions_layer_pointer\n";
NeuralNetwork nn;
nn.construct_conditions_layer();
// Test
assert_true(nn.get_conditions_layer_pointer() != NULL, LOG);
}
示例7: test_get_independent_parameters_pointer
void NeuralNetworkTest::test_get_independent_parameters_pointer(void) {
message += "test_get_independent_parameters_pointer\n";
NeuralNetwork nn;
nn.construct_independent_parameters();
// Test
assert_true(nn.get_independent_parameters_pointer() != NULL, LOG);
}
示例8: evaluate_net
void evaluate_net(vector<pair<mat, mat> > &test_data) {
NeuralNetwork net;
net.load(NET_FILE_NAME);
//net.print();
double corrects = net.evaluate(test_data);
double percentage = (corrects / CANT_TEST_ELEM) * 100;
cout << "corrects: " << corrects << ", percentage: " << percentage << "%" << endl;
cout<<"total cost: "<<net.calcule_total_cost(test_data, 0);
}
示例9: test_calculate_gradient
void LevenbergMarquardtAlgorithmTest::test_calculate_gradient(void)
{
message += "test_calculate_gradient\n";
DataSet ds;
NeuralNetwork nn;
PerformanceFunctional pf(&nn, &ds);
Vector<double> terms;
Matrix<double> terms_Jacobian;
Vector<double> gradient;
LevenbergMarquardtAlgorithm lma(&pf);
// Test
// ds.set(1, 1, 2);
// ds.randomize_data_normal();
// nn.set(1, 1);
// nn.randomize_parameters_normal();
// terms = pf.calculate_terms();
// terms_Jacobian = pf.calculate_terms_Jacobian();
// gradient = lma.calculate_gradient(terms, terms_Jacobian);
// assert_true((gradient-pf.calculate_gradient()).calculate_absolute_value() < 1.0e-3, LOG);
// Test
nn.set(1, 1);
nn.randomize_parameters_normal();
MockErrorTerm* mptp = new MockErrorTerm(&nn);
pf.set_user_error_pointer(mptp);
terms= pf.calculate_terms();
terms_Jacobian = pf.calculate_terms_Jacobian();
gradient = lma.calculate_gradient(terms, terms_Jacobian);
assert_true(gradient == pf.calculate_gradient(), LOG);
}
示例10: test_from_XML
void EvolutionaryAlgorithmTest::test_from_XML(void)
{
message += "test_from_XML\n";
DataSet ds;
NeuralNetwork nn;
PerformanceFunctional pf(&nn, &ds);
EvolutionaryAlgorithm ea(&pf);
EvolutionaryAlgorithm ea1;
EvolutionaryAlgorithm ea2;
tinyxml2::XMLDocument* document;
Matrix<double> population;
// Test
document = ea1.to_XML();
ea2.from_XML(*document);
delete document;
assert_true(ea1 == ea2, LOG);
// Test
ds.set(1, 1, 1);
ds.randomize_data_normal();
nn.set(1, 1);
ea.set_population_size(4);
ea.set_elitism_size(0);
ea.randomize_population_normal();
population = ea.get_population();
document = ea.to_XML();
ea.initialize_population(0.0);
ea.from_XML(*document);
delete document;
assert_true((ea.get_population() - population).calculate_absolute_value() < 1.0e-3, LOG);
}
示例11: test_randomize_parameters_normal
void NeuralNetworkTest::test_randomize_parameters_normal(void) {
message += "test_randomize_parameters_normal\n";
NeuralNetwork nn;
Vector<double> network_parameters;
// Test
nn.set(1, 1, 1);
nn.randomize_parameters_normal(1.0, 0.0);
network_parameters = nn.arrange_parameters();
assert_true(network_parameters == 1.0, LOG);
}
示例12: locker
void NeuralNetworkManager::valueChanged(Value *value) {
if(value == 0) {
return;
}
if(value == mBypassNetworkValue) {
QMutexLocker locker(&mNetworkExecutionMutex);
for(QListIterator<NeuralNetwork*> i(mNeuralNetworks); i.hasNext();) {
NeuralNetwork *net = i.next();
net->bypassNetwork(mBypassNetworkValue->get());
}
}
}
示例13: test_function
void test_function( NeuralNetwork &net, double *table, int rows, int cols, double err_thresh = 0.0 )
{
vector< example > examples;
load_examples( table, rows, cols, examples);
print_examples( examples);
cout << "Initial weights: \n";
net.print_net();
cout << endl;
net.train( examples, err_thresh );
print_results( examples, net );
cout << endl;
}
示例14: test_randomize_parameters_uniform
void NeuralNetworkTest::test_randomize_parameters_uniform(void) {
message += "test_randomize_parameters_uniform\n";
NeuralNetwork nn;
Vector<double> parameters;
// Test
nn.set(1, 1, 1);
nn.randomize_parameters_uniform();
parameters = nn.arrange_parameters();
assert_true(parameters >= -1.0, LOG);
assert_true(parameters <= 1.0, LOG);
}
示例15: test_calculate_parameters_norm
void NeuralNetworkTest::test_calculate_parameters_norm(void) {
message += "test_calculate_parameters_norm\n";
NeuralNetwork nn;
double parameters_norm;
// Test
nn.set();
parameters_norm = nn.calculate_parameters_norm();
assert_true(parameters_norm == 0.0, LOG);
}