function undeclared error

I'm compiling my first multilayer perceptron, and this error keeps coming up in compile.

30 C:\Dev-Cpp\main.cpp `inputcount' undeclared (first use this function)
34 C:\Dev-Cpp\main.cpp `input' undeclared (first use this function)



I can't figure out why though, I have a shadow copy of my CreateNetwork function in the main program, and it recognizes it, it has to cause it doesnt get hung up on the reference to that function.

well anyways, Here is the code, perceptron header first, neuralnet header second, and main cpp file last.
perceptron.h:
[code="perceptron.h"]
#include <iostream>
#include <cstdlib>
#include <math.h>

#ifndef _PERCEPTRON_H_
#define _PERCEPTRON_H_

double randgauss( double min, double max, double sigma, double centre)
{
double random = (min + (max-min) * (double)rand()/RAND_MAX); //create random domain between [min,max]

double tmp = (random-centre)/sigma;
double gauss= exp(-tmp*tmp/2); //gaussian formula

return gauss;
} // This code taken from a post under the alias ndemin on July 29th, 2005 all rights reserved by him/her


struct perceptron
{
int Input[16]; // Up to 16 inputs
double Bias; //bias
double Weight[16]; // often randomized
double Threshold; // often randomized
bool Fireing;
int ID; // Only used in neural nets
double Output; // only used in multilayer networks
};
#endif[/code]
neuralnet.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstdlib>
#include "perceptron.h"
#ifndef _NEURALNET_H_
#define _NEURALNET_H_

int i = 1;
int addconnection(perceptron toNeuron, double weightVal)
{
  i = i + 1
  int ConnectionID[64];
  perceptron ConnectionNeuron[64];
 
      ConnectionWeight[i] = weightVal;
      ConnectionNeuron[i] = toNeuron;
      ConnectionID[i] = toNeuron.ID;
}
int CreateNetwork(int inputcount, int hiddenlayer, int hiddencount, int outputcount) // this is the function in question
{
    int CreateLoop = 1;
    perceptron HiddenNeuron, InputNeuron, OutputNeuron;
    double Conweight;
    for (CreateLoop; CreateLoop <= inputcount; CreateLoop++)
    {
           perceptron input[CreateLoop];

    }
    for (CreateLoop = 1; CreateLoop <= hiddenlayer; CreateLoop++)
    { 
        for (CreateLoop = 1; CreateLoop <= hiddencount; CreateLoop++)
        {
                    perceptron hidden[CreateLoop];
                   Conweight = randgauss(0,1,0.5,0.0002);
                  addconnection(InputNeuron, Conweight);
        }
    }

    for (CreateLoop = 1; CreateLoop <= outputcount; CreateLoop++)
    {
        perceptron output[CreateLoop];
        Conweight = randgauss(0,1,0.5,0.0002);
        addconnection(OutputNeuron, Conweight);
    }
}



main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Author: Alex Evans 
 * Title: NeuralNetTest
 * version: 0.0.6
 *
 * NOTES: Anywhere where I output one of the weights, thresholds, or inputs is strictly for my studying of neural nets.
 */

#include <perceptron.h>
#include <neuralnet.h>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;


const double rate = 0.02; 
int CreateNetwork(int inputcount, int hiddenlayer, int hiddencount, int outputcount);

int main(int argc, char *argv[])
{
    CreateNetwork(3,2,3,2);
    {
    for (int i = 1; i <= inputcount; i++) // this is where the program hangs up
    {
    double total;
    double subOutput;
    input[i].Bias = randgauss(0,1,0.5,0.00002);
    input[i].Threshold =  randgauss(0,1,0.5,0.00002);
    input[i].Weight[1] = randgauss(0,1,0.5,0.00002);
    input[i].Weight[2] = randgauss(0,1,0.5,0.00002);
    cout << "Current Threshold is: ";
    cout << input[i].Threshold;
    cout << "\n";
    for (int j = 1; j <=2; j++)
    {
        cout << "Starting Weight is: ";
        cout << input[i].Weight[j];
        cout << "\n What is the value of input ";
        cout << i;
        cout << ": ";
        cin >> input[i].Input[j];
        cout << "\n";
        cout << total;
        cout << "\n";
        total = total + (input[i].Input[j] * input[i].Weight[j]);
        cout << total;
        cout << "\n";
    } 
   total = total + input[i].Bias;
    subOutput = 1/(1+exp((input[i].Input[1] * input[i].Threshold)));
    do 
    {
    if (subOutput >= input[i].Threshold)
    {
              input[i].Fireing = true;
              cout << "It fired ";
              cout << "\n ";
              cout << subOutput;
              
    } else { 
    input[i].Fireing = false;
    cout << "It didnt fire \n";  
    for ( int l = 1; l <=2; l++)
    {
    input[i].Weight[l] = input[i].Input[l]+ rate * (input[i].Threshold - subOutput)*input[i].Input[l]; 
    cout << "New weight is: ";
    cout << input[i].Weight[l];
    cout << "\n";
    }
    
    for (int k = 1; k <= 2; k++)
   {
       input[i].Threshold = input[i].Threshold - rate * (input[i].Threshold - subOutput);
   } cout << "New threshold is: ";
   cout << input[i].Threshold;
   cout << "\n";
}
}while(input[i].Fireing != true);
}
} 
    system("PAUSE");
    return EXIT_SUCCESS;
}


Yea I know, Seriously needs cleaning up... But bare with me please?
You haven't actually declared a variable named inputcount anywhere. Line 19 is just a function declaration.

oh wow.....Once more I fail hard...lulz.

Well thanks jsmith.

edit: well that out of the way, I found out that I was calling the wrong header....
So that fixed, It still doesnt see input. But I think I can figure it out from here.
Last edited on
Topic archived. No new replies allowed.