crumpets.workers.saliency package¶
- class crumpets.workers.saliency.SaliencyWorker(image, target_image, image_params=None, target_image_params=None, image_rng=None, **kwargs)[source]¶
Bases:
crumpets.workers.ImageWorker
Worker that outputs images and saliency maps created from raw gaze locations. Expects the following keys present in each sample:
- {“image”: encoded image data
“experiments”: [experiment, …]}
Each experiment is first checked for fixations points under key “fixations”. Falls back to key “locations” of raw gaze data if no fixations are found.
The following parameters can be configured:
image_params: see ImageWorker
- target_image_params:
- “sample_ratio” (default: 1):
float in [0, 1]; percentage of experiments sampled from the list of all experiments
- “jitter” (default: 0):
add noise to the individual gaze locations; sigma of a Gaussian distribution, scaled by the size of the target_images: noise ~ N(jitter * target_image_size)
- “interpolate” (default: False):
use linear interpolation to map gaze locations to the target_image
- “blur” (default: 0):
apply Gaussian blur with sigma blur * target_image_size to target_image
- “maxnorm” (default: False):
apply maximum norm to target_image
- prepare(sample, batch, buffers)[source]¶
Implement this method to define the behavior of the BufferWorker subclass. Results must be written to buffers and/or batch object.
- Parameters
sample – individual sample object to process
batch – the object the sample belongs to; append values to lists as necessary
buffers – output buffers to use for this sample
- crumpets.workers.saliency.multivariate_normal(mean, cov, size=None, check_valid='warn', tol=1e-08)¶
Draw random samples from a multivariate normal distribution.
The multivariate normal, multinormal or Gaussian distribution is a generalization of the one-dimensional normal distribution to higher dimensions. Such a distribution is specified by its mean and covariance matrix. These parameters are analogous to the mean (average or “center”) and variance (standard deviation, or “width,” squared) of the one-dimensional normal distribution.
Note
New code should use the
multivariate_normal
method of adefault_rng()
instance instead; please see the random-quick-start.- mean1-D array_like, of length N
Mean of the N-dimensional distribution.
- cov2-D array_like, of shape (N, N)
Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.
- sizeint or tuple of ints, optional
Given a shape of, for example,
(m,n,k)
,m*n*k
samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is(m,n,k,N)
. If no shape is specified, a single (N-D) sample is returned.- check_valid{ ‘warn’, ‘raise’, ‘ignore’ }, optional
Behavior when the covariance matrix is not positive semidefinite.
- tolfloat, optional
Tolerance when checking the singular values in covariance matrix. cov is cast to double before the check.
- outndarray
The drawn samples, of shape size, if that was provided. If not, the shape is
(N,)
.In other words, each entry
out[i,j,...,:]
is an N-dimensional value drawn from the distribution.
Generator.multivariate_normal: which should be used for new code.
The mean is a coordinate in N-dimensional space, which represents the location where samples are most likely to be generated. This is analogous to the peak of the bell curve for the one-dimensional or univariate normal distribution.
Covariance indicates the level to which two variables vary together. From the multivariate normal distribution, we draw N-dimensional samples, \(X = [x_1, x_2, ... x_N]\). The covariance matrix element \(C_{ij}\) is the covariance of \(x_i\) and \(x_j\). The element \(C_{ii}\) is the variance of \(x_i\) (i.e. its “spread”).
Instead of specifying the full covariance matrix, popular approximations include:
Spherical covariance (cov is a multiple of the identity matrix)
Diagonal covariance (cov has non-negative elements, and only on the diagonal)
This geometrical property can be seen in two dimensions by plotting generated data-points:
>>> mean = [0, 0] >>> cov = [[1, 0], [0, 100]] # diagonal covariance
Diagonal covariance means that points are oriented along x or y-axis:
>>> import matplotlib.pyplot as plt >>> x, y = np.random.multivariate_normal(mean, cov, 5000).T >>> plt.plot(x, y, 'x') >>> plt.axis('equal') >>> plt.show()
Note that the covariance matrix must be positive semidefinite (a.k.a. nonnegative-definite). Otherwise, the behavior of this method is undefined and backwards compatibility is not guaranteed.
- 1
Papoulis, A., “Probability, Random Variables, and Stochastic Processes,” 3rd ed., New York: McGraw-Hill, 1991.
- 2
Duda, R. O., Hart, P. E., and Stork, D. G., “Pattern Classification,” 2nd ed., New York: Wiley, 2001.
>>> mean = (1, 2) >>> cov = [[1, 0], [0, 1]] >>> x = np.random.multivariate_normal(mean, cov, (3, 3)) >>> x.shape (3, 3, 2)
The following is probably true, given that 0.6 is roughly twice the standard deviation:
>>> list((x[0,0,:] - mean) < 0.6) [True, True] # random