include/lwpr_binio.h File Reference
Prototypes for binary-IO related LWPR subroutines.
More...
#include <stdio.h>
Go to the source code of this file.
Functions |
int | lwpr_write_binary (const LWPR_Model *model, const char *filename) |
| Writes an LWPR model to a file.
|
int | lwpr_read_binary (LWPR_Model *model, const char *filename) |
| Reads an LWPR model from a binary file.
|
int | lwpr_write_binary_fp (const LWPR_Model *model, FILE *fp) |
| Writes an LWPR model to a file.
|
int | lwpr_read_binary_fp (LWPR_Model *model, FILE *fp) |
| Reads an LWPR model from a binary file.
|
int | lwpr_io_write_matrix (FILE *fp, int M, int Ms, int N, const double *data) |
| Writes a matrix of doubles into a binary file.
|
int | lwpr_io_read_matrix (FILE *fp, int M, int Ms, int N, double *data) |
| Reads a matrix of doubles from a binary file.
|
int | lwpr_io_write_vector (FILE *fp, int N, const double *data) |
| Writes a vector of doubles into a binary file.
|
int | lwpr_io_read_vector (FILE *fp, int N, double *data) |
| Reads a vector of doubles from a binary file.
|
int | lwpr_io_write_scalar (FILE *fp, double data) |
| Writes a scalar (double) into a binary file.
|
int | lwpr_io_read_scalar (FILE *fp, double *data) |
| Reads a scalar (double) from a binary file.
|
int | lwpr_io_write_int (FILE *fp, int data) |
| Writes an integer into a binary file.
|
int | lwpr_io_read_int (FILE *fp, int *data) |
| Reads an integer from a binary file.
|
int | lwpr_io_write_rf (FILE *fp, const LWPR_ReceptiveField *RF) |
| Writes a receptive field structure into a binary file.
|
int | lwpr_io_read_rf (FILE *fp, LWPR_SubModel *sub) |
| Reads a receptive field structure from a binary file.
|
Detailed Description
Prototypes for binary-IO related LWPR subroutines.
This header file describes routines for reading and writing LWPR models from and to binary files. Please note that these functions assume that the models are stored and loaded on the same machine architecture (i.e. endianness, word length), and NO conversion is done. If you need to exchange LWPR models across different architectures, use the routines in lwpr_xml.h
The file format is as follows:
Element description | Size of element |
"LWPR" | 4 bytes |
BINIO version | 1 integer (negative since LWPR 1.1) |
nIn | 1 integer |
nIn | 1 integer |
nOut | 1 integer |
kernel | 1 integer |
length of 'name' string (may be 0) | integer |
name of the model | nr. of bytes as determined by previous integer |
n_data | 1 integer |
mean_x | nIn doubles |
var_x | nIn doubles |
diag_only | 1 integer |
update_D | 1 integer (was not present in LWPR 1.0 due to a bug) |
meta | 1 integer |
meta_rate | 1 double |
penalty | 1 double |
init_alpha | nIn*nIn doubles |
norm_in | nIn doubles |
norm_out | nOut doubles |
init_D | nIn*nIn doubles |
init_M | nIn*nIn doubles |
w_gen | 1 double |
w_prune | 1 double |
init_lambda | 1 double |
final_lambda | 1 double |
tau_lambda | 1 double |
init_S2 | 1 double |
add_threshold | 1 double |
Then, for each LWPR_SubModel (output dimension):
Element description | Size of element |
"SUBM" | 4 bytes |
output dimension | 1 integer |
number of RFs | 1 integer |
nr. of pruned RFs | 1 integer |
Within a submodel, for each LWPR_ReceptiveField:
Element description | Size of element |
"[RF]" | 4 bytes |
nReg | 1 integer |
D | 1 nIn*nIn doubles |
M | 1 nIn*nIn doubles |
alpha | 1 nIn*nIn doubles |
beta0 | 1 double |
beta | nReg doubles |
c | nIn doubles |
SXresYres | nIn*nReg doubles |
SSs2 | nReg doubles |
SSYres | nReg doubles |
SSXres | nIn*nReg doubles |
U | nIn*nReg doubles |
P | nIn*nReg doubles |
H | nReg doubles |
r | nReg doubles |
h | nIn*nIn doubles |
b | nIn*nIn doubles |
sum_w | nReg doubles |
sum_e_cv2 | nReg doubles |
sum_e2 | 1 double |
SSp | 1 double |
n_data | nReg doubles |
trustworthy | 1 integer |
lambda | nReg doubles |
mean_x | nIn doubles |
var_x | nIn doubles |
w | 1 double |
s | nReg doubles |
As a last sanity check, the file ends with the 4 characters "RPWL". The overall structure of a binary LWPR file looks like this:
LWPR...model globals...SUBM...output dim. 0...[RF]...RF 0/0...[RF]...RF 0/1...[RF]...RF 0/2...further receptive fields...SUBM...output dim. 1...[RF]...RF 1/0...[RF]...RF 1/1...further receptive fields...SUBM...output dim. 2...[RF]...RF 2/0...[RF]...RF 2/1...further receptive fields...further sub-models (output dimensions)...RPWL
Function Documentation
int lwpr_io_read_int |
( |
FILE * |
fp, |
|
|
int * |
data | |
|
) |
| | |
Reads an integer from a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[out] | data | Pointer to integer |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_read_matrix |
( |
FILE * |
fp, |
|
|
int |
M, |
|
|
int |
Ms, |
|
|
int |
N, |
|
|
double * |
data | |
|
) |
| | |
Reads a matrix of doubles from a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | M | Number of rows |
[in] | Ms | Stride parameter (offset between columns) |
[in] | N | Number of columns |
[out] | data | Pointer to matrix elements |
- Returns:
- 0 if errors have occured
- 1 on success
Reads a receptive field structure from a binary file.
- Parameters:
-
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_read_scalar |
( |
FILE * |
fp, |
|
|
double * |
data | |
|
) |
| | |
Reads a scalar (double) from a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[out] | data | Pointer to scalar value |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_read_vector |
( |
FILE * |
fp, |
|
|
int |
N, |
|
|
double * |
data | |
|
) |
| | |
Reads a vector of doubles from a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | N | Number of elements |
[out] | data | Pointer to vector elements |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_write_int |
( |
FILE * |
fp, |
|
|
int |
data | |
|
) |
| | |
Writes an integer into a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | data | Integer value |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_write_matrix |
( |
FILE * |
fp, |
|
|
int |
M, |
|
|
int |
Ms, |
|
|
int |
N, |
|
|
const double * |
data | |
|
) |
| | |
Writes a matrix of doubles into a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | M | Number of rows |
[in] | Ms | Stride parameter (offset between columns) |
[in] | N | Number of columns |
[in] | data | Pointer to matrix elements |
- Returns:
- 0 if errors have occured
- 1 on success
Writes a receptive field structure into a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | RF | Pointer to a receptive field structure |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_write_scalar |
( |
FILE * |
fp, |
|
|
double |
data | |
|
) |
| | |
Writes a scalar (double) into a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | data | Scalar value |
- Returns:
- 0 if errors have occured
- 1 on success
int lwpr_io_write_vector |
( |
FILE * |
fp, |
|
|
int |
N, |
|
|
const double * |
data | |
|
) |
| | |
Writes a vector of doubles into a binary file.
- Parameters:
-
[in] | fp | File descriptor |
[in] | N | Number of elements |
[in] | data | Pointer to vector elements |
- Returns:
- 0 if errors have occured
- 1 on success