change setup neurons and add update learning rates
This commit is contained in:
@@ -39,8 +39,36 @@ void free_config_layers(config_layers *pconf){
|
|||||||
free(pconf);
|
free(pconf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool randomizeInitWeight=true;
|
||||||
|
|
||||||
#define GEN_NEURONS_F_(type)\
|
#define GEN_NEURONS_F_(type)\
|
||||||
\
|
\
|
||||||
|
void do_not_update_learnig_rate_##type(neurons_##type *N){}\
|
||||||
|
\
|
||||||
|
void time_based_update_learning_rate_##type(neurons_##type *nr){\
|
||||||
|
nr->learning_rate=(nr->learning_rate)/(1+(nr->decay_rate)*(nr->iteration_step));\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
type power_##type(type b, size_t p){\
|
||||||
|
type ret_pow=1;\
|
||||||
|
for(size_t i=0;i<p;++i) ret_pow *=b;\
|
||||||
|
return ret_pow;\
|
||||||
|
}\
|
||||||
|
void step_based_update_learning_rate_##type(neurons_##type *nr){\
|
||||||
|
nr->learning_rate=(nr->initial_learning_rate)*power_##type((nr->decay_rate),(1+(nr->iteration_step))/(nr->drop_rate));\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
void setup_learning_rate_params_neurons_##type(neurons_##type *base,type initial_learning_rate, type decay_rate, size_t drop_rate, void (*update_learning_rate)(neurons_##type *)){\
|
||||||
|
while(base){\
|
||||||
|
base->initial_learning_rate = initial_learning_rate;\
|
||||||
|
base->learning_rate = initial_learning_rate;\
|
||||||
|
base->decay_rate = decay_rate;\
|
||||||
|
base->drop_rate = drop_rate;\
|
||||||
|
base->update_learning_rate = update_learning_rate;\
|
||||||
|
base = base->next_layer;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
void calc_net_neurons_##type(neurons_##type *nr){\
|
void calc_net_neurons_##type(neurons_##type *nr){\
|
||||||
size_t contractNB= ((nr->weight_in)->dim)->size - ((nr->input)->dim)->size ;\
|
size_t contractNB= ((nr->weight_in)->dim)->size - ((nr->input)->dim)->size ;\
|
||||||
/*print_tensor_msg_##type((nr->weight_in)," weight_in calc");*/\
|
/*print_tensor_msg_##type((nr->weight_in)," weight_in calc");*/\
|
||||||
@@ -66,6 +94,9 @@ type funcalc_delta_hidden_out_##type (type net, type temp, type(*df_act)(type)){
|
|||||||
return df_act(net)* temp;\
|
return df_act(net)* temp;\
|
||||||
}\
|
}\
|
||||||
void calc_delta_neurons_##type(neurons_##type *nr){\
|
void calc_delta_neurons_##type(neurons_##type *nr){\
|
||||||
|
(nr->update_learning_rate)(nr);\
|
||||||
|
/*printf("leraning rt :%f , step : %ld\n",nr->learning_rate,nr->iteration_step);\
|
||||||
|
*/++(nr->iteration_step);\
|
||||||
if(nr->next_layer == NULL){\
|
if(nr->next_layer == NULL){\
|
||||||
if(nr->nb_calc_thread < 2){\
|
if(nr->nb_calc_thread < 2){\
|
||||||
for(size_t i = 0; i<(nr->net)->dim->rank; ++i)\
|
for(size_t i = 0; i<(nr->net)->dim->rank; ++i)\
|
||||||
@@ -107,6 +138,24 @@ void calc_delta_neurons_##type(neurons_##type *nr){\
|
|||||||
free_tensor_##type(temp_w_d);\
|
free_tensor_##type(temp_w_d);\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
|
\
|
||||||
|
type func_only_weight_in_##type(type w0, type w1, type scalar){\
|
||||||
|
return w0 - scalar * w1;\
|
||||||
|
}\
|
||||||
|
void only_update_weight_neurons_##type(neurons_##type *nr){\
|
||||||
|
if(nr->nb_calc_thread < 2){\
|
||||||
|
for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
||||||
|
/*(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
||||||
|
*/(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate * (nr->weight_out)->x[i] ;\
|
||||||
|
}\
|
||||||
|
}else{\
|
||||||
|
update_6tensor_func_##type(nr->weight_in, nr->weight_out, \
|
||||||
|
func_only_weight_in_##type,\
|
||||||
|
nr->learning_rate,\
|
||||||
|
nr->nb_calc_thread);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
void update_weight_neurons_##type(neurons_##type *nr){\
|
void update_weight_neurons_##type(neurons_##type *nr){\
|
||||||
nr->TensorProduct(&(nr->weight_out), nr->input, nr->delta_out, nr->nb_prod_thread);\
|
nr->TensorProduct(&(nr->weight_out), nr->input, nr->delta_out, nr->nb_prod_thread);\
|
||||||
/*tensor_##type *tmp_e_w=NULL;\
|
/*tensor_##type *tmp_e_w=NULL;\
|
||||||
@@ -115,11 +164,13 @@ void update_weight_neurons_##type(neurons_##type *nr){\
|
|||||||
/*print_tensor_msg_##type(nr->delta_out," nr delta_out update wei");*/\
|
/*print_tensor_msg_##type(nr->delta_out," nr delta_out update wei");*/\
|
||||||
/*print_tensor_msg_##type(tmp_e_w," tmp_e_w update wei");*/\
|
/*print_tensor_msg_##type(tmp_e_w," tmp_e_w update wei");*/\
|
||||||
\
|
\
|
||||||
for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
only_update_weight_neurons_##type(nr);\
|
||||||
/*(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
/*for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
||||||
*/(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate * (nr->weight_out)->x[i] ;\
|
*//*(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
||||||
|
*/\
|
||||||
|
/*(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate * (nr->weight_out)->x[i] ;\
|
||||||
}\
|
}\
|
||||||
/*print_tensor_msg_##type(nr->weight_in," weight_in updated ");*/\
|
*//*print_tensor_msg_##type(nr->weight_in," weight_in updated ");*/\
|
||||||
/*free_tensor_##type(tmp_e_w);\
|
/*free_tensor_##type(tmp_e_w);\
|
||||||
*/\
|
*/\
|
||||||
}\
|
}\
|
||||||
@@ -153,7 +204,7 @@ void link_layers_##type(neurons_##type *nPrev, neurons_##type *nNext ){\
|
|||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers){\
|
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers, bool randomize, type minR, type maxR, int randomRange){\
|
||||||
neurons_##type *tmp_l=NULL, *ttmp_l=NULL;\
|
neurons_##type *tmp_l=NULL, *ttmp_l=NULL;\
|
||||||
for(size_t l=0; l<nb_layers; ++l){\
|
for(size_t l=0; l<nb_layers; ++l){\
|
||||||
tmp_l = malloc(sizeof(neurons_##type)); \
|
tmp_l = malloc(sizeof(neurons_##type)); \
|
||||||
@@ -163,6 +214,7 @@ void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_d
|
|||||||
ttmp_l->next_layer = tmp_l ;\
|
ttmp_l->next_layer = tmp_l ;\
|
||||||
}\
|
}\
|
||||||
tmp_l->id_layer= l;\
|
tmp_l->id_layer= l;\
|
||||||
|
tmp_l->iteration_step= 0;\
|
||||||
tmp_l->input = NULL; \
|
tmp_l->input = NULL; \
|
||||||
tmp_l->net = NULL; \
|
tmp_l->net = NULL; \
|
||||||
tmp_l->output = NULL; \
|
tmp_l->output = NULL; \
|
||||||
@@ -171,6 +223,7 @@ void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_d
|
|||||||
tmp_l->weight_out = NULL; \
|
tmp_l->weight_out = NULL; \
|
||||||
tmp_l->delta_out = NULL; \
|
tmp_l->delta_out = NULL; \
|
||||||
tmp_l->bias = NULL; \
|
tmp_l->bias = NULL; \
|
||||||
|
tmp_l->update_learning_rate = do_not_update_learnig_rate_##type; \
|
||||||
tmp_l->prev_layer = ttmp_l;\
|
tmp_l->prev_layer = ttmp_l;\
|
||||||
tmp_l->next_layer = NULL;\
|
tmp_l->next_layer = NULL;\
|
||||||
\
|
\
|
||||||
@@ -191,9 +244,9 @@ void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_d
|
|||||||
dimension *d_w_in; \
|
dimension *d_w_in; \
|
||||||
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
||||||
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
for(size_t i=0;i<((ttmp_l->weight_in)->dim)->rank;++i) (ttmp_l->weight_in)->x[i]=0.5;\
|
if(randomize) init_random_x_##type(ttmp_l->weight_in,minR,maxR,randomRange);\
|
||||||
/*init_random_x_##type(ttmp_l->weight_in,0,1,5000);\
|
else\
|
||||||
*/\
|
for(size_t i=0;i<((ttmp_l->weight_in)->dim)->rank;++i) (ttmp_l->weight_in)->x[i]=(minR+maxR)/2;\
|
||||||
}\
|
}\
|
||||||
if(l==nb_layers-1) {\
|
if(l==nb_layers-1) {\
|
||||||
dimension *dim_out=init_copy_dim(array_dim_in_layers[l],sz_layers[l]);\
|
dimension *dim_out=init_copy_dim(array_dim_in_layers[l],sz_layers[l]);\
|
||||||
@@ -208,9 +261,81 @@ void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_d
|
|||||||
dimension *d_w_in; \
|
dimension *d_w_in; \
|
||||||
add_dimension(&d_w_in, (tmp_l->input)->dim, ((tmp_l->output)->dim)); \
|
add_dimension(&d_w_in, (tmp_l->input)->dim, ((tmp_l->output)->dim)); \
|
||||||
tmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
tmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
|
if(randomize) init_random_x_##type(tmp_l->weight_in,minR,maxR,randomRange);\
|
||||||
|
else\
|
||||||
|
for(size_t i=0;i<((tmp_l->weight_in)->dim)->rank;++i) (tmp_l->weight_in)->x[i]=(minR+maxR)/2;\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
ttmp_l = tmp_l;\
|
||||||
|
\
|
||||||
|
\
|
||||||
|
\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
\
|
||||||
|
void setup_networks_alloutputs_GLOBAL_rdm01_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers){\
|
||||||
|
neurons_##type *tmp_l=NULL, *ttmp_l=NULL;\
|
||||||
|
for(size_t l=0; l<nb_layers; ++l){\
|
||||||
|
tmp_l = malloc(sizeof(neurons_##type)); \
|
||||||
|
if(l==0){\
|
||||||
|
*base_nr = tmp_l ;\
|
||||||
|
}else{\
|
||||||
|
ttmp_l->next_layer = tmp_l ;\
|
||||||
|
}\
|
||||||
|
tmp_l->id_layer= l;\
|
||||||
|
tmp_l->iteration_step= 0;\
|
||||||
|
tmp_l->input = NULL; \
|
||||||
|
tmp_l->net = NULL; \
|
||||||
|
tmp_l->output = NULL; \
|
||||||
|
tmp_l->target = NULL; \
|
||||||
|
tmp_l->weight_in = NULL; \
|
||||||
|
tmp_l->weight_out = NULL; \
|
||||||
|
tmp_l->delta_out = NULL; \
|
||||||
|
tmp_l->bias = NULL; \
|
||||||
|
tmp_l->update_learning_rate = do_not_update_learnig_rate_##type; \
|
||||||
|
tmp_l->prev_layer = ttmp_l;\
|
||||||
|
tmp_l->next_layer = NULL;\
|
||||||
|
\
|
||||||
|
if(ttmp_l != NULL){\
|
||||||
|
dimension *dim=init_copy_dim(array_dim_in_layers[l-1],sz_layers[l-1]);\
|
||||||
|
increment_dim_var(dim);\
|
||||||
|
tmp_l->input = CREATE_TENSOR_##type(dim);\
|
||||||
|
for(size_t i=0;i<((tmp_l->input)->dim)->rank;++i) (tmp_l->input)->x[i]=(type)l;\
|
||||||
|
\
|
||||||
|
link_layers_##type(ttmp_l,tmp_l);\
|
||||||
|
if(l>1 ){\
|
||||||
|
dimension *dim_out = (ttmp_l->output)->dim;\
|
||||||
|
for(size_t i=0;i<dim_out->rank; ++i) (ttmp_l->output)->x[i]=(type)(l-1);\
|
||||||
|
ttmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
|
for(size_t i=0;i<dim_out->rank; ++i) (ttmp_l->net)->x[i]=(type)(l-1);\
|
||||||
|
ttmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); \
|
||||||
|
for(size_t i=0;i< dim_out->rank; ++i) (ttmp_l->delta_out)->x[i]=(type)(l-1);\
|
||||||
|
dimension *d_w_in; \
|
||||||
|
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
||||||
|
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
|
if(randomizeInitWeight) init_random_x_##type(ttmp_l->weight_in,0,1,5000);\
|
||||||
|
else\
|
||||||
|
for(size_t i=0;i<((ttmp_l->weight_in)->dim)->rank;++i) (ttmp_l->weight_in)->x[i]=0.5;\
|
||||||
|
}\
|
||||||
|
if(l==nb_layers-1) {\
|
||||||
|
dimension *dim_out=init_copy_dim(array_dim_in_layers[l],sz_layers[l]);\
|
||||||
|
tmp_l->output = CREATE_TENSOR_##type(dim_out);\
|
||||||
|
for(size_t i=0;i<((tmp_l->output)->dim)->rank;++i) (tmp_l->output)->x[i]=(type)l;\
|
||||||
|
tmp_l->target = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
|
for(size_t i=0;i<((tmp_l->target)->dim)->rank;++i) (tmp_l->target)->x[i]=(type)(l);\
|
||||||
|
tmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
|
for(size_t i=0;i<((tmp_l->net)->dim)->rank;++i) (tmp_l->net)->x[i]=(type)(l);\
|
||||||
|
tmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); \
|
||||||
|
for(size_t i=0;i<((tmp_l->delta_out)->dim)->rank;++i) (tmp_l->delta_out)->x[i]=(type)(l);\
|
||||||
|
dimension *d_w_in; \
|
||||||
|
add_dimension(&d_w_in, (tmp_l->input)->dim, ((tmp_l->output)->dim)); \
|
||||||
|
tmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
|
if(randomizeInitWeight) init_random_x_##type(tmp_l->weight_in,0,1,5000);\
|
||||||
|
else\
|
||||||
for(size_t i=0;i<((tmp_l->weight_in)->dim)->rank;++i) (tmp_l->weight_in)->x[i]=0.5;\
|
for(size_t i=0;i<((tmp_l->weight_in)->dim)->rank;++i) (tmp_l->weight_in)->x[i]=0.5;\
|
||||||
/*init_random_x_##type(tmp_l->weight_in,0,1,5000);\
|
|
||||||
*/\
|
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
}\
|
}\
|
||||||
@@ -233,6 +358,7 @@ void setup_networks_layers_without_weights_##type(neurons_##type **base_nr, size
|
|||||||
ttmp_l->next_layer = tmp_l ;\
|
ttmp_l->next_layer = tmp_l ;\
|
||||||
}\
|
}\
|
||||||
tmp_l->id_layer= l;\
|
tmp_l->id_layer= l;\
|
||||||
|
tmp_l->iteration_step= 0;\
|
||||||
tmp_l->input = NULL; \
|
tmp_l->input = NULL; \
|
||||||
tmp_l->net = NULL; \
|
tmp_l->net = NULL; \
|
||||||
tmp_l->output = NULL; \
|
tmp_l->output = NULL; \
|
||||||
@@ -241,6 +367,7 @@ void setup_networks_layers_without_weights_##type(neurons_##type **base_nr, size
|
|||||||
tmp_l->weight_out = NULL; \
|
tmp_l->weight_out = NULL; \
|
||||||
tmp_l->delta_out = NULL; \
|
tmp_l->delta_out = NULL; \
|
||||||
tmp_l->bias = NULL; \
|
tmp_l->bias = NULL; \
|
||||||
|
tmp_l->update_learning_rate = do_not_update_learnig_rate_##type; \
|
||||||
tmp_l->prev_layer = ttmp_l;\
|
tmp_l->prev_layer = ttmp_l;\
|
||||||
tmp_l->next_layer = NULL;\
|
tmp_l->next_layer = NULL;\
|
||||||
\
|
\
|
||||||
@@ -309,8 +436,8 @@ void setup_weights_neurons_##type(neurons_##type *base, bool randomize, type min
|
|||||||
\
|
\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void setup_networks_alloutputs_config_##type(neurons_##type **base_nr, config_layers *lconf){\
|
void setup_networks_alloutputs_config_##type(neurons_##type **base_nr, config_layers *lconf, bool randomize, type minR, type maxR, int randomRange){\
|
||||||
setup_networks_alloutputs_##type(base_nr, lconf->array_dim_in_layers, lconf->sz_layers, lconf->nb_layers);\
|
setup_networks_alloutputs_##type(base_nr, lconf->array_dim_in_layers, lconf->sz_layers, lconf->nb_layers, randomize, minR, maxR, randomRange);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void setup_all_layers_functions_##type(neurons_##type *base, \
|
void setup_all_layers_functions_##type(neurons_##type *base, \
|
||||||
@@ -342,13 +469,14 @@ void setup_all_layers_params_##type(neurons_##type *base,\
|
|||||||
while(temp){\
|
while(temp){\
|
||||||
temp->nb_prod_thread=nb_prod_thread;\
|
temp->nb_prod_thread=nb_prod_thread;\
|
||||||
temp->nb_calc_thread=nb_calc_thread;\
|
temp->nb_calc_thread=nb_calc_thread;\
|
||||||
|
temp->initial_learning_rate=learning_rate;\
|
||||||
temp->learning_rate=learning_rate;\
|
temp->learning_rate=learning_rate;\
|
||||||
temp=temp->next_layer;\
|
temp=temp->next_layer;\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *array_dim_in_layers, size_t nb_layers){\
|
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *array_dim_in_layers, size_t nb_layers, bool randomize, type minR, type maxR, int randomRange){\
|
||||||
size_t *sz_layers=malloc(nb_layers*sizeof(size_t));\
|
size_t *sz_layers=malloc(nb_layers*sizeof(size_t));\
|
||||||
for(size_t i=0; i<nb_layers;++i) sz_layers[i]=1;\
|
for(size_t i=0; i<nb_layers;++i) sz_layers[i]=1;\
|
||||||
size_t **tarray_dim_in_layers=malloc(nb_layers*sizeof(size_t));\
|
size_t **tarray_dim_in_layers=malloc(nb_layers*sizeof(size_t));\
|
||||||
@@ -356,7 +484,7 @@ void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *array_dim_in_l
|
|||||||
tarray_dim_in_layers[i]=malloc(sizeof(size_t));\
|
tarray_dim_in_layers[i]=malloc(sizeof(size_t));\
|
||||||
tarray_dim_in_layers[i][0]=array_dim_in_layers[i];\
|
tarray_dim_in_layers[i][0]=array_dim_in_layers[i];\
|
||||||
}\
|
}\
|
||||||
setup_networks_alloutputs_##type(base_nr, tarray_dim_in_layers, sz_layers, nb_layers);\
|
setup_networks_alloutputs_##type(base_nr, tarray_dim_in_layers, sz_layers, nb_layers, randomize, minR, maxR, randomRange);\
|
||||||
\
|
\
|
||||||
for(size_t i=0; i<nb_layers;++i) {\
|
for(size_t i=0; i<nb_layers;++i) {\
|
||||||
free(tarray_dim_in_layers[i]);\
|
free(tarray_dim_in_layers[i]);\
|
||||||
@@ -420,7 +548,9 @@ void free_cloneuronset_##type(cloneuronset_##type *clnrnst){\
|
|||||||
unlink_all_weigth_in_neurons_##type(clnrnst->cloneurons[i]);\
|
unlink_all_weigth_in_neurons_##type(clnrnst->cloneurons[i]);\
|
||||||
free_neurons_##type(clnrnst->cloneurons[i]);\
|
free_neurons_##type(clnrnst->cloneurons[i]);\
|
||||||
}\
|
}\
|
||||||
|
free(clnrnst->cloneurons);\
|
||||||
free_config_layers(clnrnst->conf);\
|
free_config_layers(clnrnst->conf);\
|
||||||
|
free(clnrnst);\
|
||||||
}\
|
}\
|
||||||
void link_cloneuronset_weight_in_funcs_params_from_base_##type(cloneuronset_##type *clnrnst){\
|
void link_cloneuronset_weight_in_funcs_params_from_base_##type(cloneuronset_##type *clnrnst){\
|
||||||
neurons_##type **tmp_c=malloc(clnrnst->nb_clone * sizeof(neurons_##type *));\
|
neurons_##type **tmp_c=malloc(clnrnst->nb_clone * sizeof(neurons_##type *));\
|
||||||
@@ -437,7 +567,11 @@ void link_cloneuronset_weight_in_funcs_params_from_base_##type(cloneuronset_##ty
|
|||||||
tmp_c[c]->d_f_act = tmp_b->d_f_act;\
|
tmp_c[c]->d_f_act = tmp_b->d_f_act;\
|
||||||
tmp_c[c]->TensorContraction = tmp_b->TensorContraction;\
|
tmp_c[c]->TensorContraction = tmp_b->TensorContraction;\
|
||||||
tmp_c[c]->TensorProduct = tmp_b->TensorProduct;\
|
tmp_c[c]->TensorProduct = tmp_b->TensorProduct;\
|
||||||
|
tmp_c[c]->initial_learning_rate = tmp_b->initial_learning_rate;\
|
||||||
tmp_c[c]->learning_rate = tmp_b->learning_rate;\
|
tmp_c[c]->learning_rate = tmp_b->learning_rate;\
|
||||||
|
tmp_c[c]->decay_rate= tmp_b->decay_rate;\
|
||||||
|
tmp_c[c]->drop_rate= tmp_b->drop_rate;\
|
||||||
|
tmp_c[c]->update_learning_rate = tmp_b->update_learning_rate ;\
|
||||||
tmp_c[c]->nb_prod_thread = tmp_b->nb_prod_thread;\
|
tmp_c[c]->nb_prod_thread = tmp_b->nb_prod_thread;\
|
||||||
tmp_c[c]->nb_calc_thread = tmp_b->nb_calc_thread;\
|
tmp_c[c]->nb_calc_thread = tmp_b->nb_calc_thread;\
|
||||||
tmp_c[c]->id_layer = tmp_b->id_layer;\
|
tmp_c[c]->id_layer = tmp_b->id_layer;\
|
||||||
@@ -486,6 +620,8 @@ void print_neurons_msg_##type(neurons_##type *nr, char *msg){\
|
|||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
if(nr->target) print_tensor_msg_##type(nr->target," target "); else printf(" target NULL\n");\
|
if(nr->target) print_tensor_msg_##type(nr->target," target "); else printf(" target NULL\n");\
|
||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
|
if(nr->next_layer == NULL) printf("next layer of %s = NULL\n",msg);\
|
||||||
|
PR_LINE;\
|
||||||
\
|
\
|
||||||
nr=nr->next_layer;\
|
nr=nr->next_layer;\
|
||||||
}\
|
}\
|
||||||
@@ -569,8 +705,8 @@ size_t learning_online_neurons_##type(neurons_##type *base, data_set_##type *dat
|
|||||||
ttmp = ttmp->prev_layer;\
|
ttmp = ttmp->prev_layer;\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
\
|
nbreps += (dataset->size);\
|
||||||
}while(!condition(error_out_##type(base), nbreps++));\
|
}while(!condition(error_out_##type(base), nbreps));\
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
printf(" ### reps : %ld \n",nbreps);\
|
printf(" ### reps : %ld \n",nbreps);\
|
||||||
@@ -592,11 +728,16 @@ size_t learning_online2_neurons_##type(neurons_##type *base, data_set_##type *da
|
|||||||
}\
|
}\
|
||||||
while(ttmp != base){\
|
while(ttmp != base){\
|
||||||
calc_delta_neurons_##type(ttmp);\
|
calc_delta_neurons_##type(ttmp);\
|
||||||
update_weight_neurons_##type(ttmp);\
|
/*update_weight_neurons_##type(ttmp);\
|
||||||
ttmp = ttmp->prev_layer;\
|
*/ttmp = ttmp->prev_layer;\
|
||||||
|
}\
|
||||||
|
tmp = ttmp->next_layer;\
|
||||||
|
while(tmp){\
|
||||||
|
update_weight_neurons_##type(tmp);\
|
||||||
|
tmp = tmp->next_layer;\
|
||||||
}\
|
}\
|
||||||
err = ABSMAX(err,error_out_##type(base));\
|
err = ABSMAX(err,error_out_##type(base));\
|
||||||
ending = condition(err, nbreps++);\
|
ending = condition(err, ++nbreps);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
}while(!ending);\
|
}while(!ending);\
|
||||||
@@ -640,13 +781,6 @@ void print_predict_by_network_with_error_neurons_##type(neurons_##type *base, te
|
|||||||
\
|
\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void only_update_weight_neurons_##type(neurons_##type *nr){\
|
|
||||||
for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
|
||||||
/*(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
|
||||||
*/(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate * (nr->weight_out)->x[i] ;\
|
|
||||||
}\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
void update_cloneuronesets_weight_in_base_##type(cloneuronset_##type * clnrnst){\
|
void update_cloneuronesets_weight_in_base_##type(cloneuronset_##type * clnrnst){\
|
||||||
type sumDw=0;\
|
type sumDw=0;\
|
||||||
size_t nb_clone=clnrnst->nb_clone;\
|
size_t nb_clone=clnrnst->nb_clone;\
|
||||||
@@ -659,45 +793,63 @@ void update_cloneuronesets_weight_in_base_##type(cloneuronset_##type * clnrnst){
|
|||||||
sumDw=0;\
|
sumDw=0;\
|
||||||
for(size_t c=0; c<nb_clone; ++c){\
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
sumDw += ((tmp_c[c])->weight_out)->x[i];\
|
sumDw += ((tmp_c[c])->weight_out)->x[i];\
|
||||||
|
\
|
||||||
|
\
|
||||||
}\
|
}\
|
||||||
(tmp->weight_in)->x[i] += ((-1) * (tmp->learning_rate) * sumDw) / nb_clone ;\
|
(tmp->weight_in)->x[i] = (tmp->weight_in)->x[i] - ( (tmp->learning_rate) * sumDw) / nb_clone ;\
|
||||||
}\
|
}\
|
||||||
for(size_t c=0; c<nb_clone; ++c){\
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
tmp_c[c]=(tmp_c[c])->next_layer;\
|
tmp_c[c]=(tmp_c[c])->next_layer;\
|
||||||
}\
|
}\
|
||||||
tmp=tmp->next_layer;\
|
tmp=tmp->next_layer;\
|
||||||
}\
|
}\
|
||||||
|
/*while(tmp->next_layer){\
|
||||||
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
|
tmp_c[c]=(tmp_c[c])->next_layer;\
|
||||||
|
}\
|
||||||
|
tmp=tmp->next_layer;\
|
||||||
|
}\
|
||||||
|
while(tmp != clnrnst->base){\
|
||||||
|
for(size_t i=0; i<((tmp->weight_in)->dim)->rank; ++i){\
|
||||||
|
sumDw=0;\
|
||||||
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
|
(tmp_c[c])->TensorProduct(&((tmp_c[c])->weight_out), (tmp_c[c])->input, (tmp_c[c])->delta_out, (tmp_c[c])->nb_prod_thread);\
|
||||||
|
sumDw += ((tmp_c[c])->weight_out)->x[i];\
|
||||||
|
\
|
||||||
|
\
|
||||||
|
}\
|
||||||
|
(tmp->weight_in)->x[i] = (tmp->weight_in)->x[i] - ( (tmp->learning_rate) * sumDw) / nb_clone ;\
|
||||||
|
}\
|
||||||
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
|
tmp_c[c]=(tmp_c[c])->prev_layer;\
|
||||||
|
}\
|
||||||
|
tmp=tmp->prev_layer;\
|
||||||
|
}*/\
|
||||||
free(tmp_c);\
|
free(tmp_c);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
type clon_error_batch_##type(cloneuronset_##type * clnrnst){\
|
type clon_error_batch_##type(cloneuronset_##type * clnrnst){\
|
||||||
\
|
\
|
||||||
type err=0;\
|
type err=0;\
|
||||||
type sumErrP=0;\
|
|
||||||
size_t nb_clone=clnrnst->nb_clone;\
|
size_t nb_clone=clnrnst->nb_clone;\
|
||||||
neurons_##type **tmp_c=malloc(nb_clone*sizeof(neurons_##type *));\
|
neurons_##type **tmp_c=malloc(nb_clone*sizeof(neurons_##type *));\
|
||||||
for(size_t c=0; c<nb_clone; ++c)\
|
for(size_t c=0; c<nb_clone; ++c)\
|
||||||
tmp_c[c] = (clnrnst->cloneurons[c])->next_layer;\
|
tmp_c[c] = (clnrnst->cloneurons[c]);\
|
||||||
neurons_##type *tmp=(clnrnst->base)->next_layer;\
|
neurons_##type *tmp=(clnrnst->base);\
|
||||||
while(tmp){\
|
while(tmp->next_layer){\
|
||||||
if(tmp->next_layer==NULL){\
|
for(size_t c=0; c<nb_clone; ++c)\
|
||||||
for(size_t i=0; i<((tmp->target)->dim)->rank; ++i){\
|
|
||||||
sumErrP=0;\
|
|
||||||
for(size_t c=0; c<nb_clone; ++c){\
|
|
||||||
sumErrP += (tmp_c[c])->L(((tmp_c[c])->target)->x[i],((tmp_c[c])->output)->x[i]);\
|
|
||||||
}\
|
|
||||||
err += sumErrP/nb_clone;\
|
|
||||||
}\
|
|
||||||
break;\
|
|
||||||
}\
|
|
||||||
for(size_t c=0; c<nb_clone; ++c){\
|
|
||||||
tmp_c[c]=(tmp_c[c])->next_layer;\
|
tmp_c[c]=(tmp_c[c])->next_layer;\
|
||||||
}\
|
|
||||||
tmp=tmp->next_layer;\
|
tmp=tmp->next_layer;\
|
||||||
}\
|
}\
|
||||||
|
err=0;\
|
||||||
|
for(size_t i=0; i<((tmp->target)->dim)->rank; ++i){\
|
||||||
|
for(size_t c=0; c<nb_clone; ++c){\
|
||||||
|
err += (tmp_c[c])->L(((tmp_c[c])->target)->x[i],((tmp_c[c])->output)->x[i]);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
free(tmp_c);\
|
free(tmp_c);\
|
||||||
\
|
\
|
||||||
return err / (((tmp->target)->dim)->rank);\
|
return err / (nb_clone * ((tmp->target)->dim)->rank);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
struct arg_learnCloneuronset_##type{\
|
struct arg_learnCloneuronset_##type{\
|
||||||
@@ -721,9 +873,10 @@ void* run_learnCloneuronset_thread_##type(void *arg){\
|
|||||||
neurons_##type *tmp, *ttmp;\
|
neurons_##type *tmp, *ttmp;\
|
||||||
while(!(*ending)){\
|
while(!(*ending)){\
|
||||||
sem_wait(semaphore_datas);\
|
sem_wait(semaphore_datas);\
|
||||||
if(!(*ending)) break;\
|
/*if((*ending)) break;\
|
||||||
init_copy_in_out_networks_from_tensors_##type(base_c, dataset->input[id_datas[id_th]],dataset->target[id_datas[id_th]]);\
|
*/init_copy_in_out_networks_from_tensors_##type(base_c, dataset->input[id_datas[id_th]],dataset->target[id_datas[id_th]]);\
|
||||||
tmp=base_c->next_layer;\
|
/*printf(" id_datas [%ld] = %ld\n",id_th,id_datas[id_th]);\
|
||||||
|
*/tmp=base_c->next_layer;\
|
||||||
while(tmp){\
|
while(tmp){\
|
||||||
calc_out_neurons_##type(tmp);\
|
calc_out_neurons_##type(tmp);\
|
||||||
ttmp = tmp;\
|
ttmp = tmp;\
|
||||||
@@ -731,9 +884,10 @@ void* run_learnCloneuronset_thread_##type(void *arg){\
|
|||||||
}\
|
}\
|
||||||
while(ttmp != base_c){\
|
while(ttmp != base_c){\
|
||||||
calc_delta_neurons_##type(ttmp);\
|
calc_delta_neurons_##type(ttmp);\
|
||||||
/*update_weight_neurons_##type(ttmp);\
|
|
||||||
*/\
|
|
||||||
ttmp->TensorProduct(&(ttmp->weight_out), ttmp->input, ttmp->delta_out, ttmp->nb_prod_thread);\
|
ttmp->TensorProduct(&(ttmp->weight_out), ttmp->input, ttmp->delta_out, ttmp->nb_prod_thread);\
|
||||||
|
/*only_update_weight_neurons_##type(ttmp);\
|
||||||
|
*//*update_weight_neurons_##type(ttmp);\
|
||||||
|
*/\
|
||||||
ttmp = ttmp->prev_layer;\
|
ttmp = ttmp->prev_layer;\
|
||||||
}\
|
}\
|
||||||
sem_post(semaphore_learn);\
|
sem_post(semaphore_learn);\
|
||||||
@@ -741,7 +895,7 @@ void* run_learnCloneuronset_thread_##type(void *arg){\
|
|||||||
sem_post(semaphore_learn);\
|
sem_post(semaphore_learn);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##type *dataset, neurons_##type *base, bool (*condition)(type, size_t)){\
|
size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##type *dataset, bool (*condition)(type, size_t)){\
|
||||||
size_t nbreps=0;\
|
size_t nbreps=0;\
|
||||||
size_t curData=0;\
|
size_t curData=0;\
|
||||||
type err=0;\
|
type err=0;\
|
||||||
@@ -765,8 +919,10 @@ size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##typ
|
|||||||
arg_th[i]->ending=ending;\
|
arg_th[i]->ending=ending;\
|
||||||
arg_th[i]->base_c = clnrnst->cloneurons[i] ;\
|
arg_th[i]->base_c = clnrnst->cloneurons[i] ;\
|
||||||
arg_th[i]->dataset = dataset ;\
|
arg_th[i]->dataset = dataset ;\
|
||||||
|
arg_th[i]->id_datas= id_datas ;\
|
||||||
\
|
\
|
||||||
pthread_create(&thrd[i], NULL, run_learnCloneuronset_thread_##type, (void*)arg_th[i]);\
|
pthread_create(&thrd[i], NULL, run_learnCloneuronset_thread_##type, (void*)arg_th[i]);\
|
||||||
|
\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
@@ -785,9 +941,17 @@ size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##typ
|
|||||||
sem_wait(semaphore_learn);\
|
sem_wait(semaphore_learn);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
/*neurons_##type *tmp = (clnrnst->cloneurons[0])->next_layer;\
|
||||||
|
while(tmp){\
|
||||||
|
only_update_weight_neurons_##type(tmp);\
|
||||||
|
tmp=tmp->next_layer;\
|
||||||
|
}*/\
|
||||||
update_cloneuronesets_weight_in_base_##type(clnrnst);\
|
update_cloneuronesets_weight_in_base_##type(clnrnst);\
|
||||||
err = clon_error_batch_##type(clnrnst);\
|
err = ABSMAX(err,clon_error_batch_##type(clnrnst));\
|
||||||
*ending = condition(err, nbreps++) ;\
|
\
|
||||||
|
/*err = ABSMAX(err,error_out_##type(clnrnst->cloneurons[0]));\
|
||||||
|
*/nbreps += nb_clone;\
|
||||||
|
*ending = condition(err, nbreps) ;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
printf("reps batch learning : %ld\n",nbreps);\
|
printf("reps batch learning : %ld\n",nbreps);\
|
||||||
@@ -809,7 +973,7 @@ size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##typ
|
|||||||
free(semaphore_learn);\
|
free(semaphore_learn);\
|
||||||
free(ending);\
|
free(ending);\
|
||||||
free(id_datas);\
|
free(id_datas);\
|
||||||
return err;\
|
return nbreps;\
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
//#include "tools_t/tools_t.h"
|
//#include "tools_t/tools_t.h"
|
||||||
#include "tensor_t/tensor_t.h"
|
#include "tensor_t/tensor_t.h"
|
||||||
|
|
||||||
|
extern bool randomizeInitWeight;
|
||||||
|
|
||||||
struct config_layers{
|
struct config_layers{
|
||||||
size_t nb_layers;
|
size_t nb_layers;
|
||||||
size_t *sz_layers;
|
size_t *sz_layers;
|
||||||
@@ -23,9 +25,14 @@ void free_config_layers(config_layers *pconf);
|
|||||||
\
|
\
|
||||||
struct neurons_##type {/* layer */\
|
struct neurons_##type {/* layer */\
|
||||||
size_t id_layer;\
|
size_t id_layer;\
|
||||||
|
size_t iteration_step;\
|
||||||
size_t nb_prod_thread;\
|
size_t nb_prod_thread;\
|
||||||
size_t nb_calc_thread;\
|
size_t nb_calc_thread;\
|
||||||
|
type initial_learning_rate;\
|
||||||
type learning_rate;\
|
type learning_rate;\
|
||||||
|
type decay_rate;\
|
||||||
|
size_t drop_rate;\
|
||||||
|
void (*update_learning_rate)(struct neurons_##type *N); \
|
||||||
tensor_##type *input; \
|
tensor_##type *input; \
|
||||||
tensor_##type *net; /* output tensor_prodContract */\
|
tensor_##type *net; /* output tensor_prodContract */\
|
||||||
tensor_##type *output; \
|
tensor_##type *output; \
|
||||||
@@ -50,6 +57,10 @@ struct func_act_##type {\
|
|||||||
type (*deriv_func_act)(type x); /* derivate func act */\
|
type (*deriv_func_act)(type x); /* derivate func act */\
|
||||||
};\
|
};\
|
||||||
\
|
\
|
||||||
|
void do_not_update_learnig_rate_##type(neurons_##type *N);\
|
||||||
|
void time_based_update_learning_rate_##type(neurons_##type *nr);\
|
||||||
|
void step_based_update_learning_rate_##type(neurons_##type *nr);\
|
||||||
|
void setup_learning_rate_params_neurons_##type(neurons_##type *base,type initial_learning_rate, type decay_rate, size_t drop_rate, void (*update_learning_rate)(neurons_##type *));\
|
||||||
/*void calc_net_neurons_##type(neurons_##type *nr);*/\
|
/*void calc_net_neurons_##type(neurons_##type *nr);*/\
|
||||||
void calc_out_neurons_##type(neurons_##type *nr);\
|
void calc_out_neurons_##type(neurons_##type *nr);\
|
||||||
void calc_delta_neurons_##type(neurons_##type *nr);\
|
void calc_delta_neurons_##type(neurons_##type *nr);\
|
||||||
@@ -58,11 +69,12 @@ void update_weight_neurons_##type(neurons_##type *nr);\
|
|||||||
void init_copy_in_out_networks_from_tensors_##type(neurons_##type *nr, tensor_##type *input, tensor_##type *target);\
|
void init_copy_in_out_networks_from_tensors_##type(neurons_##type *nr, tensor_##type *input, tensor_##type *target);\
|
||||||
void init_in_out_networks_from_tensors_##type(neurons_##type *nr, tensor_##type *input, tensor_##type *target, neurons_##type *base);\
|
void init_in_out_networks_from_tensors_##type(neurons_##type *nr, tensor_##type *input, tensor_##type *target, neurons_##type *base);\
|
||||||
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out);\
|
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out);\
|
||||||
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers);\
|
void setup_networks_alloutputs_GLOBAL_rdm01_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers);\
|
||||||
void setup_networks_alloutputs_config_##type(neurons_##type **base_nr, config_layers *lconf);\
|
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers, bool randomize, type minR, type maxR, int randomRange);\
|
||||||
|
void setup_networks_alloutputs_config_##type(neurons_##type **base_nr, config_layers *lconf, bool randomize, type minR, type maxR, int randomRange);\
|
||||||
void setup_networks_layers_without_weights_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers);\
|
void setup_networks_layers_without_weights_##type(neurons_##type **base_nr, size_t **array_dim_in_layers, size_t *sz_layers, size_t nb_layers);\
|
||||||
void setup_networks_layers_without_weights_from_config_##type(neurons_##type **base, config_layers *pconf);\
|
void setup_networks_layers_without_weights_from_config_##type(neurons_##type **base, config_layers *pconf);\
|
||||||
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *array_dim_in_layers, size_t nb_layers);\
|
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *array_dim_in_layers, size_t nb_layers, bool randomize, type minR, type maxR, int randomRange);\
|
||||||
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out);\
|
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out);\
|
||||||
void print_neurons_msg_##type(neurons_##type *nr, char * msg);\
|
void print_neurons_msg_##type(neurons_##type *nr, char * msg);\
|
||||||
\
|
\
|
||||||
@@ -106,7 +118,7 @@ struct cloneuronset_##type{\
|
|||||||
typedef struct cloneuronset_##type cloneuronset_##type;\
|
typedef struct cloneuronset_##type cloneuronset_##type;\
|
||||||
void free_cloneuronset_##type(cloneuronset_##type *clnrnst);\
|
void free_cloneuronset_##type(cloneuronset_##type *clnrnst);\
|
||||||
cloneuronset_##type * create_cloneuronset_from_base_conf_##type(neurons_##type *base, config_layers *conf, size_t nb_clone);\
|
cloneuronset_##type * create_cloneuronset_from_base_conf_##type(neurons_##type *base, config_layers *conf, size_t nb_clone);\
|
||||||
size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##type *dataset, neurons_##type *base, bool (*condition)(type, size_t));\
|
size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##type *dataset, bool (*condition)(type, size_t));\
|
||||||
|
|
||||||
GEN_NEURON_(TYPE_FLOAT)
|
GEN_NEURON_(TYPE_FLOAT)
|
||||||
GEN_NEURON_(TYPE_DOUBLE)
|
GEN_NEURON_(TYPE_DOUBLE)
|
||||||
|
|||||||
+122
-11
@@ -40,7 +40,7 @@ float df(float x){
|
|||||||
TEST(init_One){
|
TEST(init_One){
|
||||||
//endian=false;
|
//endian=false;
|
||||||
neurons_TYPE_FLOAT *bn=NULL, *tmp=NULL, *ttmp=NULL;
|
neurons_TYPE_FLOAT *bn=NULL, *tmp=NULL, *ttmp=NULL;
|
||||||
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){3,5,2},3);
|
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){3,5,2},3,false,0,1,5000);
|
||||||
init_in_out_all_networks_OneD_TYPE_FLOAT(bn,(float[]){1.2,0.5,1.3},3,(float[]){0.1,0.8},2);
|
init_in_out_all_networks_OneD_TYPE_FLOAT(bn,(float[]){1.2,0.5,1.3},3,(float[]){0.1,0.8},2);
|
||||||
|
|
||||||
|
|
||||||
@@ -92,17 +92,18 @@ TEST(data_set_from_file){
|
|||||||
#define epsilon 0.0001
|
#define epsilon 0.0001
|
||||||
|
|
||||||
bool cond(float e, size_t nbreps){
|
bool cond(float e, size_t nbreps){
|
||||||
if (nbreps > 1) return true;
|
if (nbreps > 20000) return true;
|
||||||
if ((e<epsilon) && (e>-epsilon)) return true;
|
if ((e<epsilon) && (e>-epsilon)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(learning_first){
|
TEST(learning_first){
|
||||||
|
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||||
|
randomizeInitWeight =false;
|
||||||
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
||||||
print_data_set_msg_TYPE_FLOAT(ds,"data");
|
print_data_set_msg_TYPE_FLOAT(ds,"data");
|
||||||
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
||||||
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){2,4,1},3); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){2,4,1},3,false,0,1,5000); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
||||||
|
|
||||||
setup_all_layers_functions_TYPE_FLOAT(bn,
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
tensorContractnProdThread_TYPE_FLOAT,
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
@@ -112,7 +113,7 @@ TEST(learning_first){
|
|||||||
f,
|
f,
|
||||||
df);
|
df);
|
||||||
|
|
||||||
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.5);
|
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.1);
|
||||||
|
|
||||||
|
|
||||||
size_t reps = learning_online_neurons_TYPE_FLOAT(bn,ds,cond);
|
size_t reps = learning_online_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||||
@@ -120,7 +121,8 @@ TEST(learning_first){
|
|||||||
|
|
||||||
//char msg[256];
|
//char msg[256];
|
||||||
for(size_t i=0; i<ds->size; ++i){
|
for(size_t i=0; i<ds->size; ++i){
|
||||||
print_predict_by_network_neurons_TYPE_FLOAT(bn,ds->input[i]);
|
print_predict_by_network_with_error_neurons_TYPE_FLOAT(bn,ds->input[i],ds->target[i]);
|
||||||
|
//print_predict_by_network_neurons_TYPE_FLOAT(bn,ds->input[i]);
|
||||||
/*sprintf(msg, "data set [%ld]",i);
|
/*sprintf(msg, "data set [%ld]",i);
|
||||||
init_copy_in_out_networks_from_tensors_TYPE_FLOAT(bn, ds->input[i],ds->target[i]);\
|
init_copy_in_out_networks_from_tensors_TYPE_FLOAT(bn, ds->input[i],ds->target[i]);\
|
||||||
tmp=bn->next_layer;\
|
tmp=bn->next_layer;\
|
||||||
@@ -137,16 +139,19 @@ TEST(learning_first){
|
|||||||
free_neurons_TYPE_FLOAT(bn);
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
|
|
||||||
LOG("reps = %ld\n",reps);
|
LOG("reps = %ld\n",reps);
|
||||||
|
randomizeInitWeight = rec_randomizeInitWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(learning_second){
|
TEST(learning_second){
|
||||||
|
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||||
|
randomizeInitWeight =false;
|
||||||
|
|
||||||
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
||||||
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
||||||
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
||||||
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){2,4,1},3); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){2,4,1},3,false,0,1,5000); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
||||||
|
|
||||||
setup_all_layers_functions_TYPE_FLOAT(bn,
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
tensorContractnProdThread_TYPE_FLOAT,
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
@@ -156,7 +161,7 @@ TEST(learning_second){
|
|||||||
f,
|
f,
|
||||||
df);
|
df);
|
||||||
|
|
||||||
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.5);
|
setup_all_layers_params_TYPE_FLOAT(bn, 5, 3 , 0.1);
|
||||||
|
|
||||||
|
|
||||||
size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||||
@@ -164,7 +169,8 @@ TEST(learning_second){
|
|||||||
|
|
||||||
char msg[256];
|
char msg[256];
|
||||||
for(size_t i=0; i<ds->size; ++i){
|
for(size_t i=0; i<ds->size; ++i){
|
||||||
print_predict_by_network_neurons_TYPE_FLOAT(bn,ds->input[i]);
|
print_predict_by_network_with_error_neurons_TYPE_FLOAT(bn,ds->input[i],ds->target[i]);
|
||||||
|
//print_predict_by_network_neurons_TYPE_FLOAT(bn,ds->input[i]);
|
||||||
/*sprintf(msg, "data set [%ld]",i);
|
/*sprintf(msg, "data set [%ld]",i);
|
||||||
init_copy_in_out_networks_from_tensors_TYPE_FLOAT(bn, ds->input[i],ds->target[i]);\
|
init_copy_in_out_networks_from_tensors_TYPE_FLOAT(bn, ds->input[i],ds->target[i]);\
|
||||||
tmp=bn->next_layer;\
|
tmp=bn->next_layer;\
|
||||||
@@ -182,15 +188,19 @@ TEST(learning_second){
|
|||||||
free_neurons_TYPE_FLOAT(bn);
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
|
|
||||||
LOG("reps = %ld\n",reps);
|
LOG("reps = %ld\n",reps);
|
||||||
|
randomizeInitWeight = rec_randomizeInitWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(learning_withconfig2){
|
TEST(learning_withconfig2){
|
||||||
|
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||||
|
randomizeInitWeight =false;
|
||||||
|
|
||||||
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
||||||
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
||||||
config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){2,4,1}); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){2,4,1}); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
||||||
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
||||||
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf);
|
//setup_networks_alloutputs_config_GLOBAL_rdm01_TYPE_FLOAT(setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf);bn,pconf);
|
||||||
|
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000);
|
||||||
|
|
||||||
setup_all_layers_functions_TYPE_FLOAT(bn,
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
tensorContractnProdThread_TYPE_FLOAT,
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
@@ -200,7 +210,7 @@ TEST(learning_withconfig2){
|
|||||||
f,
|
f,
|
||||||
df);
|
df);
|
||||||
|
|
||||||
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.5);
|
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.1);
|
||||||
|
|
||||||
|
|
||||||
size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||||
@@ -218,9 +228,110 @@ TEST(learning_withconfig2){
|
|||||||
free_neurons_TYPE_FLOAT(bn);
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
|
|
||||||
LOG("reps = %ld\n",reps);
|
LOG("reps = %ld\n",reps);
|
||||||
|
randomizeInitWeight = rec_randomizeInitWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(learning_cloneuroneset){
|
||||||
|
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||||
|
randomizeInitWeight =false;
|
||||||
|
|
||||||
|
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
||||||
|
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
||||||
|
config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){2,4,1}); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
||||||
|
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
||||||
|
//setup_networks_alloutputs_config_GLOBAL_rdm01_TYPE_FLOAT(setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf);bn,pconf);
|
||||||
|
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000);
|
||||||
|
|
||||||
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
|
tensorProdThread_TYPE_FLOAT,
|
||||||
|
DL,
|
||||||
|
L,
|
||||||
|
f,
|
||||||
|
df);
|
||||||
|
|
||||||
|
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.1);
|
||||||
|
|
||||||
|
//print_neurons_msg_TYPE_FLOAT(bn,"before create clones");
|
||||||
|
|
||||||
|
cloneuronset_TYPE_FLOAT *clnrnst = create_cloneuronset_from_base_conf_TYPE_FLOAT(bn, pconf, 3);
|
||||||
|
|
||||||
|
// size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||||
|
size_t reps = learning_cloneuronset_TYPE_FLOAT(clnrnst, ds,cond);
|
||||||
|
|
||||||
|
|
||||||
|
char msg[256];
|
||||||
|
for(size_t i=0; i<ds->size; ++i){
|
||||||
|
print_predict_by_network_with_error_neurons_TYPE_FLOAT(bn,ds->input[i],ds->target[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free_cloneuronset_TYPE_FLOAT(clnrnst);
|
||||||
|
|
||||||
|
free_data_set_TYPE_FLOAT(ds);
|
||||||
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
|
|
||||||
|
LOG("reps = %ld\n",reps);
|
||||||
|
randomizeInitWeight = rec_randomizeInitWeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(learning_cloneuroneset_LEARN_RATE){
|
||||||
|
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||||
|
randomizeInitWeight =false;
|
||||||
|
|
||||||
|
data_set_TYPE_FLOAT *ds= fill_data_set_from_file_TYPE_FLOAT("xor.txt",1);
|
||||||
|
// print_data_set_msg_TYPE_FLOAT(ds,"data");
|
||||||
|
config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){2,4,1}); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
|
||||||
|
neurons_TYPE_FLOAT *bn=NULL, *tmp ;
|
||||||
|
//setup_networks_alloutputs_config_GLOBAL_rdm01_TYPE_FLOAT(setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf);bn,pconf);
|
||||||
|
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000);
|
||||||
|
|
||||||
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
|
tensorProdThread_TYPE_FLOAT,
|
||||||
|
DL,
|
||||||
|
L,
|
||||||
|
f,
|
||||||
|
df);
|
||||||
|
|
||||||
|
setup_all_layers_params_TYPE_FLOAT(bn, 5, 1 , 0.4);
|
||||||
|
float initRate=0.6;
|
||||||
|
float decayRate=0.85; /* halving*/
|
||||||
|
size_t dropRate = 100;
|
||||||
|
// setup_learning_rate_params_neurons_TYPE_FLOAT(bn, initRate, decayRate, dropRate, time_based_update_learning_rate_TYPE_FLOAT);
|
||||||
|
setup_learning_rate_params_neurons_TYPE_FLOAT(bn, initRate, decayRate, dropRate, step_based_update_learning_rate_TYPE_FLOAT);
|
||||||
|
|
||||||
|
//print_neurons_msg_TYPE_FLOAT(bn,"before create clones");
|
||||||
|
|
||||||
|
cloneuronset_TYPE_FLOAT *clnrnst = create_cloneuronset_from_base_conf_TYPE_FLOAT(bn, pconf, 3);
|
||||||
|
|
||||||
|
// size_t reps = learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||||
|
size_t reps = learning_cloneuronset_TYPE_FLOAT(clnrnst, ds,cond);
|
||||||
|
|
||||||
|
|
||||||
|
char msg[256];
|
||||||
|
for(size_t i=0; i<ds->size; ++i){
|
||||||
|
print_predict_by_network_with_error_neurons_TYPE_FLOAT(bn,ds->input[i],ds->target[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free_cloneuronset_TYPE_FLOAT(clnrnst);
|
||||||
|
|
||||||
|
free_data_set_TYPE_FLOAT(ds);
|
||||||
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
|
|
||||||
|
LOG("reps = %ld\n",reps);
|
||||||
|
randomizeInitWeight = rec_randomizeInitWeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[*,2,1]
|
[*,2,1]
|
||||||
((1,0),1)
|
((1,0),1)
|
||||||
|
((0,0),0)
|
||||||
((1,1),0)
|
((1,1),0)
|
||||||
((1,0),1)
|
((1,0),1)
|
||||||
((0,0),0)
|
|
||||||
|
|||||||
@@ -402,6 +402,63 @@ void print_tensor_msg_##type(tensor_##type *T,char *msg) {\
|
|||||||
free(dimsg);\
|
free(dimsg);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
\
|
||||||
|
void fprint_tensor_##type(char *file_name, tensor_##type *T) {\
|
||||||
|
size_t j=0,k=0;\
|
||||||
|
long int *coord = malloc(sizeof(long int)*(T->dim)->size); \
|
||||||
|
char *val=NULL;\
|
||||||
|
FILE *fileWrite = fopen(file_name, "w");\
|
||||||
|
if(fileWrite == NULL) {\
|
||||||
|
printf("error while opening %s\n",file_name);\
|
||||||
|
exit(1);\
|
||||||
|
}\
|
||||||
|
long int begin , end, beginIter, endIter ;\
|
||||||
|
long int (*iter)(long int) ;\
|
||||||
|
bool (*cond)(long int, long int) ; \
|
||||||
|
if (endian ) {\
|
||||||
|
begin = (T->dim->size) - 1; end = 0;\
|
||||||
|
iter = decr; cond = isGreatEqThan; \
|
||||||
|
/*fprintf(fileWrite,"endian(=true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index \n");*/\
|
||||||
|
}else{\
|
||||||
|
begin = 0 ; end = (T->dim->size) - 1; \
|
||||||
|
iter = incr; cond = isLessEqThan; \
|
||||||
|
/*fprintf(fileWrite,"endian(=false): the lowest index varies first, e.g: [x0,x1,x2,...,xn] x0 is the lowest index \n");*/\
|
||||||
|
}\
|
||||||
|
fprintf(fileWrite,"[");\
|
||||||
|
for(size_t i=0; i<(T->dim)->size; ++i)\
|
||||||
|
fprintf(fileWrite," %ld,", (T->dim)->perm[i]);\
|
||||||
|
fprintf(fileWrite,"] \n");\
|
||||||
|
\
|
||||||
|
for(long int i=0;i<(T->dim)->rank;++i){\
|
||||||
|
vCoordFromLin(coord,i,T->dim);\
|
||||||
|
if(coord[begin]==0){\
|
||||||
|
for(long int j=begin; cond(j,end); j= iter(j) ){\
|
||||||
|
if(coord[j]==0) fprintf(fileWrite,"(");\
|
||||||
|
else break;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
/*fprintf(fileWrite," [");\
|
||||||
|
for(size_t k=0; k<(T->dim)->size;++k) fprintf(fileWrite," %ld,",coord[k]);\
|
||||||
|
*/val=type##_TO_STR(T->x[i]);\
|
||||||
|
fprintf(fileWrite," %s, ",val);\
|
||||||
|
free(val); val=NULL;\
|
||||||
|
if(coord[begin]==(T->dim)->perm[begin]-1){\
|
||||||
|
size_t count=0;\
|
||||||
|
for(long int j=begin; cond(j,end); j = iter(j)){\
|
||||||
|
if(coord[j]==(T->dim)->perm[j]-1) {\
|
||||||
|
fprintf(fileWrite,")"); ++count;\
|
||||||
|
}\
|
||||||
|
else break;\
|
||||||
|
}\
|
||||||
|
if(count == (T->dim)->size-1) fprintf(fileWrite,"\n ");\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
free(coord);\
|
||||||
|
fprintf(fileWrite,"\n");\
|
||||||
|
fclose(fileWrite);\
|
||||||
|
}\
|
||||||
|
\
|
||||||
size_t sprint_tensor_##type(char **tensorContent,tensor_##type *T, bool withIndex) {\
|
size_t sprint_tensor_##type(char **tensorContent,tensor_##type *T, bool withIndex) {\
|
||||||
if(*tensorContent != NULL) {\
|
if(*tensorContent != NULL) {\
|
||||||
free(*tensorContent);\
|
free(*tensorContent);\
|
||||||
@@ -1772,7 +1829,57 @@ void update_5tensor_func_##type(tensor_##type *M0, tensor_##type *M1, tensor_##t
|
|||||||
}\
|
}\
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
\
|
||||||
|
struct arg_6Update_##type{\
|
||||||
|
type *M0x;\
|
||||||
|
type *M1x;\
|
||||||
|
size_t beginRange;\
|
||||||
|
size_t endRange;\
|
||||||
|
type (*func)(type, type, type);\
|
||||||
|
type scalar;\
|
||||||
|
};\
|
||||||
|
void* run6UpdatCalcfunc_thread_##type(void *arg){\
|
||||||
|
struct arg_6Update_##type *arg_t = arg;\
|
||||||
|
for (size_t i = arg_t->beginRange; i < arg_t->endRange; i++) {\
|
||||||
|
arg_t->M0x[i] = arg_t->func(arg_t->M0x[i], arg_t->M1x[i], arg_t->scalar);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
void update_6tensor_func_##type(tensor_##type *M0, tensor_##type *M1, \
|
||||||
|
type (*func)(type, type, type),\
|
||||||
|
type scalar,\
|
||||||
|
size_t nbthread){\
|
||||||
|
/*printf(" rankM0=%ld , rank M2:%ld ; iseq :%d \n",(M0->dim)->rank,(M2->dim)->rank,is_equal_dim(M0->dim,M2->dim) );\
|
||||||
|
*/\
|
||||||
|
/* printDebug_dimension(M0->dim," dim M0 in update6 "); \
|
||||||
|
printDebug_dimension(M2->dim," dim M2 in update6 "); \
|
||||||
|
*/if ( is_equal_dim(M0->dim, M1->dim) /*&& (is_equal_dim(M0->dim, M2->dim))*/){ \
|
||||||
|
/*printDebug_dimension(M0->dim," dim M0 in update6 "); \
|
||||||
|
*/pthread_t *thrd = malloc(nbthread * sizeof(pthread_t));\
|
||||||
|
struct arg_6Update_##type **arg_th = malloc( nbthread * sizeof(struct arg_6Update_##type *));\
|
||||||
|
\
|
||||||
|
for(size_t i = 0; i < nbthread; ++i){\
|
||||||
|
arg_th[i]=malloc(sizeof(struct arg_6Update_##type));\
|
||||||
|
arg_th[i]->M0x=M0->x;\
|
||||||
|
arg_th[i]->M1x=M1->x;\
|
||||||
|
arg_th[i]->func=func;\
|
||||||
|
arg_th[i]->scalar=scalar;\
|
||||||
|
arg_th[i]->beginRange = i*(M0->dim->rank)/nbthread ;\
|
||||||
|
arg_th[i]->endRange = (i+1)*(M0->dim->rank)/nbthread ;\
|
||||||
|
\
|
||||||
|
pthread_create(&thrd[i], NULL, run6UpdatCalcfunc_thread_##type, (void*)arg_th[i]);\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
for(size_t i=0; i< nbthread; ++i){\
|
||||||
|
pthread_join(thrd[i], NULL);\
|
||||||
|
free(arg_th[i]);\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
free(thrd);\
|
||||||
|
free(arg_th);\
|
||||||
|
}\
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
|
||||||
|
|
||||||
GEN_FUNC_TENSOR(TYPE_FLOAT);
|
GEN_FUNC_TENSOR(TYPE_FLOAT);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ tensor_##type * sub_copy_minus_tensor_tail_##type(tensor_##type *rootens, size_t
|
|||||||
tensor_##type * sub_copy_tensor_head_##type(tensor_##type *rootens, size_t sub_copydim, size_t rankInDim); \
|
tensor_##type * sub_copy_tensor_head_##type(tensor_##type *rootens, size_t sub_copydim, size_t rankInDim); \
|
||||||
tensor_##type * sub_copy_tensor_tail_##type(tensor_##type *rootens, size_t sub_copydim, size_t rankInDim); \
|
tensor_##type * sub_copy_tensor_tail_##type(tensor_##type *rootens, size_t sub_copydim, size_t rankInDim); \
|
||||||
void print_tensor_msg_##type(tensor_##type *T, char *msg);\
|
void print_tensor_msg_##type(tensor_##type *T, char *msg);\
|
||||||
|
void fprint_tensor_##type(char *file_name, tensor_##type *T);\
|
||||||
size_t sprint_tensor_##type(char **tensorContent,tensor_##type *T, bool withIndex);\
|
size_t sprint_tensor_##type(char **tensorContent,tensor_##type *T, bool withIndex);\
|
||||||
void split_tensor_##type(tensor_##type *Troot, tensor_##type **Tpart1, tensor_##type **Tpart2, size_t pivotSplit, size_t rangeInPivot);\
|
void split_tensor_##type(tensor_##type *Troot, tensor_##type **Tpart1, tensor_##type **Tpart2, size_t pivotSplit, size_t rangeInPivot);\
|
||||||
void split_copy_tensor_##type(tensor_##type *Troot, tensor_##type **Tpart1, tensor_##type **Tpart2, size_t pivotSplit, size_t rangeInPivot);\
|
void split_copy_tensor_##type(tensor_##type *Troot, tensor_##type **Tpart1, tensor_##type **Tpart2, size_t pivotSplit, size_t rangeInPivot);\
|
||||||
@@ -71,7 +72,10 @@ void update_5tensor_func_##type(tensor_##type *M0, tensor_##type *M1, tensor_##t
|
|||||||
type(*f1)(type), \
|
type(*f1)(type), \
|
||||||
type (*f2)(type,type), \
|
type (*f2)(type,type), \
|
||||||
size_t nbthread);\
|
size_t nbthread);\
|
||||||
|
void update_6tensor_func_##type(tensor_##type *M0, tensor_##type *M1, \
|
||||||
|
type (*func)(type, type, type),\
|
||||||
|
type scalar,\
|
||||||
|
size_t nbthread);\
|
||||||
|
|
||||||
|
|
||||||
GENERATE_TENSOR_TYPE(TYPE_FLOAT);
|
GENERATE_TENSOR_TYPE(TYPE_FLOAT);
|
||||||
|
|||||||
+29
-1
@@ -1626,7 +1626,7 @@ float func2(float x){
|
|||||||
return x*x+1;
|
return x*x+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(update_func_){
|
TEST(print_tensor){
|
||||||
dimension *d0=create_dim(3);
|
dimension *d0=create_dim(3);
|
||||||
|
|
||||||
d0->perm[0]=2;
|
d0->perm[0]=2;
|
||||||
@@ -1648,8 +1648,36 @@ TEST(update_func_){
|
|||||||
update_1tensor_func_TYPE_FLOAT(M0, func2, 5);
|
update_1tensor_func_TYPE_FLOAT(M0, func2, 5);
|
||||||
|
|
||||||
print_tensor_float(M0, "x*x+1 M0 random");
|
print_tensor_float(M0, "x*x+1 M0 random");
|
||||||
|
free_tensor_TYPE_FLOAT(M0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(rec_in_file_tensor){
|
||||||
|
dimension *d0=create_dim(3);
|
||||||
|
|
||||||
|
d0->perm[0]=2;
|
||||||
|
d0->perm[1]=3;
|
||||||
|
d0->perm[2]=4;
|
||||||
|
|
||||||
|
|
||||||
|
updateRankDim(d0);
|
||||||
|
|
||||||
|
|
||||||
|
tensor_TYPE_FLOAT *M0 = CREATE_TENSOR_TYPE_FLOAT(d0);
|
||||||
|
|
||||||
|
LOG("M0->dim->rank = %ld\n",M0->dim->rank);
|
||||||
|
|
||||||
|
init_random_x_TYPE_FLOAT(M0,2.7,5.4,50001);
|
||||||
|
|
||||||
|
print_tensor_float(M0, "init M0 random");
|
||||||
|
|
||||||
|
update_1tensor_func_TYPE_FLOAT(M0, func2, 5);
|
||||||
|
|
||||||
|
fprint_tensor_TYPE_FLOAT(".ffrec_randomTens.txt",M0);
|
||||||
|
free_tensor_TYPE_FLOAT(M0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|||||||
Reference in New Issue
Block a user