|
-
Jun 22nd, 2001, 10:39 PM
#1
neural network & objects
I want to simulate a neural network with c++. The problem is that i never used objects seriously 
For the moment i'll stick to feed forward networks.
I need to create a Cell object with all its properties (kind of cell, connections to other cells, activation state & some flags etc...), but where should i place all the cells?
1) in an array of Cells?
can I create arrays of objects? I guess the answer is yes, but could anyone give me some hints?
2) should i place the array of cells in a new object called Network?
This is more tricky:
Cells will have a property with all the connections to oter cells; pointers I suppose, but I need to create two more objects, input_Cell & output_Cell. These i will place at the beginning and the end of the network, so that i can set the input and read the output. But how can i make allthese three objects (Cell, input_Cell & output_Cell) compatible with the connections property?
I guess that has something to do with inheritance: am i right?
Shold I define a basic object (basic_Cell) that will have 3 different particular cases, and then set the connections among these primary basic_Cell?
thank you
-
Jun 24th, 2001, 03:25 PM
#2
You can contain all of the cells in an STL vector class ("std::vector<CELL> myCells;"). For the connections, you can set it up like this:
Code:
class CELL
{
//constructor/destructor//stuff
std::vector<CELL*> inputCell; //all of the input cells
CELL* outputCell;
};
This stores all of the cells in a tree-like structure:
Code:
I = input; O= output;
I I I I I I I // input cells. all entires in input vector are NULL
\ / \ / \ / \ / \ /
O I OI OI OI OI
\ / \ / \ /
O O O //Ouput cells. outputCell pointer = NULL
See how it all ties together? This way, you can check for NULL pointers in input and output cells to see what kind of cell it is. That should get you started. Sorry for the bad ASCII art =).
-
Jun 25th, 2001, 11:36 AM
#3
transcendental analytic
Using some virtual inheritance you could derive from an abstract class cell and add on functionality like input and output devices.
i'd use an array of pointers to cells as ADT's and then access/process the functionality of each cell by a simple call to a virtual function. something like
cell** cellf;// first
cell** celll;// last
cell** celli;//iterator
for (celli=cellf;celli<celll {Loggresult((*celli++)->Process())};
whereas loggresult would display the result of each process, process would be the virtually inherited function on celli iterator object that could be any type of a cell.
Last edited by kedaman; Jun 26th, 2001 at 12:06 AM.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 26th, 2001, 12:15 AM
#4
transcendental analytic
I was in a bit hurry last time, so i'll continue here..
Code:
//this is the ADT cell
class cell {
cell(){}
virtual ~cell(){};
virtual RESULT Process()=0;
;}
//some derivatives of cell that virtually inherits Process
//you can add other methods and vars if you need...
class outputcell:public cell{
Process() {/* do something here */};
};
class inputcell:public cell{
Process() {/* do something here */};
};
//then to populate the array you could do as you wish
//but to instantiate the cells you need to new them dynamically, heres a sample with 3 cells two output ones and a input one.
cellf=new cell*[3];
celli=cellf;
*celli++=new outputcell;
*celli++=new inputcell;
*celli=new outputcell;
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 26th, 2001, 06:16 PM
#5
thank's guys, you have given me a lot of new info.
Zaei: The idea of using templates doesn't sound bad at all, but I really don't know how to do it . I would love it to learn it, but i think it's still a bit far ahead. Actually i'm a real newbie for most things about OOP.
However i will take it into account, and i already rose some questions:
the following sentence
std::vector<CELL*> inputCell;
creates a pointer (named inputCell) to some sort of "array" or vector of cells, isn't it? I think i should study what this STL can do for me...
Besides, the tree-like structure is ok for some kind of feed forward networks, but is not general enough, though i do not doubt that you can make it more flexible in quite the same fashion.
If i would want multiple outputs, i.e. the same value forwarded to many cells should i use:
class cell {
//constructor/destructor stuff
std::vector<CELL*> inputCell;
std::vector<CELL*> outputCell;
};
I imagine this would give me a cell with multiple inputs and multiple outputs (correct me if i'm wrong!)
Kedaman: Your suggestion is more close to what i already had in mind though i think i can merge it with Zaei's method, so i'm sure that your piece of code will be very helpful!
Already i have some questions: the code
class outputcell: public cell{
Process() {/* do something here */};
};
i suppose is the constructor of the cell (outputcell) although the name of it is "cell". Is that right? (same for inputcell, of couse)
Thank's guys. You have been really helpful. I will come up with more questions, but it will take me some time (for i do this for hobby and i don't have much spare time!)
bye!
-
Jun 27th, 2001, 02:51 PM
#6
transcendental analytic
the STL vector can be used as an array wrapper, it's not hard to understand templates but i'd just suggest using an array of pointers instead.
the idea i was suggesting is called polymorphism, which in this case means objects can be derive from the same class but also act differently.
class outputcell: public cell{
Process() {/* do something here */};
};
this is the declaration of the outputcell class, it derives cell, which means it is a cell and inherit it's properties and methods, Process() function in cell is a "pure" virtual function, which means you have to derive from it to use it, this also makes cell an ADT (abstract data type) which you cannot instantiate. The idea is that you can make different types of cells but they are all cells, so when you call Process() on them, it calls the Process() function in the aproperiate class. This makes things much easier for you when you can process all cells without even knowing what they are and do.
a constructor is a function with the same name as the class, and is called when you instantiate the class, you can use it to initialize variables or pass parameters to it on initialisation.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 27th, 2001, 07:18 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|