y_socket: try send file, neuron_t: modify EXTRACT from filr to neuron/tensor
This commit is contained in:
@@ -635,7 +635,7 @@ void print_weight_in_neurons_##type(neurons_##type *nn, char *msg){\
|
||||
if(tmp->weight_in){\
|
||||
sprintf(vmsg,"%s layer %ld",msg,i++);\
|
||||
print_tensor_msg_##type(tmp->weight_in, vmsg);\
|
||||
}\
|
||||
}else{printf("weight_in %d NULL\n",i);}\
|
||||
tmp = tmp->next_layer;\
|
||||
}\
|
||||
}\
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef NNEURONE_T_FILE_H__C_
|
||||
#define NNEURONE_T_FILE_H__C_
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "neuron_t/neuron_t.h"
|
||||
#include "tensor_t/tensor_t.h"
|
||||
|
||||
@@ -146,7 +149,7 @@ do{\
|
||||
\
|
||||
}while(0);
|
||||
|
||||
#define EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \
|
||||
#define __EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \
|
||||
do{\
|
||||
FILE *f_input;\
|
||||
f_input=fopen(file_name_input,"r");\
|
||||
@@ -254,5 +257,190 @@ do{\
|
||||
\
|
||||
}while(0);
|
||||
|
||||
#define EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \
|
||||
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);\
|
||||
bracketsDown = true;\
|
||||
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);\
|
||||
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);\
|
||||
\
|
||||
}while(0);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* NNEURONE_T_FILE_H__C_ */
|
||||
|
||||
+94
-4
@@ -424,7 +424,7 @@ TEST(Extract_weight_in_neurons){
|
||||
|
||||
|
||||
size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract.txt")
|
||||
//EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract.txt")
|
||||
|
||||
setup_all_layers_functions_TYPE_FLOAT(cpyn,
|
||||
tensorContractnProdThread_TYPE_FLOAT,
|
||||
@@ -438,6 +438,7 @@ TEST(Extract_weight_in_neurons){
|
||||
|
||||
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, cpyn, weight_in, ".ff_bn_weight_in__toExtract.txt")
|
||||
// copy_weight_in_neurons_TYPE_FLOAT(cpyn, bn);
|
||||
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract___exp.txt")
|
||||
|
||||
char msg[256];
|
||||
tensor_TYPE_FLOAT * linked_tens = NULL;
|
||||
@@ -465,8 +466,6 @@ TEST(Extract_weight_in_neurons){
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(Extract_EXPORT_weight_in_neurons){
|
||||
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||
randomizeInitWeight =false;
|
||||
@@ -481,6 +480,7 @@ TEST(Extract_EXPORT_weight_in_neurons){
|
||||
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000);
|
||||
setup_networks_alloutputs_config_TYPE_FLOAT(&cpyn, pconf,false,0,1,5000);
|
||||
|
||||
//print_weight_in_neurons_TYPE_FLOAT(bn, "");
|
||||
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_target_20240717_01h43m41s_13300.txt")
|
||||
|
||||
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||
@@ -495,7 +495,8 @@ TEST(Extract_EXPORT_weight_in_neurons){
|
||||
|
||||
|
||||
size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
|
||||
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toCMP.txt")
|
||||
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toCMP__.txt")
|
||||
print_weight_in_neurons_TYPE_FLOAT(bn, "");
|
||||
|
||||
setup_all_layers_functions_TYPE_FLOAT(cpyn,
|
||||
tensorContractnProdThread_TYPE_FLOAT,
|
||||
@@ -538,6 +539,95 @@ TEST(Extract_EXPORT_weight_in_neurons){
|
||||
|
||||
|
||||
|
||||
double doubleL(double t, double o){
|
||||
return (o - t) * (o - t)/2;
|
||||
}
|
||||
double doubleDL(double t, double o){
|
||||
return (o - t);
|
||||
}
|
||||
|
||||
double doublef(double x){
|
||||
return 1/(1+exp((double)(-x)));
|
||||
}
|
||||
|
||||
double doubledf(double x){
|
||||
return exp(-x)/ ((1+exp(-x)) * (1+exp(-x)));
|
||||
}
|
||||
|
||||
|
||||
TEST(Extract_EXPORT_weight_in_neurons_double){
|
||||
bool rec_randomizeInitWeight = randomizeInitWeight;
|
||||
randomizeInitWeight =false;
|
||||
|
||||
data_set_TYPE_DOUBLE *ds= fill_data_set_from_file_TYPE_DOUBLE("xor.txt",1);
|
||||
// print_data_set_msg_TYPE_DOUBLE(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(4,(size_t[]){3,24,24,3});
|
||||
neurons_TYPE_DOUBLE *bn=NULL, *tmp ;
|
||||
neurons_TYPE_DOUBLE *cpyn=NULL;
|
||||
//setup_networks_alloutputs_config_GLOBAL_rdm01_TYPE_DOUBLE(setup_networks_alloutputs_config_TYPE_DOUBLE(&bn,pconf);bn,pconf);
|
||||
setup_networks_alloutputs_config_TYPE_DOUBLE(&bn,pconf,false,0,1,5000);
|
||||
setup_networks_alloutputs_config_TYPE_DOUBLE(&cpyn, pconf,false,0,1,5000);
|
||||
|
||||
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_DOUBLE, bn, weight_in, ".ff_target_20240717_01h43m41s_13300.txt")
|
||||
|
||||
setup_all_layers_functions_TYPE_DOUBLE(bn,
|
||||
tensorContractnProdThread_TYPE_DOUBLE,
|
||||
tensorProdThread_TYPE_DOUBLE,
|
||||
doubleDL,
|
||||
doubleL,
|
||||
doublef,
|
||||
doubledf);
|
||||
|
||||
setup_all_layers_params_TYPE_DOUBLE(bn, 5, 1 , 0.1);
|
||||
|
||||
|
||||
size_t reps = 1;// learning_online2_neurons_TYPE_DOUBLE(bn,ds,cond);
|
||||
// EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_DOUBLE, bn, weight_in, ".ff_bn_weight_in__toCMP__.txt")
|
||||
print_weight_in_neurons_TYPE_DOUBLE(bn, "");
|
||||
|
||||
|
||||
setup_all_layers_functions_TYPE_DOUBLE(cpyn,
|
||||
tensorContractnProdThread_TYPE_DOUBLE,
|
||||
tensorProdThread_TYPE_DOUBLE,
|
||||
doubleDL,
|
||||
doubleL,
|
||||
doublef,
|
||||
doubledf);
|
||||
|
||||
setup_all_layers_params_TYPE_DOUBLE(cpyn, 5, 1 , 0.1);
|
||||
|
||||
// EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_DOUBLE, cpyn, weight_in, ".ff_bn_weight_in__toExtract.txt")
|
||||
// copy_weight_in_neurons_TYPE_DOUBLE(cpyn, bn);
|
||||
|
||||
char msg[256];
|
||||
tensor_TYPE_DOUBLE * linked_tens = NULL;
|
||||
for(size_t i=0; i<ds->size; ++i){
|
||||
// print_predict_by_network_with_error_neurons_TYPE_DOUBLE(bn,ds->input[i],ds->target[i]);
|
||||
// print_predict_by_network_with_error_neurons_TYPE_DOUBLE(cpyn,ds->input[i],ds->target[i]);
|
||||
calculate_output_by_network_neurons_TYPE_DOUBLE(bn,ds->input[i],&linked_tens);
|
||||
sprintf(msg," output base %ld ",i);
|
||||
print_tensor_msg_TYPE_DOUBLE(linked_tens,msg);
|
||||
calculate_output_by_network_neurons_TYPE_DOUBLE(cpyn,ds->input[i],&linked_tens);
|
||||
sprintf(msg," output copy %ld ",i);
|
||||
print_tensor_msg_TYPE_DOUBLE(linked_tens,msg);
|
||||
}
|
||||
|
||||
|
||||
// EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_DOUBLE, cpyn, weight_in, ".ff_bn_weight_in__exportedCPYfromExtract.txt")
|
||||
|
||||
|
||||
free_data_set_TYPE_DOUBLE(ds);
|
||||
free_neurons_TYPE_DOUBLE(bn);
|
||||
free_neurons_TYPE_DOUBLE(cpyn);
|
||||
|
||||
LOG("reps = %ld\n",reps);
|
||||
randomizeInitWeight = rec_randomizeInitWeight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
Reference in New Issue
Block a user