www.pudn.com > asm_java.zip > AgentParam.java


package asm;

import java.awt.Frame;

/**
 * Title:        Artificial Stock Market
 * Description:  人工模拟股市(来源:SFI的Swarm版本)的Java版本
 * Copyright:    Copyright (c) 2003
 * Company:      http://agents.yeah.net
 * @author jake
 * @version 1.0
 */

public class AgentParam extends Frame {
  public int numfcasts; /*"number of forecasts maintained by this agent"*/
  //public int condwords; /*"number of words of memory required to hold bits"*/
  public int condbits; /*"number of conditions bits are monitored"*/
  public int mincount; /*"minimum number of times forecast must be used to become active"*/
  public int gafrequency; /*"how often is genetic algorithm done?"*/
  public int firstgatime; /*"after how many time steps is the genetic algorithm done"*/
  public int longtime;	/*" unused time before Generalize() in genetic algorithm"*/
  public int individual;
  public double tauv;
  public double lambda;
  public double maxbid;
  public double bitprob;
  public double subrange;	/*" fraction of min-max range for initial random values"*/
  public double a_min,a_max;	/*" min and max for p+d coef"*/
  public double b_min,b_max;	/*" min and max for div coef"*/
  public double c_min,c_max;	/*" min and max for constant term"*/
  public double a_range,b_range,c_range;	/*" derived: max - min" */
  public double newfcastvar;	/*" variance assigned to a new forecaster"*/
  public double newfcastspec;
  public double addvar;
  public double initvar;	/*" variance of overall forecast for t<200"*/
  public double bitcost;	/*" penalty parameter for specificity"*/
  public double maxdev;	/*" max deviation of a forecast in variance estimation"*/
  public double poolfrac;	/*" fraction of rules in replacement pool"*/
  public double newfrac;	/*" fraction of rules replaced"*/
  public double pcrossover;	/*" probability of running Crossover()."*/
  public double plinear;	/*" linear combination "crossover" prob."*/
  public double prandom;	/*" random from each parent crossover prob."*/
  public double pmutation;	/*" per bit mutation prob."*/
  public double plong;	        /*" long jump prob."*/
  public double pshort;	/*" short (neighborhood) jump prob."*/
  public double nhood;	        /*" size of neighborhood."*/
  public double genfrac;	/*" fraction of 0/1 bits to generalize"*/
  public double gaprob;	/*" derived: 1/gafrequency"*/
  public int npool;		/*" derived: replacement pool size"*/
  public int nnew;		/*" derived: number of new rules"*/
  public int nnulls;            /*" unnused bits"*/
  //int *bitlist;		/*" dynamic array, length condbits"*/
  //double *problist;	/*" dynamic array, length condbits"*/

  public int npoolmax ;		/* size of reject array */
  public int nnewmax ;		/* size of newfcast array */
  public int ncondmax;		/* size of newc*/

  public AgentParam() {
    numfcasts=100;//规则数目
    initvar=1.0; //初始化方差
    a_min=0;
    b_min=-10;
    c_min=-1;
    a_max=4;
    b_max=10;
    c_max=5;
    subrange=1;//系数的一个变化范围,sub只能取[0,1]的数值
    condbits=60;//规则if部分的二进制位数
    nnulls=0;//无用空位的个数
    bitcost=0.02;//位部分的适应度对总是硬度的贡献权重
    newfcastvar=0.6;//新规则的方差
    newfcastspec=0.4;//新规则条件部分出现2的概率[0,1]取值
    firstgatime=2;//第一次执行遗传算法的允许时间
    gafrequency=1000;//执行遗传算法的频率
    mincount=1;//被激活唤醒的最小次数
    individual=0;//是否仅仅采用最好规则进行方差计算?布尔值
    tauv=50;//更新规则表现时候的权重系数global_mean = b*global_mean + a*ftarget;
    lambda=0.9;//需求函数x=(E(p+d)-(1+r)p)/lambda*variance的系数
    addvar=10;//改造的需求函数x=(E(p+d)-(1+r)p)/(lambda*variance+addvar)为了防止variance对结果英想过大
    maxbid=10;//最大持股量
    initvar=50;//初始方差
    maxdev=100;//最大的离差
    pcrossover=0.3;//交叉概率
    pmutation=0.01;//变异概率
    plong=0.6;//大变异的概率
    pshort=0.3;//小变异的概率
    plinear=0.4;//线性交叉的概率
    prandom=0.3;//随机交叉的概率

    longtime=200;//长时间没有被激活
    genfrac=0.1;//位2的平均长度
    nhood=3;//邻域的长度

    poolfrac=0.3;//淘汰规则池的比例
    newfrac=0.2;//新规则的比例
    npoolmax=10;
    nnewmax=10;
    ncondmax=10;

    reinit();
  }
  public void reinit(){
    //重新初始化一些参数
    a_range = a_max - a_min;
    b_range = b_max - b_min;
    c_range = c_max - c_min;
    gaprob = 1.0/(double)gafrequency;
    if (1.0+bitcost*(condbits-nnulls) <= 0.0){
      //system.Out("wrong with the bitcost,condbits,nnulls");
      return;
    }
    npool = (int)(numfcasts*poolfrac + 0.5);
    nnew = (int)(numfcasts*newfrac + 0.5);

  // Record maxima needed for GA working space
  if (npool > npoolmax) npoolmax = npool;
  if (nnew > nnewmax) nnewmax = nnew;
  }
}