The python function CRL in CRL.py implements the Count-Randomize-Least squares (CRL) estimator of the paper "Feeling the Bern: Adaptive Estimators for Bernoulli Probabilities of Pairwise Comparisons" by N. B. Shah, S. Balakrishnan, M. J. Wainwright (http://arxiv.org/abs/1603.06881)

DEPENDENCIES:
This code uses the Iso package in R for the least squares step. In order to use the package, please do the following:
- You must have R installed: https://cran.cnr.berkeley.edu/
- Please download the Iso package for R: https://cran.r-project.org/web/packages/Iso/index.html
- If the Iso package is a compressed archive, uncompress it
- Now install the package in R. One way to install it is to open R, go to the Packages menu, select add package, and then select the folder where you downloaded the Iso package.
- Install the rpy2 package which allows for interfacing python with R. On OSX, go to the terminal and type "pip install rpy2" (without the quotes). See http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html for more details.
If you are using an external IDE for python such as Spyder, you may also need to change the PYTHONPATH to point to where the rpy2 package is installed.

INPUTS:
Y is an n x n matrix with entries in {0,1}, where n = number of items. The entries of Y above and below the diagonal are related as Y[i,j] = 1 - Y[j,i]
randomize_threshold is a non-negative real number such that the set chosen in the randomize step is the largest set such that every item in the set has number of pairwise wins at most randomize_threshold*sqrt(n)*log(n) of each other

OUTPUT:
An n x n matrix with entries in the interval [0,1]

Note: Sometimes, the interface between python and R gives an error "sys.stdout.write(bytes(x, 'utf-8'))
TypeError: must be str, not bytes," usually the first time that a (new) python interpreter calls R. I have found that even in the case that it throws this error, the result is reliable.

EXAMPLE:
Here is an example of a python script to interface with CRL.py

import numpy
from CRL import *
Y = numpy.array([[1, 0, 1],[0, 1, 0], [1, 1, 1]])
M = CRL(Y, 0.1)
print(M)