9 #ifndef __NETFACTORY_HPP 10 #define __NETFACTORY_HPP 46 return new BPNet(layercount,layers);
52 return new UESNet(layercount,layers);
62 FILE *a = fopen(fn,
"rb");
64 throw new std::runtime_error(
"cannot open file");
68 if(!fread(&magic,
sizeof(uint32_t),1,a)){
70 throw new std::runtime_error(
"bad net save file");
77 uint32_t layercount,tmp;
78 if(!fread(&layercount,
sizeof(uint32_t),1,a)){
80 throw new std::runtime_error(
"bad net save file");
82 int *layers =
new int[layercount];
83 for(
int i=0;i<layercount;i++){
84 if(!fread(&tmp,
sizeof(uint32_t),1,a)){
87 throw new std::runtime_error(
"bad net save file");
97 double *buf =
new double[size];
100 int readData = fread(buf,
sizeof(
double),size,a);
105 throw new std::runtime_error(
"bad net save file");
119 inline static void save(
const char *fn,
Net *n) {
120 FILE *a = fopen(fn,
"wb");
122 throw new std::runtime_error(
"cannot open file");
125 uint32_t magic=
static_cast<uint32_t
>(n->
type);
126 fwrite(&magic,
sizeof(uint32_t),1,a);
130 fwrite(&layercount,
sizeof(uint32_t),1,a);
131 for(
int i=0;i<layercount;i++){
133 fwrite(&layersize,
sizeof(uint32_t),1,a);
139 double *buf =
new double[size];
142 fwrite(buf,
sizeof(
double),size,a);
NetType
The different types of network - each has an associated integer for saving/loading file data...
static Net * load(const char *fn)
Load a network of any type from a file - note, endianness not checked!
This class - really a namespace - contains functions which create, load or save networks of all types...
virtual int getLayerCount() const =0
Get the number of layers.
A modulatory network architecture which uses two plain backprop networks, each of which is trained se...
virtual void save(double *buf) const =0
Serialize the data (not including any network type magic number or layer/node counts) to the given me...
The "basic" back-propagation network using a logistic sigmoid, as described by Rumelhart, Hinton and Williams (and many others). This class is used by output blending and h-as-input networks.
int getInputCount() const
get the number of inputs in all examples
static Net * makeNet(NetType t, int layercount, int *layers)
virtual int getLayerSize(int n) const =0
Get the number of nodes in a given layer.
h-as-input network - only
This implements a plain backprop network.
static void save(const char *fn, Net *n)
Save a net of any type to a file - note, endianness not checked!
static Net * makeNet(NetType t, ExampleSet &e, int hnodes)
Construct a single hidden layer network of a given type which conforms to the example set...
This file contains the implementation of the UESMANN network itself - at least, those parts which are...
int getOutputCount() const
get the number of outputs in all examples
virtual int getDataSize() const =0
Get the length of the serialised data block for this network.
virtual void load(double *buf)=0
Given that the pointer points to a data block of the correct size for the current network...
NetType type
type of the network, used for load/save
The UESMANN network, which it itself based on the BPNet code as it has the same architecture as the p...
Output blending network - only works with 2 h-levels, 0 and 1, and only with SGD. ...
The abstract network type upon which all others are based. It's not pure virtual, in that it encapsul...
A set of example data. Each datum consists of hormone (i.e. modulator value), inputs and outputs...