Optimize categorical

Added optimized code for Categorical distributions greatly diminishing runtime if #categories < #samples. This might be a case of premature optimization though, so I leave it up to John wether or not to merge this.