Choose the delta at the scale of distance
   between x and perturbed sample.
346347
def select_delta(dist_post_update, current_iteration,
                 clip_max, clip_min, d, theta, constraint):
  
  if current_iteration == 1:
    delta = 0.1 * (clip_max - clip_min)
  else:
    if constraint == 'l2':
      delta = np.sqrt(d) * theta * dist_post_update
    elif constraint == 'linf':
      delta = d * theta * dist_post_update

  return delta
150046
def predict(self, X):
        """"""
        return self.__cost(self.__unroll(self.__thetas), 0, np.matrix(X))
1369154
def dnde(self, x, params=None):
        """"""
        params = self.params if params is None else params
        return np.squeeze(self.eval_dnde(x, params, self.scale,
                                         self.extra_params))
903680
private int sampleLine(ResultPoint p1, ResultPoint p2, int size) {
    int result = 0;

    float d = distance(p1, p2);
    float moduleSize = d / size;
    float px = p1.getX();
    float py = p1.getY();
    float dx = moduleSize * (p2.getX() - p1.getX()) / d;
    float dy = moduleSize * (p2.getY() - p1.getY()) / d;
    for (int i = 0; i < size; i++) {
      if (image.get(MathUtils.round(px + i * dx), MathUtils.round(py + i * dy))) {
        result |= 1 << (size - i - 1);
      }
    }
    return result;
  }
232639
def _sample_points(X, centers, oversampling_factor, random_state):
    

    """
    # re-implement evaluate_cost here, to avoid redundant computation
    distances = pairwise_distances(X, centers).min(1) ** 2
    denom = distances.sum()
    p = oversampling_factor * distances / denom

    draws = random_state.uniform(size=len(p), chunks=p.chunks)
    picked = p > draws

    new_idxs, = da.where(picked)
    return new_idxs
173820
def change_response(x, prob, index):
    '''
    
    '''
    #pdb.set_trace()
    N = (x==index).sum()
    #x[x==index]=9
    x[x==index] = dist.sample(N)
926689
private int findSampleRate(int sampleIndex, int version)
	{
		int ind = -1;

		switch (version)
		{
			case MPEG_V_1:
				ind = 0;
				break;
			case MPEG_V_2:
				ind = 1;
				break;
			case MPEG_V_25:
				ind = 2;
		}

		if ((ind != -1) && (sampleIndex >= 0) && (sampleIndex <= 3))
		{
			return sampleTable[sampleIndex][ind];
		}
		return -1;
	}
550243
private double delta(double y, double bMutationParameter) {
    double rand = randomGenenerator.getRandomValue();
    int it, maxIt;
    it = currentIteration;
    maxIt = maxIterations;

    return (y * (1.0 -
        Math.pow(rand,
            Math.pow((1.0 - it / (double) maxIt), bMutationParameter)
        )));
  }
116891
def _sample_d(self):
        

        p = self._get_next() / PRNG_MAX_RAND
        for ix, v in enumerate(self.cdf):
            if v > p:
                return ix + 1
        return ix + 1
924021
function sampleSizeFraction(num, total, withReplacement) {
  const minSamplingRate = 1e-10;        // Limited by RNG's resolution
  const delta = 1e-4;                   // To have 0.9999 success rate
  const fraction = num / total;
  let upperBound;

  if (withReplacement) {
    // Poisson upper bound for Pr(num successful poisson trials) > (1-delta)
    let numStd = num < 6 ? 12 : num < 16 ? 9 : 6;
    upperBound = Math.max(num + numStd * Math.sqrt(num), minSamplingRate) / total;
  } else {
    // Binomial upper bound for Pr(num successful bernoulli trials) > (1-delta)
    let gamma = - Math.log(delta) / total;
    upperBound = Math.min(1, Math.max(minSamplingRate, fraction + gamma + Math.sqrt(gamma * gamma + 2 * gamma * fraction)));
  }
  return upperBound;
}
493865
def at_time(self, time, nearest_sample=False):
        
        if nearest_sample:
            time += self.delta_t / 2.0
        return self[int((time-self.start_time)*self.sample_rate)]
1082079
def feature_scaling(x, xmin, xmax, a=0, b=1):
    ''''''
    return a + float(x - xmin) * (b - a) / (xmax - xmin)
528732
def _scale_prof(step, rprof, rad=None):
    """"""
    rbot, rtop = misc.get_rbounds(step)
    if rbot == 0:  # not spherical
        return rprof
    if rad is None:
        rad = step.rprof['r'].values + rbot
    return rprof * (2 * rad / (rtop + rbot))**2
1018310
def downsample(self, sample_factor=2):
        
        if sample_factor < 0:
            raise Exception('Factor for subsampling must be postive, got %g' % sample_factor)
        newlength = floor(len(self.index) / sample_factor)
        func = lambda v: v[0:int(newlength * sample_factor)].reshape(-1, sample_factor).mean(axis=1)
        newindex = arange(newlength)
        return self.map(func, index=newindex)
995101
def tdist_ci(x, df, stderr, level):
    
    q = (1 + level)/2
    delta = stats.t.ppf(q, df) * stderr
    return x - delta, x + delta
1036285
def sample_epsilon_greedy(self, epsilon=0.1):
        
        if epsilon > np.random.random():
            sampling_mode = self.sampling_mode
            sampling_mode['mode'] = 'random'
            return self.sample(sampling_mode=sampling_mode)
        else:
            sampling_mode = self.sampling_mode
            sampling_mode['mode'] = 'greedy'
            return self.sample(sampling_mode=sampling_mode)
684323
def noise_uniform(self, lower_bound, upper_bound):
        """"""
        assert upper_bound > lower_bound
        nu = self.sym.sym('nu_{:d}'.format(len(self.scope['nu'])))
        self.scope['nu'].append(nu)
        return lower_bound + nu*(upper_bound - lower_bound)