📄 bfagent.html
字号:
<HTML><HEAD><TITLE></TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<BR><BR><FONT COLOR="#000066"><H1><A NAME="//apple_ref/occ/cl/BFagent">BFagent</A></H1></FONT><BR>
<blockquote><DL><DT><B>Inherits From:</B></DT>
<DD>Agent</DD>
</DL></blockquote>
<blockquote><DL><DT><B>Declared In:</B></DT>
<DD>BFagent.h</DD>
</DL></blockquote>
<BR><BR>
<H2>Class Description</H2>
The BFagent--"bitstring forecasting agent" is the centerpiece of
the ASM model. The agent competes in a stock market, it buy, it
sells. It decides to buy or sell by making predictions about what the
price of the stock is likely to do in future. In order to make
predictions, it keeps a large list of forecast objects on hand, and
each forecast object makes a price prediction. These forecasts, which
are created from the BFCast subclass, are fairly sophisticated
entities, they may monitor many different conditions of the world.
The forecast which has the best performance record at any given
instant is used to predict the future price, which in turn leads to
the buy/sell decision.<P>
Inside the file BFagent.m, there is a long set of comments about the
updating that went on in the redesign of this code for ASM-2.2. In
order to faciliate this revision, several new classes were introduced.
BFParams is an object that keeps values of the parameters for
BFagents, and BFCast is the forecast object itself. BFCast, in turn,
keeps its conditions bits with a subclass called BitVector.<P>
If you dig into the code of this agent, you will find a confusing
thing, so be warned. This code and articles based on it use the term
"bit" to refer to something that can be valued either 0, 1, or 2. 0
means "don't care," 1 means "NO" and 2 means "YES". The confusing
thing is that it takes two bits to represent this amount of
information. In binary, the values would be {00,01,10},
respectively. I'm told some people call these trits to keep that in
mind that two digits are required. As a result of the fact that it
takes "two bits" to store "one bit's" worth of information, some
relatively complicated book keeping has to be done. That's where all
the parameters like "condbits" and "condwors" come into play. In
ASM-2.0, that book keeping was all "manually done" right here in
BFagent.m, but in the 2.2 version, it is all hidden in the subclass
BitVector. So, for purposes of the interface of this class, a bit is
a 3 valued piece of information, and values of bits inside forecasts
are set by messages to the forecast, like [aForecast setConditionsbit:
bit FromZeroTo: 2], for example, will set that bit to 2. If you want
to know if a forecast has YES or NO for a bit x, [aForecast
getConditionsbit: x].
<P><HR WIDTH=50% ALIGN=LEFT>
<H2>Instance Variables</H2>
<blockquote>
<CODE>int <B>currentTime</B>;</CODE><BR>
<CODE>int <B>lastgatime</B>;</CODE><BR>
<CODE>double <B>avspecificity</B>;</CODE><BR>
<CODE>double <B>forecast</B>;</CODE><BR>
<CODE>double <B>lforecast</B>;</CODE><BR>
<CODE>double <B>global_mean</B>;</CODE><BR>
<CODE>double <B>realDeviation</B>;</CODE><BR>
<CODE>double <B>variance</B>;</CODE><BR>
<CODE>double <B>pdcoeff</B>;</CODE><BR>
<CODE>double <B>offset</B>;</CODE><BR>
<CODE>double <B>divisor</B>;</CODE><BR>
<CODE>int <B>gacount</B>;</CODE><BR>
<CODE>BFParams * <B>privateParams</B>;</CODE><BR>
<CODE>id <Array> <B>fcastList</B>;</CODE><BR>
<CODE>id <List> <B>activeList</B>;</CODE><BR>
<CODE>id <List> <B>oldActiveList</B>;</CODE><BR>
<P><TABLE>
<TR><TD>currentTime</TD><TD>The agent regularly checks with Swarm to see what time it is</TD></TR>
<TR><TD>lastgatime</TD><TD>last time period when the GeneticAlgorithm was run</TD></TR>
<TR><TD>avspecificity</TD><TD>No description.</TD></TR>
<TR><TD>forecast</TD><TD>prediction of stock price: (trialprice+dividend)*pdcoeff + offset.</TD></TR>
<TR><TD>lforecast</TD><TD>lagged forecast: forecast value from previous period</TD></TR>
<TR><TD>global_mean</TD><TD>price+dividend</TD></TR>
<TR><TD>realDeviation</TD><TD>ftarget-lforecast: how far off was the agent's forecast?</TD></TR>
<TR><TD>variance</TD><TD>an Exp.Weighted MA of the agent's historical variance: Combine the old variance with deviation^squared, as in: bv*variance + av*deviation*deviation</TD></TR>
<TR><TD>pdcoeff</TD><TD>coefficient used in predicting stock price, recalculated each period in prepareForTrading</TD></TR>
<TR><TD>offset</TD><TD>coefficient used in predicting stock price, recalculated each period in prepareForTrading</TD></TR>
<TR><TD>divisor</TD><TD>a coefficient used to calculate demand for stock. It is a proportion (lambda) of forecastvar (basically, accuracy of forecasts)</TD></TR>
<TR><TD>gacount</TD><TD>how many times has the Genetic Algorithm been used?</TD></TR>
<TR><TD>privateParams</TD><TD>BFParams object holds parameters of this object</TD></TR>
<TR><TD>fcastList</TD><TD>A Swarm Array, holding the forecasts that the agent might use</TD></TR>
<TR><TD>activeList</TD><TD>A Swarm list containing a subset of all forecasts</TD></TR>
<TR><TD>oldActiveList</TD><TD>A copy of the activeList from the previous time step</TD></TR>
</TABLE>
</blockquote>
<P><HR WIDTH=50% ALIGN=LEFT>
<H2>Method Types</H2>
<blockquote>
<DL><DT></DT>
<DD> <A HREF="#+ setBFParameterObject:">+ setBFParameterObject:</A></DD>
<DD> <A HREF="#+ init">+ init</A></DD>
<DD> <A HREF="#- createEnd">- createEnd</A></DD>
<DD> <A HREF="#- initForecasts">- initForecasts</A></DD>
<DD> <A HREF="#- createNewForecast">- createNewForecast</A></DD>
<DD> <A HREF="#- setConditionsRandomly:">- setConditionsRandomly:</A></DD>
<DD> <A HREF="#- prepareForTrading">- prepareForTrading</A></DD>
<DD> <A HREF="#- collectWorldData:">- collectWorldData:</A></DD>
<DD> <A HREF="#- updateActiveList:">- updateActiveList:</A></DD>
<DD> <A HREF="#- getInputValues">- getInputValues</A></DD>
<DD> <A HREF="#- feedForward">- feedForward</A></DD>
<DD> <A HREF="#- getDemandAndSlope:forPrice:">- getDemandAndSlope:forPrice:</A></DD>
<DD> <A HREF="#- getRealForecast">- getRealForecast</A></DD>
<DD> <A HREF="#- updatePerformance">- updatePerformance</A></DD>
<DD> <A HREF="#- getDeviation">- getDeviation</A></DD>
<DD> <A HREF="#- updateWeights">- updateWeights</A></DD>
<DD> <A HREF="#- nbits">- nbits</A></DD>
<DD> <A HREF="#- nrules">- nrules</A></DD>
<DD> <A HREF="#- performGA">- performGA</A></DD>
<DD> <A HREF="#- lastgatime">- lastgatime</A></DD>
<DD> <A HREF="#- printcond:">- printcond:</A></DD>
<DD> <A HREF="#- copyList:To:">- copyList:To:</A></DD>
<DD> <A HREF="#- bitDistribution:cumulative:">- bitDistribution:cumulative:</A></DD>
<DD> <A HREF="#- fMoments:cumulative:">- fMoments:cumulative:</A></DD>
<DD> <A HREF="#- descriptionOfBit:">- descriptionOfBit:</A></DD>
</DL>
</blockquote>
<P><HR WIDTH=50% ALIGN=LEFT>
<H2>Class Methods</H2>
<A NAME="+ init"></A><H3><A NAME="//apple_ref/occ/clm/BFagent/init">init</A></H3>
<CODE>+ (void)<B>init</B>
</CODE><P>
This is vital to set values in the forecast class, BFCast, which in
turn initializes BitVector class
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="+ setBFParameterObject:"></A><H3><A NAME="//apple_ref/occ/clm/BFagent/setBFParameterObject:">setBFParameterObject:</A></H3>
<CODE>+ (void)<B>setBFParameterObject:</B><EM>x</EM>
</CODE><P>
This tells BFagents where they should look to get the default
parameters. it should give the agent an object from the BFParams
class.
<HR WIDTH=50% ALIGN=LEFT>
<H2>Instance Methods</H2>
<A NAME="- bitDistribution:cumulative:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/bitDistribution:cumulative:">bitDistribution:cumulative:</A></H3><P>
<CODE>- (int)<B>bitDistribution:</B>(int *(*)[4])<EM>countptr</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="- collectWorldData:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/collectWorldData:">collectWorldData:</A></H3><P>
<CODE>- (BitVector *)<B>collectWorldData:</B><EM>aZone</EM>
</CODE><P>
A forecast has a set of conditions it is watching. These are packed
tight in a BitVector. We need the world data about the status of those
conditions packed the same way, in order to make quick checks to find
out if the world conditions are matched by the BitVector's
conditions. This method creates a BitVector to match the conditions
that are being monitored by the agent's forecasts. This requires the
use of the design assumption that all of an agent's forecasts have the
same bitlist.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- copyList:To:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/copyList:To:">copyList:To:</A></H3><P>
<CODE>- <B>copyList:</B><EM>list</EM> <B>To:</B><EM>outputList</EM>
</CODE><P>
This is a general utility method for Swarm lists. It removes all
objects form the "<I>outputList</I>" and copies the elements from <I>list</I> into
it. It does not actually destroy any elements from either <I>list</I>, it
just updates references.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- createEnd"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/createEnd">createEnd</A></H3><P>
<CODE>- <B>createEnd</B>
</CODE><P>
This creates the container objects activeList and oldActiveList.
In addition, it makes sure that any initialization in the createEnd
of the <B>super</B> class is done.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- createNewForecast"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/createNewForecast">createNewForecast</A></H3><P>
<CODE>- (BFCast *)<B>createNewForecast</B>
</CODE><P>
Creates a new forecast object (instance of BFCast), with all
condition bits set to 00 here, meaning "don't care. It also sets
values for the other coefficients inside the BFCast. This method is
accessed at several points throughout the BFagent class when new
forecasts are needed.
<P><HR WIDTH=25% ALIGN=LEFT>
<A NAME="- descriptionOfBit:"></A><H3><A NAME="//apple_ref/occ/instm/BFagent/descriptionOfBit:">descriptionOfBit:</A></H3><P>
<CODE>- (const char *)<B>descriptionOfBit:</B>(int)<EM>bit</EM>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -