Randomly augment a single image tensor.

        # Arguments
            sample: 3D or 4D tensor, single sample.
            seed: random seed.

        # Returns
            A randomly transformed version of the input (same shape).
738
def random_transform(self, sample, seed=None):
        
        img_row_axis = self.row_axis - 1
        img_col_axis = self.col_axis - 1
        img_channel_axis = self.channel_axis - 1

        transform_matrix = self.get_random_transform_matrix(sample, seed)

        if transform_matrix is not None:
            h, w = sample.shape[img_row_axis], sample.shape[img_col_axis]
            transform_matrix = transform_matrix_offset_center(transform_matrix, h, w)
            sample = apply_transform(sample, transform_matrix, img_channel_axis,
                                     fill_mode=self.fill_mode, cval=self.cval)

        if self.channel_shift_range != 0:
            sample = random_channel_shift(sample,
                                          self.channel_shift_range,
                                          img_channel_axis)
        if self.horizontal_flip:
            if np.random.random() < 0.5:
                sample = flip_axis(sample, img_col_axis)

        if self.vertical_flip:
            if np.random.random() < 0.5:
                sample = flip_axis(sample, img_row_axis)

        return sample
713467
def resample(self,N):
        
        inds = rand.randint(len(self.samples),size=N)
        return self.samples[inds]
475952
def cifar_image_augmentation(images):
  
  images = tf.image.resize_image_with_crop_or_pad(images, 40, 40)
  images = tf.random_crop(images, [32, 32, 3])
  images = tf.image.random_flip_left_right(images)
  return images
219587
def random_draw(self, size=None):
        
        return scipy.asarray([numpy.random.uniform(low=b[0], high=b[1], size=size) for b in self.bounds])
965959
def random_crop_and_flip(x, pad_rows=4, pad_cols=4):
  """"""
  rows = tf.shape(x)[1]
  cols = tf.shape(x)[2]
  channels = x.get_shape()[3]

  def _rand_crop_img(img):
    """Randomly crop an individual image"""
    return tf.random_crop(img, [rows, cols, channels])

  # Some of these ops are only on CPU.
  # This function will often be called with the device set to GPU.
  # We need to set it to CPU temporarily to avoid an exception.
  with tf.device('/CPU:0'):
    x = tf.image.resize_image_with_crop_or_pad(x, rows + pad_rows,
                                               cols + pad_cols)
    x = tf.map_fn(_rand_crop_img, x)
    x = tf.image.random_flip_left_right(x)
  return x
509114
def sample_view(min_dist, max_dist=None):
  '''
  '''
  if max_dist is None:
    max_dist = min_dist
  dist = np.random.uniform(min_dist, max_dist)
  eye = np.random.normal(size=3)
  eye = normalize(eye)*dist
  return lookat(eye)
52361
def random_samples(self, n):
        
        samples = self.samples
        inds = rand.randint(len(samples),size=int(n))

        newsamples = samples.iloc[inds]
        newsamples.reset_index(inplace=True)
        return newsamples
1059943
def samples_multidimensional_uniform(bounds,num_data):
    '''
    

    '''
    dim = len(bounds)
    Z_rand = np.zeros(shape=(num_data,dim))
    for k in range(0,dim): Z_rand[:,k] = np.random.uniform(low=bounds[k][0],high=bounds[k][1],size=num_data)
    return Z_rand
617351
def random(self, shape, tf_fn, kwargs):
    
    # TODO(noam): can we make things better with stateless_random?
    slice_shape = self.slice_shape(shape)
    x = tf_fn(slice_shape, **kwargs)
    # TPU does not have seeds enabled.  Sync up the
    # random choices by zeroing out all but the first core per group of
    # identical slices, then allreducing by group.
    layout = self.tensor_layout(shape)
    # we need to sync across these axes.
    mesh_axes = [i for i in xrange(self.ndims)
                 if i not in layout.tensor_axis_to_mesh_axis]
    multiplier = 1.0
    for axis in mesh_axes:
      multiplier *= tf.cast(
          tf.equal(self.laid_out_pcoord(axis).one_slice, 0), x.dtype)
    x *= multiplier
    x = self.LaidOutTensor([x])
    x = self.allreduce(x, mesh_axes, "SUM")
    return x
730891
def sample(self, nsample=None, **kwargs):
        
        if len(kwargs) > 0:
            self.update(**kwargs)
        return self.distribution.rvs(*self.args, size=len(self),
                                     loc=self.loc, scale=self.scale)
