code: public static List<Integer> johnsonLindenstraussMinDim(int[] n, double... eps){
          Boolean basicCheck = n == null || n.length == 0 || eps == null || eps.length == 0;
          if (basicCheck)
              throw new IllegalArgumentException("Johnson-Lindenstrauss dimension estimation requires > 0 components and at least a relative error");
          for (double epsilon: eps){
              if (epsilon <= 0 || epsilon >= 1) {
                  throw new IllegalArgumentException("A relative error should be in ]0, 1[");
              }
          }
          List<Integer> res = new ArrayList(n.length * eps.length);
          for (double epsilon : eps){
              double denom = (Math.pow(epsilon, 2) / 2 - Math.pow(epsilon, 3) / 3);
              for (int components: n){
                  res.add((int) (4 * Math.log(components) / denom));
              }
          }
          return res;
      }
docs: Find a safe number of components to project this to, through
  the Johnson-Lindenstrauss lemma
  The minimum number n' of components to guarantee the eps-embedding is
  given by:
  
  n' >= 4 log(n) / (eps² / 2 - eps³ / 3)
  
  see http://cseweb.ucsd.edu/~dasgupta/papers/jl.pdf §2.1
  @param n Number of samples. If an array is given, it will compute
  a safe number of components array-wise.
  @param eps Maximum distortion rate as defined by the Johnson-Lindenstrauss lemma.
  Will compute array-wise if an array is given.
  @return