package p3;
public class pro {
int[] point=new int[100];
int[] pointx=new int[100];
double[] p=new double[11];
double[] mu=new double[11];
double[] sig=new double[11];
double[] ps=new double[11];
double[][] q=new double[31][11];
public static void main(String[] args) {
pro r=new pro();
}
pro(){
int s,sx;
point[ 1 ]=1351 ;
point[ 2 ]= 296 ;
point[ 3 ]= 265 ;
point[ 4 ]= 227 ;
point[ 5 ]= 238 ;
point[ 6 ]= 209 ;
point[ 7 ]= 197 ;
point[ 8 ]= 169 ;
point[ 9 ]= 183 ;
point[ 10 ]= 149 ;
point[ 11 ]= 164 ;
point[ 12 ]= 133 ;
point[ 13 ]= 136 ;
point[ 14 ]= 125 ;
point[ 15 ]= 141 ;
point[ 16 ]= 124 ;
point[ 17 ]= 99 ;
point[ 18 ]= 89 ;
point[ 19 ]= 61 ;
point[ 20 ]= 60 ;
point[ 21 ]= 410 ;
pointx[ 1 ]= 54 ;
pointx[ 2 ]= 205 ;
pointx[ 3 ]= 339 ;
pointx[ 4 ]= 380 ;
pointx[ 5 ]= 407 ;
pointx[ 6 ]= 385 ;
pointx[ 7 ]= 358 ;
pointx[ 8 ]= 336 ;
pointx[ 9 ]= 298 ;
pointx[ 10 ]= 265 ;
pointx[ 11 ]= 223 ;
pointx[ 12 ]= 234 ;
pointx[ 13 ]= 191 ;
pointx[ 14 ]= 168 ;
pointx[ 15 ]= 157 ;
pointx[ 16 ]= 133 ;
pointx[ 17 ]= 93 ;
pointx[ 18 ]= 89 ;
pointx[ 19 ]= 86 ;
pointx[ 20 ]= 77 ;
pointx[ 21 ]= 348 ;
for(sx=1;sx<11;sx++){
mu[sx]=2*sx;
sig[sx]=2;
p[sx]=0.1;
}
int tr;
for(tr=1;tr<6;tr++){
trial sub=new trial();
sub.point=point;
sub.mu=mu;
sub.p=p;
sub.sig=sig;
sub.makedata();
p=sub.p;
mu=sub.mu;
sig=sub.sig;
}
for(sx=1;sx<11;sx++){
System.out.println(p[sx]+","+mu[sx]+","+sig[sx]);
}
}
double f(double x,double mux,double sigx){
double pi,f1,f2;
pi=Math.PI;
f2=Math.sqrt(2*pi*sigx*sigx);
f1=-(x-mux)*(x-mux)/(2*sigx*sigx);
return Math.exp(f1)/f2;
}
}
package p3;
public class trial {
int[] point=new int[100];
int[] pointx=new int[100];
double[] p=new double[11];
double[] mu=new double[11];
double[] sig=new double[11];
double[] ps=new double[11];
double[][] q=new double[31][11];
void makedata(){
int s,sx;
for(s=1;s<22;s++){
double p2=0;
for(sx=1;sx<11;sx++){
p2=p2+p[sx]*f(s,mu[sx],sig[sx]);
}
for(sx=1;sx<11;sx++){
q[s][sx]=p[sx]*f(s,mu[sx],sig[sx])/p2;
}
}
int de=0;
for(s=1;s<22;s++){
de=de+point[s];
}
for(sx=1;sx<11;sx++){
double pp=0;
for(s=1;s<22;s++){
pp=pp+q[s][sx]*point[s];
}
ps[sx]=pp/de;
}
for(sx=1;sx<11;sx++){
double a1=0;
double a2=0;
for(s=1;s<22;s++){
a1=a1+q[s][sx]*point[s];
a2=a2+s*q[s][sx]*point[s];
}
if(a1>0)mu[sx]=a2/a1;
a1=0;
a2=0;
for(s=1;s<22;s++){
a1=a1+q[s][sx]*point[s];
a2=a2+q[s][sx]*point[s]*(s-mu[sx])*(s-mu[sx]);
}
if(a1>0)sig[sx]=Math.sqrt(a2/a1);
}
for(sx=1;sx<11;sx++){
p[sx]=ps[sx];
}
}
double f(double x,double mux,double sigx){
double pi,f1,f2;
pi=Math.PI;
f2=Math.sqrt(2*pi*sigx*sigx);
f1=-(x-mux)*(x-mux)/(2*sigx*sigx);
return Math.exp(f1)/f2;
}
}
最終更新:2017年01月01日 14:54