?? 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; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -