simulation
¶
error_function (neural_sigma, voxel_sigma, ...) |
|
generate_scatter_volume (roi, prf, threshold, ...) |
|
parallel_simulate_neural_sigma (args) |
|
recast_simulation_results (output, grid_parent) |
|
simulate_neural_sigma (estimate, scatter, ...) |
VisualStimulus
¶
-
class
popeye.simulation.
VisualStimulus
(stim_arr, viewing_distance, screen_width, scale_factor, tr_length, dtype, interp='nearest')¶ Bases:
popeye.base.StimulusModel
-
__init__
(stim_arr, viewing_distance, screen_width, scale_factor, tr_length, dtype, interp='nearest')¶ A child of the StimulusModel class for visual stimuli.
- stim_arr : ndarray
- An array containing the visual stimulus at the native resolution. The visual stimulus is assumed to be three-dimensional (x,y,time).
- viewing_distance : float
- The distance between the participant and the display (cm).
- screen_width : float
- The width of the display (cm). This is used to compute the visual angle for determining the pixels per degree of visual angle.
- scale_factor : float
- The downsampling rate for ball=parking a solution. The stim_arr is downsampled so as to speed up the fitting procedure. The final model estimates will be derived using the non-downsampled stimulus.
-
error_function¶
-
popeye.simulation.
error_function
(neural_sigma, voxel_sigma, voxel_rf, deg_x, deg_y, xs, ys)¶
fmin¶
-
popeye.simulation.
fmin
(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None)¶ Minimize a function using the downhill simplex algorithm.
This algorithm only uses function values, not derivatives or second derivatives.
- func : callable func(x,*args)
- The objective function to be minimized.
- x0 : ndarray
- Initial guess.
- args : tuple, optional
- Extra arguments passed to func, i.e.
f(x,*args)
. - callback : callable, optional
- Called after each iteration, as callback(xk), where xk is the current parameter vector.
- xtol : float, optional
- Relative error in xopt acceptable for convergence.
- ftol : number, optional
- Relative error in func(xopt) acceptable for convergence.
- maxiter : int, optional
- Maximum number of iterations to perform.
- maxfun : number, optional
- Maximum number of function evaluations to make.
- full_output : bool, optional
- Set to True if fopt and warnflag outputs are desired.
- disp : bool, optional
- Set to True to print convergence messages.
- retall : bool, optional
- Set to True to return list of solutions at each iteration.
- xopt : ndarray
- Parameter that minimizes function.
- fopt : float
- Value of function at minimum:
fopt = func(xopt)
. - iter : int
- Number of iterations performed.
- funcalls : int
- Number of function calls made.
- warnflag : int
- 1 : Maximum number of function evaluations made. 2 : Maximum number of iterations reached.
- allvecs : list
- Solution at each iteration.
- minimize: Interface to minimization algorithms for multivariate
- functions. See the ‘Nelder-Mead’ method in particular.
Uses a Nelder-Mead simplex algorithm to find the minimum of function of one or more variables.
This algorithm has a long history of successful use in applications. But it will usually be slower than an algorithm that uses first or second derivative information. In practice it can have poor performance in high-dimensional problems and is not robust to minimizing complicated functions. Additionally, there currently is no complete theory describing when the algorithm will successfully converge to the minimum, or how fast it will if it does.
[1] Nelder, J.A. and Mead, R. (1965), “A simplex method for function minimization”, The Computer Journal, 7, pp. 308-313 [2] Wright, M.H. (1996), “Direct Search Methods: Once Scorned, Now Respectable”, in Numerical Analysis 1995, Proceedings of the 1995 Dundee Biennial Conference in Numerical Analysis, D.F. Griffiths and G.A. Watson (Eds.), Addison Wesley Longman, Harlow, UK, pp. 191-208.
fmin_powell¶
-
popeye.simulation.
fmin_powell
(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None, direc=None)¶ Minimize a function using modified Powell’s method. This method only uses function values, not derivatives.
- func : callable f(x,*args)
- Objective function to be minimized.
- x0 : ndarray
- Initial guess.
- args : tuple, optional
- Extra arguments passed to func.
- callback : callable, optional
- An optional user-supplied function, called after each
iteration. Called as
callback(xk)
, wherexk
is the current parameter vector. - direc : ndarray, optional
- Initial direction set.
- xtol : float, optional
- Line-search error tolerance.
- ftol : float, optional
- Relative error in
func(xopt)
acceptable for convergence. - maxiter : int, optional
- Maximum number of iterations to perform.
- maxfun : int, optional
- Maximum number of function evaluations to make.
- full_output : bool, optional
- If True, fopt, xi, direc, iter, funcalls, and warnflag are returned.
- disp : bool, optional
- If True, print convergence messages.
- retall : bool, optional
- If True, return a list of the solution at each iteration.
- xopt : ndarray
- Parameter which minimizes func.
- fopt : number
- Value of function at minimum:
fopt = func(xopt)
. - direc : ndarray
- Current direction set.
- iter : int
- Number of iterations.
- funcalls : int
- Number of function calls made.
- warnflag : int
- Integer warning flag:
- 1 : Maximum number of function evaluations. 2 : Maximum number of iterations.
- allvecs : list
- List of solutions at each iteration.
- minimize: Interface to unconstrained minimization algorithms for
- multivariate functions. See the ‘Powell’ method in particular.
Uses a modification of Powell’s method to find the minimum of a function of N variables. Powell’s method is a conjugate direction method.
The algorithm has two loops. The outer loop merely iterates over the inner loop. The inner loop minimizes over each current direction in the direction set. At the end of the inner loop, if certain conditions are met, the direction that gave the largest decrease is dropped and replaced with the difference between the current estiamted x and the estimated x from the beginning of the inner-loop.
The technical conditions for replacing the direction of greatest increase amount to checking that
- No further gain can be made along the direction of greatest increase from that iteration.
- The direction of greatest increase accounted for a large sufficient fraction of the decrease in the function value from that iteration of the inner loop.
Powell M.J.D. (1964) An efficient method for finding the minimum of a function of several variables without calculating derivatives, Computer Journal, 7 (2):155-162.
Press W., Teukolsky S.A., Vetterling W.T., and Flannery B.P.: Numerical Recipes (any edition), Cambridge University Press
generate_og_receptive_field¶
-
popeye.simulation.
generate_og_receptive_field
()¶ Generate a Gaussian.
- x : float
- The x coordinate of the center of the Gaussian (degrees)
- y : float
- The y coordinate of the center of the Gaussian (degrees)
- s : float
- The dispersion of the Gaussian (degrees)
- beta : float
- The amplitude of the Gaussian
- deg_x : 2D array
- The coordinate matrix along the horizontal dimension of the display (degrees)
- deg_y : 2D array
- The coordinate matrix along the vertical dimension of the display (degrees)
Returns
- stim : ndarray
- The 1D array containing the stimulus energies given the Gaussian coordinates
generate_scatter_volume¶
-
popeye.simulation.
generate_scatter_volume
(roi, prf, threshold, iterations)¶
resample_stimulus¶
-
popeye.simulation.
resample_stimulus
(stim_arr, scale_factor=0.05, mode='nearest', dtype='uint8')¶ Resamples the visual stimulus
The function takes an ndarray stim_arr and resamples it by the user specified scale_factor. The stimulus array is assumed to be a three dimensional ndarray representing the stimulus, in screen pixel coordinates, over time. The first two dimensions of stim_arr together represent the exent of the visual display (pixels) and the last dimensions represents time (TRs).
- stim_arr : ndarray
- Array_like means all those objects – lists, nested lists, etc. – that can be converted to an array.
- scale_factor : float
- The scale factor by which the stimulus is resampled. The scale factor must be a float, and must be greater than 0.
- mode : str, optional
- Points outside the boundaries of the input are filled according to the given mode (‘constant’, ‘nearest’, ‘reflect’ or ‘wrap’). Default is ‘nearest’.
- resampled_arr : ndarray
- An array that is resampled according to the user-specified scale factor.
shuffle¶
-
popeye.simulation.
shuffle
(self, x, random=None, int=<type 'int'>)¶ x, random=random.random -> shuffle list x in place; return None.
Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random.
simulate_bar_stimulus¶
-
popeye.simulation.
simulate_bar_stimulus
(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc, clip=0.33)¶ A utility function for creating a sweeping bar stimulus in memory.
This function creates a standard retinotopic mapping stimulus, the sweeping bar. The user specifies some of the display and stimulus parameters. This is particularly useful for writing tests and simulating responses of visually driven voxels.
- pixels_across : int
- The number of pixels along the horizontal dimension of the display.
- pixels_down : int
- The number of pixels along the vertical dimension of the display.
- viewing_distance : float
- The distance between the participant and the display (cm).
- screen_width : float
- The width of the display (cm). This is used to compute the visual angle for determining the pixels per degree of visual angle.
- thetas : array-like
- An array containing the orientations of the bars that will sweep across the display. For example thetas = np.arange(0,360,360/8).
- num_steps : int
- The number of steps the bar makes on each sweep through the visual field.
- ecc : float
- The distance from fixation each bar sweep begins and ends (degees).
- blanks : bool
- A flag determining whether there are blank periods inserted at the beginning and the end of the stimulus run.
- clip : float
- The bar stimulus is created by cliping a very oblong two-dimensional Gaussian oriented orthogonally to the direction of the sweep.
- bar : ndarray
- An array containing the bar stimulus. The array is three-dimensional, with the first two dimensions representing the size of the display and the third dimension representing time.