Skip to content

Instantly share code, notes, and snippets.

@doolin
Created January 17, 2016 14:52
Show Gist options
  • Select an option

  • Save doolin/0a502394720ddc43ee95 to your computer and use it in GitHub Desktop.

Select an option

Save doolin/0a502394720ddc43ee95 to your computer and use it in GitHub Desktop.
/* compile with g++ ip.c++ -lboost_system */
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
class Perceptron {
public:
Perceptron(vector<double> weights, double bias) : weights(weights), bias(bias) {};
double think(vector<double> & v);
private:
vector<double> weights;
double bias;
};
double
Perceptron::think(vector<double> & input) {
return inner_prod(weights, input) + bias;
}
int
main(int argc, char ** argv) {
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i) {
v (i) = i;
}
vector<double> u (3);
for (unsigned i = 0; i < u.size (); ++ i) {
u (i) = i;
}
Perceptron * p = new Perceptron(v, 1.0);
std::cout << p->think(u) << std::endl;
delete p;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment