#ifndef NETWORK_H_ #define NETWORK_H_ #include #include #include #include using namespace std; inline float sigmoid(float x) { return 1.f / (1.f + exp(-x)); } class NetNode; class NetLink { public: NetLink(){}; NetLink(NetNode* in, NetNode* out, float w, unsigned int _id) : in_node(in), out_node(out), weight(w), id(_id){}; ~NetLink(){}; NetNode* in_node; NetNode* out_node; unsigned int id; float weight; }; class NetNode { public: NetNode(){}; NetNode(int t, unsigned int _id) : type(t), id(_id), value(0), activated(false){}; ~NetNode(){}; void addLinkIn(NetLink* l) {in_links.push_back(l);} void addLinkOut(NetLink* l) {out_links.push_back(l);} vector in_links; vector out_links; unsigned int id; int type; float value; bool activated; }; class Network { private: bool removeNodeHelper(NetNode* n, vector n_list); bool clearActivationFlags(); bool activateNetwork(); bool outputsActive(); public: Network(){}; ~Network(){}; bool removeNode(NetNode* n); bool removeLink(NetLink* l); bool addNode(NetNode* n, int in_or_out); void runNet(unsigned int in_count, float * inputs, unsigned int out_count, float * outputs); float runNet(unsigned int in_count, float * inputs); //one output bool outputFile(string& filename); bool inputFile(string& filename); int num_nodes; int num_links; static unsigned int g_lid; //global link id counter static unsigned int g_nid; //global node id counter vector all_nodes; vector in_nodes; vector out_nodes; }; #endif