<!--
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Bayesian Personalized Ranking}
-->

## Bayesian Personalized Ranking

The algorithm addresses the One Class Collaborative Filtering problem (OCCF) by turning it into a ranking problem and implicitly assuming that users prefer items they have already interacted with another time.
Instead of applying rating prediction techniques, BPR ranks candidate items for a user without calculating a "virtual" rating.

The overall goal of the algorithm is to find a personalized total ranking $>_u \subset I^2$ for any user $u \in Users$ and pairs of items $(i,j) \in I^2$ that meet the properties of a total order (totality, anti-symmetry, transitivity).

The model uses a pair-wise interpretation of the implicit feedback matrix and tries to reconstruct for each user parts of $>_u$, meaning a user's positive feedback represents a preference of the user over an item that the user did not provide any feedback on. In other words a positive only feedback will be transformed into positive and negative feedback in terms of pairs of items $(i,j)$, where the user prefers i over j (positive) and correspondingly rephrased dislikes j over i(negative).

Given $\Theta$ the parameter vector of a model (in rrecsys the model is a factorized matrix) to determine the personalized ranking for any $i \in I$, BPR aims to maximize $p(\Theta | >_u) \propto p(>_u|\Theta) p(\Theta)$ posterior probabilities. Optimization of $\Theta$ is achieved through a criterion called BPR-OPT which is related to the AUC metric and optimizes it implicitly. We optimized the parameter $\Theta$ with gradient descent, by choosing randomly choosing triples $(u,i,j)$ from the training data.

```{r, eval=FALSE}
bpr <- rrecsys(smallML, "BPR", k = 10, randomInit = FALSE, regU = .0025, regI = .0025, regJ = 0.0025, updateJ = TRUE)
bpr
```
_k_ is he number of features, _randomInit_ to randomly initialize to a small value the item and user feature matrix, _regU_ the regularization term for user, _regI_ the regularization term for positive item, _updateJ_ a Boolean argument to impose if negative terms must be updated and _regJ_ the regularization term for negative items. The above call is configured to the default values.

The returned object is of type _BPRclass_. 

To configure the updater to a specific number of loops:
```{r, eval=FALSE}
setStoppingCriteria(nrLoops = 10)
```
Default value is set to 10.
The threshold controller configuration:
```{r, eval=FALSE}
setStoppingCriteria(autoConverge = TRUE, deltaErrorThreshold = 1e-5, minNrLoops = 10)
```
Default values are given in the above call to the method. 

The method uses the *global environment* and a configuration will be the same for all three algorithms that require this kind of iteration.

To get more details about the slots read the reference [manual](https://CRAN.R-project.org/package=rrecsys).


