not declared in scope and no member name with vectors.

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
86
87
  #include <iostream>
#include <vector>
#include <cmath>
#include "ANN.h"
using namespace std;

const int NUM_HIDDEN_NEURONS = 3;


//*****************************************************************************


void Neuron::SetWeights(int n) {
  weights.clear();
  for (int k = 0; k < n; k++)
    weights.push_back(0.5);
  return;
}


//*****************************************************************************


void Neuron::PrintWeights() {

  for (int k = 0; k < weights.size(); k++)
    cout << weights[k] << endl;
  return;
}


//*****************************************************************************


void ANN::JustDoIt() {
  hidden.SetWeights(NUM_HIDDEN_NEURONS);
  output.SetWeights(NUM_HIDDEN_NEURONS);
  output.PrintWeights();
}


//*****************************************************************************
void HiddenNeuron::SetNeuronData(double down, double yards , int i){

  theNeuron = down + yards;
  theNeuron = theNeuron * weights[i];
  theNeuron = 1 / (1 + pow(2.71828, theNeuron));
}


//*****************************************************************************


void OutputNeuron::SetNeuronData(vector<HiddenNeuron> neurons){
  double value;
  for(int i = 0; i < NUM_HIDDEN_NEURONS; ++i){
    value = neurons[i].GetNeuronData();
    theNeuron = theNeuron + (value * weights[i]);
  }
}


//*****************************************************************************


double Neuron::GetNeuronData() const{
  return theNeuron;
}


//*****************************************************************************


double ANN::GetOutputValue() const{
  return output.GetNeuronData();
}


//*****************************************************************************


void ANN::SetData(double down, double yards){
  for(int i = 0; i < NUM_HIDDEN_NEURONS; ++i)
    hidden.push_back(SetNeuronData(down, yards, i));
  output.SetNeuronData(hidden);
}


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
#ifndef ANN_H
#define ANN_H
#include <iostream>
#include <vector>
#include "TrainData.h"
using namespace std;




class Neuron {
  protected:
    vector<double> weights;
    double theNeuron;
  public:
    double GetNeuronData() const;
    void PrintWeights();
    void SetWeights(int n);
};



class HiddenNeuron : public Neuron {
  public:
    void SetNeuronData(double down, double pass, int i);
};



class OutputNeuron : public Neuron {
  public:
    void SetNeuronData(vector<HiddenNeuron> neurons);
};



class ANN {
  private:
    vector<HiddenNeuron> hidden;
    OutputNeuron output;
  public:
    double GetOutputValue() const;
    void JustDoIt();
    void SetData(double down, double yards);

};
#endif 


So I am getting 2 errors that I need help explaining. Here is both of them.

ANN.cpp: In member function ‘void ANN::JustDoIt()’:
ANN.cpp:36: error: ‘class std::vector<HiddenNeuron, std::allocator<HiddenNeuron> >’ has no member named ‘SetWeights’
ANN.cpp: In member function ‘void ANN::SetData(double, double)’:
ANN.cpp:85: error: ‘SetNeuronData’ was not declared in this scope
Last edited on
ANN.cpp: In member function ‘void ANN::JustDoIt()’:
ANN.cpp:36: error: ‘class std::vector<HiddenNeuron, std::allocator<HiddenNeuron> >’ has no member named ‘SetWeights’


You are trying to called SetWeights on your ANN::hidden vector. What exactly are you trying to do here?

ANN.cpp: In member function ‘void ANN::SetData(double, double)’:
ANN.cpp:85: error: ‘SetNeuronData’ was not declared in this scope


You are trying to push_back the results of some function SetNeuronData(), which doesn't exist.
Ok so I see what I did wrong for the second one but the first one confuses me still. I need to set the weights first so I was calling the function to set the weights but it says that it doesn't exist. why?\

Topic archived. No new replies allowed.