/* <<>> p[1]*w[1]--->----------- p[2]*w[2]--->| | .| + |--------> f() ----> a .| | p[n]*w[n]--->----------- ^ | | b */ #include using namespace std; class perceptron{ public: double b; vector w; // 0 <= w[i] <= 1 bool a(vector p){ double wp = 0; for(int i = 0; i < p.size(); i++){ wp += p[i] * w[i]; } return hardlim(wp + b); } perceptron(int n = 1){ b = ((double)rand()/(double)RAND_MAX); //random number between 0 and 1 for(int i = 0; i < n; i++){ int t = ((double)rand()/(double)RAND_MAX); w.push_back(t); } } //perceptron function is the constructor* private: bool hardlim(double x){ if(x > 0) return 1; else return 0; } }; int main() { srand(time(NULL)); /* initialize random seed: */ perceptron test(361); //just for you to know how to define an object from perceptron class return 0; }