wip: set_neurons : transfert training

This commit is contained in:
2025-12-19 15:33:47 +01:00
parent 3c1e2a18ed
commit 3b446bada3
8 changed files with 602 additions and 11 deletions
+2 -1
View File
@@ -3,10 +3,11 @@ CC=gcc
ROOTPROJECTDIR:=$(realpath ..) ROOTPROJECTDIR:=$(realpath ..)
TOOLDIR=$(ROOTPROJECTDIR)/ytools_t TOOLDIR=$(ROOTPROJECTDIR)/ytools_t
PERMDIR=$(ROOTPROJECTDIR)/ypermutation_t PERMDIR=$(ROOTPROJECTDIR)/ypermutation_t
LISTDIR=$(ROOTPROJECTDIR)/list_t
INCLUDE_PERMDIR=$(PERMDIR)/src INCLUDE_PERMDIR=$(PERMDIR)/src
INCLUDE_TOOLDIR=$(TOOLDIR)/include INCLUDE_TOOLDIR=$(TOOLDIR)/include
CFLAGS=-I$(INCLUDE_TOOLDIR) -I$(INCLUDE_PERMDIR) -I./src CFLAGS=-I$(INCLUDE_TOOLDIR) -I$(INCLUDE_PERMDIR) -I./src -I$(LISTDIR)/src
#SRC_DIR=$(ROOT_DIR)/src #SRC_DIR=$(ROOT_DIR)/src
#SRC=$(wildcard */*/*.c) #SRC=$(wildcard */*/*.c)
+10 -2
View File
@@ -30,7 +30,7 @@ create_dim(size_t sz){
} }
dimension* clone_dim(dimension *dim){ dimension* clone_dim(dimension *dim){
return init_copy_dim(dim->perm,dim->size); return init_copy_dim(dim->perm,dim->size);
} }
dimension * dimension *
@@ -209,7 +209,7 @@ void min_dimension(dimension **d, dimension *d0, dimension *d1) {
void printDebug_dimension(dimension *d,char *msg){ void printDebug_dimension(dimension *d,char *msg){
printf("(%s)->size = %ld | (%s)->rank = %ld \n[",msg,d->size,msg,d->rank); printf("<%p>(%s)->size = %ld | (%s)->rank = %ld \n[",d,msg,d->size,msg,d->rank);
for(size_t i=0; i<d->size; ++i) for(size_t i=0; i<d->size; ++i)
printf(" %ld,", d->perm[i]); printf(" %ld,", d->perm[i]);
printf("] \n"); printf("] \n");
@@ -451,3 +451,11 @@ void free_list_perm_in_dim(list_perm_in_dim *l_p){
} }
} }
GEN_LIST_ALL(dimension)
GEN_LIST_ALL(ptr_DIMENSION)
GEN_FUNC_PTR_LIST_FREE(ptr_DIMENSION){
dimension *pdim=(dimension*)arg;
free_dimension(pdim);
//free(pdim);
}
@@ -2,6 +2,7 @@
#define __DIMENSION_T__H__ #define __DIMENSION_T__H__
#include "permutation_t/permutation_t.h" #include "permutation_t/permutation_t.h"
#include "list_t/list_t.h"
extern bool endian; extern bool endian;
@@ -74,5 +75,11 @@ dimension * create_binary_dim(size_t dimension_size);
void free_list_perm_in_dim(list_perm_in_dim *l_p); void free_list_perm_in_dim(list_perm_in_dim *l_p);
GENERATE_LIST_ALL(dimension)
typedef dimension * ptr_DIMENSION;
GENERATE_LIST_ALL(ptr_DIMENSION)
GEN_HEAD_PTR_LIST(ptr_DIMENSION)
#endif /* __DIMENSION_T__H__ */ #endif /* __DIMENSION_T__H__ */
//int compare_dimension(dimension *d1, dimension *d2); //int compare_dimension(dimension *d1, dimension *d2);
+144 -3
View File
@@ -39,9 +39,98 @@ void free_config_layers(config_layers *pconf){
free(pconf); free(pconf);
} }
long int cmp_config_layers(config_layers *c1, config_layers *c2){
long int diff_nb=c1->nb_layers - c2->nb_layers;
if(diff_nb) return diff_nb;
for(long int i=0; i<c1->nb_layers; ++i){
long int diff_sz_layers = c1->sz_layers[i] - c2->sz_layers[i];
if(diff_sz_layers) return diff_sz_layers;
for(long int j=0; j<c1->sz_layers[i]; ++j){
long int diff_dim = c1->array_dim_in_layers[i][j] - c2->array_dim_in_layers[i][j];
if(diff_dim) return diff_dim;
}
}
return 0;
}
config_layers * create_config_layers_from_m_list_ptr_DIMENSION(struct main_list_ptr_DIMENSION *m_l_dim){
config_layers * pconf=malloc(sizeof(struct config_layers));
pconf->nb_layers=m_l_dim->size;
//printf("debug: pconf->nb_layers=%ld\n",pconf->nb_layers);
pconf->sz_layers=malloc(pconf->nb_layers * sizeof(size_t));
pconf->array_dim_in_layers=malloc((pconf->nb_layers)*sizeof(size_t*));
for(struct list_ptr_DIMENSION *local_l_dim=m_l_dim->begin_list; local_l_dim; local_l_dim=local_l_dim->next){
size_t i = local_l_dim->index;
pconf->sz_layers[i]=local_l_dim->value->size;
//printf("debug: pconf->sz_layers[%ld]=%ld\n",i,pconf->sz_layers[i]);
pconf->array_dim_in_layers[i]=malloc((pconf->sz_layers[i])*sizeof(size_t));
for(size_t j=0; j< pconf->sz_layers[i];++j){
pconf->array_dim_in_layers[i][j] = local_l_dim->value->perm[j];
//printf("debug: pconf->array_dim_in_layers[%ld][%ld]=%ld\n",i,j,pconf->array_dim_in_layers[i][j]);
}
}
return pconf;
}
config_layers * create_config_layers_from_m_list_dimension(struct main_list_dimension * m_l_dim){
config_layers * pconf=malloc(sizeof(struct config_layers));
pconf->nb_layers=m_l_dim->size;
printf("debug: pconf->nb_layers=%ld\n",pconf->nb_layers);
pconf->sz_layers=malloc(pconf->nb_layers * sizeof(size_t));
pconf->array_dim_in_layers=malloc((pconf->nb_layers)*sizeof(size_t*));
for(struct list_dimension *local_l_dim=m_l_dim->begin_list; local_l_dim; local_l_dim=local_l_dim->next){
size_t i = local_l_dim->index;
char msg[50]; sprintf(msg, "dim[%ld] ",i);
printDebug_dimension(&(local_l_dim->value), msg);
pconf->sz_layers[i]=local_l_dim->value.size;
printf("debug: pconf->sz_layers[%ld]=%ld\n",i,pconf->sz_layers[i]);
pconf->array_dim_in_layers[i]=malloc((pconf->sz_layers[i])*sizeof(size_t));
for(size_t j=0; j< pconf->sz_layers[i];++j){
pconf->array_dim_in_layers[i][j] = local_l_dim->value.perm[j];
printf("debug: pconf->array_dim_in_layers[%ld][%ld]=%ld\n",i,j,pconf->array_dim_in_layers[i][j]);
}
}
return pconf;
}
void print_config_layers(config_layers * pconf){
for(size_t i=0;i<pconf->nb_layers; ++i){
printf("debug: pconf->sz_layers[%ld]=%ld\n",i,pconf->sz_layers[i]);
for(size_t j=0; j< pconf->sz_layers[i];++j){
printf(" [%ld][%ld]=%ld | ",i,j,pconf->array_dim_in_layers[i][j]);
}
printf("debug: pconf->nb_layers=%ld\n",pconf->nb_layers);
}
}
bool randomizeInitWeight=true; bool randomizeInitWeight=true;
#define GEN_NEURONS_F_(type)\ #define GEN_NEURONS_F_(type)\
config_layers * create_config_layers_from_weight_in_neurons_##type(neurons_##type *base){\
config_layers *pconf=malloc(sizeof(struct config_layers));\
neurons_##type *tmp=base->next_layer;\
pconf->nb_layers=0;\
while(tmp){ ++(pconf->nb_layers); tmp=tmp->next_layer;}\
tmp=base->next_layer;\
pconf->sz_layers=malloc((pconf->nb_layers)*sizeof(size_t));\
pconf->array_dim_in_layers=malloc((pconf->nb_layers)*sizeof(size_t*));\
printf("debug: pconf->nb_layers=%ld\n",pconf->nb_layers);\
size_t layer=0;\
while(tmp){\
pconf->sz_layers[layer]=tmp->weight_in->dim->size;\
printf("debug: pconf->sz_layers[%ld]=%ld\n",layer,pconf->sz_layers[layer]);\
pconf->array_dim_in_layers[layer]=malloc((pconf->sz_layers[layer])*sizeof(size_t));\
for(size_t j=0;j<pconf->sz_layers[layer];++j){\
pconf->array_dim_in_layers[layer][j]=tmp->weight_in->dim->perm[j];\
}\
++layer; tmp=tmp->next_layer;\
}\
return pconf;\
}\
\ \
void do_not_update_learnig_rate_##type(neurons_##type *N){}\ void do_not_update_learnig_rate_##type(neurons_##type *N){}\
\ \
@@ -1034,14 +1123,66 @@ size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##typ
} \ } \
\ \
\ \
GEN_LIST_ALL(ptr_set_NEURONS_##type)\ struct set_neurons_##type * create_set_neurons_##type(config_layers *pconf, struct neurons_##type *base, ssize_t score, size_t dateid){\
GEN_FUNC_PTR_LIST_FREE(ptr_set_NEURONS_##type){\ struct set_neurons_##type *p_set_n=malloc(sizeof(struct set_neurons_##type));\
ptr_set_NEURONS_##type p_s_nn = (struct set_neurons_##type *)arg;\ p_set_n->pconf=pconf;\
p_set_n->base=base;\
p_set_n->score=score;\
p_set_n->dateid=dateid;\
return p_set_n;\
}\
\
void free_set_neurons_##type(struct set_neurons_##type *p_s_nn){\
free_config_layers(p_s_nn->pconf);\ free_config_layers(p_s_nn->pconf);\
free_neurons_##type(p_s_nn->base);\ free_neurons_##type(p_s_nn->base);\
free(p_s_nn);\ free(p_s_nn);\
}\ }\
\ \
GEN_LIST_ALL(ptr_set_NEURONS_##type)\
GEN_FUNC_PTR_LIST_FREE(ptr_set_NEURONS_##type){\
ptr_set_NEURONS_##type p_s_nn = (struct set_neurons_##type *)arg;\
free_set_neurons_##type(p_s_nn);\
}\
\
ssize_t sum_score_set_neurons_##type(struct main_list_ptr_set_NEURONS_##type *m_set_nrns){\
ssize_t sum_score=0;\
for(struct list_ptr_set_NEURONS_##type *local_set_n=m_set_nrns->begin_list; local_set_n ; local_set_n = local_set_n->next ){\
sum_score+=(local_set_n->value->score);\
}\
return sum_score;\
}\
void put_meaning_of_weitgh_in_set_neurons_##type(struct set_neurons_##type *dst_nrns, struct main_list_ptr_set_NEURONS_##type * m_set_nrns)\
{\
ssize_t sum_score=0;\
for(struct list_ptr_set_NEURONS_##type *local_set_n=m_set_nrns->begin_list; local_set_n ; local_set_n = local_set_n->next ){\
sum_score+=(local_set_n->value->score);\
if(cmp_config_layers(dst_nrns->pconf, local_set_n->value->pconf)){\
printf("debug: config_layers not match in inex = %ls \n",local_set_n->index);\
return;\
}\
}\
struct neurons_##type *tmp_dst=dst_nrns->base;\
while(tmp_dst){\
for(size_t i=0; i<tmp_dst->weight_in->dim->size;++i){\
tmp_dst->weight_in->x[i]=0;\
}\
tmp_dst=tmp_dst->next_layer;\
}\
for(struct list_ptr_set_NEURONS_##type *local_set_n=m_set_nrns->begin_list; local_set_n ; local_set_n = local_set_n->next ){\
local_set_n->value->cur_neurons=local_set_n->value->base;\
tmp_dst=dst_nrns->base;\
while(tmp_dst){\
for(size_t i=0; i<tmp_dst->weight_in->dim->size;++i){\
tmp_dst->weight_in->x[i] +=(((local_set_n->value->score) * (local_set_n->value->cur_neurons->weight_in->x[i]))/sum_score);\
}\
tmp_dst=tmp_dst->next_layer;\
local_set_n->value->cur_neurons=local_set_n->value->cur_neurons->next_layer;\
}\
}\
}\
\
\
+10 -1
View File
@@ -20,7 +20,10 @@ typedef struct config_layers config_layers;
config_layers *create_config_layers(size_t nb_layers, size_t *sz_layers, size_t **array_dim_in_layers); config_layers *create_config_layers(size_t nb_layers, size_t *sz_layers, size_t **array_dim_in_layers);
config_layers *create_config_layers_from_OneD(size_t nb_layers, size_t *array_dim_in_layers); config_layers *create_config_layers_from_OneD(size_t nb_layers, size_t *array_dim_in_layers);
void free_config_layers(config_layers *pconf); void free_config_layers(config_layers *pconf);
long int cmp_config_layers(config_layers *c1, config_layers *c2);
config_layers * create_config_layers_from_m_list_ptr_DIMENSION(struct main_list_ptr_DIMENSION *m_l_dim);
config_layers * create_config_layers_from_m_list_dimension(struct main_list_dimension *m_l_dim);
void print_config_layers(config_layers * pconf);
#define GEN_NEURON_(type)\ #define GEN_NEURON_(type)\
\ \
@@ -53,6 +56,8 @@ struct neurons_##type {/* layer */\
};\ };\
typedef struct neurons_##type neurons_##type;\ typedef struct neurons_##type neurons_##type;\
\ \
config_layers * create_config_layers_from_weight_in_neurons_##type(neurons_##type *base);\
\
struct func_act_##type {\ struct func_act_##type {\
type (*func_act)(type x); /* function activation */\ type (*func_act)(type x); /* function activation */\
type (*deriv_func_act)(type x); /* derivate func act */\ type (*deriv_func_act)(type x); /* derivate func act */\
@@ -131,10 +136,14 @@ size_t learning_cloneuronset_##type(cloneuronset_##type *clnrnst, data_set_##typ
struct set_neurons_##type{\ struct set_neurons_##type{\
struct config_layers *pconf;\ struct config_layers *pconf;\
struct neurons_##type *base;\ struct neurons_##type *base;\
struct neurons_##type *cur_neurons;\
ssize_t score;\ ssize_t score;\
size_t dateid;\
};\ };\
typedef struct set_neurons_##type * ptr_set_NEURONS_##type;\ typedef struct set_neurons_##type * ptr_set_NEURONS_##type;\
\ \
struct set_neurons_##type * create_set_neurons_##type(config_layers *pconf, struct neurons_##type *base, ssize_t score, size_t dateid);\
\
GENERATE_LIST_ALL(ptr_set_NEURONS_##type)\ GENERATE_LIST_ALL(ptr_set_NEURONS_##type)\
GEN_HEAD_PTR_LIST(ptr_set_NEURONS_##type)\ GEN_HEAD_PTR_LIST(ptr_set_NEURONS_##type)\
\ \
+193 -2
View File
@@ -447,9 +447,200 @@ j=0;\
\ \
\ \
\ \
\
\
#define EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS_PCONF(type, neuronDst, attribute, file_name_input, m_l_dim) \
do{\
int fd_input;\
fd_input=open(file_name_input, O_RDONLY);\
if ( fd_input == -1 ) {\
fprintf( stderr, "Cannot open file: %s for reading\n",file_name_input );\
exit( -1 );\
}\
size_t buf_size=820;/*need to be more than the nb of char representation of the type*/\
char *input=malloc(buf_size + 1);\
char *recInput=malloc(buf_size + 1);\
memset(recInput,0, buf_size + 1);\
char *iinput=malloc(buf_size * 2);\
/*bool size_unknown=false, broken=false*/; \
bool Done=false;\
int retread = 0, curIn=0, lastNonNumber=0, lenRecIn=0;\
\
list_perm_in_dim *l_p=NULL;\
dimension *dim=NULL;\
size_t ss;\
char *ttmp=NULL;\
char *ppEnd=NULL;\
bool bracketsDown=false/*, endTensor = false*/;\
size_t j=0;\
neurons_##type * tmpNN = neuronDst;\
tensor_##type * T=NULL;\
while(tmpNN /*&& !endTensor*/){\
bracketsDown = false;\
Done = false;\
/* T = tmpNN->attribute;\
if(T == NULL){\
Done = true;\
}*/\
T = tmpNN->attribute;\
while((T == NULL) && (tmpNN!=NULL)){\
tmpNN = tmpNN->next_layer;\
if(tmpNN)\
T = tmpNN->attribute;\
}\
/*printf("debug : dd ttmp = %s, T == NULL?=%d %s\n",ttmp,(T==NULL),#attribute);*/\
if(T == NULL){\
Done = true;\
} \
j=0;\
while(!Done /*&& !endTensor*/){\
if(ttmp == NULL || *ttmp=='\0'){\
for(curIn=0; curIn<lenRecIn; ++curIn){\
iinput[curIn]=recInput[lenRecIn-curIn-1];\
}\
retread = read(fd_input, input, buf_size) ;\
/*endTensor = (retread != buf_size);*/\
/*printf("debug: ************************* ------>input = |%s|, retread=%d, input[ret-1]={%c}\n", input,retread,input[retread-1]);*/\
lenRecIn = 0;\
for(lastNonNumber=retread-1; lastNonNumber>=0; --lastNonNumber){ \
if(((input[lastNonNumber] >='0') && (input[lastNonNumber] <='9'))||(input[lastNonNumber] =='-')||(input[lastNonNumber] =='.')||(input[lastNonNumber] =='E')||(input[lastNonNumber] =='e')){\
recInput[lenRecIn++]=input[lastNonNumber];\
}\
else break; \
}\
recInput[lenRecIn]='\0';\
/*printf("recInput = |%s|\n", recInput);*/\
for(int ii=0; ii<=lastNonNumber; ++ii){\
iinput[curIn++]=input[ii];\
}\
\
iinput[curIn]='\0';\
/*printf("iinput = |%s|\nDone=%d\n", iinput,Done);*/\
ttmp=iinput;\
}\
while(!Done && (*ttmp != '\0') /*&& !endTensor*/){\
/*printf("debug : >> ttmp = %s, bracketsDown=%d\n",ttmp, bracketsDown);*/\
if(*ttmp=='[') {\
bracketsDown=false;\
}\
ppEnd=ttmp;\
if( !bracketsDown){\
while(*ttmp!='\0' && *ppEnd!=']' ){\
if(*ttmp=='['){\
/*printf("debug : [[ ttmp = %s\n",ttmp);\
if(dim)printDebug_dimension(dim,"[DIM]");*/\
if(l_p != NULL){\
free_dimension(dim);\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
/*if(dim)printDebug_dimension(dim,"{DIM}");*/\
}\
ss = strtoul(ttmp, &ppEnd, 10);\
while(ttmp == ppEnd && *ttmp!='\0' && ppEnd[0] !=']'){\
\
if(*ttmp=='['){\
/*printf("debug : [[ ttmp = %s\n",ttmp);\
if(dim)printDebug_dimension(dim,"[DIM]");*/\
if(l_p != NULL){\
free_dimension(dim);\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
/*if(dim)printDebug_dimension(dim,"{DIM}");*/\
}\
\
/*printf("debug : aa ttmp = %s\n",ttmp);*/\
ttmp++;\
ss = strtoul(ttmp, &ppEnd, 10);\
/*printf("debug : bb ttmp = %s\n",ttmp);*/\
}\
if(ppEnd !=ttmp ){\
append_in_list_perm(&l_p,ss);\
}\
ttmp=ppEnd;\
}\
/*printf("debug : cc ttmp = %s\n",ttmp);*/\
if( *ttmp ==']'){\
dim=create_dim_from_list_perm(l_p);\
push_back_list_ptr_DIMENSION(m_l_dim, clone_dim(dim));\
/*push_back_list_dimension(m_l_dim, *dim);*/\
bracketsDown = true;\
printf("debug: dim ptr: %p sizeof(*dim)=%ld sizeof(dimension)=%ld\n",dim,sizeof(*dim), sizeof(dimension));\
if(dim){printDebug_dimension(dim,"{DIM}");}\
j=0;\
\
}\
\
}\
/*printf("debug : <<---->> ttmp = %s, bracketsDown=%d T==NULL? =%d, done?=%d\n",ttmp, bracketsDown, (T==NULL), Done);*/\
if(!Done && bracketsDown){\
/*printf("debug : ee ttmp = %s, T==NULL ? = %d\n %ld vs %ld\n",ttmp,(T==NULL),T->dim->rank,dim->rank);\
printDebug_dimension(dim," DIM");*/\
if((T->dim->rank == dim->rank)){\
\
\
\
type x;\
while(strlen(ttmp) && (*ttmp!='[') && (j<dim->rank)){ \
x = strto_##type(ttmp, &ppEnd);\
while(ttmp == ppEnd && strlen(ttmp) && *ttmp!='[' ){\
/*printf("debug : dd ttmp = %s\n",ttmp);*/\
ttmp++;\
x = strto_##type(ttmp, &ppEnd);\
/*printf("debug : ww ttmp = %s\n",ttmp);*/\
}\
if((*ttmp!='[') && (ttmp != ppEnd)){\
T->x[j++]=x;\
/*printf("debug : x=%lf ===> %d\n",x,(j==dim->rank));*/\
}\
else if ( *ttmp =='[') {\
bracketsDown = false;\
Done=true;\
break;\
}\
ttmp=ppEnd;\
Done=(j==dim->rank);\
/*endTensor=(j==dim->rank);*/\
}\
if(Done) break;\
if(j == dim->rank ){\
Done = true;\
}\
}else {\
/*endTensor = true;*/\
/*Done = true;\
bracketsDown = false;*/\
break;\
}\
}\
if(Done){\
/*printf("debug : done=%d , l_p==NULL?=%d, endTensor=%d\n",Done, (l_p==NULL), endTensor);*/\
if(l_p != NULL){\
free_dimension(dim);\
dim=NULL;\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
}\
\
}\
if(Done) break;\
\
}\
tmpNN = tmpNN->next_layer;\
}\
free(input);\
free(iinput);\
free(recInput);\
close(fd_input);\
if(dim) free_dimension(dim);\
if(l_p) free_list_perm_in_dim(l_p);\
\
}while(0);\
\
\
\
#endif /* NNEURONE_T_FILE_H__C_ */ #endif /* NNEURONE_T_FILE_H__C_ */
+2 -1
View File
@@ -23,8 +23,9 @@ YLISTDIR=$(ROOTPROJECTDIR)/list_t
YWORKDIR=$(ROOTPROJECTDIR)/y_worker_t YWORKDIR=$(ROOTPROJECTDIR)/y_worker_t
YJSONDIR=$(ROOTPROJECTDIR)/yjson_t YJSONDIR=$(ROOTPROJECTDIR)/yjson_t
YSOCKET_DIR=$(ROOTPROJECTDIR)/y_socket_t YSOCKET_DIR=$(ROOTPROJECTDIR)/y_socket_t
#DIMENSIONDIR=$(ROOTPROJECTDIR)/dimension_t
INCLUDE_SOCKET=-I$(YSOCKET_DIR)/include -I$(YLISTDIR)/src -I$(YWORKDIR)/include -I$(YJSONDIR)/src -I$(YSOCKET_DIR)/include INCLUDE_SOCKET=-I$(YSOCKET_DIR)/include -I$(YLISTDIR)/src -I$(YWORKDIR)/include -I$(YJSONDIR)/src -I$(YSOCKET_DIR)/include #-I$(DIMENSIONDIR)/src
LIB_SOCKET=$(YSOCKET_DIR)/libysocket.so LIB_SOCKET=$(YSOCKET_DIR)/libysocket.so
+234 -1
View File
@@ -14,6 +14,7 @@
#include "fmock/fmock.h" #include "fmock/fmock.h"
#include "neuron_t/neuron_t.h" #include "neuron_t/neuron_t.h"
//#include "dimension_t/dimension_t.h"
#include "vehicle.h" #include "vehicle.h"
#include "learn_to_drive.h" #include "learn_to_drive.h"
@@ -772,8 +773,240 @@ struct status_qlearning *qlstatus = create_status_qlearning ();
} }
TEST(extract_with_pconf){
size_t nb_block = 7;
size_t dim= 2;
struct blocks * path = create_blocks(nb_block, dim);
LOG("debug: f_name = %s\n", __func__);
#if 1 #if 1
TEST(_first_learn_vehicle_50__11){
copy_coordinate(path->lower_bound_block[0], (float[]){0,0});
copy_coordinate(path->upper_bound_block[0], (float[]){100,250});
copy_coordinate(path->lower_bound_block[1], (float[]){100,0});
copy_coordinate(path->upper_bound_block[1], (float[]){250,80});
copy_coordinate(path->lower_bound_block[2], (float[]){250,0});
copy_coordinate(path->upper_bound_block[2], (float[]){360,140});
copy_coordinate(path->lower_bound_block[3], (float[]){360,70});
copy_coordinate(path->upper_bound_block[3], (float[]){600,140});
copy_coordinate(path->lower_bound_block[4], (float[]){600,90});
copy_coordinate(path->upper_bound_block[4], (float[]){720,300});
copy_coordinate(path->lower_bound_block[5], (float[]){300,300});
copy_coordinate(path->upper_bound_block[5], (float[]){720,350});
copy_coordinate(path->lower_bound_block[6], (float[]){0,250});
copy_coordinate(path->upper_bound_block[6], (float[]){410,300});
/*
copy_coordinate(path->lower_bound_block[4], (float[]){0,0});
copy_coordinate(path->upper_bound_block[4], (float[]){150,250});
copy_coordinate(path->lower_bound_block[3], (float[]){150,40});
copy_coordinate(path->upper_bound_block[3], (float[]){250,150});
copy_coordinate(path->lower_bound_block[2], (float[]){250,80});
copy_coordinate(path->upper_bound_block[2], (float[]){360,200});
copy_coordinate(path->lower_bound_block[1], (float[]){360,70});
copy_coordinate(path->upper_bound_block[1], (float[]){600,150});
copy_coordinate(path->lower_bound_block[0], (float[]){600,90});
copy_coordinate(path->upper_bound_block[0], (float[]){760,300});
copy_coordinate(path->lower_bound_block[6], (float[]){260,300});
copy_coordinate(path->upper_bound_block[6], (float[]){760,360});
copy_coordinate(path->lower_bound_block[5], (float[]){0,250});
copy_coordinate(path->upper_bound_block[5], (float[]){410,300});
copy_coordinate(path->lower_bound_block[0], (float[]){0,0});
copy_coordinate(path->upper_bound_block[0], (float[]){150,250});
copy_coordinate(path->lower_bound_block[1], (float[]){150,0});
copy_coordinate(path->upper_bound_block[1], (float[]){250,150});
copy_coordinate(path->lower_bound_block[2], (float[]){250,80});
copy_coordinate(path->upper_bound_block[2], (float[]){360,200});
copy_coordinate(path->lower_bound_block[3], (float[]){360,70});
copy_coordinate(path->upper_bound_block[3], (float[]){600,170});
copy_coordinate(path->lower_bound_block[4], (float[]){600,90});
copy_coordinate(path->upper_bound_block[4], (float[]){760,300});
copy_coordinate(path->lower_bound_block[5], (float[]){300,300});
copy_coordinate(path->upper_bound_block[5], (float[]){760,350});
copy_coordinate(path->lower_bound_block[6], (float[]){0,250});
copy_coordinate(path->upper_bound_block[6], (float[]){410,300});
copy_coordinate(path->lower_bound_block[0], (float[]){0,300});
copy_coordinate(path->upper_bound_block[0], (float[]){400,700});
copy_coordinate(path->lower_bound_block[1], (float[]){100,0});
copy_coordinate(path->upper_bound_block[1], (float[]){1000,300});
copy_coordinate(path->lower_bound_block[2], (float[]){1000,50});
copy_coordinate(path->upper_bound_block[2], (float[]){1400,500});
copy_coordinate(path->lower_bound_block[3], (float[]){1400,200});
copy_coordinate(path->upper_bound_block[3], (float[]){1800,700});
copy_coordinate(path->lower_bound_block[4], (float[]){1100,700});
copy_coordinate(path->upper_bound_block[4], (float[]){1700,1000});
copy_coordinate(path->lower_bound_block[5], (float[]){800,600});
copy_coordinate(path->upper_bound_block[5], (float[]){1100,975});
copy_coordinate(path->lower_bound_block[6], (float[]){100,700});
copy_coordinate(path->upper_bound_block[6], (float[]){800,975});
*/
#else
copy_coordinate(path->lower_bound_block[0], (float[]){0,3});
copy_coordinate(path->upper_bound_block[0], (float[]){4,7});
copy_coordinate(path->lower_bound_block[1], (float[]){1,0});
copy_coordinate(path->upper_bound_block[1], (float[]){10,3});
copy_coordinate(path->lower_bound_block[2], (float[]){10,0.5});
copy_coordinate(path->upper_bound_block[2], (float[]){14,5});
copy_coordinate(path->lower_bound_block[3], (float[]){14,2});
copy_coordinate(path->upper_bound_block[3], (float[]){18,7});
copy_coordinate(path->lower_bound_block[4], (float[]){11,7});
copy_coordinate(path->upper_bound_block[4], (float[]){17,10});
copy_coordinate(path->lower_bound_block[5], (float[]){8,6});
copy_coordinate(path->upper_bound_block[5], (float[]){11,9.75});
copy_coordinate(path->lower_bound_block[6], (float[]){1,7});
copy_coordinate(path->upper_bound_block[6], (float[]){8,9.75});
#endif
update_bounds_limits_blocks(path);
struct vehicle *car = create_vehicle(path);
config_layers *pconf = create_config_layers_from_OneD(4,(size_t[]){3,24,24,3}); /* 3 input , 3 target; 2 hidden layer with 24 neurons each */
//config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){3,24,3}); /* 3 input , 3 target; 2 hidden layer with 24 neurons each */
bool randomize=true;
float minR = -0.5, maxR = 0.5;
//float minR = 0, maxR = 1;
int randomRange = 500;
size_t nb_prod_thread = 2;
size_t nb_calc_thread = 4;
float learning_rate = 0.0007 /*0.001*//* 0.0001*/; /* 0.000001*/ /* 0.001*/;
struct networks_qlearning *nnetworks = create_network_qlearning(
pconf,
randomize, minR, maxR, randomRange,
nb_prod_thread, nb_calc_thread,
learning_rate
);
/*
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_20240717_01h42m16s_5300.txt");
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_20240717_01h42m16s_5300.txt");
*/
struct main_list_ptr_DIMENSION *m_l_dim=create_var_list_ptr_DIMENSION();
//struct main_list_dimension *m_l_dim=create_var_list_dimension();
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS_PCONF(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_TEST__first_learn_vehicle_50__11____9.symlink",m_l_dim);
for(struct list_ptr_DIMENSION *local_l_dim=m_l_dim->begin_list; local_l_dim; local_l_dim=local_l_dim->next){
size_t i=local_l_dim->index;
char msg[50]; sprintf(msg, " DIM[%ld] ",i);
printDebug_dimension((local_l_dim->value), msg);
}
LOG("%s","==========================================");
config_layers *base_conf=create_config_layers_from_weight_in_neurons_TYPE_FLOAT(nnetworks->main_net);
config_layers *p_conf=create_config_layers_from_m_list_ptr_DIMENSION(m_l_dim);
//config_layers *p_conf=create_config_layers_from_m_list_dimension(m_l_dim);
if(cmp_config_layers(p_conf, base_conf)==0){
LOG("base_conf == %s\n","p_conf");
}else{
LOG("base_conf != %s\n","p_conf");
}
LOG("%s ", "base_conf"); print_config_layers(base_conf);
LOG("%s ", "p_conf"); print_config_layers(p_conf);
free_config_layers(base_conf);
free_config_layers(p_conf);
//free_all_var_list_dimension(m_l_dim);
///free_all_var_list_ptr_DIMENSION(m_l_dim);
//remove_all_ptr_type_list_ptr_DIMENSION(m_l_dim);
purge_ptr_type_list_ptr_DIMENSION(m_l_dim);
//EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_20250508_17h50m56s_26300.txt");
///EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_.symlink");
///EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_.symlink");
/*
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_20250508_23h02m40s_29000.txt");
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_20250508_23h02m40s_29000.txt");
*/
struct status_qlearning *qlstatus = create_status_qlearning ();
struct delay_params *dly = create_delay_params (
500/*size_t delay_between_episodes*/,
50/*size_t delay_between_games*/
);
struct qlearning_params *qlparams = create_qlearning_params (
0.95/*float gamma*/,
learning_rate,
0 /* (not used!)float discount_factor*/,
1.0/*0.99*//*0.0001*//*0.99*/ /*float exploration_factor*/,
20/*long int nb_training_before_update_weight_in_target*/,
10000/*size_t number_episodes*/
);
/* UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->main_net, d_f_act , df );
UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->main_net, f_act, f );
UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->target_net, d_f_act , df );
UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->target_net, f_act , f );
*/
qlparams->caller_func_name=malloc(strlen(__func__)+1);
strcpy(qlparams->caller_func_name, __func__);
struct print_params *pprint = create_print_params(
12/*float scale_x*/,12 /*float scale_y*/,
dly/*struct delay_params * dly_p*/
);
struct RL_agent *rlAgent = create_RL_agent (
nnetworks /*struct networks_qlearning * networks*/,
car /*struct vehicle * car*/,
qlstatus /*struct status_qlearning * status*/,
pprint /*struct print_params * pprint*/,
qlparams/*struct qlearning_params *qlearnParams*/
);
//learn_to_drive(rlAgent);
//learn_to_drive(rlAgent);
struct arg_bash *bash_arg= create_arg_bash();
struct arg_run_qlearn_bprint *argQL_BP = create_arg_run_qlearn_bprint(bash_arg, rlAgent);
struct arg_var_ * var = create_arg_var_(y_nnn_manager_handle_input, argQL_BP);
struct y_socket_t *argS = y_socket_create("1600", 2, 3, var);
pthread_t pollTh;
pthread_create(&pollTh, NULL, y_socket_poll_fds, (void*)argS);
pthread_join(pollTh, NULL);
//pthread_join(thread_learn, NULL);
y_socket_free(argS);
free_arg_var_(var);
free_arg_run_qlearn_bprint(argQL_BP);
//free_RL_agent(rlAgent);
}
#if 1
HIDE_TEST(_first_learn_vehicle_50__11){
size_t nb_block = 7; size_t nb_block = 7;
size_t dim= 2; size_t dim= 2;
struct blocks * path = create_blocks(nb_block, dim); struct blocks * path = create_blocks(nb_block, dim);