📄 bfagent.html
字号:
</CODE><P>
Currently, this method is not called anywhere in ASM-2.2. It might
serve some purpose, past or present, I don't know (pj:
2001-10-26)
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- fMoments:cumulative:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/fMoments:cumulative:">fMoments:cumulative:</A></H3><P>
<CODE>- (int)<B>fMoments:</B>(double *)<EM>moment</EM> <B>cumulative:</B>(BOOL)<EM>cum</EM>
</CODE><P>
Currently, this method is not called anywhere in ASM-2.2. It might
serve some purpose, past or present, I don't know (pj:
2001-11-26)
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- feedForward"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/feedForward">feedForward</A></H3><P>
<CODE>- <B>feedForward</B>
</CODE><P>
Currently does nothing, used only if their are ANNagents
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- getDemandAndSlope:forPrice:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/getDemandAndSlope:forPrice:">getDemandAndSlope:forPrice:</A></H3><P>
<CODE>- (double)<B>getDemandAndSlope:</B>(double *)<EM>slope</EM> <B>forPrice:</B>(double)<EM>trialprice</EM>
</CODE><P>
Returns the agent's requested bid (if >0) or offer (if <0) using
best (or mean) linear forecast chosen by -prepareForTrading. The
forecast is given by<P>
forecast = pdcoeff*(<I>trialprice</I>+dividend) + offset<P>
where pdcoeff and offset are set by -prepareForTrading.<P>
A risk aversion computation gives a target holding, and its
derivative ("<I>slope</I>") with respect to price. The <I>slope</I> is calculated
as the linear approximated response of a change in price on the
traders' demand at time t, based on the change in the forecast
according to the currently active linear rule.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- getDeviation"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/getDeviation">getDeviation</A></H3><P>
<CODE>- (double)<B>getDeviation</B>
</CODE><P>
Returns the absolute value of realDeviation
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- getInputValues"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/getInputValues">getInputValues</A></H3><P>
<CODE>- <B>getInputValues</B>
</CODE><P>
Currently does nothing, used only if their are ANNagents
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- getRealForecast"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/getRealForecast">getRealForecast</A></H3><P>
<CODE>- (double)<B>getRealForecast</B>
</CODE><P>
Return agent's forecast
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- initForecasts"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/initForecasts">initForecasts</A></H3><P>
<CODE>- <B>initForecasts</B>
</CODE><P>
initForecasts. Creates BFCast objects (forecasts) and puts them
into an array called fCastList. These are the "meat" of this
agent's functionality, as they are repeatedly updated, improved, and
tested in the remainder of the class. Please note each BFagent has
a copy of the default params object called privateParams. It can be
used to set individualized values of settings in BFParams for each
agent. That would allow true diversity! I don't see how that diversity
would be allowed for in the ASM-2.0.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- lastgatime"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/lastgatime">lastgatime</A></H3><P>
<CODE>- (int)<B>lastgatime</B>
</CODE><P>
Return the last time the Genetic Algorithm was run.
Agents that don't use a genetic algorithm return MININT. This
may be used to see if the bit distribution might have changed,
since a change can only occur through a genetic algorithm.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- nbits"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/nbits">nbits</A></H3><P>
<CODE>- (int)<B>nbits</B>
</CODE><P>
Returns the "condbits" variable from parameters: the number of
condition bits that are monitored in the world, or 0 if
condition bits aren't used.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- nrules"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/nrules">nrules</A></H3><P>
<CODE>- (int)<B>nrules</B>
</CODE><P>
Returns the number of forecasts that are used. In the original
design, this was a constant set in the parameters, although revision
of the code for ASM-2.2 conceivably should allow agents to alter the
number of forecasts they maintain.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- performGA"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/performGA">performGA</A></H3><P>
<CODE>- <B>performGA</B>
</CODE><P>
Genetic algorithm. It relies on the following separate methods.
(pj: 2001-11-25. I still see some room for improvement here, but the
emphasis is to eliminate all global variables and explicitly pass
return values instead. Any values needed for computations should
either be passed explicitly or taken from someplace safe)<P>
1. MakePool makes a list of the weakest forecasts:
rejectList. That is the "npool" weakest rules.<P>
2. "nnew" new rules are created. They are put into a Swarm list
called newList. Their bit settings are taken from either crossover
(using tournament selection to get parents), or mutation.
"Tournament selection" means picking two candidates purely at
random and then choosing the one with the higher strength. See
the Crossover and Mutate methods for more details about how they
work.<P>
3. The nnew new rules replace weakest old ones found in step
1. This is done by the method "TransferFcastsFrom:To:" It pays no
attention to strength, but looks at similarity of the bitstrings
-- rather like tournament selection, we pick two candidates from
the rejectList at random and choose the one with the MORE similar
bitstring to be replaced. This maintains more diversity.<P>
4. Generalize looks for rules that haven't been triggered for
"longtime" and generalizes them by changing a randomly chosen
fraction "genfrac" of 0/1 bits to "don't care". It does this
independently of strength to all rules in the population.<P>
There are several private methods that take care of this
work. They don't show up in the public interface, but here they
are:<P>
-(BFCast *) CopyRule:(BFCast *) to From: (BFCast *) from<P>
-(void) MakePool: rejects From: (<B>id</B> <Array>) list<P>
-(BOOL) Mutate: (BFCast *) new Status: (BOOL) changed<P>
-(BFCast *) Crossover:(BFCast *) newForecast Parent1: (BFCast *) parent1 Parent2: (BFCast *) parent2<P>
- (void) TransferFcastsFrom: newlist To: forecastList Replace: rejects<P>
- (BFCast *) GetMort: (BFCast *) new Rejects: (<B>id</B> <List>) rejects<P>
-(void) Generalize: (<B>id</B>) list AvgStrength: (double) avgstrength<P>
Parameter list:<P>
<TABLE BORDER="3">
<TR><TD>npool</TD><TD>-- size of pool of weakest rules for possible relacement;
specified as a fraction of numfcasts by "poolfrac"</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>nnew</TD><TD>-- number of new rules produced
specified as a fraction of numfcasts by "newfrac"</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>pcrossover</TD><TD>-- probability of running Crossover.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>plinear</TD><TD>-- linear combination "crossover" prob.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>prandom</TD><TD>-- random from each parent crossover prob.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>pmutation</TD><TD>-- per bit mutation prob.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>plong</TD><TD>-- long jump prob.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>pshort</TD><TD>-- short (neighborhood) jump prob.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>nhood</TD><TD>-- size of neighborhood.</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>longtime</TD><TD>-- generalize if rule unused for this length of time</TD></TR>
</TABLE>
<P>
<TABLE BORDER="3">
<TR><TD>genfrac</TD><TD>-- fraction of 0/1 bits to make don't-care when generalising</TD></TR>
</TABLE>
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- prepareForTrading"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/prepareForTrading">prepareForTrading</A></H3><P>
<CODE>- <B>prepareForTrading</B>
</CODE><P>
Set up a new active list for this agent's forecasts, and compute the
coefficients pdcoeff and offset in the equation
forecast = pdcoeff*(trialprice+dividend) + offset<P>
The active list of all the fcasts matching the present conditions is saved
for later updates.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- printcond:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/printcond:">printcond:</A></H3><P>
<CODE>- <B>printcond:</B>(int)<EM>word</EM>
</CODE><P>
in case you want to see the 0101 representation of an
integer. Sometimes this comes in handy if you are looking at a
particular forecast's value as an int and you need to convert it to
the 0's and 1's
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- setConditionsRandomly:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/setConditionsRandomly:">setConditionsRandomly:</A></H3><P>
<CODE>- <B>setConditionsRandomly:</B>(BFCast *)<EM>fcastObject</EM>
</CODE><P>
Take a forecast object and randomly change the bits that govern
which conditions it monitors. This appears to be a piece of
functionality that could move to the BFCast class itself. There were
quite a few of these details floating around in BFagent at one time,
many are gone now.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- updateActiveList:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/updateActiveList:">updateActiveList:</A></H3><P>
<CODE>- <B>updateActiveList:</B>(BitVector *)<EM>worldvalues</EM>
</CODE><P>
This is the main inner loop over forecasts. Go through the list
of active forecasts, compare how they did against the world. Notice
the switch that checks to see how big the bitvector (condwords) is
before proceeding. At one time, this gave a significant
speedup. The original sfsm authors say 'Its ugly, but it
works. Don't mess with it!' (pj: I've messed with it, and don't
notice much of a speed effect on modern computers with modern
compilers :> My alternative implementation is commented out inside
this method)
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- updatePerformance"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/updatePerformance">updatePerformance</A></H3><P>
<CODE>- <B>updatePerformance</B>
</CODE><P>
Now update the variance and strength of all the forecasts that
were active in the previous period, since now we know how they
performed. This method causes an update of price/dividend
information from the world, then it measures how far off each
forecast was and puts the square of that "deviance" measure into the
forecast with the forecast's setVariance: method. Each forecast in
the active list is told to update its forecast. It also updates the
instance variable variance, which is calculated here as an
exponentially weignted moving average of that forecast's
squared-error (variance). Inside the code of updatePerformance,
there is a description of the strength formula that is used, and how
the formula now matches the formula used in the original sfsm,
rather than ASM-2.0.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- updateWeights"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/updateWeights">updateWeights</A></H3><P>
<CODE>- <B>updateWeights</B>
</CODE><P>
Currently, does nothing, used only if their are ANNagents
<P><HR>
Version 1.1 Copyright ©2001. All Rights Reserved.
<P>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -