i've got read many posts here , tutorials, tried failed. don't know what's wrong class instance , inheritance structure. first language java , don't know c++. want join files 1 namespace compiler. corrupt part of code. hope can help, working in months:
<file: activationfunction.h> ... using namespace std; namespace bl { class activationfunction { // used abstract class public: activationfunction() {} virtual double p(double); virtual double derivate(double); }; class exponential : public activationfunction { /* concrete implementation inherits abstract class */ public: exponential(){} //seems error ? double p(double n) { return 1/(1 + exp(n)); } double derivate(double n){ double r = 1/(1+exp(n)); return r - (r*r); } }; class ident : public activationfunction{ /* concrete implementation inherits abstract class */ public: ident(){} double p(double n){ return n; } double derivate(double n){ return 1.0; } }; } <file: neuron.h> #include... namespace bl {/* files shall fused 1 namespace different files */ class neuron{ ////seems error private: double currentactivity; double derivated; activationfunction phi; public: neuron(activationfunction f_act){ ////////////////////////seems error phi = f_act; currentactivity = 0; derivated = 0; neuron(const neuron & n){//how write correct copy constructor ? currentactivity = n.currentactivity; derivated = n.derivated; } neuron & operator = (const neuron & n){// how write correct assignment operator ? neuron nscr = n; // necessery ? if (&nsrc == this) return *this; else{ neuron * buffer = this; this.this = 𝓃 delete buffer; } return *this; } neuron & operator = (const neuron & nscr){//how write correct assignment operator ? if(&nscr == this)//////not declared in scope error return *this; = nscr; return *this; } } ... }; } <file: layer.h> #include... using namespace std; namespace bl { class weighttable{...}; class layer { // abstract class use of polymorphism (don't know how implement in c++ correctly public: virtual void connect(layer,layer); // shall override virtual void connect(layer) = 0; //ideally class have abstract layer(){} weighttable in_weight; vector<neuron> cell; //vector of neuron objects unsigned int getnr(void) const{ return neuronnr; } protected: unsigned int neuronnr; virtual void update(vector<double>,double); /*only derived class should use protected functions */ virtual void calcactivity(void); }; class hiddenl : public layer { public: layer down; layer top; hiddenl(unsigned int nr, activationfunction ph){ neuronnr = nr; //in_weight = null; ? neuron z; //seems error for(int n = 0; n < neuronnr ; n++){// initializing class variables z = neuron(ph); cell.push_back(z); } } void update(vector<double> delta, double nu) { ... down.update(mdelta,nu);//////////////////error caused protected } void calcactivity(void) { ... top.calcactivity(); ///////////////////////////error caused protected } void connect (layer sub, layer up){ down = sub; top = up; in_weight = weighttable(neuronnr, down.getnr() + 1, 1); } void connect(layer x){ assert(false); } }; class inputlayer : public layer { layer top; public: inputlayer(){} inputlayer(int nr, activationfunction basis) { neuronnr = nr; neuron x; // use double x; class variable for(int n = 0; n < neuronnr ; n++){ x = neuron(basis); cell.push_back(x); } } inputlayer(int nr){ //in_weight = nullptr; ? neuronnr = nr; activationfunction basis = ident(); //seems error neuron x; //seems error for(int n = 0; n < neuronnr ; n++){ x = neuron(basis); cell.push_back(x); } } void connect(layer t){ top = t; } void netactivity(vector<double> data){ ... top.calcactivity();//error caused protected } void update(vector<double> end, double n){ return; } void calcactivity(void){ return; } void connect(layer x, layer y){ top = x; } }; class outl : public layer { public: layer down; outl(){} outl(int nr){ // „in_weight“ = nullptr; correct ? neuronnr = nr; activationfunction o = ident(); for(int n = 0; n < neuronnr ; n++){ neuron y = neuron(o); cell.push_back(y); } } void connect(layer dlayer){ down = dlayer; in_weight = weighttable(neuronnr, down.getnr() + 1, 1); } void bpupdate(vector<double> t, double nu){ ... down.update(d,nu);//protected } } void calcactivity(void) { ... return; } void update(vector<double> no, double l){ return; } void connect(layer x, layer y){ down = x; } }; } <file: net.h> #include... using namespace std; namespace bl { class net{ public: outl result; //outl class variable inputlayer input; // inputlayer class variable //////referece-problems vector<layer> level; /* vector of layer objects, using polymorphism referece wrong(not type error) */ net(vector<int> m){ int end = m.size() - 1; // last index of m exponential act = exponential(); /* creating concrete object of activationfunction abstract class */ layer hidden; //a class type variable using polymorphism input = inputlayer(m[0]); ///////////////scope-error, no idea why////// level.push_back(input); // polymorphism///////////////////type-error for(int l = 1; l < m.size() - 1 ; l++){ hidden = hiddenl(m[l],act); level.push_back(hidden);//////////////////type-error } result = outl(m[end]); ////////////////////////scope-error////// level.push_back(result);//polymorphism///////////////type-error input.connect(level[1]); /////////type-error result.connect(level[end-1]);///////////////error///// for(int h = 1; h < level.size()-1; h++) level[h].connect(level[h-1],level[h+1]); //type-error } ... }; } <file: main.cpp> #include <iostream> #include <vector> #include "activationfunction.h" #include "neuron.h" #include "weighttable.h" #include "layer.h" #include "net.h" using namespace std; int main(int argc, char** argv){ vector<int> form = {1,20,1}; bl::net knn = bl::net(form); knn.initialize_weights_random(-4.0,4.0); vector<double> in = {4.3}; knn.test(in); return 0; }; // right ?
the code posted neither complete or valid, nor readable or understandable.
it looks you're writing sort of neuronal network simulation program. might not best starting problem code in c++ if new language. maybe should step bit , learn basics language first.
some tutorials online:
- http://www.cplusplus.com/doc/tutorial/
- http://www.tutorialspoint.com/cplusplus/
- http://www.learncpp.com/
also, if you're interested in namespace layouts , best practice guidelines, check google c++ style guide:
to automatically check guideline compatibility of cpp code, try using cpplint:
just few pointers started. question malformed here; please restate after went on c++ basics.
Comments
Post a Comment