📄 algorithm.java
字号:
int i;
for(i=0;i<this.Gene_Len;i++)
{
w[i]=group[k][i];
// System.out.println(w[i]);
}
}
public double Learn_Process(double xx)
{ int L0=1;
int L1=4;
int L2=2;
int L3=1;
int i,j,tx1,tx2,tw;
x_pos[0]=0;
x_pos[1]=2;
x_pos[2]=7;
x_pos[3]=10;
x[1]=-1;
x[7]=-1;
x[9]=-1;
x[0]=xx;
tx1=x_pos[1];
tw=0;
double s;
//L1
for(i=0;i<L1;i++)
{
s=0;
tx2=x_pos[0];
for(j=0;j<L0+1;j++)
{
s=s+x[tx2]*w[tw];
tw=tw+1;
tx2=tx2+1;
}
x[tx1]=1/(1+Math.exp(-s));
tx1=tx1+1;
}
//L2
tx1=x_pos[2];
tw=6;
for(i=0;i<L2;i++)
{
s=0;
tx2=x_pos[1];
for(j=0;j<L1+1;j++)
{
s=s+w[tw]*x[tx2];
tw=tw+1;
tx2=tx2+1;
}
x[tx1]=1/(1+Math.exp(-s));
tx1=tx1+1;
}
tx1=x_pos[3];
tw=18;
for(i=0;i<L3;i++)
{
s=0;
tx2=x_pos[2];
for(j=0;j<L2+1;j++)
{
s=s+w[tw]*x[tx2];
tw=tw+1;
tx2=tx2+1;
}
x[tx1]=1/(1+Math.exp(-s));;
}
return x[tx1];
}
public void select()
{ int i,k,j,a;
sort();
fit_ave=fit_min+(fit_max-fit_min)/10;
k=0;
for(i=0;i<(int)(Group_Size*0.90);i++)//0.95
{ for(j=0;j<Gene_Len;j++)
// group[pool2[i]][j]=old_Group[k][j];
old_Group[k][j]=group[pool2[i]][j];
k=k+1;
}
i=0;
while(k<Group_Size)
{
//System.arraycopy(group[pool2[i]],0,old_Group[k],0,Gene_Len);
for(j=0;j<Gene_Len;j++)
{
// group[pool2[i]][a]=old_Group[k][a];
old_Group[k][j]=group[pool2[i]][j];
}
i=i+1;
k=k+1;
}
for(i=0;i<Group_Size;i++)
{ for(j=0;j<Gene_Len;j++)
// old_Group[i][j]=group[i][j];
group[i][j]=old_Group[i][j];
}
}
public double f(double x)
{
double result;
result=x*(1+Math.cos(x))*(2+Math.sin(2*x));
return result;
}
public void sort()
{
int i,j,k,s;
for(i=0;i<Group_Size;i++)
pool2[i]=i;
for(i=0;i<Group_Size;i++)
{
k=pool2[i];
for(j=i+1;j<Group_Size;j++)
{
if(gene_fit[pool2[j]]<gene_fit[k])
k=j;
}
s=pool2[i];
pool2[i]=k;
pool2[k]=s;
}
}
public void mutate()
{
int i,j,n,k,p1,p2,pa;
double p,q;
double a,b;
q=diff;
if(diff>0.09)
q=0.09;
p=q*200;
for(n=0;n<28;n++)//n<(int)((q*200)/2);
for(k=0;k<20;k++)//(int)(q*200)/3
{
if(Math.random()*100<p)
{
a=Math.random()*(Group_Size-nn)+(double)nn;
b=Math.random()*Gene_Len;
i=(int)a;
j=(int)b;
pa=60;
if(diff<0.05)
pa=40;
p1=(int)(Math.random()*100);
p2=(int)(Math.random()*100);
if(p1>pa)
group[i][j]=Math.random()*width-width/2;
else if(p1>pa+(100-pa)/2)
{
if(p2>70)
group[i][j]=group[i][j]+Math.random()*2;
else if(p2<30)
group[i][j]=group[i][j]+Math.random();
else
group[i][j]=group[i][j]+Math.random()/10;
}
else
{ if(p2>70)
group[i][j]=group[i][j]-Math.random()*2;
else if(p2<30)
group[i][j]=group[i][j]-Math.random()/2;
else
group[i][j]=group[i][j]-Math.random()/10;
}
}
}
}
public void invert()
{
int start,stop,i,j,n,k,ptr;
double t,p,q;
q=diff;
if(diff>0.09)
q=0.09;
p=diff*200;
for(n=0;n<(int)((q*200)/3);n++)
for(j=0;j<(int)((q*200)/3);j++)
{
if(Math.random()*100<p)
{
ptr=(int)(Math.random()*(Group_Size-nn)+nn);
start=(int)(Math.random()*Gene_Len);
stop=(int)(Math.random()*Gene_Len);
if(start<stop)
{k=start;
start=stop;
stop=k;
}
k=stop;
for(i=start;i<=(start+stop)/2;i++)
{
t=group[ptr][i];
group[ptr][i]=group[ptr][k];
group[ptr][k]=t;
k=k-1;
}
}
}
}
public void denormalize()
{ int i;
for(i=0;i<STEP;i++)
{
sampleResult[i]=sampleResult[i]*(max-min)+min;
actualResult[i]=actualResult[i]*(max-min)+min;
}
for(i=0;i<STEP;i++)
{
System.out.print(0+i*(Stop_X-Start_X)/STEP);
System.out.print(" ");
System.out.print(sampleResult[i]);
System.out.print(" ");
System.out.print(actualResult[i]);
System.out.println();
}
}
public void showWindow(){
ResultFrame frame =new ResultFrame(actualResult,sampleResult,listofinfo,max,min);
frame.show();
}
static boolean Quit_Flag;//是否学习完毕
private static final int STEP=40;
File fhw;//输入文件
File fhy;
File fhny;
BufferedReader reader;
PrintWriter writer;
private static int circle ;
private static double fit_max,fit_min,fit_ave;
private static final int Group_Size=30;
private double[] gene_fit =new double[Group_Size];
private static final int Gene_Len=21;
double[][] Gene_Array= new double[Group_Size][Gene_Len];
private static double[][] group=new double[Group_Size][Gene_Len];
private static double[][] old_Group=new double[Group_Size][Gene_Len];
private static final float width=90;
private static final double Start_X=0;
private static final double Stop_X=2*Math.PI;
double[] px= new double[STEP];
double[] py= new double[STEP];
private static final double pc=0.8;//0.8
private static final int nn=2;
int[] pool= new int[Group_Size];
int[] pool2=new int[Group_Size];
private int ptr_good;
private double diff;
Point[] learn_newpxy= new Point[STEP];
Point[] learn_oldpxy= new Point[STEP];
double[] w= new double[Gene_Len];
FileOutputStream outfw;
private static final double EPS=0.001;
double[] x=new double[11];
int[] x_pos=new int[4];
private static final int View_WEIGHT_NUM=5;
private LinkedList[] listofinfo=new LinkedList[View_WEIGHT_NUM];
private double[] info=new double[View_WEIGHT_NUM];
double min=9999;
double max=0;
double infoMinOutput=9999;
double infoMaxOutput=-9999;
double[] actualResult =new double[STEP];
double[] sampleResult =new double[STEP];
PrintWriter fw;
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -