Assignment 7
Due: 11:00 AM on Monday, November 16, 2009
Question
Consider the following design for a vector statistics derivation and
display system: All vectors stored and manipulated by this system are either
(1) read in from
single-column files of real numbers whose filenames end with a ".vec" extension or
(2) extracted from multi-column files of real numbers corresponding to 2D
matrices, each of whose filenames end with a ".mat" extension.
The system itself accepts the following commands:
- read FN into V: Read vector in file FN.vec into system
and store under name V. If vector with name V
already stored in system, overwrite with file contents.
- read {dia, row, col} N from FN into V: Read {row, column,
diagonal} vector number N in matrix file FN.mat
into system and store under name V. If vector with name
V already stored in system, overwrite with extracted
vector.
- list: Display names of vectors stored in system.
- print V: Print vector with name V if stored in system
and print error message otherwise.
- length V: Print the number of elements in vector with name
V if stored in system and error message otherwise.
- sum V: Print the sum of the elements in vector with name
V if stored in system and error message otherwise.
- mean V: Print the mean of the elements in vector with name
V if stored in system and error message otherwise.
- min V: Print the minimum of the elements in vector with name
V if stored in system and error message otherwise.
- max V: Print the maximum of the elements in vector with name
V if stored in system and error message otherwise.
- stdDev V: Print the standard deviation of the elements in vector
with name V if stored in system and error message otherwise.
- var V: Print the variance of the elements in vector
with name V if stored in system and error message otherwise.
- correlation V1 V2: Print the Pearson correlation coefficient of
the elements in vectors V1 and V2
if these vectors are stored in the system and have the same length,
and appropriate error messages otherwise.
- clear: Delete all vectors stored in the system.
- exit: Exit system.
Write and document a Python script stats4.py which implements
the system described above using the following functions:
- initVector(): Return an empty vector-storage dictionary.
- readVector(vecFName): read in and return the vector of
real numbers stored in file vecFName.
- extractVector(vecType, vecNum, matFName): Extract and return
the vector of type vecType and number vecNum from
the 2D matrix file matFName.
- listVector(vecDict): Return a multi-line string of the names of
vectors stored in vecDict (one name per line).
- setVector(vecName, vecList, vecDesc, vecDict): Add vector named
vecName with element-list vecList and origin-description
vecDesc to vector-storage dictionary vecDict, if there is
not already a vector named vecName
stored in vecDict; otherwise, overwrite the
vector named vecName in vecDict with the new
vector element-list and description.
- isVector(vecName, vecDict): Return True if a vector
named vecName is in vector-storage dictionary vecDict and False otherwise.
- getVector(vecName, vecDict): return the (element-list, description)
tuple associated with the vector named vecName if there is such a
vector in vector-storage dictionary vecDict;
otherwise, return an error message.
- vectorStats(vecName, vecDict): Return a 7-tuple consisting of
the length, sum, mean, minimum, maximum, standard deviation, and
variance of the elements in the vector named vecName if there is
such a vector in vector-storage dictionary vecDict; otherwise,
return an error message.
- vectorCorr(vecName1, vecName2, vecDict): Return the Pearson
correlation coefficient of the vectors named vecName and
vecName2 if these vectors are in vector-storage dictionary
vecDict and these vectors have the same length; otherwise,
return appropriate error messages.
- clearVector(vecDict): Delete all vectors in vector-storage
dictionary vecDict.
All manipulation of both vectors and vector-storage dictionaries must occur within these
specified functions.
Your script must work on datafiles
stats4a.vec,
stats4b.vec,
stats4c.vec,
stats4d.vec, and
stats4a.mat
and command file
stats4.cmd
to produce the output given in typescript-file
stats4.script.
You may assume that all vector and matrix files exist and are valid and
that all requested rows, columns, and diagonals exist in the specified
matrix files.
Hints
You may find portions of the various statistics-computation scripts written for
Assignments # 2, 4, and 5 of use in constructing the functions specified above.
You may find it useful to store vectors in the system as a
dictionary of vector-description items, where each item has the system-internal
vector name as the key and value (X, Y), where X is a
list of the real-valued elements comprising that vector and Y is
an origin-description for the vector.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
Note that each script file must have the following comment
block at the top, where the X's are replaced with the appropriate
information, followed by a docstring briefly describing the program in that
script. For instance, my script for Question #1 of this assignment would
begin with the following comment block:
#########################################################
## CS 2500 (Fall 2009), Assignment #7 ##
## Script File Name: stats4.py ##
## Student Name: Todd Wareham ##
## Login Name: harold ##
## MUN #: 8008765 ##
#########################################################
If you choose to base your script on any answer-scripts for previous
assignments, please note this in the docstring.
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- Oct 28, 10:25am
Assignment #7 posted.
Created: October 27, 2009
Last Modified: October 28, 2009