Actualizing data generator and data print functions
This commit is contained in:
parent
b003e51538
commit
2d0c0b8e4b
11 changed files with 107 additions and 10 deletions
2
Makefile
2
Makefile
|
@ -17,4 +17,4 @@ send :
|
|||
git commit
|
||||
git push
|
||||
|
||||
|
||||
rebuild : clean default
|
||||
|
|
BIN
activations.o
Normal file
BIN
activations.o
Normal file
Binary file not shown.
5
main.c
5
main.c
|
@ -20,8 +20,9 @@ int main(int argc, char *argv[])
|
|||
print_network(net);
|
||||
destroy_network(net);*/
|
||||
|
||||
/*Data *data = csv_to_samples("mydata.csv", 3, ",", 70.0, "yes", 3);
|
||||
destroy_data(data);*/
|
||||
Data *data = csv_to_samples("mydata.csv", 3, ",", 70.0, "yes", 3);
|
||||
print_data(data);
|
||||
destroy_data(data);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
main.o
Normal file
BIN
main.o
Normal file
Binary file not shown.
BIN
myprogram
Executable file
BIN
myprogram
Executable file
Binary file not shown.
BIN
network.o
Normal file
BIN
network.o
Normal file
Binary file not shown.
BIN
neurons.o
Normal file
BIN
neurons.o
Normal file
Binary file not shown.
110
preprocessing.c
110
preprocessing.c
|
@ -44,9 +44,17 @@ Data *init_data()
|
|||
|
||||
void add_sample_to_data(Data *data, Sample *sample)
|
||||
{
|
||||
data->last_sample->next_sample = sample;
|
||||
data->last_sample = sample;
|
||||
data->size++;
|
||||
if(data->size == 0)
|
||||
{
|
||||
data->first_sample = sample;
|
||||
data->last_sample = sample;
|
||||
data->size++;
|
||||
}else
|
||||
{
|
||||
data->last_sample->next_sample = sample;
|
||||
data->last_sample = sample;
|
||||
data->size++;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
char line[100], *dup;
|
||||
char *token;
|
||||
//float val;
|
||||
int features_count;
|
||||
if(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'
|
||||
token = strtok(dup, features_separator);
|
||||
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);
|
||||
}
|
||||
printf("----------------\n");
|
||||
add_sample_to_data(data, current_sample);
|
||||
}
|
||||
fclose(file);
|
||||
}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)
|
||||
{
|
||||
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");
|
||||
}
|
BIN
preprocessing.o
Normal file
BIN
preprocessing.o
Normal file
Binary file not shown.
BIN
randomness.o
Normal file
BIN
randomness.o
Normal file
Binary file not shown.
BIN
training.o
Normal file
BIN
training.o
Normal file
Binary file not shown.
Loading…
Reference in a new issue