package pu;
public class pro {
double[][] p=new double[5][3];
int creditnumber,datanumber;
int[][] x=new int[101][5];
int[] number=new int[5];
int[] y=new int[5];
int n,sx;
double[][] tablex=new double[3][3];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
datanumber=100;
creditnumber=2;
number[1]=2;
number[2]=2;
p[1][1]=0.7;
p[1][2]=0.3;
p[2][1]=0.7;
p[2][2]=0.3;
faststep();
tablex[1][1]=0.1;
tablex[1][2]=0.5;
tablex[2][1]=0.2;
tablex[2][2]=0.2;
int tr;
for(tr=1;tr<1001;tr++){
trial();
n=select();
for(sx=1;sx<creditnumber+1;sx++){
x[n][sx]=y[sx];
}
}
}
int select(){
int s,sx;
double maxv,v1;
maxv=-9999;
sx=0;
for(s=1;s<datanumber+1;s++){
v1=replacev(s);
if(v1>maxv)sx=s;
if(v1>maxv)maxv=v1;
}
return sx;
}
double replacev(int c){
int s,sx,s1,s2;
double p1,p2;
p2=0;
for(s=1;s<datanumber+1;s++){
s1=x[s][1];
s2=x[s][2];
p1=Math.log(tablex[s1][s2]);
s1=y[1];
s2=y[2];
if(c==s)p1=Math.log(tablex[s1][s2]);
p2=p2+p1;
}
return p2;
}
void faststep(){
int s,sx;
for(s=1;s<datanumber+1;s++){
trial();
for(sx=1;sx<creditnumber+1;sx++){
x[s][sx]=y[sx];
}
}
}
void trial(){
int sx;
for(sx=1;sx<creditnumber+1;sx++){
y[sx]=makep(sx);
}
}
int makep(int sx){
double p1;
double[] q=new double[50];
int s,x1;
q[1]=p[sx][1];
for(s=2;s<number[sx]+1;s++){
q[s]=q[s-1]+p[sx][s];
}
p1=Math.random();
x1=1;
for(s=1;s<number[sx]+1;s++){
if(p1>q[s])x1=s+1;
}
return x1;
}
}
最終更新:2014年03月20日 01:35