Module Ext
module Ext: sig
.. end
The ext library includes miscellaneous utility functions,
extensions to the OCaml standard library (including List and Array),
and two utility modules, Timer and Heap (priority queue implemented as
a binary heap). ext also includes common arguments, shared
mechanisms for working with log files, probability distributions, and
more.
module List: sig
.. end
Standard Ocaml List module with extended functionality.
module Array: sig
.. end
Standard Ocaml Array module with extended functionality.
module Hashtbl: sig
.. end
Standard Ocaml Hashtbl module with extended functionality.
module Hashset: sig
.. end
Hashset
is similar to Hashtbl
, but it stores only keys, and
the value is unit
for all keys.
module String: sig
.. end
module Heap: sig
.. end
Simple implementation of an array-based binary heap in OCaml.
module Timer: sig
.. end
Named timers.
Supported filetypes
type
libra_filetype =
| |
ACFile |
| |
BNFile |
| |
MNFile |
| |
DataFile |
| |
SPNFile |
| |
UnknownFile |
val filetype : string -> libra_filetype
Utility functions
val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
val ($) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
val identity : 'a -> 'a
Returns its arguement.
Mathematical functions
val absf : float -> float
Returns the absolute value.
val f_true : 'a -> bool
Tautology function, i.e. always returns true
.
val log_zero : float
Negative infinity constant.
val log_one : float
Zero constant.
val maxf : float -> float -> float
maxf x y
returns the maximum of the float values x
and y
.
val minf : float -> float -> float
minf x y
returns the minmum of the float values x
and y
.
val fast_exp : float -> float
fast_exp x
returns the exponential of the given argument, but
approximates very small return values with zero. If x
is smaller
than -37.0 it returns zero.
val logsumexp : float list -> float
logsumexp xl
computes log(\sum_i e^{x_i})
, where x_i
is the
i
th entry of the float list xl
. This function avoids numerical
underflow.
val alogsumexp : float array -> float
logsumexp xa
computes log(\sum_i e^{x_i})
, where x_i
is the
i
th entry of the float array xa
. This function avoids numerical
underflow.
val logsumexp2 : float -> float -> float
logsumexp2 x y
computes log(exp(x)+exp(y)
, but avoids
numerical underflow.
exception EmptyList
val dotprod : float list -> float list -> float
dotprod xl yl
returns the dot product of the two float lists
xl
and yl
.
Raises EmptyList
if the lists have different lengths.
val dotprod_bias : float list -> float list -> float -> float
dotprod_bias xl yl bias
returns the dot product of the two float
lists xl
and yl
plus the bias bias
. If the size of yl
is
greater than xl
it ignores the extra elements in yl
.
Raises EmptyList
if the size of xl
is greater than the size of yl
.
val adotprod : float array -> float array -> float
adotprod xa ya
returns the dot product of the two float array
xa
and ya
. If the size of ya
is greater than the size of xa
it
ignores the extra elements in ya
.
val adotprod_bias : float array -> float array -> float -> float
adotprod_bias xa ya
returns the dot product of the two float
array xa
and ya
plus the bias term bias
. if the size ya
is
greater than the size of xl
it ignores the extra elements in ya
.
val adotprod_autobias : float array -> float array -> float
adotprod_autobias xa ya
returns the dot product of the two float
array xa
and ya
and assumes that the last entry in ya
is the
bias term. It assumes that the size of ya
is one item more than the
size of xa
.
val normalize_inplace_raw : float array -> unit
normalize_inplace_raw xa
Normalizes the elements of xa
so that
they represent a valid probability distribution. Modifies xa
in
place.
val normalize_inplace_log : float array -> unit
normalize_inplace_log xa
Normalizes the elements of xa
so that
they represent the log probabilities of a valid probability
distribution. Modifies xa
in place.
val normalize_raw : float array -> float array
Similar to normalize_inplace_raw
, but returns a new array as the
result (does not modify the argument.
val normalize_log : float array -> float array
Similar to normalize_inplace_log
, but returns a new array as the
result (does not modify the argument.
Functions for gathering statistics conveniently
type
stats_counter = float Pervasives.ref * float Pervasives.ref * float Pervasives.ref
val stats_make : unit -> stats_counter
Create an object to help compute of mean and variance statistics.
val stats_add : stats_counter -> float -> unit
stats_add s w x
adds one observation of x to the counters
val stats_wadd : stats_counter -> float -> float -> unit
stats_wadd s w x
adds w observations of x to the counters
val stats_n : stats_counter -> float
stats_n s
returns the number of (weighted) observations
val stats_sum : stats_counter -> float
stats_sum s
returns the sum of the observations
val stats_mean : stats_counter -> float
stats_mean s
returns the arithmetic mean of the observations
val stats_var : stats_counter -> float
stats_var s
returns the estimated variance of the observations
val stats_stddev : stats_counter -> float
stats_stddev s
returns the standard deviation of the observations
val stats_stderr : stats_counter -> float
stats_stderr s
returns the standard deviation of the mean
Common argument handling
val common_arguments : (string * Arg.spec * string) list
Set of arguments common to most programs
I/O and Debuging functions
val output_int : Pervasives.out_channel -> int -> unit
output_int out i
writes the integer value i
on the output
channel out
.
val output_float : Pervasives.out_channel -> float -> unit
output_float out f
writes the float value f
on the output
channel out
.
val output_sep : Pervasives.out_channel -> string -> string array -> unit
output_string ouput sep sa
concatinates the string elements of
the string array sa
using the separator sep
, and then writes the
result on the output channel out
.
val log_normal : string
Constant string normal
for logging in the normal mode.
val log_verbose : string
Constant string verbose
for logging in the verbose mode.
val log_debug : string
Constant string debug
for logging in the debug mode.
val log_hash : (string, Pervasives.out_channel) Hashtbl.t
Used for mapping output channel to a specific name. Libra uses
normal, verbose, debug
for the output channel name.
val register_log : string -> Pervasives.out_channel -> unit
register_log name out
maps the output channel out
to the
string name
.
val unregister_log : string -> unit
unregister_log name
removes the channel-name mapping for the
given name
.
val log_exists : string -> bool
Checks if the given name maps to any output channel.
val log_stream : string -> Pervasives.out_channel
Returns the output channel corresponding to the given name.
val log_string : string -> string -> unit
Outputs a string to the specified log, if defined.
val logf : string -> ('a, unit, string, unit) Pervasives.format4 -> 'a
logf outname fmt arg1 ... argN
prints to a log named outname
with printf-style formatting. outname
can be one of the default log names, or a registered log. (A new log can be registered using register_log channel outname
).
val nlogf : ('a, unit, string, unit) Pervasives.format4 -> 'a
Prints to a log with printf-style formatting in the normal mode.
val vlogf : ('a, unit, string, unit) Pervasives.format4 -> 'a
Prints to a log with printf-style formatting in the verbose mode.
val vlogfz : ('a -> unit, unit, string, unit) Pervasives.format4 -> 'a lazy_t -> unit
Prints to a log with printf-style formatting in the verbose mode.
vlogfz
performes lazy argument evaluation, so its arguments should
be lazy expressions, e.g. vlogfz "%d" (lazy (exp))
. vlogfz
accepts only one argument.
val vlogfz2 : ('a -> 'b -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> unit
Similar to vlogfz
, but accepts two lazy arguments.
val vlogfz3 : ('a -> 'b -> 'c -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> 'c lazy_t -> unit
Similar to vlogfz
, but accepts three lazy arguments.
val vlogfz4 : ('a -> 'b -> 'c -> 'd -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> 'c lazy_t -> 'd lazy_t -> unit
Similar to vlogfz
, but accepts four arguments.
val dlogf : ('a, unit, string, unit) Pervasives.format4 -> 'a
Prints to a log with printf-style formatting in the debug mode.
val dlogfz : ('a -> unit, unit, string, unit) Pervasives.format4 -> 'a lazy_t -> unit
Prints to a log with printf-style formatting in the debug mode.
dlogfz
performes lazy argument evaluation, so its arguments should
be lazy expressions, e.g. dlogfz "%d" (lazy (exp))
. dlogfz
accepts only one argument.
val dlogfz2 : ('a -> 'b -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> unit
Similar to dlogfz
, but accepts two lazy arguments.
val dlogfz3 : ('a -> 'b -> 'c -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> 'c lazy_t -> unit
Similar to dlogfz
, but accepts three lazy arguments.
val dlogfz4 : ('a -> 'b -> 'c -> 'd -> unit, unit, string, unit) Pervasives.format4 ->
'a lazy_t -> 'b lazy_t -> 'c lazy_t -> 'd lazy_t -> unit
Similar to dlogfz
, but accepts four lazy arguments.
val log_args : unit -> unit
Prints the arguments to a log in the verbose mode.
val common_log_init : unit -> unit
Initializes the common log channels in Libra.
val debug : string -> unit
Prints the given string into the standard output.
val string_of_ilist : int list -> string
Converts an int list to a string.
val string_of_flist : float list -> string
Converts a float list to a string.
val string_of_iarray : int array -> string
Converts an int array to a string.
val string_of_farray : float array -> string
Converts a float array to a string.