[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Global variables and parcellfun
From: |
richard |
Subject: |
Global variables and parcellfun |
Date: |
Mon, 15 Jul 2013 20:34:28 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Hi All,
I *think* I may have a problem with parcellfun and a global variable
I am running a calculation that simulates the economy of Imperial Rome.
The calculation carries out three tasks:
It reads values E from a database, and uses these to calculate the
trajectory of variables X, with "noise" (Minsky). That seems to work.
It copies a selected variable into Y for display in a graph, and
prepares X for printing their final values. That seems to work.
It calculates (one) ratio(s) and (one) internal value(s) as a check on
the performance of the system, and stores the results in Z. These have
final values printed as X(h, 16|17) with incorrect values of "1".
Any advice on why the calculation for Y succeeds and the calculation
for Z fails? I have a calculation that works but does not use the
parcellfun or the pararrayfun, but it is slower.
TIA
Richard
########################################################################
postfun = @(XX, Minsky) postprocess (XX,Minsky,E);
########################################################################
function X = main_loop (X, t, Minsky)
# Set up the E matrix, initialise with ones
E= ones(1,62);
########################################################################
######################read the first emperor data#######################
########################################################################
pkg load database # the autoload for database is usually unset
conn = pq_connect (setdbopts ("host", "localhost", "dbname", "rome", "user",
"user", "password", "secret"));
S = pq_exec_params (conn, "select * from Ematrix01 where E00='Augustus';");
########################################################################
j=1; while (j< 60)
E(1,j)= cell2mat(S.data(1,j+1));
j++;
endwhile
########################################################################
incfun = @(XX, Minsky) increment (XX,Minsky,E); # add this for the test
for i = 2 : 5279 # Augustus reigns 44*120
##Increment the X variables by one step in time
X(i, 1:15) = X(i-1, 1:15) + t * incfun (X(i-1, 1:15),Minsky);
endfor
########################################################################
S = pq_exec_params (conn, "select * from Ematrix01 where E00='Tiberius I';");
########################################################################
j=1; while (j< 60)
E(1,j)= cell2mat(S.data(1,j+1));
j++;
endwhile
########################################################################
########New Emperor Tiberius I makes changes ###########################
########################################################################
# Tiberius renages on the bonus promised by Augustus: no changes to X ##
########################################################################
incfun = @(XX, Minsky) increment (XX,Minsky,E);
for i = 5280 : 7439 # Tiberius I
##Increment the X variables by one step in time
X(i, 1:15) = X(i-1, 1:15) + t * incfun (X(i-1, 1:15),Minsky);
endfor
#######################################################################
S = pq_exec_params (conn, "select * from Ematrix01 where E00='Tiberius II';");
#######################################################################
j=1; while (j< 60)
E(1,j)= cell2mat(S.data(1,j+1));
j++;
endwhile
######################################################################
########Emperor Tiberius II makes changes ############################
######################################################################
# Tiberius extends zero interest loans, pays donative to loyalists ###
# Loans are handled in the E matrix ##################################
######################################################################
X(7440,5)= X(7440,5)+10; # Wages deposited in a Bank account +donative
10
X(7440,12)= X(7440,12) -10; # Emperor personal account - donative 10
###########################################################
incfun = @(XX, Minsky) increment (XX,Minsky,E); # add add this for the test
for i = 7440 : rows (X) # Tiberius II
##Increment the X variables by one step in time
X(i, 1:15) = X(i-1, 1:15) + t * incfun (X(i-1, 1:15),Minsky);
endfor
###########################################################
endfunction # main_loop
Minsky = 1200 ./ (8950 + (1:10)'); # Keen's model had a fixed value of 1.0 now
reduced x10
## main loop starts here ###################################################
## parallel version needs the package "general"
ncpus = 4;
X = pararrayfun (ncpus, @(M) main_loop (X(:, 1:15), t, M), Minsky,
'UniformOutput', false);
Z = parcellfun (ncpus, @(XX, M) postfun (XX, M), X, mat2cell (ones (10, 1),
ones (10, 1)), 'UniformOutput', false);
Y = cellfun (@(XX) XX(:,6), X, 'UniformOutput', false);
Y = [Y{:}];
X = ([X{end}(:, 1:15) ones(rows (X{end}), 2) Z{end}]);
#### end of main loop ###########################################
#### finally, print graphs and things
#################################################################
printf ("# 17 =: %8.4f\n", X(h, 17));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Global variables and parcellfun,
richard <=