Adding functions

This commit is contained in:
Abdel Kader Chabi Sika Boni 2021-11-30 20:06:44 +01:00
parent 694ef200df
commit 3245044e4e
4 changed files with 63 additions and 19 deletions

15
main.c
View file

@ -28,6 +28,21 @@ int main(int argc, char *argv[])
Network *net = init_network(n_neurons, 6, activations);
print_network(net);
destroy_network(net);*/
FILE *file = fopen("mydata.csv", "r");
char line[100];
if(file != NULL)
{
while(fgets(line, 100, file) != NULL)
{
//line[strlen(line)-1] = (char)"";
printf("%s", line);
}
fclose(file);
}else
{
printf("Unable to open the file\n");
}
return 0;
}

3
mydata.csv Normal file
View file

@ -0,0 +1,3 @@
1,2,3.2,0
4,1.1,2.1,1
5,4,1,2
1 1 2 3.2 0
2 4 1.1 2.1 1
3 5 4 1 2

View file

@ -41,29 +41,55 @@ Data *init_data()
return data;
}
void destroy_features_from_feature(Feature *feature)
void destroy_sample(Sample *sample)
{
}
void destroy_hots_from_hot(OneHotLabel *first_hot)
{
}
void destroy_samples_from_sample(Sample *sample)
{
Feature *temp1;
while (sample->first_feature != NULL)
{
temp1 = sample->first_feature;
sample->first_feature = sample->first_feature->next_feature;
free(temp1);
}
OneHotLabel *temp2;
while (sample->first_hot != NULL)
{
temp2 = sample->first_hot;
sample->first_hot = sample->first_hot->next;
free(temp2);
}
free(sample);
}
void destroy_data(Data *data)
{
Sample *temp;
while (data->first_sample != NULL)
{
temp = data->first_sample;
data->first_sample = data->first_sample->next_sample;
destroy_sample(temp);
}
free(data);
}
Data *csv_to_samples(char *path_to_csv, char *features_separator, float train_percent)
Data *csv_to_samples(char *path_to_csv, char *features_separator, float train_percent, char *apply_onthot_encode, int n_classes)
{
Data *data = init_data();
/*FILE *file;
char *chaine;
file = fopen(path_to_csv, "r");
if(file != NULL)
{
while(fgets(chaine, 30, file) != NULL)
{
printf("%s", chaine);
}
}*/
//TODO : complete
return data;
return data;
}
void print_data(const Data *data)
{
printf("Hello");
}

View file

@ -42,10 +42,10 @@ Feature *init_feature(float value);
OneHotLabel *init_onehotlabel(float value);
Sample *init_sample();
Data *init_data();
void destroy_features_from_feature(Feature *feature);
void destroy_hots_from_hot(OneHotLabel *first_hot);
void destroy_samples_from_sample(Sample *sample);
void destroy_sample(Sample *sample);
void destroy_data(Data *data);
Data *csv_to_samples(char *path_to_csv, char *features_separator, float train_percent);
Data *csv_to_samples(char *path_to_csv, char *features_separator, float train_percent, char *apply_onthot_encode, int n_classes);
//Data *csv_to_samples(char *path_to_csv, char *features_separator, float train_percent);
void print_data(const Data *data);
#endif