Hello again
Many thanks for all the contributions, Raul and Roger, R.E. and Markus,
it's been quite an struggle to work through them all!
I now have a new version, based largely on Raul's suggestions,
and all but one of the functions are defined tacitly.
This one runs for about three minutes on my (slow) machine,
and graphs an interesting phase transition in the agents' collective behaviour.
I do wonder if I'm missing a trick with the tacit programming...
I seem just to be replacing standard arguments with (0 {:: ]), (1 {:: ]) etc.
S=: 2 NB. strategies per agent
M=: 10 NB. length of history
NB. H addresses the look-up table R according to recent history
NB. Raul called this 'Sbid', time indices are left argument
H=: (#. @ (0 & <) @ ({ 2 {:: ])) { 0 {:: ]
NB. Pn updates the strategy valuation (performance) figures P
NB. Raul called this 'Pbid'
Pn=: (1 {:: ]) - {: @ (2 {:: ]) * (- 2 + i. M) & H
NB. b returns a vector of the bids made by individual agents
NB. Each bid is prescribed by the agent's best-performing strategy
NB. Raul called this 'Snew'
b=: (i. >./) " _1 @ (1 {:: ]) { " _1 (- 1 + i. M) & H
NB. Total bid. This will lead to price change in the market
NB. Raul called this 'Bid'
An=: (2 {:: ]) , (+/ % %: @ #) @ b
NB. I am now doing the bidding first, afterwards updating P
NB. Raul called this 'Bids'
g=: ({. , Pn ; {:) @ ((}:@[ , <@]) An)
NB. f returns the average volatility of the marketplace
f=: 3 : 0
R=. 1 - 2 * ? ((2 ^ M) , y , S) $ 2
P=. 32 %~ +/ 0.5 - ? (12 , y , S) $ 0
A=. +/ 0.5 - ? (12 , M) $ 0
%: (+/ % #) *: 2 {:: g ^: (2 ^ 14) R ; P ; A
)
NB. Plot the log-volatility against log-market size
load 'plot'
j=: 4 6 8 10 11 12 13
plot j ; ^. (f " 0) 1 + 2 ^ j
NB. Observe the phase transition when the number of agents exceeds 2000
NB. This is terribly exciting to a statistical mechanic.
NB. Sudden changes in the collective behaviour, like this,
NB. are thought by some to underly the irrational market behaviour
NB. observed during phenomena such as crashes and bubbles.
Ali
http://www.see.eclipse.co.uk
----- Original Message ----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Monday, 9 October, 2006 10:50:34 PM
Subject: RE: [Jprogramming] Minority Game
Ok, I've poked around at this Minority Game stuff a bit more.
This is mostly shooting from the hip, but I've at least figured
out a way to express the program tacitly.
First off, I should note that 0.5 * 1 + * y is better expressed
as 0 < y. There's a vanishingly small chance that the expressions
would differ (when 0=y-0.5), but in those cases the surrounding
expressions would almost always throw domain errors.
Second off, I'm going to disclaim again: I have not studied
the concepts underlying this code. So some of my comments and
or function names might be bogus.
Anyways, here's the modified code:
N=: 4097 NB. number of agents
M=: 5 NB. length of history
S=: 2 NB. strategies per agent
NB. initial figures (roughly Gaussian):
P=: +/ 0.5-? (12, N, S)$0 NB. performance
A=: +/ 0.5-? (12, M+1) $0 NB. time sequence
Note 'Bidding logic'
Unless otherwise indicated, performance numbers
will be the left argument for these verbs, and
time sequence will be the right argument for these
verbs. Increasing time is indicated by increasing
index in the time sequence.
)
NB. strategy look-up table (frozen disorder)
R=:1-2*? ((2^M), N, S)$2
NB. strategy look-up function
NB. time indices are left argument
Sbid=: R {~ [: #. 0 < {
NB. performance function
Pbid=: [ - {:@] * (_2-i.-M) Sbid ]
NB. Next strategy
Snew=: (i. >./)"[EMAIL PROTECTED] {"_1 (_1-i.-M) Sbid ]
NB. Impact on outcome
Bid=: (%:N) %~ +/@Snew
NB. (Bids P;A): next P and corresponding A
Bids=: (Pbid ([ ; ] , Bid) ])&>/
L =: (_160 + i. 320) % 4
U =: (_159 + i. 320) % 4
cum =: 3 : '+/ (y > " 0 1 L) *. (y < " 0 1 U)'
load 'plot'
plot (0.5 * L + U) ; cum 1 {:: (Bids ^: (2 ^ 14)) P;A
FYI,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
___________________________________________________________
Try the all-new Yahoo! Mail. "The New Version is radically easier to use" – The
Wall Street Journal
http://uk.docs.yahoo.com/nowyoucan.html
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm