module Data: sig
.. end
The Data module reads/writes data and schema files, which have a
common format throughout
Libra
exception Eof
exception Invalid_length of int array
exception Invalid_value of (int array * int)
exception Parse_error of string
type
schema_t = int array
type
example_t = int array
type
wexample_t = float * int array
type
marginal_t = float array
Read/Write schema files
val load_schema : string -> schema_t
load_schema filename
loads a schema from file filename
.
val dump_schema : schema_t -> string -> unit
dump_schema s filename
writes schema s
to file filename
.
val output_schema : Pervasives.out_channel -> schema_t -> unit
dump_schema o s
writes schema s
to output channel o
.
Read/Write data files
val input_example : Pervasives.in_channel -> example_t
Reads one data example from the input.
val input_example_list : Pervasives.in_channel -> example_t list
Reads a list of data examples from the input.
val input_wexample : Pervasives.in_channel -> wexample_t
Reads one weighted data example from the input, e.g., 10 | 0 1 1 1
is equivalent to 10 copies of the example 0 1 1 1.
val input_wexample_list : Pervasives.in_channel -> wexample_t list
Reads a list of weighted data examples from the input.
val input_evidence : Pervasives.in_channel -> float array
Reads real-valued evidence vector from the input. Used only for
conditional distributions - for general-purpose ACs, MNs, and BNs, use
input_example to load discrete evidence values.
val input_evidence_list : Pervasives.in_channel -> float array list
Reads a list of real-valued evidence vectors from the input.
val input_example_list_schema : schema_t -> Pervasives.in_channel -> example_t list
Reads a list of data examples and validates them against the given
schema.
val input_wexample_list_schema : schema_t -> Pervasives.in_channel -> wexample_t list
Reads a list of weighted data examples and validates them against
the given schema.
val output_example : Pervasives.out_channel -> example_t -> unit
Writes an example to the output channel.
val load_data : string -> example_t list
load_data file
reads examples from file filename
and returns
them as a list.
val load_data_ar : string -> example_t array
load_data_ar file
reads examples from file filename
and returns
them as an array.
val load_evidence : string -> float array list
load_evidence filename
reads real-valued evidence vectors from
file filename
and returns them as a list.
val load_evidence_ar : string -> float array array
load_evidence_ar filename
reads real-valued evidence vectors from
file filename
and returns them as an array.
val dump_data : example_t array -> string -> unit
dump_data data filename
writes data
examples to file filename
.
Read/write marginals
val input_marginals : Pervasives.in_channel -> marginal_t array
Reads vector of marginal distributions from the input.
val output_marginals : Pervasives.out_channel -> marginal_t array -> unit
Writes vector of marginal distributions to the output.
val print_marginals : marginal_t array -> unit
Prints marginals to stdout.
Inferring schema
val schema : example_t list -> schema_t
Infers the data schema from the given examples.
val stream_schema : Pervasives.in_channel -> schema_t
Infers the data schema from the given input stream.
Validating examples
val check_point : schema_t -> example_t -> unit
check_point schema example
is used for simple input validation.
RaisesInvalid_length
for inconsistent length compared to the number
of variables in the schema, or
Invalid_value
for a variable
value that is inconsistent with the schema.
val check_evidence : schema_t -> example_t -> int array
check_evidence schema ev
runs
Data.check_point
for evidence
ev
and returns
ev
. If
ev
is an empty array, returns a new evidence
array of the appropriate dimension.
Debug
val to_string_example : example_t -> string
Converts the given example to a string.
val to_string_schema : schema_t -> string
Converts the given schema to a string.