implementation of Rand index