Next: Development, Previous: Examples, Up: Top [Contents]
The following is a list of exported predicates available to the library users’.
Each predicate corresponds to one of the following categories
Each argument of a predicate correponds to a data type. See the SWI Prolog data types manual12 and the Learn Prolog Now manual13. Have a look at the Cplint help manual14 to learn in details about the functionality of each predicate.
Given to lists X and Y build an output list Out
in the form [X1-Y1,X2-Y2,...,XN-YN]
.
Given two atoms X and Y, build the term r(X,Y)
in Out.
Given an input list L in the form [X1-Y1,X2-Y2,...,XN-YN]
,
transform it in an output list R in the form
[r(X1,Y1),r(X2,Y2),...,r(XN,YN)]
.
This means that R
will contain an X-Y relationship
which can be then passed to an R data frame.
The predicate computes and plots the probability of Query as a bar chart with a bar for the probability of Query true and a bar for the probability of Query false. If Query is not ground, it returns in backtracking all ground instantiations of Query together with their probabilities.
The predicate computes and plots the probability of Query given Evidence as a bar chart with a bar for the probability of Query true and a bar for the probability of Query false given Evidence. If Query / Evidence are not ground, it returns in backtracking all ground instantiations of Query / Evidence together with their probabilities.
See prob_bar_r/2.
The predicate samples Query a number of Samples times and plots a bar chart with a bar for the number of successes and a bar for the number of failures. If Query is not ground, it considers it as an existential query.
The predicate samples Query Samples times. Arg should be a variable in Query. The predicate plots a bar chart with a bar for each possible value of L, the list of values of Arg for which Query succeeds in a world sampled at random. The size of the bar is the number of samples returning that list of values.
The predicate samples Query Samples times. Arg should be a variable in Query. The predicate plots a bar chart with a bar for each value of Arg returned as a first answer by Query in a world sampled at random. The size of the bar is the number of samples that returned that value. The value is failure if the query fails.
The predicate calls mc_rejection_sample_arg/5
and builds an R graph
of the results.
It plots a bar chart with a bar for each possible value of L,
the list of values of Arg for which Query succeeds
given that Evidence is true
The size of the bar is the number of samples
returning that list of values.
The predicate calls mc_mh_sample_arg/6
and builds an R graph
of the results.
The predicate plots a bar chart
with a bar for each possible value of L,
the list of values of Arg for which Query succeeds in
a world sampled at random.
The size of the bar is the number of samples
returning that list of values.
The predicate calls mc_mh_sample_arg/7
and builds an R graph
of the results.
The predicate plots a bar chart
with a bar for each possible value of L,
the list of values of Arg for which Query succeeds in
a world sampled at random.
The size of the bar is the number of samples
returning that list of values.
Draws a histogram of the samples in List dividing the domain in NBins bins. List must be a list of couples of the form [V]-W or V-W where V is a sampled value and W is its weight.
Display a smooth density estimate of a sets of samples. The samples are in List as couples V-W where V is a value and W its weigth.
Display a smooth density estimate of two sets of samples, usually prior and post observations. The samples from the prior are in PriorList while the samples from the posterior are in PostList as couples V-W where V is a value and W its weigth.
The predicate takes as input a list LG of pairs probability-literal in asceding order on probability where the literal can be an Atom (incading a positive example) or \+ Atom, indicating a negative example while the probability is the probability of Atom of being true. PR and ROC diagrams are plotted. The predicate returns:
See http://cplint.lamping.unife.it/example/exauc.pl for an example.
Important predicates in this library follow a common structure to avoid confusion and promote standardization.
Interface predicates are involved in the interaction between input data from a program and the plot of that same data. These predicates are usable from the programs.
As the name suggests, plotting predicates are only involved in plotting the data.
Finally there are other functions which handle the lists and other types of data.
All interface predicates have a similar structure. Their names
end with _r
(except the Helpers) in order to distinguish them from the
original Cplint predicates.
First and last operations are always load_r_libraries
and
finalize_r_graph
respectively.
Plotting is done right before the last operation with one of the geom_
predicates.
A skeleton of the structure follows.
<cplint_graphing_predicate>_r(<input>):- load_r_libraries, <operations on the input>, geom_<something>(<new input, possibly lists>), finalize_r_graph.
Predicates directly involved in plotting all start with geom_
as prefix.
These predicates work with lists which are then transformed into R data frames, and, as a final instruction, a corresponding plot is generated.
You can visualize the structure with the following pseudocode:
geom_<something>(<Lists and/or other input>) :- <handle lists>, <create one or more R data frame with the lists data>, <rename data frame colnames to avoid using default ones>, <- ggplot <something>
List handling is useful to pass information between Prolog and
R. This is done thanks to build_xy_list/3
, r_row/3
and get_set_from_xy_list/2
predicates,
described in the interface section.
In case there are multiple distributions we simply have to call
get_set_from_xy_list/2
the appropriate number of times,
like: get_set_from_xy_list(<something>,R#)
.
As descibed before, a data frame is useful to pass structured information between Prolog and R.
In Cplint R in particular, we use r_data_frame_from_rows/2
provided by
the Rserve Client library, in the following
manner:
r_data_frame_from_rows(df[#], R[#])
For each distribution the optional number is incremented by one.
In case it is the last (or only) data frame then its name
will simply be df
.
What follows are extracts of some trivial predicates indicated as internal helpers.
bin_width(Min,Max,NBins,Width) :- D is Max-Min, Width is D/NBins. load_r_libraries :- <- library("ggplot2"). finalize_r_graph :- r_download.
See item [SWI Prolog data types] in SWI Prolog data types.
See item [LPN] in LPN.
See item [Cplint] in Cplint.
Next: Development, Previous: Examples, Up: Top [Contents]