Package pype :: Module pype_aux
[frames] | no frames]

Module pype_aux

source code

Auxiliary functions

Supplemental frequently used function -- either in pype code directly or in user-tasks.

Author -- James A. Mazer (mazerj@gmail.com)

Classes
  Timestamp
  Logfile
  ConditionBucket
Functions
 
tic()
Start timer.
source code
 
toc(label=None)
Stop/lap timer (and perhaps print value).
source code
 
nextfile(s)
Next available file in sequence.
source code
 
lastfile(s)
Last existing file in sequence.
source code
 
frange(start, stop, step, inclusive=None)
Floating point version of range().
source code
 
vrandint(center, pvar)
Random variable generator.
source code
 
pickints(lo, hi, n)
Pick n integers.
source code
 
urand(min=0, max=1.0, integer=None)
Generate uniformly distributed random numbers (was uniform())
source code
 
nrand(mean=0, sigma=1.0, integer=None)
Generate normally (Gaussian) distributed random numbers.
source code
 
from_discrete_dist(v)
Generate random numbers from a discrete distribution.
source code
 
permute(v)
Return a random permutation of the input vector.
source code
 
pick_one(v, available=None)
Pick on element from a vector.
source code
 
navailable(available)
Count number of available slots; see pick_one()
source code
 
pick_n(v, n)
Randomly pick n-elements from vector.
source code
 
pick_n_replace(v, n)
Randomly pick n-elements from vector
source code
 
param_expand(s, integer=None)
Expand pype parameter string.
source code
 
showparams(app, P, clearfirst=1)
Pretty-print a parameter table into the info window.
source code
 
dir2ori(dir)
Convert stimulus DIRECTION to an ORIENTATION.
source code
Function Details

tic()

source code 

Start timer.

Benchmark function: start a simple timer (like matlab tic/toc)

toc(label=None)

source code 

Stop/lap timer (and perhaps print value).

Benchmark function: stop & print simple timer (like matlab tic/toc)

nextfile(s)

source code 
Next available file in sequence.
Returns:
next available file from pattern. For example, nextfile('foo.%04d.dat') will return 'foo.0000.dat', then 'foo.0001.dat' etc..

lastfile(s)

source code 
Last existing file in sequence.
Returns:
last opened file from pattern (like nextfile, but returns the last existing file in the sequence).

vrandint(center, pvar)

source code 

Random variable generator.

Generate a uniformly distributed random number in range [center-var, center+var].

pickints(lo, hi, n)

source code 

Pick n integers.

Select n random integers in the range [lo,hi].

urand(min=0, max=1.0, integer=None)

source code 
Generate uniformly distributed random numbers (was uniform())
Parameters:
  • min, max - (float) specifies bounds on range
  • integer - (boolean) if true, only return integers
Returns:
(int | float) random number in specified range

nrand(mean=0, sigma=1.0, integer=None)

source code 
Generate normally (Gaussian) distributed random numbers.
Parameters:
  • mean, sigma - (float) specifies normal/Gaussian dist params
  • integer - (boolean) if true, only return integers
Returns:
(int | float) random number in specified range

from_discrete_dist(v)

source code 

Generate random numbers from a discrete distribution.

Assume v represents somethine like a probability density function, with each scalar in v representing the prob. of that index, choose an index from that distribution. Note, the sum(v) MUST equal 1!!!

NB Returned values start from 0, i.e. for v=[0.5, 0.5] possible return values are 0 or 1, with 50/50 chance..

Parameters:
  • v - (array) frequency distribution
Returns:
(int) index into distribution

permute(v)

source code 
Return a random permutation of the input vector.
Parameters:
  • v - (array) input vector
Returns:
randomly permuted version of v

pick_one(v, available=None)

source code 

Pick on element from a vector.

Tue Jan 7 19:15:43 2003 mazer: This used to return a random element of vector, when available==None, but that was inconsistent with the other junk in this file. Now it always returns an INDEX (small int).

Parameters:
  • v - (array) vector of elements to select from
  • available - (boolean vector) -- mask specifying which elements are actually available for selection. This can be used to mask out stimuli that have already been presented etc.
Returns:
(int) index of selected element in v

navailable(available)

source code 
Count number of available slots; see pick_one()
Parameters:
  • available - (boolean vector) see pick_one()
Returns:
(int) number of available (non-zero) elements in list

pick_n(v, n)

source code 

Randomly pick n-elements from vector.

Pick elements without replacement from vector.

Parameters:
  • v - (array) input vector
  • n - (int) number of elements to pick
Returns:
(array) vector length N containing indices of all selected elements.

pick_n_replace(v, n)

source code 

Randomly pick n-elements from vector

Pick elements with replacement from vector.

NB 11-Jul-2005: changed this back to replace returning the selected elements, not the indicies; returning indicies is incompatible with pick_n() and broke zvs10.py ...

Parameters:
  • v - (array) input vector
  • n - (int) number elements to pick
Returns:
(array) vector length N containing selected elements.

param_expand(s, integer=None)

source code 

Expand pype parameter string.

Allowed formats for parameter string (see ptable.py):

  • X+-Y -- uniform dist'd number: [X-Y, X+Y]
  • X+-Y% -- uniform dist'd number: [X-(X*Y/100), X+(X*Y/100)]
  • U[min,max] -- uniform dist'd number between min and max
  • N[mu,sigma] -- normally dist'd number from N(mu, sigma)
  • G[mu,sigma] -- same as N (Gaussian)
  • E[mu] -- exponential of mean mu
  • TE[mu,{max | min,max}] -- exponential of mean mu; values are constrained to be within min:max (by resampling). If only max is specified, min is assumed to be zero
  • ITE[mu,{max | min,max}] -- integer exponential -- like TE[], but discretized to integer values
  • EDC[mu,min,max,nbins] -- discrete exponential of mean mu, contrained to min:max (by resampling). 'nbins' specifies number of discrete points in distribution (edc = exponential dirac comb)
  • start:step[:stride] -- generate non-inclusive range (python style) and pick one at random (default stride is 1)
  • =start:step[:stride] -- generate inclusive range (matlab style) and pick one at random (default stride is 1)
  • [#,#,#,#] -- pick one of these numbers
  • X -- just X
Parameters:
  • s - (string) parameter specification string
  • integer - (boolean) if true, return nearest integer
Returns:
(float or int) number from specified distirbution

showparams(app, P, clearfirst=1)

source code 

Pretty-print a parameter table into the info window.

See info() function.

Parameters:
  • app - (PypeApp) appliation handle
  • P - parameter dictionary
Returns:
nothing