summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike <mike@d8baa203-390c-0410-a584-dba4c0749223>2011-07-16 18:53:45 +0000
committermike <mike@d8baa203-390c-0410-a584-dba4c0749223>2011-07-16 18:53:45 +0000
commit3005ed13f0fde6d61ab8a229c1490f9389cd75b5 (patch)
tree737c067dc4ceb0e4cee26e3e5f60ef91f8e71cdb
parent6bf9a32cf42b3f1a6dad7018d1b1925cc909b585 (diff)
downloadlibneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.gz
libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.bz2
libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.xz
libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.zip
Everything is in place except for columns, networks, and a cute language for
describing the networks. ...and tests, don't forget about tests. git-svn-id: http://svn.xagasoft.com/misc/libneural/trunk@470 d8baa203-390c-0410-a584-dba4c0749223
Diffstat (limited to '')
-rw-r--r--default.bld9
l---------neural1
-rw-r--r--src/column.cpp0
-rw-r--r--src/column.h0
-rw-r--r--src/container.cpp5
-rw-r--r--src/container.h46
-rw-r--r--src/network.cpp0
-rw-r--r--src/network.h0
-rw-r--r--src/neuron.cpp5
-rw-r--r--src/neuron.h71
-rw-r--r--src/node.cpp5
-rw-r--r--src/node.h29
-rw-r--r--src/row.cpp5
-rw-r--r--src/row.h81
-rw-r--r--src/slope.cpp1
-rw-r--r--src/slope.h22
-rw-r--r--src/slopestd.cpp5
-rw-r--r--src/slopestd.h55
18 files changed, 340 insertions, 0 deletions
diff --git a/default.bld b/default.bld
new file mode 100644
index 0000000..be99b23
--- /dev/null
+++ b/default.bld
@@ -0,0 +1,9 @@
1target "libneural.a"
2{
3 rule "lib";
4 input files("src/*.cpp");
5
6 CXXFLAGS += "-I.";
7 LDCONFIG += "-lbu++";
8}
9
diff --git a/neural b/neural
new file mode 120000
index 0000000..e831038
--- /dev/null
+++ b/neural
@@ -0,0 +1 @@
src \ No newline at end of file
diff --git a/src/column.cpp b/src/column.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/column.cpp
diff --git a/src/column.h b/src/column.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/column.h
diff --git a/src/container.cpp b/src/container.cpp
new file mode 100644
index 0000000..00e7cad
--- /dev/null
+++ b/src/container.cpp
@@ -0,0 +1,5 @@
1#include "neural/container.h"
2
3template class Neural::Container<float>;
4template class Neural::Container<double>;
5template class Neural::Container<long double>;
diff --git a/src/container.h b/src/container.h
new file mode 100644
index 0000000..d9eeffd
--- /dev/null
+++ b/src/container.h
@@ -0,0 +1,46 @@
1#ifndef NEURAL_CONTAINER_H
2#define NEURAL_CONTAINER_H
3
4#include "neural/node.h"
5#include <bu/list.h>
6
7namespace Neural
8{
9 template<typename sigtype>
10 class Container : public Node<sigtype>
11 {
12 public:
13 typedef Bu::List<Neural::Node<sigtype> *> NodeList;
14
15 Container()
16 {
17 }
18
19 virtual ~Container()
20 {
21 for( typename NodeList::iterator i = lNodes.begin(); i; i++ )
22 delete *i;
23 }
24
25 virtual void addNode( Node<sigtype> *pNode )
26 {
27 lNodes.append( pNode );
28 }
29
30 virtual const NodeList &getNodeList() const
31 {
32 return lNodes;
33 }
34
35 protected:
36 virtual NodeList &getNodeList()
37 {
38 return lNodes;
39 }
40
41 private:
42 NodeList lNodes;
43 };
44};
45
46#endif
diff --git a/src/network.cpp b/src/network.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/network.cpp
diff --git a/src/network.h b/src/network.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/network.h
diff --git a/src/neuron.cpp b/src/neuron.cpp
new file mode 100644
index 0000000..a951b45
--- /dev/null
+++ b/src/neuron.cpp
@@ -0,0 +1,5 @@
1#include "neural/neuron.h"
2
3template class Neural::Neuron<float>;
4template class Neural::Neuron<double>;
5template class Neural::Neuron<long double>;
diff --git a/src/neuron.h b/src/neuron.h
new file mode 100644
index 0000000..dc30471
--- /dev/null
+++ b/src/neuron.h
@@ -0,0 +1,71 @@
1#ifndef NEURAL_NEURON_H
2#define NEURAL_NEURON_H
3
4#include "neural/node.h"
5#include "neural/slope.h"
6
7namespace Neural
8{
9 template<typename sigtype>
10 class Neuron : public Node<sigtype>
11 {
12 public:
13 Neuron() :
14 iInputs( 0 ),
15 aWeights( 0 ),
16 sBias( 0.0 ),
17 pSlope( 0 )
18 {
19 }
20
21 virtual ~Neuron()
22 {
23 delete[] aWeights;
24 delete pSlope;
25 }
26
27 virtual void finalize( int iNumInputs )
28 {
29 iInputs = iNumInputs;
30 aWeights = new sigtype[iInputs];
31 }
32
33 virtual void process( sigtype *aInput, sigtype *aOutput )
34 {
35 sigtype sOutput = sBias;
36 for( int j = 0; j < iInputs; j++ )
37 {
38 sOutput += aWeights[j] * aInput[j];
39 }
40 *aOutput = (*pSlope)( sOutput );
41 }
42
43 virtual int getNumInputs() const
44 {
45 return iInputs;
46 }
47
48 virtual int getNumOutputs() const
49 {
50 return 1;
51 }
52
53 virtual int getNumWeights() const
54 {
55 return iInputs;
56 }
57
58 virtual int getNumBiases() const
59 {
60 return 1;
61 }
62
63 private:
64 int iInputs;
65 sigtype *aWeights;
66 sigtype sBias;
67 Slope<sigtype> *pSlope;
68 };
69};
70
71#endif
diff --git a/src/node.cpp b/src/node.cpp
new file mode 100644
index 0000000..1a02875
--- /dev/null
+++ b/src/node.cpp
@@ -0,0 +1,5 @@
1#include "neural/node.h"
2
3template class Neural::Node<float>;
4template class Neural::Node<double>;
5template class Neural::Node<long double>;
diff --git a/src/node.h b/src/node.h
new file mode 100644
index 0000000..fe2b720
--- /dev/null
+++ b/src/node.h
@@ -0,0 +1,29 @@
1#ifndef NEURAL_NODE_H
2#define NEURAL_NODE_H
3
4namespace Neural
5{
6 template<typename sigtype>
7 class Node
8 {
9 public:
10 Node()
11 {
12 }
13
14 virtual ~Node()
15 {
16 }
17
18 virtual void finalize( int iNumInputs )=0;
19 virtual void process( sigtype *aInput, sigtype *aOutput )=0;
20
21 virtual int getNumInputs() const=0;
22 virtual int getNumOutputs() const=0;
23 virtual int getNumWeights() const=0;
24 virtual int getNumBiases() const=0;
25 };
26};
27
28#endif
29
diff --git a/src/row.cpp b/src/row.cpp
new file mode 100644
index 0000000..ea050d2
--- /dev/null
+++ b/src/row.cpp
@@ -0,0 +1,5 @@
1#include "neural/row.h"
2
3template class Neural::Row<float>;
4template class Neural::Row<double>;
5template class Neural::Row<long double>;
diff --git a/src/row.h b/src/row.h
new file mode 100644
index 0000000..0ec5dde
--- /dev/null
+++ b/src/row.h
@@ -0,0 +1,81 @@
1#ifndef NEURAL_ROW_H
2#define NEURAL_ROW_H
3
4#include "neural/container.h"
5
6namespace Neural
7{
8 template<typename sigtype>
9 class Row : public Container<sigtype>
10 {
11 public:
12 //typedef Bu::List<Neural::Node<sigtype> *> NodeList;
13 Row() :
14 iInputs( 0 ),
15 iOutputs( 0 ),
16 iWeights( 0 ),
17 iBiases( 0 )
18 {
19 }
20
21 virtual ~Row()
22 {
23 }
24
25 virtual void finalize( int iNumInputs )
26 {
27 iInputs = iNumInputs;
28 iOutputs = 0;
29 iWeights = 0;
30 iBiases = 0;
31
32 for( typename Container<sigtype>::NodeList::iterator i =
33 Container<sigtype>::getNodeList().begin(); i; i++ )
34 {
35 (*i)->finalize( iInputs );
36 iOutputs += (*i)->getNumOutputs();
37 iWeights += (*i)->getNumWeights();
38 iBiases += (*i)->getNumBiases();
39 }
40 }
41
42 virtual void process( sigtype *aInput, sigtype *aOutput )
43 {
44 int iOutputOffset = 0;
45 for( typename Container<sigtype>::NodeList::iterator i =
46 Container<sigtype>::getNodeList().begin(); i; i++ )
47 {
48 (*i)->process( aInput, aOutput+iOutputOffset );
49 iOutputOffset += (*i)->getNumOutputs();
50 }
51 }
52
53 virtual int getNumInputs() const
54 {
55 return iInputs;
56 }
57
58 virtual int getNumOutputs() const
59 {
60 return iOutputs;
61 }
62
63 virtual int getNumWeights() const
64 {
65 return iWeights;
66 }
67
68 virtual int getNumBiases() const
69 {
70 return iBiases;
71 }
72
73 private:
74 int iInputs;
75 int iOutputs;
76 int iWeights;
77 int iBiases;
78 };
79};
80
81#endif
diff --git a/src/slope.cpp b/src/slope.cpp
new file mode 100644
index 0000000..5b380af
--- /dev/null
+++ b/src/slope.cpp
@@ -0,0 +1 @@
#include "neural/slope.h"
diff --git a/src/slope.h b/src/slope.h
new file mode 100644
index 0000000..acdbb41
--- /dev/null
+++ b/src/slope.h
@@ -0,0 +1,22 @@
1#ifndef NEURAL_SLOPE_H
2#define NEURAL_SLOPE_H
3
4namespace Neural
5{
6 template<typename sigtype>
7 class Slope
8 {
9 public:
10 Slope()
11 {
12 }
13
14 virtual ~Slope()
15 {
16 }
17
18 virtual sigtype operator()( sigtype sInput )=0;
19 };
20};
21
22#endif
diff --git a/src/slopestd.cpp b/src/slopestd.cpp
new file mode 100644
index 0000000..16b2be4
--- /dev/null
+++ b/src/slopestd.cpp
@@ -0,0 +1,5 @@
1#include "neural/slopestd.h"
2
3template class Neural::SlopeStd<float>;
4template class Neural::SlopeStd<double>;
5template class Neural::SlopeStd<long double>;
diff --git a/src/slopestd.h b/src/slopestd.h
new file mode 100644
index 0000000..40ceef2
--- /dev/null
+++ b/src/slopestd.h
@@ -0,0 +1,55 @@
1#ifndef NEURAL_SLOPE_STD_H
2#define NEURAL_SLOPE_STD_H
3
4#include <math.h>
5
6#include "neural/slope.h"
7
8namespace Neural
9{
10 template<typename sigtype>
11 sigtype tpltanh( sigtype sInput );
12
13 template<>
14 float tpltanh<float>( float sInput )
15 {
16 return tanhf( sInput );
17 }
18
19 template<>
20 double tpltanh<double>( double sInput )
21 {
22 return tanh( sInput );
23 }
24
25 template<>
26 long double tpltanh<long double>( long double sInput )
27 {
28 return tanhl( sInput );
29 }
30
31 template<typename sigtype>
32 class SlopeStd : public Slope<sigtype>
33 {
34 public:
35 SlopeStd( sigtype sSlope=1.0 ) :
36 sSlope( sSlope )
37 {
38 }
39
40 virtual ~SlopeStd()
41 {
42 }
43
44 virtual sigtype operator()( sigtype sInput )
45 {
46 return (tpltanh<sigtype>(2.0*sSlope*sInput) + 1.0)/2.0;
47 }
48
49 private:
50 sigtype sSlope;
51 };
52};
53
54#endif
55