forked from elpriet8/PerceptronV2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
68 lines (50 loc) · 1.42 KB
/
Copy pathmain.c
File metadata and controls
68 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// main.c
//
//
// Created by Diego Prieto on 13/05/21.
//
#include <stdio.h>
#include "dataset.h"
#include "weights_module.h"
#include "perceptron_module.h"
void showArray(float **array,int filas, int cols);
int main (void){
char datafile[] = "DatasetV2.csv";
int columnas = 1,filas = 0;
float learningRate = .99;
int itn;
float **array = NULL;
float **weights = NULL;
float *error = NULL;
float *prediction = NULL;
FILE *fp;
fp = fopen(datafile, "r");
if(fp==NULL){
printf("Error al abrir archivo");
exit(1);
}
printf("Iteraciones [Entero]: ");
scanf(" %i", &itn);
// get dataset dimensions
getMatrixSize(&filas,&columnas,fp);
// Allocate memory
array = allocateArrayMem(&filas,&columnas);
error = malloc((itn)*sizeof(float));
prediction = malloc((itn)*sizeof(float));
// relocate file pointer, fill dataset array
rewind(fp);
toFloat(array, &filas, &columnas, fp);
fclose(fp);
// Allocate memory weights array
weights = allocateArrayMem(&filas,&columnas);
// init weights array rand 0-1
init_weights_array(filas, columnas, weights);
// p2p product x1w1
hebbian_start(learningRate, weights, array, itn, filas,columnas,error,prediction);
// Free memory
free(array);
free(weights);
free(error);
free(prediction);
}