Vector

classes
   Fourier        get            median         setrand        
   abs            hist           min            sin            
   add            histogram      min_ind        size           
   addrand        ind            mul            smhist         
   append         index          play           sort           
   apply          indgen         play_remove    sortindex      
   at             indvwhere      plot           spikebin       
   buffer_size    indwhere       ploterr        sqrt           
   c              inf            pow            stderr         
   cl             insrt          printf         stdev          
   contains       integral       psth           sub            
   copy           interpolate    rebin          sum            
   deriv          label          record         sumgauss       
   div            line           reduce         sumsq          
   dot            log            remove         tanh           
   eq             log10          resample       to_python      
   fill           mag            resize         trigavg        
   fit            mark           reverse        var            
   floor          max            rotate         vread          
   fread          max_ind        scale          vwrite         
   from_double    mean           scanf          where          
   from_python    meansqerr      scantil        x              
   fwrite         medfltr        set            

This class was implemented by

---------------------------
Zach Mainen
Computational Neurobiology Laboratory
Salk Institute 
10010 N. Torrey Pines Rd.
La Jolla, CA 92037
zach@salk.edu
----------------------------

SYNTAX

obj = new Vector()
obj = new Vector(size)
obj = new Vector(size, init)

DESCRIPTION

The vector class provides convenient functions for manipulating one-dimensional arrays of numbers. An object created with this class can be thought of as containing a double x[] variable. Individual elements of this array can be manipulated with the normal objref.x[index] notation. Most of the Vector functions apply their operations to each element of the x array thus avoiding the often tedious scaffolding required by an otherwise un-encapsulated double array.

A vector can be created with length size and with each element set to the value of init.

Vector methods that modify the elements are generally of the form

obj = vsrcdest.method(...)
in which the values of vsrcdest on entry to the method are used as source values by the method to compute values which replace the old values in vsrcdest and the original vsrcdest object reference is the return value of the method. For example, v1 = v2 + v3 would be written,
v1 = v2.add(v3)
However, this results in two, often serious, side effects. First, the v2 elements are changed and so the original values are lost. Furthermore v1 at the end is a reference to the same Vector object pointed to by v2. That is, if you subsequently change the elements of v2, the elements of v1 will change as well since v1 and v2 are in fact labels for the same object.

When these side effects need to be avoided, one uses the Vector.c function which returns a reference to a completely new Vector which is an identical copy. ie.

	v1 = v2.c.add(v3)
leaves v2 unchanged, and v1 points to a completely new Vector. One can build up elaborate vector expressions in this manner, ie v1 = v2*s2 + v3*s3 + v4*s4could be written
	v1 = v2.c.mul(s2).add(v3.c.mul(s3)).add(v4.c.mul(s4))
but if the expressions get too complex it is probably clearer to employ temporary objects to break the process into several separate expressions.

EXAMPLES

objref vec
vec = new Vector(20,5)
will create a vector with 20 indices, each having the value of 5.
objref vec1
vec1 = new Vector()
will create a vector with 1 index which has value of 0. It is seldom necessary to specify a size for a new vector since most operations, if necessary, increase or decrease the number of available elements as needed.

SEE ALSO

double , x , resize


x

Vector

SYNTAX

vec.x[index]

DESCRIPTION

Elements of a vector can be accessed with vec.x[index] notation. Vector indices range from 0 to Vector.size()-1. This notation is superior to the older vec.get() and vec.set() notations for three reasons:
  1. It performs the roles of both vec.get and vec.set with a syntax that is consistent with the normal syntax for a double array inside of an object.
  2. It can be viewed by a field editor (since it can appear on the left hand side of an assignment statement).
  3. You can take its address for functions which require that kind of argument.

EXAMPLES

print vec.x[0] prints the value of the 0th (first) element.

vec.x[i] = 3 sets the i'th element to 3.

xpanel("show a field editor")
xvalue("vec.x[3]")
xpvalue("last element", &vec.x[vec.size() - 1])
xpanel()
Note, however, that there is a potential difficulty with the xpvalue field editor since, if vec is ever resized, then the pointer will be invalid. In this case, the field editor will display the string, "Free'd".

BUGS

vec.x[-1] returns the value of the first element of the vector, just as would vec.x[0].

vec.x(i) returns the value of index i just as does vec.x[i].


size

Vector

SYNTAX

size = vec.size()

DESCRIPTION

Return the number of elements in the vector. The last element has the index: vec.size() - 1. Most explicit for loops over a vector can take the form:
for i=0, vec.size()-1 {... vec.x[i] ...}
Note: There is a distinction between the size of a vector and the amount of memory allocated to hold the vector. Generally, memory is only freed and reallocated if the size needed is greater than the memory storage previously allocated to the vector. Thus the memory used by vectors tends to grow but not shrink. To reduce the memory used by a vector, one can explicitly call buffer_size .


resize

Vector

SYNTAX

obj = vsrcdest.resize(new_size)

DESCRIPTION

Resize the vector. If the vector is made smaller, then trailing elements will be deleted. If it is expanded, new elements will be initialized to 0 and original elements will remain unchanged.

Warning: Any function that resizes the vector to a larger size than its available space will make existing pointers to the elements invalid (see note in size ). For example, resizing vectors that have been plotted will remove that vector from the plot list. Other functions may not be so forgiving and result in a memory error (segmentation violation or unhandled exception).

EXAMPLES

objref vec
vec = new Vector(20,5)
vec.resize(30)
appends 10 elements, each having a value of 0, to vec.
vec.resize(10)
removes the last 20 elements from the vec.The values of the first 10 elements are unchanged.

SEE ALSO

buffer_size


buffer_size

Vector

SYNTAX

space = vsrc.buffer_size()
space = vsrc.buffer_size(request)

DESCRIPTION

Returns the length of the double precision array memory allocated to hold the vector. This is NOT the size of the vector. The vector size can efficiently grow up to this value without reallocating memory.

With an argument, frees the old memory space and allocates new memory space for the vector, copying old element values to the new elements. If the request is less than the size, the size is truncated to the request. For vectors that grow continuously, it may be more efficient to allocate enough space at the outset, or else occasionally change the buffer_size by larger chunks. It is not necessary to worry about the efficiency of growth during a Vector.record since the space available automatically increases by doubling.

EXAMPLES

execute following example
objref y
y = new Vector(10)
y.size()
y.buffer_size()
y.resize(5)
y.size
y.buffer_size()
y.buffer_size(100)
y.size()


get

Vector

SYNTAX

x = vec.get(index)

DESCRIPTION

Return the value of a vector element index. This function is superseded by the vec.x[] notation but is retained for backward compatibility.


set

Vector

SYNTAX

obj = vsrcdest.set(index,value)

DESCRIPTION

Set vector element index to value. This function is superseded by the vec.x[i] = expr notation but is retained for backward compatibility.


fill

Vector

SYNTAX

obj = vsrcdest.fill(value)
obj = vsrcdest.fill(value, start, end)

DESCRIPTION

The first form assigns value to every element in vsrcdest.

If start and end arguments are present, they specify the index range for the assignment.

EXAMPLES

objref vec
vec = new Vector(20,5)
vec.fill(9,2,7)
assigns 9 to vec.x[2] through vec.x[7] (a total of 6 elements)

SEE ALSO

indgen append


label

Vector

SYNTAX

strdef s
s = vec.label()
s = vec.label(s)

DESCRIPTION

Label the vector with a string. The return value is the label, which is an empty string if there is no label. Labels are printed on a Graph when the plot method is called.

EXAMPLES

objref vec
vec = new Vector()
print vec.label()
vec.label("hello")
print vec.label()

SEE ALSO

family , beginline


record

Vector

SYNTAX

vdest.record(&var)
vdest.record(&var, Dt)
vdest.record(&var, tvec)
vdest.record(point_process_object, &varvar, ...)

DESCRIPTION

Save the stream of values of "var" during a simulation into the vdest vector. Previous record and play specifications of this Vector (if any) are destroyed.

Details: Transfers take place on exit from finitialize() and on exit from fadvance(). At the end of finitialize(), v.x[0] = var. At the end of fadvance, var will be saved if t (after being incremented by fadvance) is equal or greater than the associated time of the next index. The system maintains a set of record vectors and the vector will be removed from the list if the vector or var is destroyed. The vector is automatically increased in size by 100 elements at a time if more space is required, so efficiency will be slightly improved if one creates vectors with sufficient size to hold the entire stream, and plots will be more persistent (recall that resizing may cause reallocation of memory to hold elements and this will make pointers invalid).

The record semantics can be thought of as:
var(t) -> v.x[index]

The default relationship between index and t is t = index*dt.
In the second form, t = index*Dt.
In the third form, t = tvec.x[index].

For the local variable timestep method, use_local_dt and/or multiple threads, nthread , it is often helpful to provide specific information about which cell the var pointer is associated with by inserting as the first arg some POINT_PROCESS object which is located on the cell. This is necessary if the pointer is not a RANGE variable and is much more efficient if it is. The fixed step and global variable time step method do not need or use this information for the local step method but will use it for multiple threads. It is therefore a good idea to supply it if possible.

BUGS

record/play behavior is reasonable but surprising if dt is greater than Dt. Things work best if Dt happens to be a multiple of dt. All combinations of record ; play ; Dt =>< dt ; and tvec sequences have not been tested.

EXAMPLES

See tests/nrniv/vrecord.hoc for examples of usage.

If one is using the graphical interface generated by "Standard Run Library" to simulate a neuron containing a "terminal" section, Then one can store the time course of the terminal voltage (between runs) with:

objref dv
dv = new Vector()
dv.record(&terminal.v(.5))
init()	// or push the "Init and Run" button on the control panel
run()
Note that the next "run" will overwrite the previous time course stored in the vector. Thus dv should be copied to another vector ( see copy ). To remove dv from the list of record vectors, the easiest method is to destroy the instance with dv = new Vector()

SEE ALSO

finitialize , fadvance , play , t , play_remove


play

Vector

SYNTAX

vsrc.play(&var, Dt)
vsrc.play(&var, tvec)
vsrc.play("stmt involving $1", optional Dt or tvec arg)
vsrc.play(index)
vsrc.play(&var or stmt, Dt or Tvec, continuous)
vsrc.play(&var or stmt, tvec, indices_of_discontinuities_vector)
vsrc.play(point_process_object, &var, ...)

DESCRIPTION

The vsrc vector values are assigned to the "var" variable during a simulation.

The same vector can be played into different variables.

If the "stmt involving $1" form is used, that statement is executed with the appropriate value of the $1 arg. This is not as efficient as the pointer form but is useful for playing a value into a set of variables as in

forall g_pas = $1

The index form immediately sets the var (or executes the stmt) with the value of vsrc.x[index]

The play semantics can be thought of as v.x[index] -> var(t) where t(index) is Dt*index or tvec.x[index] The discrete event delivery system is used to determine the precise time at which values are copied from vsrc to var. Note that for variable step methods, unless continuity is specifically requested, the function is a step function. Also, for the local variable dt method, var MUST be associated with the cell that contains the currently accessed section (but see the paragraph below about the use of a point_process_object inserted as the first arg).

For the fixed step method transfers take place on entry to finitialize() and on entry to fadvance(). At the beginning of finitialize(), var = v.x[0]. On fadvance a transfer will take place if t will be (after the fadvance increment) equal or greater than the associated time of the next index. For the variable step methods, transfers take place exactly at the times specified by the Dt or tvec arguments.

The system maintains a set of play vectors and the vector will be removed from the list if the vector or var is destroyed. If the end of the vector is reached, no further transfers are made (var becomes constant)

Note well: for the fixed step method, if fadvance exits with time equal to t (ie enters at time t-dt), then on entry to fadvance, var is set equal to the value of the vector at the index appropriate to time t. Execute tests/nrniv/vrecord.hoc to see what this implies during a simulation. ie the value of var from t-dt to t played into by a vector is equal to the value of the vector at index(t). If the vector was meant to serve as a continuous stimulus function, this results in a first order correct simulation with respect to dt. If a second order correct simulation is desired, it is necessary (though perhaps not sufficient since all other equations in the system must also be solved using methods at least second order correct) to fill the vector with function values at f((i-.5)*dt).

When continuous is 1 then linear interpolation is used to define the values between time points. However, events at each Dt or tvec are still used and that has beneficial performance implications for variable step methods since vsrc is equivalent to a piecewise linear function and variable step methods can excessively reduce dt as one approaches a discontinuity in the first derivative. Note that if there are discontinuities in the function itself, then tvec should have adjacent elements with the same time value. As of version 6.2, when a value is greater than the range of the t vector, linear extrapolation of the last two points is used instead of a constant last value. If a constant outside the range is desired, make sure the last two points have the same y value and have different t values (if the last two values are at the same time, the constant average will be returned). (note: the 6.2 change allows greater variable time step efficiency as one approaches discontinuities.)

The indices_of_discontinuities_vector argument is used to specifying the indices in tvec of the times at which discrete events should be used to notify that a discontinuity in the function, or any derivative of the function, occurs. Presently, linear interpolation is used to determine var(t) in the interval between these discontinuities (instead of cubic spline) so the length of steps used by variable step methods near the breakpoints depends on the details of how the parameter being played into affects the states.

For the local variable timestep method, use_local_dt and/or multiple threads, nthread , it is often helpful to provide specific information about which cell the var pointer is associated with by inserting as the first arg some POINT_PROCESS object which is located on the cell. This is necessary if the pointer is not a RANGE variable and is much more efficient if it is. The fixed step and global variable time step method do not need or use this information for the local step method but will use it for multiple threads. It is therefore a good idea to supply it if possible.

SEE ALSO

record play_remove


play_remove

Vector

SYNTAX

v.play_remove()

DESCRIPTION

Removes the vector from BOTH record and play lists. Note that the vector is automatically removed if the variable which is recorded or played is destroyed or if the vector is destroyed. This function is used in those cases where one wishes to keep the vector data even under subsequent runs.

record and play have been implemented by Michael Hines.

SEE ALSO

record play


indgen

Vector

SYNTAX

obj = vsrcdest.indgen()
obj = vsrcdest.indgen(stepsize)
obj = vsrcdest.indgen(start,stepsize)
obj = vsrcdest.indgen(start,stop,stepsize)

DESCRIPTION

Fill the elements of a vector with a sequence of values. With no arguments, the sequence is integers from 0 to (size-1).

With only stepsize passed, the sequence goes from 0 to stepsize*(size-1) in steps of stepsize. Stepsize does not have to be an integer.

With start, stop and stepsize, the vector is resized to be 1 + (stop - $varstart)/stepsize long and the sequence goes from start up to and including stop in increments of stepsize.

EXAMPLES

objref vec
vec = new Vector(100)
vec.indgen(5)
creates a vector with 100 elements going from 0 to 495 in increments of 5.
vec.indgen(50, 100, 10)
reduces the vector to 6 elements going from 50 to 100 in increments of 10.
vec.indgen(90, 1000, 30)
expands the vector to 31 elements going from 90 to 990 in increments of 30.

SEE ALSO

fill append


append

Vector

SYNTAX

obj = vsrcdest.append(vec1, vec2, ...)

DESCRIPTION

Concatenate values onto the end of a vector. The arguments may be either scalars or vectors. The values are appended to the end of the vsrcdest vector.

EXAMPLES

objref vec, vec1, vec2
vec = new Vector (10,4)
vec1 = new Vector (10,5)
vec2 = new Vector (10,6)
vec.append(vec1, vec2, 7, 8, 9)
turns vec into a 33 element vector, whose first ten elements = 4, whose second ten elements = 5, whose third ten elements = 6, and whose 31st, 32nd, and 33rd elements = 7, 8, and 9, respectively. Remember, index 32 refers to the 33rd element.


insrt

Vector

SYNTAX

obj = vsrcdest.insrt(index, vec1, vec2, ...)

DESCRIPTION

Inserts values before the index element. The arguments may be either scalars or vectors.

obj.insrt(obj.size, ...) is equivalent to obj.append(...)


remove

Vector

SYNTAX

obj = vsrcdest.remove(index)
obj = vsrcdest.remove(start, end)

DESCRIPTION

Remove the indexed element (or inclusive range) from the vector. The vector is resized.


contains

Vector

SYNTAX

boolean = vsrc.contains(value)

DESCRIPTION

Return whether or not the vector contains value as at least one of its elements (to within float_epsilon ). A return value of 1 signifies true; 0 signifies false.

EXAMPLES

vec = new Vector (10)
vec.indgen(5)
vec.contains(30)
returns a 1, meaning the vector does contain an element whose value is 30.
vec.contains(50)
returns a 0. The vector does not contain an element whose value is 50.


copy

Vector

SYNTAX

obj = vdest.copy(vsrc)
obj = vdest.copy(vsrc, dest_start)
obj = vdest.copy(vsrc, src_start, src_end)
obj = vdest.copy(vsrc, dest_start, src_start, src_end)
obj = vdest.copy(vsrc, dest_start, src_start, src_end, dest_inc, src_inc)
obj = vdest.copy(vsrc, vsrcdestindex)
obj = vdest.copy(vsrc, vsrcindex, vdestindex)

DESCRIPTION

Copies some or all of vsrc into vdest. If the dest_start argument is present (an integer index), source elements (beginning at src.x[0]) are copied to vdest beginning at dest.x[dest_start], Src_start and src_end here refer to indices of vsrcx, not vdest. If vdest is too small for the size required by vsrc and the arguments, then it is resized to hold the data. If the dest is larger than required AND there is more than one argument the dest is NOT resized. One may use -1 for the src_end argument to specify the entire size (instead of the tedious src.size()-1)

If the second (and third) argument is a vector, the elements of that vector are the indices of the vsrc to be copied to the same indices of the vdest. In this case the vdest is not resized and any indices that are out of range of either vsrc or vdest are ignored. This function allows mapping of a subset of a source vector into the subset of a destination vector.

This function can be slightly more efficient than c since if vdest contains enough space, memory will not have to be allocated for it. Also it is convenient for those cases in which vdest is being plotted and therefore reallocation of memory (with consequent removal of vdest from the Graph) is to be explicitly avoided.

EXAMPLES

To copy the odd elements use:
execute following example
...
v2 = new Vector()
v2.copy(v1, 0, 1, -1, 1, 2)
v2.printf()
To merge or shuffle two vectors into a third, use:
execute following example
...
v3 = new Vector()
v3.copy(v1, 0, 0, -1, 2, 1)
v3.copy(v2, 1, 0, -1, 2, 1)
v3.printf

EXAMPLES

vec = new Vector(100,10)
vec1 = new Vector()
vec1.indgen(5,105,10)
vec.copy(vec1, 50, 3, 6)
turns vec from a 100 element into a 54 element vector. The first 50 elements will each have the value 10 and the last four will have the values 35, 45, 55, and 65 respectively.

BUGS

Vectors copied to themselves are not usually what is expected. eg.
vec = new Vector(20)
vec.indgen()
vec.copy(vec, 10)
produces a 30 element vector cycling three times from 0 to 9. However the self copy may work if the src index is always greater than or equal to the destination index.


c

Vector

SYNTAX

newvec = vsrc.c
newvec = vsrc.c(srcstart)
newvec = vsrc.c(srcstart, srcend)

DESCRIPTION

Return a new vector which is a copy of the vsrc vector, but does not copy the label. For a complete copy including the label use cl . (Identical to the at function but has a short name that suggests copy or clone). Useful in the construction of filter chains. Note that with no arguments, it is not necessary to type the parentheses.


cl

Vector

SYNTAX

newvec = vsrc.cl
newvec = vsrc.cl(srcstart)
newvec = vsrc.cl(srcstart, srcend)

DESCRIPTION

Return a new vector which is a copy, including the label, of the vsrc vector. (Similar to the c function which does not copy the label) Useful in the construction of filter chains. Note that with no arguments, it is not necessary to type the parentheses.


at

Vector

SYNTAX

newvec = vsrc.at()
newvec = vsrc.at(start)
newvec = vsrc.at(start,end)

DESCRIPTION

Return a new vector consisting of all or part of another.

This function predates the introduction of the vsrc.c, "clone", function which is synonymous but is retained for backward compatibility.

It merely avoids the necessity of a vdest = new Vector() command and is equivalent to

vdest = new Vector()
vdest.copy(vsrc, start, end)

EXAMPLES

objref vec, vec1
vec = new Vector()
vec.indgen(10,50,2)
vec1 = vec.at(2, 10)
creates vec1 with 9 elements which correspond to the values at indices 2 - 10 in vec. The contents of vec1 would then be, in order: 14, 16, 18, 20, 22, 24, 26, 28, 30.


from_double

Vector

SYNTAX

double px[n]
obj = vdest.from_double(n, &px)

DESCRIPTION

Resizes the vector to size n and copies the values from the double array to the vector.


where

Vector

SYNTAX

obj = vdest.where(vsource, opstring, value1)
obj = vdest.where(vsource, op2string, value1, value2)
obj = vsrcdest.where(opstring, value1)
obj = vsrcdest.where(op2string, value1, value2)

DESCRIPTION

vdest is vector consisting of those elements of the given vector, vsource that match the condition opstring.

Opstring is a string matching one of these (all comparisons are with respect to float_epsilon ):

 ==		!=
 >		<
 >=		<=
Op2string requires two numbers defining open/closed ranges and matches one of these:
 []		[)
 (]		()

EXAMPLES

vec = new Vector(25)
vec1 = new Vector()
vec.indgen(10)
vec1.where(vec, ">=", 50)
creates vec1 with 20 elements ranging in value from 50 to 240 in increments of 10.
objref r
r = new Random()
vec = new Vector(25)
vec1 = new Vector()
r.uniform(10,20)
vec.fill(r)
vec1.where(vec, ">", 15)
creates vec1 with random elements gotten from vec which have values greater than 15. The new elements in vec1 will be ordered according to the order of their appearance in vec.

SEE ALSO

indvwhere , indwhere


indwhere

Vector

SEE ALSO

indvwhere


indvwhere

Vector

SYNTAX

i = vsrc.indwhere(opstring, value)
i = vsrc.indwhere(op2string, low, high)

obj = vsrcdest.indvwhere(opstring,value)
obj = vsrcdest.indvwhere(opstring,value)
obj = vdest.indvwhere(vsource,op2string,low, high)
obj = vdest.indvwhere(vsource,op2string,low, high)

DESCRIPTION

The i = vsrc form returns the index of the first element of v matching the criterion given by the opstring. If there is no match, the return value is -1.

vdest is a vector consisting of the indices of those elements of the source vector that match the condition opstring.

Opstring is a string matching one of these:

 ==		!=
 >		<
 >=		<=
Op2string is a string matching one of these:
 []		[)
 (]		()

Comparisons are relative to the float_epsilon global variable.

EXAMPLES

execute following example
vs = new Vector()

{vs.indgen(0, .9, .1)
vs.printf()}

print vs.indwhere(">", .3)
print "note roundoff error, vs.x[3] - .3 =", vs.x[3] - .3
print vs.indwhere("==", .5)

vd = vs.c.indvwhere(vs, "[)", .3, .7)
{vd.printf()}

SEE ALSO

where


fwrite

Vector

SYNTAX

n = vsrc.fwrite(fileobj)
n = vsrc.fwrite(fileobj, start, end)

DESCRIPTION

Write the vector vec to an open fileobj of type File in machine dependent binary format. You must keep track of the vector's size for later reading, so it is recommended that you store the size of the vector as the first element of the file.

It is almost always better to use vwrite since it stores the size of the vector automatically and is more portable since the corresponding vread will take care of machine dependent binary byte ordering differences.

Return value is the number of items. (0 if error)

fread is used to read a file containing numbers stored by fwrite but must have the same size.


fread

Vector

SYNTAX

n = vdest.fread(fileobj)
n = vdest.fread(fileobj, n)
n = vdest.fread(fileobj, n, precision)

DESCRIPTION

Read the elements of a vector from the file in binary as written by fwrite. If n is present, the vector is resized before reading. Note that files created with fwrite cannot be fread on a machine with different byte ordering. E.g. spark and intel cpus have different byte ordering.

It is almost always better to use vwrite in combination with vread. See vwrite for the meaning of the precision argment.

Return value is 1 (no error checking).


vwrite

Vector

SYNTAX

n = vec.vwrite(fileobj)
n = vec.vwrite(fileobj, precision)

DESCRIPTION

Write the vector in binary format to an already opened for writing fileobj of type File . vwrite() is easier to use than fwrite() since it stores the size of the vector and type information for a more automated read/write. The file data can also be vread on a machine with different byte ordering. e.g. you can vwrite with an intel cpu and vread on a sparc. Precision formats 1 and 2 employ a simple automatic compression which is uncompressed automatically by vread. Formats 3 and 4 remain uncompressed.

Default precision is 4 (double) because this is the usual type used for numbers in oc and therefore requires no conversion or compression

*  1 : char            shortest    8  bits   
*  2 : short                       16 bits
   3 : float                       32 bits
   4 : double          longest     64 bits   
   5 : int                         sizeof(int) bytes

* Warning! these are useful primarily for storage of data: exact values will not necessarily be maintained due to the conversion process

Return value is 1 . Only if the type field is invalid will the return value be 0.


vread

Vector

SYNTAX

n = vec.vread(fileobj)

DESCRIPTION

Read vector from binary format file written with vwrite(). Size and data type have been stored by vwrite() to allow correct retrieval syntax, byte ordering, and decompression (where necessary). The vector is automatically resized.

Return value is 1. (No error checking.)

EXAMPLES

objref v1, v2, f
v1 = new Vector()
v1.indgen(20,30,2)
v1.printf()
f = new File()
f.wopen("temp.tmp")
v1.vwrite(f)

v2 = new Vector()
f.ropen("temp.tmp")
v2.vread(f)
v2.printf()


printf

Vector

SYNTAX

n = vec.printf()
n = vec.printf(format_string)
n = vec.printf(format_string, start, end)
n = vec.printf(fileobj)
n = vec.printf(fileobj, format_string)
n = vec.printf(fileobj, format_string, start, end)

DESCRIPTION

Print the values of the vector in ascii either to the screen or a File instance (if fileobj is present). Start and end enable you to specify which particular set of indexed values to print. Use format_string for formatting the output of each element. This string must contain exactly one %f, %g, or %e, but can also contain additional formatting instructions.

Return value is number of items printed.

EXAMPLES

vec = new Vector()
vec.indgen(0, 1, 0.1)
vec.printf("%8.4f\n")
prints the numbers 0.0000 through 0.9000 in increments of 0.1. Each number will take up a total of eight spaces, will have four decimal places and will be printed on a new line.

BUGS

No error checking is done on the format string and invalid formats can cause segmentation violations.


scanf

Vector

SYNTAX

n = vec.scanf(fileobj)
n = vec.scanf(fileobj, n)
n = vec.scanf(fileobj, c, nc)
n = vec.scanf(fileobj, n, c, nc)

DESCRIPTION

Read ascii values from a File instance (must already be opened for reading) into vector. If present, scanning takes place til n items are read or until EOF. Otherwise, vec.scanf reads until end of file. If reading til eof, a number followed by a newline must be the last string in the file. (no trailing spaces after the number and no extra newlines). When reading til EOF, the vector grows approximately by doubling when its currently allocated space is filled. To avoid the overhead of memory reallocation when scanning very long vectors (e.g. > 50000 elements) it is a good idea to presize the vector to a larger value than the expected number of elements to be scanned. Note that although the vector is resized to the actual number of elements scanned, the space allocated to the vector remains available for growth. See buffer_size .

Read from column c of nc columns when data is in column format. It numbers the columns beginning from 1.

The scan takes place at the current position of the file.

Return value is number of items read.

SEE ALSO

scantil


scantil

Vector

SYNTAX

n = vec.scantil(fileobj, sentinel)
n = vec.scantil(fileobj, sentinel, c, nc)

DESCRIPTION

Like scanf but scans til it reads a value equal to the sentinel. e.g. -1e15 is a possible sentinel value in many situations. The vector does not include the sentinel value. The file pointer is left at the character following the sentinel.

Read from column c of nc columns when data is in column format. It numbers the columns beginning from 1. The scan stops when the sentinel is found in any position prior to column c+1 but it is recommended that the sentinel appear by itself on its own line. The file pointer is left at the character following the sentinel.

The scan takes place at the current position of the file.

Return value is number of items read.


plot

Vector

SYNTAX

obj = vec.plot(graphobj)
obj = vec.plot(graphobj, color, brush)
obj = vec.plot(graphobj, x_vec)
obj = vec.plot(graphobj, x_vec, color, brush)
obj = vec.plot(graphobj, x_increment)
obj = vec.plot(graphobj, x_increment, color, brush)

DESCRIPTION

Plot vector in a Graph object. The default is to plot the elements of the vector as y values with their indices as x values. An optional argument can be used to specify the x-axis. Such an argument can be either a vector, x_vec, in which case its values are used for x values, or a scalar, x_increment, in which case x is incremented according to this number.

This function plots the vec values that exist in the vector at the time of graph flushing or window resizing. The alternative is vec.line() which plots the vector values that exist at the time of the call to plot. It is therefore possible with vec.line() to produce multiple plots on the same graph.

Once a vector is plotted, it is only necessary to call graphobj.flush() in order to display further changes to the vector. In this way it is possible to produce rather rapid line animation.

If the vector label is not empty it will be used as the label for the line on the Graph.

Resizing a vector that has been plotted will remove it from the Graph.

The number of points plotted is the minimum of vec.size and x_vec.size at the time vec.plot is called. x_vec is assumed to be an unchanging Vector.

EXAMPLES

execute following example
objref vec, g
g = new Graph()
g.size(0,10,-1,1)
vec = new Vector()
vec.indgen(0,10, .1)
vec.apply("sin")
vec.plot(g, .1)
xpanel("")
xbutton("run", "for i=0,vec.size()-1 { vec.rotate(1) g.flush() doNotify()}")
xpanel()

SEE ALSO

vector


line

Vector

SYNTAX

obj = vec.line(graphobj)
obj = vec.line(graphobj, color, brush)
obj = vec.line(graphobj, x_vec)
obj = vec.line(graphobj, x_vec, color, brush)
obj = vec.line(graphobj, x_increment)
obj = vec.line(graphobj, x_increment, color, brush)

DESCRIPTION

Plot vector on a Graph . Exactly like .plot() except the vector is not plotted by reference so that the values may be changed subsequently w/o disturbing the plot. It is therefore possible to produce a number of plots of the same function on the same graph, without erasing any previous plot.

The line on a graph is given the label if the label is not empty.

The number of point plotted is the minimum of vec.size and x_vec.size .

EXAMPLES

execute following example
objref vec, g
g = new Graph()
g.size(0,10,-1,1)
vec = new Vector()
vec.indgen(0,10, .1)
vec.apply("sin")
for i=0,3 { vec.line(g, .1) vec.rotate(10) }

SEE ALSO

family


ploterr

Vector

SYNTAX

obj = vec.ploterr(graphobj, x_vec, err_vec)
obj = vec.ploterr(graphobj, x_vec, err_vec, size)
obj = vec.ploterr(graphobj, x_vec, err_vec, size, color, brush)

DESCRIPTION

Similar to vec.line(), but plots error bars with size +/- the elements of vector err_vec.

size sets the width of the seraphs on the error bars to a number of printer dots.

brush sets the width of the plot line. 0=invisible, 1=minimum width, 2=1point, etc.

EXAMPLES

execute following example
objref vec, xvec, errvec
objref g
g = new Graph()
g.size(0,100, 0,250)
vec = new Vector()
xvec = new Vector()
errvec = new Vector()

vec.indgen(0,200,20)
xvec.indgen(0,100,10)
errvec.copy(xvec)
errvec.apply("sqrt")
vec.ploterr(g, xvec, errvec, 10)
vec.mark(g, xvec, "O", 5)
creates a graph which has x values of 0 through 100 in increments of 10 and y values of 0 through 200 in increments of 20. At each point graphed, vertical error bars are also drawn which are the +/- the length of the square root of the values 0 through 100 in increments of 10. Each error bar has seraphs which are ten printer points wide. The graph is also marked with filled circles 5 printers points in diameter.


mark

Vector

SYNTAX

obj = vec.mark(graphobj, x_vector)
obj = vec.mark(graphobj, x_vector, "style")
obj = vec.mark(graphobj, x_vector, "style", size)
obj = vec.mark(graphobj, x_vector, "style", size, color, brush)
obj = vec.mark(graphobj, x_increment)
obj = vec.mark(graphobj, x_increment, "style", size, color, brush)

DESCRIPTION

Similar to vec.line, but instead of connecting by lines, it make marks, centered at the indicated position, which do not change size when window is zoomed or resized. The style is a single character |,-,+,o,O,t,T,s,S where o,t,s stand for circle, triangle, square and capitalized means filled. Default size is 12 points.


histogram

Vector

SYNTAX

newvect = vsrc.histogram(low, high, width)

DESCRIPTION

Create a histogram constructed by binning the values in vsrc.

Bins run from low to high in divisions of width. Data outside the range is not binned.

This function returns a vector that contains the counts in each bin, so while it is necessary to declare an object reference (objref newvect), it is not necessary to execute newvect = new Vector().

The first element of newvect is 0 (newvect.x[0] = 0). For ii > 0, newvect.x[ii] equals the number of items in vsrc whose values lie in the half open interval [a,b) where b = low + ii*width and a = b - width. In other words, newvect.x[ii] is the number of items in vsrc that fall in the bin just below the boundary b.

EXAMPLES

execute following example
objref interval, hist, rand

rand = new Random()
rand.negexp(1)

interval = new Vector(100)
interval.setrand(rand) // random intervals

hist = interval.histogram(0, 10, .1)

// and for a manhattan style plot ...
objref g, v2, v3
g = new Graph()
g.size(0,10,0,30)
// create an index vector with 0,0, 1,1, 2,2, 3,3, ...
v2 = new Vector(2*hist.size())     
v2.indgen(.5) 
v2.apply("int") 
// 
v3 = new Vector(1) 
v3.index(hist, v2) 
v3.rotate(-1)            // so different y's within each pair
v3.x[0] = 0 
v3.plot(g, v2)
creates a histogram of the occurrences of random numbers ranging from 0 to 10 in divisions of 0.1.


hist

Vector

SYNTAX

obj = vdest.hist(vsrc, low, size, width)

DESCRIPTION

Similar to histogram (but notice the different argument meanings. Put a histogram in vdest by binning the data in vsrc. Bins run from low to low + size * width in divisions of width. Data outside the range is not binned.


sumgauss

Vector

SYNTAX

newvect = vsrc.sumgauss(low, high, width, var)
newvect = vsrc.sumgauss(low, high, width, var, weight_vec)

DESCRIPTION

Create a vector which is a curve calculated by summing gaussians of area 1 centered on all the points in the vector. This has the advantage over histogram of not imposing arbitrary bins. low and high set the range of the curve. width determines the granularity of the curve. var sets the variance of the gaussians.

The optional argument weight_vec is a vector which should be the same size as vec and is used to scale or weight the gaussians (default is for them all to have areas of 1 unit).

This function returns a vector, so while it is necessary to declare a vector object (objref vectobj), it is not necessary to declare vectobj as a new Vector().

To plot, use v.indgen(low,high,width) for the x-vector argument.

EXAMPLES

execute following example
objref r, data, hist, x, g

r = new Random()
r.normal(1, 2)

data = new Vector(100)
data.setrand(r)

hist = data.sumgauss(-4, 6, .5, 1)
x = new Vector(hist.size())
x.indgen(-4, 6, .5)

g = new Graph()
g.size(-4, 6, 0, 30)
hist.plot(g, x)


smhist

Vector

SYNTAX

obj = vdest.smhist(vsrc, start, size, step, var)
obj = vdest.smhist(vsrc, start, size, step, var, weight_vec)

DESCRIPTION

Very similar to sumgauss . Calculate a smooth histogram by convolving the raw data set with a gaussian kernel. The histogram begins at varstart and has varsize values in increments of size varstep. varvar sets the variance of the gaussians. The optional argument weight_vec is a vector which should be the same size as vsrc and is used to scale or weight the number of data points at a particular value.


ind

Vector

SYNTAX

newvect = vsrc.ind(vindex)

DESCRIPTION

Return a new vector consisting of the elements of vsrc whose indices are given by the elements of vindex.

EXAMPLES

objref vec, vec1, vec2
vec = new Vector(100)
vec2 = new Vector()
vec.indgen(5)
vec2.indgen(49, 59, 1)
vec1 = vec.ind(vec2)
creates vec1 to contain the fiftieth through the sixtieth elements of vec2 which would have the values 245 through 295 in increments of 5.


addrand

Vector

SYNTAX

obj = vsrcdest.addrand(randobj)
obj = vsrcdest.addrand(randobj, start, end)

DESCRIPTION

Adds random values to the elements of the vector by sampling from the same distribution as last picked in the Random object randobj.

EXAMPLES

execute following example
objref vec, g, r
vec = new Vector(50)
g = new Graph()
g.size(0,50,0,100)
r = new Random()
r.poisson(.2)
vec.plot(g)

proc race() {local i
        vec.fill(0)
        for i=1,300 {
                vec.addrand(r)
                g.flush()
                doNotify()
        }
}

race() 


setrand

Vector

SYNTAX

obj = vdest.setrand(randobj)
obj = vdest.setrand(randobj, start, end)

DESCRIPTION

Sets random values for the elements of the vector by sampling from the same distribution as last picked in randobj.


sin

Vector

SYNTAX

obj = vdest.sin(freq, phase)
obj = vdest.sin(freq, phase, dt)

DESCRIPTION

Generate a sin function in vector vec with frequency freq hz, phase phase in radians. dt is assumed to be 1 msec unless specified.


apply

Vector

SYNTAX

obj = vsrcdest.apply("func")
obj = vsrcdest.apply("func", start, end)

DESCRIPTION

Apply a hoc function to each of the elements in the vector. The function can be any function that is accessible in oc. It must take only one scalar argument and return a scalar. Note that the function name must be in quotes and that the parentheses are omitted.

EXAMPLES

vec.apply("sin", 0, 9)
applies the sin function to the first ten elements of the vector vec.


reduce

Vector

SYNTAX

x = vsrc.reduce("func")
x = vsrc.reduce("func", base)
x = vsrc.reduce("func", base, start, end)

DESCRIPTION

Pass all elements of a vector through a function and return the sum of the results. Use base to initialize the value x. Note that the function name must be in quotes and that the parentheses are omitted.

EXAMPLES

objref vec
vec = new Vector()
vec.indgen(0, 10, 2)
func sq(){
	return $1*$1
}
vec.reduce("sq", 100)
returns the value 320.

100 + 0*0 + 2*2 + 4*4 + 6*6 + 8*8 + 10*10 = 320


floor

Vector

SYNTAX

vec.floor()

DESCRIPTION

Rounds toward negative infinity. Note that float_epsilon is not used in this calculation.


to_python

Vector

SYNTAX

pythonlist = vec.to_python()
pythonlist = vec.to_python(pythonlist)
numpyarray = vec.to_python(numpyarray)

DESCRIPTION

Copy the vector elements from the hoc vector to a pythonlist or 1-d numpyarray. If the arg exists the pythonobject must have the same size as the hoc vector.


from_python

Vector

SYNTAX

vec = vec.from_python(pythonlist)
vec = vec.from_python(numpyarray)

DESCRIPTION

Copy the python list elements into the hoc vector. The elements must be numbers that are convertable to doubles. Copy the numpy 1-d array elements into the hoc vector. The hoc vector is resized.


neuron/general/classes/vector/vect.hel : Nov 29 12:23