Initialise from a function to sample.
        N: optional parameter which indicates the range of the dichotomy
556559
def from_function(self, f, domain=None, N=None):
        
        # rescale f to the unit domain
        domain = self.get_default_domain(domain)
        a,b = domain[0], domain[-1]
        map_ui_ab = lambda t: 0.5*(b-a)*t + 0.5*(a+b)
        args = {'f': lambda t: f(map_ui_ab(t))}
        if N is not None: # N is provided
            nextpow2 = int(np.log2(N))+1
            args['kmin'] = nextpow2
            args['kmax'] = nextpow2+1
            args['raise_no_convergence'] = False
        else:
            args['raise_no_convergence'] = True

        # Find out the right number of coefficients to keep
        coeffs = self.dichotomy(**args)

        return self.from_coeff(coeffs, domain)
101524
def asmono(samples:np.ndarray, channel:Union[int, str]=0) -> np.ndarray:
    
    if numchannels(samples) == 1:
        # it could be [1,2,3,4,...], or [[1], [2], [3], [4], ...]
        if isinstance(samples[0], float):
            return samples
        elif isinstance(samples[0], np.dnarray):
            return np.reshape(samples, (len(samples),))
        else:
            raise TypeError("Samples should be numeric, found: %s"
                            % str(type(samples[0])))
    if isinstance(channel, int):
        return samples[:, channel]
    elif channel == 'mix':
        return _mix(samples, scale_by_numchannels=True)
    else:
        raise ValueError("channel has to be an integer indicating a channel,"
                         " or 'mix' to mix down all channels")
393032
def samplevar(inlist):
    
    n = len(inlist)
    mn = mean(inlist)
    deviations = []
    for item in inlist:
        deviations.append(item - mn)
    return ss(deviations) / float(n)
451241
function createRange(fromRight) {
  return function(start, end, step) {
    if (step && typeof step != 'number' && _isIterateeCall(start, end, step)) {
      end = step = undefined;
    }
    // Ensure the sign of `-0` is preserved.
    start = toFinite_1(start);
    if (end === undefined) {
      end = start;
      start = 0;
    } else {
      end = toFinite_1(end);
    }
    step = step === undefined ? (start < end ? 1 : -1) : toFinite_1(step);
    return _baseRange(start, end, step, fromRight);
  };
}
989220
def _set_initial_x(self):
        

        return np.random.random(self._data_shape).astype(self._data_type)
736875
def get_in_samples(samples, fn):
    
    for sample in samples:
        sample = to_single_data(sample)
        if fn(sample, None):
            return fn(sample)
    return None
345451
function(n, loc, scale) {
                    n = this._v(n, "n");
                    loc = this._v(loc, "r", 0);
                    scale = this._v(scale, "nn", 1);

                    var toReturn = [];

                    for(var i=0; i<n; i++) {
                        var core = this.sample([-1,1])[0] * ln(this.prng());

                        var x = loc - scale * core;

                        toReturn[i] = x;
                    }

                    return toReturn
                }
325784
def sampleset(self):
        """"""
        x1, x4 = self.bounding_box
        dw = self.width * 0.5
        x2 = self.x_0 - dw
        x3 = self.x_0 + dw

        if self._n_models == 1:
            w = [x1, x2, x3, x4]
        else:
            w = list(zip(x1, x2, x3, x4))

        return np.asarray(w)
212014
def initialize(decision_function, sample, shape, clip_min, clip_max):
  
  success = 0
  num_evals = 0

  # Find a misclassified random noise.
  while True:
    random_noise = np.random.uniform(clip_min, clip_max, size=shape)
    success = decision_function(random_noise[None])[0]
    if success:
      break
    num_evals += 1
    message = "Initialization failed! Try to use a misclassified image as `target_image`"
    assert num_evals < 1e4, message

  # Binary search to minimize l2 distance to original image.
  low = 0.0
  high = 1.0
  while high - low > 0.001:
    mid = (high + low) / 2.0
    blended = (1 - mid) * sample + mid * random_noise
    success = decision_function(blended[None])[0]
    if success:
      high = mid
    else:
      low = mid

  initialization = (1 - high) * sample + high * random_noise
  return initialization
164289
function sample(alpha, beta) {
    var u = jStat.randg(alpha);
    return u / (u + jStat.randg(beta));
  }
119319
def _call(self, x, out=None):
        
        if out is None:
            return x.interpolation
        else:
            out.sampling(x.interpolation)
145554
function range(n,type) {
  n = (typeof n !== 'undefined') ?  n : 0;
  if (!(Number.isInteger(n))) throw Error("Error in range: Value must be an integer");
  let array;
    
  if(type=='Uint8')  array = new Uint8Array(n);
  if(type=='Uint16') array = new Uint16Array(n);
  if(type=='Uint32') array = new Uint32Array(n);
  if(type=='Int8')  array = new Int8Array(n);
  if(type=='Int16') array = new Int16Array(n);
  if(type=='Int32') array = new Int32Array(n);
  if(type=='Float32')  array = new Float32Array(n);
  if((typeof type === 'undefined') || !array)array = new Array(n);
    
  for(let i=0;i<n;i++)array[i]=i;
  return array;
}
612705
def _range_func(self, withscores, score_cast_func):
        
        if withscores:
            return lambda score_member: (score_member[1], score_cast_func(self._encode(score_member[0])))  # noqa
        else:
            return lambda score_member: score_member[1]
413933
def set_rf_samples(n):
    
    forest._generate_sample_indices = (lambda rs, n_samples:
        forest.check_random_state(rs).randint(0, n_samples, n))
1065897
def n_func(self):
        '''
        
        '''
        return interpolate.interp2d(self.x, self.y, self.n)
1284108
def _before_after(n_samples):
    """"""
    if not isinstance(n_samples, (tuple, list)):
        before = n_samples // 2
        after = n_samples - before
    else:
        assert len(n_samples) == 2
        before, after = n_samples
        n_samples = before + after
    assert before >= 0
    assert after >= 0
    assert before + after == n_samples
    return before, after
804151
def sample_given_context(self, c, c_dims):
        '''
        
        '''
        return self.sample()[list(set(range(self.ndims)) - set(c_dims))]