File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,12 @@ int main(){
11
11
vector <double > in{ 0 , 2 , 3 };
12
12
vector <double > out{ 1 , 0 , .5 , 0 };
13
13
net n1 (dims, true );// creates fully connected net with weights initialized to random values in the shape of dims
14
- n1.TrainBackpropagation ( out, in);// run backpropagation once
15
14
cout<<" n1:" <<endl;
16
15
for (int i= 0 ; i<n1.get_size (); i++){
17
16
cout<<" layer " <<i<<" = " <<n1.get_size (i)<<endl;
18
17
}
19
18
19
+
20
20
net n2 = n1;
21
21
cout<<" n2:" <<endl;
22
22
for (int i= 0 ; i<n2.get_size (); i++){
@@ -33,10 +33,17 @@ int main(){
33
33
n3.AppendNet (&n2,false );
34
34
35
35
cout<<" n3:" <<endl;
36
- for (int i= 0 ; i<n3-> get_size (); i++){
37
- cout<<" layer " <<i<<" = " <<n3-> get_size (i)<<endl;
36
+ for (int i= 0 ; i<n3. get_size (); i++){
37
+ cout<<" layer " <<i<<" = " <<n3. get_size (i)<<endl;
38
38
}
39
-
39
+
40
+ n3.TrainBackpropagation (out,in);
41
+ cout<<endl<<" n1 output = " ;
42
+ n1.Output ();
43
+ cout<<endl<<" n2 output = " ;
44
+ n2.Output ();
45
+ cout<<endl<<" n3 output = " ;
46
+ n3.Output ();
40
47
41
48
42
49
return 0 ;
Original file line number Diff line number Diff line change @@ -39,8 +39,6 @@ class net //represents a the vector of vectors of neurons
39
39
int col;
40
40
bool isnetfunc=false ;
41
41
42
-
43
-
44
42
union
45
43
{
46
44
// pointer to function to run
@@ -92,6 +90,7 @@ class net //represents a the vector of vectors of neurons
92
90
vector<double > input;
93
91
typedef vector <string> group;
94
92
vector<group>groups;
93
+ bool netPointersCopied=false ;
95
94
// vector<thread> threads;
96
95
97
96
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ net::net(vector <int> &dimensions, bool fullyconnected)
64
64
// destructor
65
65
net::~net ()
66
66
{
67
+ if (this ->netPointersCopied ){
68
+ cout <<endl<<" netPointersCopied" ;
69
+ return ;
70
+ }
67
71
// deletes all neurons and their inweights
68
72
for (row=layers.begin (); row!=layers.end (); row++)
69
73
{
@@ -803,11 +807,12 @@ net* net::AppendNet(net* net_from, bool pasteOver)
803
807
this ->layers .resize (0 );
804
808
this ->layers .insert (this ->layers .end (), l.begin (), l.end ());
805
809
810
+
806
811
}else {
807
812
this ->layers .insert (this ->layers .end (), net_from->layers .begin (), net_from->layers .end ());
808
813
}
809
814
810
-
815
+ net_from-> netPointersCopied = true ;
811
816
return this ;
812
817
}
813
818
You can’t perform that action at this time.
0 commit comments