How should the values in range be sampled, uniformly or via some function.
        :return:
431402
def dist(self):
        
        if self.func is None:
            return random.uniform(self.min, self.max)
        if self._dist is None:
            x = numpy.arange(self.min, self.max, (self.max-self.min)/1000.0)
            p = self.func(x).cumsum()
            p -= p.min()
            p /= p.max()
            self._dist = interpolate.interp1d(p, x)
        return self._dist(random.random())
1192341
def __gen_random_values(self):
        '''
        '''

        values = []
        if self._value_ranges is None:
            self._logger.log(
                'crit',
                'Must set the type/range of possible values'
            )
            raise RuntimeError("Must set the type/range of possible values")
        else:
            for t in self._value_ranges:
                if t[0] == 'int':
                    values.append(randint(t[1][0], t[1][1]))
                elif t[0] == 'float':
                    values.append(np.random.uniform(t[1][0], t[1][1]))
                else:
                    self._logger.log(
                        'crit',
                        'Value type must be either an `int` or a `float`'
                    )
                    raise RuntimeError(
                        'Value type must be either an `int` or a `float`'
                    )
        return values
393032
def samplevar(inlist):
    
    n = len(inlist)
    mn = mean(inlist)
    deviations = []
    for item in inlist:
        deviations.append(item - mn)
    return ss(deviations) / float(n)
975334
def samples(self, nsamples, rstate=None):
        

        if rstate is None:
            rstate = np.random

        xs = np.array([self.sample(rstate=rstate) for i in range(nsamples)])

        return xs
666627
def range_per(self):
    
    rp = float((self.raw_data[-1] - self.raw_data[-2]) / self.raw_data[-2] * 100)
    return rp
1304447
def sample_with_temperature(x, dim, temperature=1.0, dtype=tf.int32, name=None):
  
  dim = convert_to_dimension(dim)
  with tf.name_scope(name, default_name="sample_with_temperature"):
    if temperature != 0.0:
      # gumbel trick.
      # Note: we don't want to generate 0 or 1 because:
      # * -log(-log(0)) is -infinity
      # * -log(-log(1)) is +infinity.
      # np.finfo(x.dtype.as_numpy_dtype).tiny doesn't work on bfloat16
      tiny_val = 1e-9
      g = -log(-log(
          random_uniform(
              x.mesh,
              x.shape,
              minval=tiny_val,
              maxval=1.,
              dtype=x.dtype)))
      x += g * temperature
    return argmax(x, dim, dtype, name)
696478
def sample_random(self):
        
        if self.sampling_mode['volume']:  
            # Choose a leaf weighted by volume, randomly
            if self.leafnode:
                return self.sample_bounds()
            else:
                split_ratio = ((self.split_value - self.bounds_x[0,self.split_dim]) / 
                               (self.bounds_x[1,self.split_dim] - self.bounds_x[0,self.split_dim]))
                if split_ratio > np.random.random():
                    return self.lower.sample(sampling_mode=['random'])
                else:
                    return self.greater.sample(sampling_mode=['random'])
        else: 
            # Choose a leaf randomly
            return np.random.choice(self.get_leaves()).sample_bounds()
64342
def update(self, value):
    """"""
    super(UniformSample, self).update(value)

    self.count += 1
    c = self.count
    if c < len(self.sample):
      self.sample[c-1] = value
    else:
      r = random.randint(0, c)
      if r < len(self.sample):
        self.sample[r] = value
744806
def peaks(samples):
    
    max_index = numpy.argmax(samples)
    max_value = samples[max_index]

    min_index = numpy.argmin(samples)
    min_value = samples[min_index]

    if min_index < max_index:
        return (min_value, max_value)
    else:
        return (max_value, min_value)
1057310
def representative_sample(X, num_samples, save=False):
    
    X = X.values if hasattr(X, 'values') else np.array(X)
    N, M = X.shape
    rownums = np.arange(N)
    np.random.shuffle(rownums)

    idx = AnnoyIndex(M)
    for i, row in enumerate(X):
        idx.add_item(i, row)
    idx.build(int(np.log2(N)) + 1)

    if save:
        if isinstance(save, basestring):
            idxfilename = save
        else:
            idxfile = tempfile.NamedTemporaryFile(delete=False)
            idxfile.close()
            idxfilename = idxfile.name
        idx.save(idxfilename)
        idx = AnnoyIndex(M)
        idx.load(idxfile.name)

    samples = -1 * np.ones(shape=(num_samples,), dtype=int)
    samples[0] = rownums[0]
    # FIXME: some integer determined by N and num_samples and distribution
    j, num_nns = 0, min(1000, int(num_samples / 2. + 1))
    for i in rownums:
        if i in samples:
            continue
        nns = idx.get_nns_by_item(i, num_nns)
        # FIXME: pick vector furthest from past K (K > 1) points or outside of a hypercube
        #        (sized to uniformly fill the space) around the last sample
        samples[j + 1] = np.setdiff1d(nns, samples)[-1]
        if len(num_nns) < num_samples / 3.:
            num_nns = min(N, 1.3 * num_nns)
        j += 1
    return samples
713467
def resample(self,N):
        
        inds = rand.randint(len(self.samples),size=N)
        return self.samples[inds]
729450
def calculateRange(self, values):
        
        self.reset()
        self._values = list(set(values))
        self._values.sort(key=lambda x: values.index(x))
982387
def sample_discrete(distn,size=[],dtype=np.int32):
    ''
    distn = np.atleast_1d(distn)
    assert (distn >=0).all() and distn.ndim == 1
    if (0 == distn).all():
        return np.random.randint(distn.shape[0],size=size)
    cumvals = np.cumsum(distn)
    return np.sum(np.array(random(size))[...,na] * cumvals[-1] > cumvals, axis=-1,dtype=dtype)
221353
def get_sample_times(self):
        
        if self._epoch is None:
            return Array(range(len(self))) * self._delta_t
        else:
            return Array(range(len(self))) * self._delta_t + float(self._epoch)
898791
def safe_range(*args):
    
    rng = range(*args)
    if len(rng) > MAX_RANGE:
        raise OverflowError('range too big, maximum size for range is %d' %
                            MAX_RANGE)
    return rng
406028
def matches_sample(output, target, threshold, is_correct, actual_output):
        
        return (bool(output > threshold) == bool(target)) == is_correct and actual_output == bool(output > threshold)
114898
def polyfit(self, sampled):
        
        asampled = np.asarray(sampled)
        if len(asampled) == 1:
            return asampled
        evened = even_data(asampled)
        coeffs = dct(evened)
        return coeffs