\subsection{Graphing the Results} \label{graphing} In \texttt{cplint} on SWISH you can draw graphs for visualizing the results either with \href{http://www.c3js.org/}{C3.js} or with \href{https://www.r-project.org/}{R}. Similar predicates are available for the two methods. There are two types of graphs: those that represent individual probability values with a bar chart and those that visualize the results of sampling arguments. \subsubsection{Using C3.js} You can draw the probability of a query being true and being false as a bar chart using the predicates \begin{verbatim} bar1(+Probability:float,-Chart:dict) is det bar(+Probability:float,-Chart:dict) is det bar(+Successes:int,+Failures:int,-Chart:dict) is det argbar(+Values:list,-Chart:dict) is det \end{verbatim} They return a dict for rendering with C3.js as a bar chart: the first returns bar chart with a single bar for the probability, the second a chart with bar for the probability and a bar for one minus the probability, the third a chart with a bar for the number of successes and a bar for the number of failures, and the fourth a chart with a for bar each value, where \verb|Values| is a list of couples \verb|V-N| where \verb|V| is the value and \verb|N| is the number of samples returning that value. To render C3.js charts you have to include \begin{verbatim} :- use_rendering(c3). \end{verbatim} before \verb|:- pita.| You can also use the \verb|bar(-Chart:dict)| option of many predicates as in \begin{verbatim} ?- prob(heads(coin),biased(coin),P,[bar(Chart)]). \end{verbatim} \verb|P| will be instantiated with a chart with a bar for the probability of \verb|heads(coin)| true and a bar for the probability of \verb|heads(coin)| false, given that \verb|biased(coin)| is true. Another example is \begin{verbatim} ?- mc_prob(heads(coin),P,[bar(Chart)]). \end{verbatim} that returns a chart representation of the probability. \begin{verbatim} ?- mc_sample(heads(coin),1000,P,[bar(Chart)]). \end{verbatim} returns in \verb|Chart| a diagram with one bar for the number of successes and one bar for the number of failures. The options of \verb|mc_sample_arg/5|, \verb|mc_sample_arg_first/5|, \verb|mc_mh_sample_arg/6|, \verb|mc_rejection_sample_arg/6|, can be used for visualizing the results of sampling arguments. An example is \begin{verbatim} ?- mc_sample_arg(reach(s0,0,S),50,S,ValList,[bar(Chart)]). \end{verbatim} of \href{http://cplint.eu/example/inference/markov_chain.pl}{\texttt{markov\_chain.pl}}. The same result can be achieved with \begin{verbatim} ?- mc_sample_arg(reach(s0,0,S),50,S,ValList),argbar(ValList,Chart) \end{verbatim} Drawing a graph is particularly interesting when sampling values for continuous arguments of goals. In this case, you can use the samples to draw the probability density function of the argument. The predicate \begin{verbatim} histogram(+List:list,-Chart:dict,+Options:list) is det \end{verbatim} draws a histogram of the samples in \verb|List| that must be a list of couples of the form \verb|[V]-W| or \verb|V-W| where \verb|V| is a sampled value and \verb|W| is its weight. This is the format of the list of samples returned by argument sampling predicates. The predicate \begin{verbatim} density(+List:list,-Chart:dict,+Options:list) is det \end{verbatim} draws a line chart of the density of the samples in \verb|List| that must take the same form as for \verb|histogram/3|. In \verb|histogram/3| and \verb|density/3| \verb|Options| is a list of options, the following are recognised: \begin{itemize} \item \verb|min(+Min:float)| the minimum value of domain, default value the minimum in \verb|List| \item \verb|max(+Max:float)| the maximum value of domain, default value the maximum in \verb|List| \item \verb|nbins(+NBins:int)| the number of bins for dividing the domain, default value 40 \end{itemize} In this way you can specify the limits and the number of intervals of the $X$. The predicate \begin{verbatim} densities(+PriorList:list,+PostList:list,-Chart:dict, +Options:list) is det \end{verbatim} draws a line chart of the density of two sets of samples, usually prior and post observations. The samples in \verb|PriorList| and \verb|PostList| can be either couples \verb|[V]-W| or \verb|V-W| where \verb|V| is a value and \verb|W| its weight. The same options as for \verb|histogram/3| and \verb|density/3| are recognized. For example, the query \begin{verbatim} ?- mc_sample_arg(value(0,X),1000,X,L0,[]), histogram(L0,Chart,[]). \end{verbatim} from \href{http://cplint.eu/example/inference/gauss_mean_est.pl}{\texttt{gauss\_mean\_est.pl}}, takes 1000 samples of argument \verb|X| of \verb|value(0,X)| and draws the density of the samples using an histogram. Instead \begin{verbatim} ?- mc_sample_arg(value(0,Y),1000,Y,L0,[]), mc_lw_sample_arg(value(0,X), (value(1,9),value(2,8)),1000,X,L), densities(L0,L,Chart). \end{verbatim} from \href{http://cplint.eu/example/inference/gauss_mean_est.pl}{\texttt{gauss\_mean\_est.pl}} takes 1000 samples of argument \verb|X| of \verb|value(0,X)| before and after observing \verb|(value(1,9),value(2,8)| and draws the prior and posterior densities of the samples using a line chart. Predicates \verb|histogram/3|, \verb|density/3| and \verb|densities/4| each have a version with one argument less that is equivalent to the predicate called with an empty option list. \subsubsection{Using R} You have to load library \texttt{cplint\_r} (a SWI-Prolog pack) with \begin{verbatim} :- use_module(library(cplint_r)). \end{verbatim} Then you can use predicates \begin{verbatim} bar_r/1 bar_r/2 argbar_r/1 \end{verbatim} that work as their C3.js counterpart but do not return the graph as an argument as the graph is printed with a different mechanism. You also have \begin{verbatim} histogram_r(+List:list,+Options:list) is det \end{verbatim} that works as \texttt{histogram/3}. \begin{verbatim} density_r(+List:list) is det \end{verbatim} is like \texttt{density/3} with the number of bins is determined by R. \begin{verbatim} densities_r(+PriorList:list,+PostList:list) is det \end{verbatim} is like \texttt{densities/3} with the number of bins is determined by R. See \href{http://cplint.eu/example/inference/gauss_mean_est_R.pl}{\texttt{gauss\_mean\_est\_R.pl}} for an example of use of these predicates.