Actualizing data generator and data print functions

这个提交包含在:
Abdel Kader Chabi Sika Boni 2021-12-12 00:46:47 +01:00
父节点 b003e51538
当前提交 2d0c0b8e4b
共有 11 个文件被更改,包括 107 次插入10 次删除

查看文件

@ -17,4 +17,4 @@ send :
git commit git commit
git push git push
rebuild : clean default

二进制
activations.o 普通文件

二进制文件未显示。

5
main.c
查看文件

@ -20,8 +20,9 @@ int main(int argc, char *argv[])
print_network(net); print_network(net);
destroy_network(net);*/ destroy_network(net);*/
/*Data *data = csv_to_samples("mydata.csv", 3, ",", 70.0, "yes", 3); Data *data = csv_to_samples("mydata.csv", 3, ",", 70.0, "yes", 3);
destroy_data(data);*/ print_data(data);
destroy_data(data);
return 0; return 0;
} }

二进制
main.o 普通文件

二进制文件未显示。

二进制
myprogram 可执行文件

二进制文件未显示。

二进制
network.o 普通文件

二进制文件未显示。

二进制
neurons.o 普通文件

二进制文件未显示。

查看文件

@ -44,9 +44,17 @@ Data *init_data()
void add_sample_to_data(Data *data, Sample *sample) void add_sample_to_data(Data *data, Sample *sample)
{ {
if(data->size == 0)
{
data->first_sample = sample;
data->last_sample = sample;
data->size++;
}else
{
data->last_sample->next_sample = sample; data->last_sample->next_sample = sample;
data->last_sample = sample; data->last_sample = sample;
data->size++; data->size++;
}
} }
void destroy_sample(Sample *sample) void destroy_sample(Sample *sample)
@ -86,19 +94,60 @@ Data *csv_to_samples(char *path_to_csv, int n_features, char *features_separator
FILE *file = fopen(path_to_csv, "r"); FILE *file = fopen(path_to_csv, "r");
char line[100], *dup; char line[100], *dup;
char *token; char *token;
//float val; int features_count;
if(file != NULL) if(file != NULL)
{ {
while(fgets(line, 100, file) != NULL) while(fgets(line, 100, file) != NULL)
{ {
Sample *current_sample = init_sample();
Feature *temp_last_feature;
features_count = n_features;
dup = strtok(line, "\n"); //extracting line content without '\n' dup = strtok(line, "\n"); //extracting line content without '\n'
token = strtok(dup, features_separator); token = strtok(dup, features_separator);
while(token != NULL) while(token != NULL)
{ {
printf("current token = %s\n", token); if(features_count > 0) //first put features into current sample
{
if(current_sample->first_feature == NULL)
{
current_sample->first_feature = init_feature( atof(token) );
temp_last_feature = current_sample->first_feature;
}else
{
temp_last_feature->next_feature = init_feature( atof(token) );
temp_last_feature = temp_last_feature->next_feature;
}
features_count--;
}else //put label into current sample
{
if(strcmp(apply_onthot_encode, "yes") == 0)
{
OneHotLabel *temp_last_hotlabel;
int i;
for(i=0 ; i<n_classes ; i++)
{
if(current_sample->first_hot == NULL)
{
current_sample->first_hot = init_onehotlabel(0.0);
temp_last_hotlabel = current_sample->first_hot;
}else
{
temp_last_hotlabel->next = init_onehotlabel(0.0);
temp_last_hotlabel = temp_last_hotlabel->next;
}
if((float)i == atof(token) )
{
temp_last_hotlabel->value = 1.0;
}
}
}else //when not applying one hot encoding, first_hot is directly equal to label
{
current_sample->first_hot = init_onehotlabel( atof(token) );
}
}
token = strtok(NULL, features_separator); token = strtok(NULL, features_separator);
} }
printf("----------------\n"); add_sample_to_data(data, current_sample);
} }
fclose(file); fclose(file);
}else }else
@ -111,5 +160,52 @@ Data *csv_to_samples(char *path_to_csv, int n_features, char *features_separator
void print_data(const Data *data) void print_data(const Data *data)
{ {
printf("Hello\n"); Sample *current_sample = data->first_sample;
Feature *temp_feature;
OneHotLabel *temp_hotlabel;
printf("#=============================================#\n");
if(current_sample != NULL)
{
int count = 1;
while(current_sample != NULL)
{
printf("Sample %d : ", count);
if(current_sample->t == TRAIN)
{
printf("TR\n");
}else if(current_sample->t == TEST)
{
printf("TE\n");
}else
{
printf("VA\n");
}
temp_feature = current_sample->first_feature;
while(temp_feature != NULL)
{
printf("%f ", temp_feature->value);
temp_feature = temp_feature->next_feature;
}
temp_hotlabel = current_sample->first_hot;
printf("##> ");
while(temp_hotlabel != NULL)
{
printf("%f ", temp_hotlabel->value);
temp_hotlabel = temp_hotlabel->next;
}
current_sample = current_sample->next_sample;
if(current_sample != NULL)
{
printf("\n#---------------------------------------------#\n");
}else
{
printf("\n");
}
count++;
}
}else
{
printf("Nothing to print : empty data !!!\n");
}
printf("#=============================================#\n");
} }

二进制
preprocessing.o 普通文件

二进制文件未显示。

二进制
randomness.o 普通文件

二进制文件未显示。

二进制
training.o 普通文件

二进制文件未显示。