-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.c
98 lines (77 loc) · 2.16 KB
/
output.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//#include "ancfis.h"
/*
This file contains functions that 'store' data for further viewing or use.
Here, store means 'write to an array' or 'write to a file'.
There are 3 functions:
1. write_parameter
2. record_parameter
3. restore_parameter
*/
/***********************************************
Description:
Write all node parameters to file 'file_name'.
Inputs:
file_name - the file name
Outputs:
A file.
Called from:
mexFunction in ancfismex.c
************************************************/
void write_parameter(char *file_name) {
FILE *fp;
PARAMETER_LIST_T *p;
int i;
fp = (FILE *)open_file(file_name, "w");
for(i = 0; i < Node_n; i++) {
if(node_p[i]->parameter == NULL)
continue;
for(p = node_p[i]->parameter; p != NULL; p = p->next)
fprintf(fp, "%4.10lf ", p->content);
fprintf(fp, "\n");
}
fclose(fp);
}
/***********************************************
Description:
Record the current parameters in an array. This is used to remember the
parameters that give the best training error.
Inputs:
*parameter_array - must be preallocated.
This will store the ANCFIS parameters
Outputs:
Copies the parameter values into *parameter_array.
Called from:
mexFunction in ancfismex.c
************************************************/
void record_parameter(double *parameter_array) {
int i, j = 0;
PARAMETER_LIST_T *p;
for(i = 0; i < Node_n; i++) {
if(node_p[i]->parameter == NULL)
continue;
for(p = node_p[i]->parameter; p != NULL; p = p->next)
parameter_array[j++] = p->content;
}
}
/***********************************************
Description:
Restore the parameters in parameter_array (created using function
record_parameter) back to ANFIS.
Inputs:
*parameter_array - must be preallocated.
This holds the stored ANCFIS parameters from record_parameter.
Outputs:
Operates on node_p[i]->parameter
Called from:
mexFunction in ancfismex.c
************************************************/
void restore_parameter(double *parameter_array) {
int i, j = 0;
PARAMETER_LIST_T *p;
for (i = 0; i < Node_n; i++) {
if (node_p[i]->parameter == NULL)
continue;
for (p = node_p[i]->parameter; p != NULL; p = p->next)
p->content = parameter_array[j++];
}
}