604104
def sample(img, coords):
    
    shape = img.get_shape().as_list()[1:]   # h, w, c
    batch = tf.shape(img)[0]
    shape2 = coords.get_shape().as_list()[1:3]  # h2, w2
    assert None not in shape2, coords.get_shape()
    max_coor = tf.constant([shape[0] - 1, shape[1] - 1], dtype=tf.float32)

    coords = tf.clip_by_value(coords, 0., max_coor)  # borderMode==repeat
    coords = tf.cast(coords, tf.int32)

    batch_index = tf.range(batch, dtype=tf.int32)
    batch_index = tf.reshape(batch_index, [-1, 1, 1, 1])
    batch_index = tf.tile(batch_index, [1, shape2[0], shape2[1], 1])    # bxh2xw2x1
    indices = tf.concat([batch_index, coords], axis=3)  # bxh2xw2x3
    sampled = tf.gather_nd(img, indices)
    return sampled
1027436
def _sample_rows(self, X, Y, sample_shape, seed):
        
        if sample_shape[0] is None or X.shape[0] <= sample_shape[0]:
            X_sample, Y_sample = X, Y
        elif Y is None:
            np.random.seed(seed)
            row_indices = np.random.choice(
                X.shape[0], size=sample_shape[0], replace=False
            )
            X_sample, Y_sample = X.iloc[row_indices], Y
        else:
            drop_size = X.shape[0] - sample_shape[0]
            sample_size = sample_shape[0]
            sss = StratifiedShuffleSplit(
                n_splits=2, test_size=drop_size, train_size=sample_size, random_state=seed
            )
            row_indices, _ = next(sss.split(X, Y))
            X_sample, Y_sample = X.iloc[row_indices], Y.iloc[row_indices]
        return (X_sample, Y_sample)
899992
def samples(self, gp, Y_metadata=None, **kw):
        
        orig_shape = gp.shape
        gp = gp.flatten()
        N = Y_metadata['trials']
        Ysim = np.random.binomial(N, self.gp_link.transf(gp))
        return Ysim.reshape(orig_shape)
504033
@Override
    public INDArray rand(int[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
        //ensure shapes that wind up being scalar end up with the write shape
        if (shape.length == 1 && shape[0] == 0) {
            shape = new int[] {1, 1};
        }
        return Nd4j.getDistributions().createUniform(min, max).sample(shape);
    }
219635
def samples(self, gp, Y_metadata=None):
        
        orig_shape = gp.shape
        gp = gp.flatten()
        #orig_shape = gp.shape
        gp = gp.flatten()
        Ysim = np.array([np.random.normal(self.gp_link.transf(gpj), scale=np.sqrt(self.variance), size=1) for gpj in gp])
        return Ysim.reshape(orig_shape)
515328
def sample(self, sampling_mode=None):
        
        if sampling_mode is None:
            sampling_mode = self.sampling_mode

        if sampling_mode['mode'] == 'random':
            return self.sample_random()
                
        elif sampling_mode['mode'] == 'greedy':
            return self.sample_greedy()
            
        elif sampling_mode['mode'] == 'epsilon_greedy':
            return self.sample_epsilon_greedy(sampling_mode['param'])
            
        elif sampling_mode['mode'] == 'softmax':
            return self.sample_softmax(sampling_mode['param'])
            
        else:
            raise NotImplementedError(sampling_mode)
459381
def sample_image(d, data, u, v, w, i=-1, verbose=0, imager='xy', wres=100):
    

    if i == -1:
        i = len(data)/2

    if imager == 'xy':
        image = rtlib.imgonefullxy(n.outer(u, d['freq']/d['freq_orig'][0]), n.outer(v, d['freq']/d['freq_orig'][0]), data[i], d['npixx'], d['npixy'], d['uvres'], verbose=verbose)
    elif imager == 'w':
        npix = max(d['npixx'], d['npixy'])
        bls, uvkers = rtlib.genuvkernels(w, wres, npix, d['uvres'], ksize=21, oversample=1)
        image = rtlib.imgonefullw(n.outer(u, d['freq']/d['freq_orig'][0]), n.outer(v, d['freq']/d['freq_orig'][0]), data[i], npix, d['uvres'], bls, uvkers, verbose=verbose)

#        bls, lmkers = rtlib.genlmkernels(w, wres, npix, d['uvres'])
#        image = rtlib.imgonefullw(n.outer(u, d['freq']/d['freq_orig'][0]), n.outer(v, d['freq']/d['freq_orig'][0]), data[i], npix, d['uvres'], [bls[0]], [lmkers[0]], verbose=verbose)

    return image