package vb;
import tool.*;
public class pro {
int[] point=new int[31];
int s,number,datanumber;
double mu[]=new double[31];
double sig[]=new double[31];
double[] p=new double[31];
double mux[]=new double[31];
double sigx[]=new double[31];
double[][] px=new double[21][31];
double[] ps=new double[24];
double[] delta=new double[50001];
String[] data=new String[600];
int[] c=new int[40];
double dmu[]=new double[31];
double dsig[]=new double[31];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readfile sub2=new readfile();
sub2.makedata("data.csv","UTF-8");
data=sub2.data;
datanumber=sub2.datanumber;
for(s=2;s<datanumber+1;s++){
data[s]=rev_csv(data[s]);
String[] x=data[s].split(",");
point[s-1]=num_int(x[1]);
}
number=21;
for(s=1;s<number+1;s++){
datanumber=datanumber+point[s];
}
for(s=1;s<11;s++){
mu[s]=2*s;
sig[s]=3;
p[s]=0.1;
}
f sub=new f();
sub.point=point;
sub.number=number;
sub.p=p;
sub.sig=sig;
sub.mu=mu;
double e=sub.makedata();
System.out.println(e);
double h=0.01;
int tr;
for(tr=1;tr<number+1;tr++){
for(s=1;s<number+1;s++){
mux[s]=mu[s];
}
mu[tr]=mu[tr]+h;
f sub3=new f();
sub3.point=point;
sub3.number=number;
sub3.p=p;
sub3.sig=sig;
sub3.mu=mux;
double e1=sub.makedata();
dmu[tr]=(e1-e)/h;
System.out.println(tr+","+dmu[tr]);
}
for(tr=1;tr<number+1;tr++){
for(s=1;s<number+1;s++){
sigx[s]=sig[s];
}
sigx[tr]=sig[tr]+h;
f sub3=new f();
sub3.point=point;
sub3.number=number;
sub3.p=p;
sub3.sig=sigx;
sub3.mu=mu;
double e2=sub.makedata();
dsig[tr]=(e2-e)/h;
System.out.println(tr+","+dsig[tr]);
}
}
int randx(){
int s;
double[] px=new double[100];
px[1]=ps[1];
for(s=2;s<number+1;s++){
px[s]=px[s-1]+ps[s];
}
double m1=Math.random();
int nn=1;
for(s=1;s<number;s++){
if(m1>px[s])nn=s;
}
return nn;
}
int num_int(String str){
int nx;
nx=0;
try{
nx=Integer.parseInt(str);
}catch (Exception e) {}
return nx;
}
String rev_csv(String str){
String str5=str;
int px=str5.indexOf("\"");
while(px>-1){
str5=rev(str5);
px=str5.indexOf("\"");
}
return str5;
}
String rev(String str){
int p1=str.indexOf("\"");
int p2=str.indexOf("\"",p1+1);
String str1=str.substring(0,p1);
String str2=str.substring(p1+1,p2);
String str3=str.substring(p2+1,str.length());
str2=str2.replace(",","");
return str1+str2+str3;
}
}
package vb;
public class f {
int[] point=new int[31];
int s,number,datanumber;
double mu[]=new double[31];
double sig[]=new double[31];
double[] p=new double[31];
double[][] px=new double[21][31];
double[] ps=new double[24];
double[] delta=new double[50001];
String[] data=new String[600];
int[] c=new int[40];
double makedata(){
datanumber=0;
for(s=1;s<number+1;s++){
datanumber=datanumber+point[s];
}
int tr=3;
for(tr=1;tr<11;tr++){
double p1=0;
for(s=1;s<number+1;s++){
p1=p1+f(s,mu[tr],sig[tr]);
}
for(s=1;s<number+1;s++){
px[tr][s]=f(s,mu[tr],sig[tr])/p1;
}
}
for(s=1;s<number+1;s++){
double p1=0;
for(tr=1;tr<11;tr++){
p1=p1+p[tr]*px[tr][s];
}
ps[s]=p1;
}
double z=0;
for(s=1;s<number+1;s++){
z=z+(point[s]-datanumber*ps[s])*(point[s]-datanumber*ps[s])/(datanumber*ps[s]);
}
return z;
}
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;
}
}
最終更新:2016年12月14日 06:54