Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/916#discussion_r13613361
  
    --- Diff: 
core/src/main/scala/org/apache/spark/util/random/SamplingUtils.scala ---
    @@ -0,0 +1,50 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.util.random
    +
    +private[spark] object SamplingUtils {
    +
    +  /**
    +   * Let p = num / total, where num is the sample size and total is the 
total number of
    +   * datapoints in the RDD. We're trying to compute q > p such that
    +   *   - when sampling with replacement, we're drawing each datapoint with 
prob_i ~ Pois(q),
    +   *     where we want to guarantee Pr[s < num] < 0.0001 for s = 
sum(prob_i for i from 0 to total),
    +   *     i.e. the failure rate of not having a sufficiently large sample < 
0.0001.
    +   *     Setting q = p + 5 * sqrt(p/total) is sufficient to guarantee 
0.9999 success rate for
    +   *     num > 12, but we need a slightly larger q (9 empirically 
determined).
    +   *   - when sampling without replacement, we're drawing each datapoint 
with prob_i
    +   *     ~ Binomial(total, fraction) and our choice of q guarantees 
1-delta, or 0.9999 success
    +   *     rate, where success rate is defined the same as in sampling with 
replacement.
    +   *
    +   * @param num sample size
    +   * @param total size of RDD
    +   * @param withReplacement whether sampling with replacement
    +   * @return a sampling rate that guarantees sufficient sample size with 
99.99% success rate
    +   */
    +  def computeFraction(num: Int, total: Long, withReplacement: Boolean): 
Double = {
    --- End diff --
    
    Let's give it a more descriptive name, e.g., 
`computeFractionForLeastSampleSize`. You may have a better name.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to