MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ann.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libann/ann.h,v 1.16 2017/01/12 14:43:23 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 /*
32  * Copyright (C) 2008
33  *
34  * Mattia Mattaboni <mattaboni@aero.polimi.it>
35  */
36 
37 #ifndef ANN_H
38 #define ANN_H
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif /* __cplusplus */
43 
44 #include "ActivationFunction.h"
45 #include "matrix.h"
46 
47 #define ANN_W_A_NONE (0x0U)
48 #define ANN_W_A_TEXT (0x1U)
49 #define ANN_W_A_BIN (0x2U)
50 
51 #define ANN_FEEDBACK_NONE (0x0U)
52 #define ANN_FEEDBACK_UPDATE (0x1U)
53 
54 /* diagnostics */
55 typedef enum {
56  ANN_OK = 0,
62 } ann_res_t;
63 
64 typedef enum {
68 
71 
72 
73 /* Artificial Neural Network structure*/
74 typedef struct ANN {
75  /* NEURON'S ACTIVATION FUNCTION */
81  void *w_priv;
82 
83  /* NETWORK ARCHITECTURE */
84  int N_input; /* network input number*/
85  int N_output; /* network (visible) output number*/
86  int N_layer; /* network layer number*/
87  int *N_neuron; /* neuron number*/
88  int r; /* number of time delay*/
89 
90  /* TRAINING PARAMETERS */
91  double eta; /* learning rate*/
92  double rho; /* momentum term*/
93 
94  /* SYNAPTIC WEIGHTS */
95  ANN_vector_matrix W; /* network synaptic weights*/
96 
97  /* JCOBIAN MATRIX */
99 
100  /* SCALE FACTORS */
101  matrix input_scale; /* input scale factors */
102  matrix output_scale; /* output scale factors */
103 
104  /* SIMULATION DATA */
105  ANN_vector_vector v; /* neurons' internal activity*/
106  ANN_vector_vector Y_neuron; /* neurons' output*/
107  vector yD; /* output */
108 
109  /* TRAINING DATA */
110  ANN_vector_matrix dEdW; /* error gradient*/
111  ANN_vector_matrix **dy; /* output network gradient*/
112 
113  /* PRIVATE TRAINING DATA */
114  ANN_vector_matrix *dydW, dW;
115  ANN_vector_vector dXdW, temp, dydV, dEdV, dXdu;
117 
118 
119 } ANN;
120 
121 
122 /* FUNCTIONS' PROTOTYPES */
123 ann_res_t ANN_init( ANN *, const char * );
125 ann_res_t ANN_write( ANN *, FILE *, unsigned );
126 ann_res_t ANN_sim( ANN *, vector *, vector *, unsigned );
127 ann_res_t ANN_DataRead( matrix *, int *, char * );
128 ann_res_t ANN_DataWrite( matrix *, char * );
129 double ANN_InternalFunction( double , ANN * );
130 double ANN_InternalFunctionDer( double , ANN * );
131 ann_res_t ANN_vector_matrix_init( ANN_vector_matrix *, int *, int );
132 ann_res_t ANN_vector_vector_init( ANN_vector_vector *, int *, int );
134 ann_res_t ANN_dXdW( ANN *, int , int , int );
135 ann_res_t ANN_WeightUpdate( ANN *, ANN_vector_matrix, double );
137 ann_res_t ANN_reset( ANN * );
138 ann_res_t ANN_TotalError( matrix *, matrix *, double *);
139 ann_res_t ANN_vector_matrix_ass( ANN_vector_matrix *, ANN_vector_matrix *, int* , int, double );
141 
142 void ANN_error( ann_res_t, char * );
143 
144 #ifdef __cplusplus
145 }
146 #endif /* __cplusplus */
147 
148 #endif /* ANN_H */
ann_res_t ANN_TrainingEpoch(ANN *, matrix *, matrix *, matrix *, int, ann_training_mode_t)
Definition: ann.c:769
ann_res_t ANN_vector_vector_init(ANN_vector_vector *, int *, int)
Definition: ann.c:588
ANN_vector_vector dXdW
Definition: ann.h:115
Definition: matrix.h:68
w_eval_f w_eval
Definition: ann.h:80
ANN_vector_matrix W
Definition: ann.h:95
void * w_priv
Definition: ann.h:81
ann_res_t ANN_vector_matrix_init(ANN_vector_matrix *, int *, int)
Definition: ann.c:569
ANN_vector_vector dEdV
Definition: ann.h:115
ann_res_t ANN_dEdW(ANN *, vector *)
Definition: ann.c:645
ann_res_t ANN_reset(ANN *)
Definition: ann.c:828
w_write_f w_write
Definition: ann.h:79
ann_res_t ANN_init(ANN *, const char *)
Definition: ann.c:48
double eta
Definition: ann.h:91
w_destroy_f w_destroy
Definition: ann.h:77
matrix * ANN_vector_matrix
Definition: ann.h:69
ann_training_mode_t
Definition: ann.h:64
int(* w_destroy_f)(void *)
ann_res_t ANN_WeightUpdate(ANN *, ANN_vector_matrix, double)
Definition: ann.c:552
int N_output
Definition: ann.h:85
ann_res_t
Definition: ann.h:55
vector error
Definition: ann.h:116
ANN_vector_vector dXdu
Definition: ann.h:115
Definition: matrix.h:61
double ANN_InternalFunctionDer(double, ANN *)
Definition: ann.c:540
ann_res_t ANN_vector_matrix_ass(ANN_vector_matrix *, ANN_vector_matrix *, int *, int, double)
Definition: ann.c:883
int(* w_eval_f)(void *, double, int, double *)
vector input
Definition: ann.h:116
ann_res_t ANN_dXdW(ANN *, int, int, int)
Definition: ann.c:609
ANN_vector_vector v
Definition: ann.h:105
int(* w_init_f)(void **)
ann_res_t ANN_sim(ANN *, vector *, vector *, unsigned)
Definition: ann.c:425
matrix output_scale
Definition: ann.h:102
double ANN_InternalFunction(double, ANN *)
Definition: ann.c:526
ANN_vector_matrix dW
Definition: ann.h:114
ann_res_t ANN_DataWrite(matrix *, char *)
Definition: ann.c:504
vector output
Definition: ann.h:116
int(* w_write_f)(void *, FILE *fd, unsigned flags)
int r
Definition: ann.h:88
w_init_f w_init
Definition: ann.h:76
ann_res_t ANN_DataRead(matrix *, int *, char *)
Definition: ann.c:475
int N_layer
Definition: ann.h:86
vector * ANN_vector_vector
Definition: ann.h:70
ANN_vector_vector temp
Definition: ann.h:115
int N_input
Definition: ann.h:84
ann_res_t ANN_destroy(ANN *)
Definition: ann.c:218
ANN_vector_matrix * dydW
Definition: ann.h:114
int * N_neuron
Definition: ann.h:87
matrix jacobian
Definition: ann.h:98
ann_res_t ANN_write(ANN *, FILE *, unsigned)
Definition: ann.c:341
Definition: ann.h:74
ann_res_t ANN_TotalError(matrix *, matrix *, double *)
Definition: ann.c:861
ANN_vector_matrix ** dy
Definition: ann.h:111
ANN_vector_vector dydV
Definition: ann.h:115
w_read_f w_read
Definition: ann.h:78
int(* w_read_f)(void *, FILE *fd, unsigned flags)
Definition: ann.h:56
struct ANN ANN
ANN_vector_matrix dEdW
Definition: ann.h:110
ANN_vector_vector Y_neuron
Definition: ann.h:106
void ANN_error(ann_res_t, char *)
Definition: ann.c:900
ann_res_t ANN_jacobian_matrix(ANN *, matrix *)
Definition: ann.c:921
double rho
Definition: ann.h:92
vector yD
Definition: ann.h:107
matrix input_scale
Definition: ann.h:101