So, I've seen a few (okay, quite a few) posts about this. I know that it means I'm referencing pointers that have been deleted - I'm pretty sure I even know what is wrong with my code. Sadly what I do not know is how to correctly fix it.
The goal of the project is simple learning (re-learning, at that, as I've been away from my compiler for several years).
The project is to create a simple feed-forward artifical neural network. Once I get the concept working correctly, I'll play around with the structure to make it do something useful.
The implementation is to create a neuron class, then create x number of arrays of them, then link layers to other layers depending on where they are logically in my mind.
I have a class... 'Neuron'. Each neuron contains your typical stuff... inputs, weights, and an output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class Neuron{
public:
Neuron(int type);
~Neuron();
float GenerateOutput();
bool LinkInput(Neuron* Source);
bool SetInput(float input);
private:
Neuron* inputs;
float* inputWeights;
float output;
int inputCount;
int MyType;
int myRand;
};
|
The way I was hoping to implement the inputs, was to create an array of Neurons (which in my code is simply Neuron *inputs;).
Within my main function, I create the layers, and attempt to link the layers (this code is truncated, does not include all layers)
1 2 3 4 5 6 7 8 9
|
Neuron* InputLayer = (Neuron*)calloc(Layer_Input_NodeCount,sizeof(Neuron));
for (int i=0;i<Layer_Input_NodeCount;i++)
InputLayer[i]= Neuron(Node_Type_Input);
Neuron* HiddenLayer = (Neuron*)calloc(Layer_Hidden_NodeCount,sizeof(Neuron));
for (int i=0;i<Layer_Hidden_NodeCount;i++){
HiddenLayer[i]=Neuron(Node_Type_Hidden);
for (int j=0;j<Layer_Input_NodeCount;j++)
HiddenLayer[i].LinkInput(&InputLayer[j]);
}
|
And this is where I think my problem lies... I think that the pointer I'm passing into the below function is going by the way side after the function returns? Is this correct?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
bool Neuron::LinkInput(Neuron* Source){
if (inputCount>=Node_MaximumInputs){
cout<<"Maximum Input Count has been reached\r\n";
return false;
}
if (MyType==Node_Type_Input){
cout<<"Cannot link node to an Input\r\n";
return false;
}
inputs[inputCount++]=*Source;
return true;
};
|