📄 binomial.cpp
字号:
/*
nn-utility (Provides neural networking utilities for c++ programmers)
Copyright (C) 2003 Panayiotis Thomakos
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
//To contact the author send an email to panthomakos@users.sourceforge.net
/*Demonstrates an operational binomial network that performs the XOR function.*/
#include <nn-utility.h>
using namespace nn_utility;
nn_utility_functions<float> derived;
int main(){
//first layer is a binomial layer
BINOMIAL *hidden1 = new BINOMIAL();
//define it's matrix
hidden1->definef( 2,2, -1.0, -1.0, -1.0, -1.0);
//define it's bias weights
derived.LoadVectorf( hidden1->weight, 2, 1.5, 0.5 );
//second layer is a binomial layer
BINOMIAL *output = new BINOMIAL();
//define it's matrix
output->definef( 2,1, 1.0, -1.0 );
//define it's weights
derived.LoadVectorf( output->weight, 1, -0.5 );
//create buffers for the layers
layer<float> *ppHidden1 = hidden1;
layer<float> *ppOutput = output;
//connect the two layers using their buffers
derived.Insert( &ppHidden1, &ppOutput );
//create an input and output VECTOR
nn_utility_functions<float>::VECTOR input, FINAL;
//next few lines load the input vector, fire to the network, and present an output
//for 1,0 0,1 1,1 and 0,0
derived.LoadVectorf( input, 2, 1.0, 0.0 );
hidden1->FeedForward( input, FINAL );
cout << "XOR Binomial Network Presented with : 1,0. Ouptut: "; derived.PrintVector( FINAL, 1 );
derived.LoadVectorf( input, 2, 0.0, 1.0 );
hidden1->FeedForward( input, FINAL );
cout << "XOR Binomial Network Presented with : 0,1. Ouptut: "; derived.PrintVector( FINAL, 1 );
derived.LoadVectorf( input, 2, 1.0, 1.0 );
hidden1->FeedForward( input, FINAL );
cout << "XOR Binomial Network Presented with : 1,1. Ouptut: "; derived.PrintVector( FINAL, 1 );
derived.LoadVectorf( input, 2, 0.0, 0.0 );
hidden1->FeedForward( input, FINAL );
cout << "XOR Binomial Network Presented with : 0,0. Ouptut: "; derived.PrintVector( FINAL, 1 );
cout << '\n';
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -