Computational Memory Lab Simulation Libraries
Home
Research
Episodic Memory
Spatial Cognition
Recognition Memory
Resources
Publications
Experiments
Programming
Word Pools
Lab People
My Account
Resources
Subject Database
Administration
Related Sites
Penn Psychology
Penn Perception
Institute for Research in Cognitive Science
Center for Cognitive Neuroscience
Institute for Neurological Sciences
Login
Login Now
Vector Matrix Library Documentation

Simulation Programming Libraries:

Vector-Matrix Library: vecmat.h, vecmat.cc, convcorr.cc

Hopfield Library: hopf.cc, hopf.h

General Simulation Library: simutils.h, simutils.cc

The entire package (with Makefile) can be downloaded at once: simlibs_v1_0_0.tgz.

If you have any questions about using these libraries, please e-mail the webmaster


Vector-Matrix Library

First, here's a list of all of the overloaded operators that are defined in the library. The defined operators can be used in the same way that you would use the operators for integers and floating points.

result

operation

action

boolean vector = = vector equality
boolean matrix = = matrix equality
boolean vector != vector inequality
boolean matrix != matrix inequality
vector vector + vector item-wise addition
matrix matrix + matrix item-wise addition
vector vector - vector item-wise subtraction
matrix matrix - matrix item-wise subtraction
vector double * vector mult all items by double
vector vector * double mult all items by double
matrix vector * vector outer product
vector matrix * vector matrix product
matrix matrix * matrix matrix multiplication
matrix double * matrix mult all items by double
matrix matrix * double mult all items by double
double vector % vector dot product
vector vector & vector convolution
vector vector & int self convolution int times
vector vector | vector correlation
vector vector | int self correlation int times
vector vector || vector concatenation

There is also a number of other functions that can be called on vectors and matrices. Briefly, here is a list of them and their syntaxes.

void vector.zero()
sets all the items in a vector to 0

double vector.magnitude()
returns the magnitude of the vector, i.e. the sum of all of the elements

double vector.variance()
returns the variance of the vector

double vector.std_err()
returns the standard error of the vector

void vector.normalize()
modifies the elements of the vector such that V[i] = V[i] / magnitude(V)

void vector()
involves the vector in place

void vector.item()
sets all the elements to random values drawn from a gaussian distribution

void vector.perturb(double rho)
perturbs the vector using rho as the correlation

vector vector.copy()
makes a copy of the data in the vector. If you have two vectors, old and new, and want to make new just like old with just a few minor changes, use new = copy(old) rather than just new = old

vector center_pad(vector v, long int i)
center-pada vector v to have a size of i

long int matrix.get_rows()
returns the number of rows in the matrix

long int matrix.getcolumns()
returns the number of columns in the matrix

void matrix.zero()
sets all elements of in the matrix to have a value of 0

void matrix.print(char *name)
prints out the matrix, one row per line. Be careful using this on a large matrix, as it will print out the whole thing. It uses name as the title to print before it prints out the data.


Sample Program

#include "vecmat.h"

const int LEX_SIZE = 50;
const int DIMENTIONALITY = 1000;
const int TOTAL_TO_TRY = 10; //How many words to try and match once
const int TOTAL_RUNS = 5;

void main(void) {

vector *lex = new vector[LEX_SIZE];
vector combined(DIMENTIONALITY);
double dp; //to store the value of the dot-product
int i; //counter variable
int words_in_mem; //how many words to try at once
int run;

for (i = 0; i < LEX_SIZE; i++) {

lex[i] = copy(tmp_vec); //set the size of the vector
lex[i].item(); //put random elements in the vector

}

for (run = 0; run < TOTAL_RUNS; run++) {

for (words_in_mem = 0; words_in_mem < TOTAL_TO_TRY; words_in_mem++) {

cout << "WORDS TESTED: " << words_in_mem << "." << endl;
combined.zero(); //zero out the combined vector
//set up the combined vector to probe on
for (i = 0; i < (words_in_mem + 5); i++)

combined = combined + lex[i]; //note that we can't use += because it is not overloaded

for (i = 0; i < (words_in_mem + 5); i++) {

dp = lex[i] % combined;
cout << "For lex[" << i << "] the dot product was " << dp << ".";
if (i <= words_in_mem)

cout << "It should have matched." << endl;

else

cout << "It should not have matched." << endl;

}

}

}

}