-
Notifications
You must be signed in to change notification settings - Fork 12
/
connection.h
111 lines (99 loc) · 3.7 KB
/
connection.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* This file is part of the Neural Network modules of the APRIL toolkit (A
* Pattern Recognizer In Lua).
*
* Copyright 2012, Salvador España-Boquera, Adrian Palacios Corella, Francisco
* Zamora-Martinez
*
* The APRIL-ANN toolkit is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef CONNECTION_H
#define CONNECTION_H
#include <cstring>
#include "aligned_memory.h"
#include "swap.h"
#include "constants.h"
#include "actunit.h"
#include "referenced.h"
#include "MersenneTwister.h"
#include "matrixFloat.h"
namespace ANN {
class Connections : public Referenced {
protected:
FloatGPUMirroredMemoryBlock *weights;
FloatGPUMirroredMemoryBlock *prev_weights;
unsigned int total_size;
/// numero de inputs y numero de outputs
unsigned int num_inputs, num_outputs;
// contador de referencias
unsigned int num_references;
/// numero de veces que se ha llamado al metodo
/// update_weights_call, se inicia a 0 cuando este valor llega a
/// getNumReferences()
unsigned int update_weights_calls;
public:
static const double weightnearzero;
Connections(unsigned int total_size,
unsigned int num_inputs, unsigned int num_outputs);
virtual ~Connections();
// contamos el numero de veces que nos referencian, asi sabemos si
// la conexion es compartida por mas de una accion
void countReference();
unsigned int getNumReferences() const;
void beginUpdate();
void endUpdate();
bool isFirstUpdateCall();
void computeMomentumOnPrevVector(float momentum,
bool use_cuda);
void computeWeightDecayOnPrevVector(float c_weight_decay,
bool use_cuda);
void copyToPrevVector(bool use_cuda);
unsigned int size() const;
void pruneSubnormalAndCheckNormal();
FloatGPUMirroredMemoryBlock *getPtr();
FloatGPUMirroredMemoryBlock *getPrevPtr();
// INTERFAZ A IMPLEMENTAR
virtual bool checkInputOutputSizes(ActivationUnits *input,
ActivationUnits *output) const = 0;
virtual void randomizeWeights(MTRand *rnd, float low, float high) = 0;
virtual void randomizeWeightsAtColumn(unsigned int col,
MTRand *rnd,
float low, float high) = 0;
// Carga/guarda los pesos de la matriz data comenzando por la
// posicion first_weight_pos. Devuelve la suma del numero de pesos
// cargados/salvados y first_weight_pos. En caso de error,
// abortara el programa con un ERROR_EXIT
virtual unsigned int loadWeights(MatrixFloat *data,
MatrixFloat *old_data,
unsigned int first_weight_pos,
unsigned int column_size) = 0;
virtual unsigned int copyWeightsTo(MatrixFloat *data,
MatrixFloat *old_data,
unsigned int first_weight_pos,
unsigned int column_size) = 0;
// para hacer copias
virtual Connections *clone() = 0;
virtual unsigned int getNumWeights() const {
return total_size;
}
virtual unsigned int getNumInputs() const {
return num_inputs;
}
virtual unsigned int getNumOutputs() const {
return num_outputs;
}
};
}
#endif