[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Memory usage - repost (plain text)
From: |
David Pruitt |
Subject: |
Memory usage - repost (plain text) |
Date: |
Thu, 9 Jan 2003 16:50:30 -0600 |
Sorry for the HTML in the first post - sort of new laptop with preinstalled
software. Didn't know it was set for HTML e-mail....
Here are two functions that I am using to sort through a database prior to
analysis. I call these function many times through a particular run. My
issue is the consumption of memory through the run. If you recall my
previous message, a long run will consume >750MB of memory while I can
account for only about 10MB. John Eaton suggested that looping in some
functions might lead to virtual memory leaks. I would appreciate any
comment on my programming in two example functions.
Thanks for the help.
Example1.m:
function [ out, weight, nmax, idx ] = S_out(code, mat1, mat2, S1, S2 )
#
# Input:
# code - the three-column vector of three-letter reference codes
# mat1 - matrix of values: if mat1 is a matrix of
# a n-length time series of values for m observations, the m values
# are averaged over time.
# mat2 - matrix of identifying codes
#
# Output:
# out - m-vector of weighted values
# weight - weights
# n - largest number of observations for any identifying code
# idx - index of codes found in mat2
#
m = size(idx,1);
n = size(cap_mat,1);
if n > 1
mat1_mean = mean(mat1);
else
mat1_mean = mat1;
endif
for i = 1:m
ix = [];
ix = find( idx(i,:) != 0 );
n(i) = size(ix,2);
out(i) = sum( mat1_mean( idx(i, ix) ) );
endfor;
nmax = max(n);
weight = zeros(m,nmax);
imx = find(mat != 0);
for i = imx'
ix = [];
ix = find( idx(i,:) != 0 );
weight(i,ix) = (mat1_mean( idx(i, ix) ))/out(i);
endfor;
endfunction;
Example 2:
function [ Rtn_val, idx ] = S_Index(mat, code)
#
# Return the ID-sorted indicies of elements in the input code
#
# Input:
# mat = database values (including several character strings -
positions known)
# code = the three-letter from the database
# S1, S2 = reference indicies
#
# Output:
# Rtn_val = Vector of identification numbers
# idx = the set of indicies from the ID-sorted list
#
#
ID = mat(:,1:5);
matrix = toascii(mat(:,S1:S2));
c_code = toascii(code);
m = size(code,1);
n = size(sec_mat,2);
idx = zeros(m,n);
Rtn_val = zeros(m,1);
for i = 1:m
iz = [];
iz1 = [];
iz2 = [];
iz3 = [];
iz1 = find( matrix(:,1) == c_code(i,1) );
iz2 = find( matrix(:,2) == c_code(i,2) );
iz3 = find( matrix(:,3) == c_code(i,3) );
iz = intersection(iz1,iz2);
iz = intersection(iz,iz3);
n = size(iz,2);
idx(i,1:n) = iz;
for j = 1:n
Rtn_val = str2num(ID(j,1:5));
endfor;
endfor;
endfunction;
David Pruitt, PhD
Ashdon Investment Analysis and Research, LLC
Phone: 931.695.3220
Mobile: 931.639.2477
Fax: 931.695.5545
e-mail: address@hidden
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Memory usage - repost (plain text),
David Pruitt <=