# Approximate Bayesian Computation

To get the approximate Bayesian computation for a given dataset, one can use function get.MaxWiK(), here, please, try 2D example:

```{r, include = TRUE, echo=TRUE, eval=FALSE}
example.2D = MaxWiK::Data.2D
obs        = as.data.frame( t ( example.2D$observation$A ) )
Matrix.Voronoi  =  example.2D$ABC$Matrix.Voronoi
res.MaxWik = get.MaxWiK( psi = example.2D$ABC$hyperparameters$psi, 
                         t   = example.2D$ABC$hyperparameters$t, 
                         param    = example.2D$X, 
                         stat.sim = example.2D$Y, 
                         stat.obs =  obs, 
                         talkative = TRUE, 
                         check_pos_def = TRUE, 
                         Matrix_Voronoi = Matrix.Voronoi )
```

To see the Posteriori a user can extract points with non-zero similarity:

```{r, include = TRUE, echo=TRUE, eval=FALSE}
w.sim = which(res.MaxWik$similarity > 0 )
posteriori.MaxWiK = Data.2D$X[ w.sim, ]
```

That looks like that (red dashed lines are true values of X1 and X2):

```{r, include = TRUE, eval=TRUE, echo=FALSE, fig.height=3, fig.width=4.5}
library(ggplot2)
library(MaxWiK)
obs=MaxWiK::Data.2D$observation
res.MaxWik = MaxWiK::Data.2D$ABC$result.MaxWiK
w.sim = which(res.MaxWik$similarity > 0 )
posteriori.MaxWiK = MaxWiK::Data.2D$X[ w.sim, ]
MaxWiK::MaxWiK.ggplot.density( title = ' Posteriori distribution of X1 parameter', 
                           datafr1 = posteriori.MaxWiK, 
                           datafr2 = NULL, 
                           var.df = 'par.sim.X1', 
                           obs.true = obs$x0[ 1 ], 
                           best.sim = NULL )
```

```{r, include = TRUE, eval=TRUE, echo=FALSE, fig.height=3, fig.width=4.5}
library(ggplot2)
library(MaxWiK)
obs=MaxWiK::Data.2D$observation
res.MaxWik = MaxWiK::Data.2D$ABC$result.MaxWiK
w.sim = which(res.MaxWik$similarity > 0 )
posteriori.MaxWiK = MaxWiK::Data.2D$X[ w.sim, ]
MaxWiK::MaxWiK.ggplot.density( title = ' Posteriori distribution of X2 parameter', 
                   datafr1 = posteriori.MaxWiK, 
                   datafr2 = NULL, 
                   var.df = 'par.sim.X2', 
                   obs.true = obs$x0[ 2 ], 
                   best.sim = NULL )
```
