# モーメント

Wikipediaの記事はこちら

３次のモーメントは歪度、尖度などに対応

```
public static double momentCentralXSt(double[] a,int dim){

double mean = momentX(a,0,1);
double sigma = momentX(a,mean,2);
double ret = momentX(a,mean,dim);
sigma = Math.sqrt(sigma);
double tmp = Math.log(sigma)*dim;
ret /=Math.exp(tmp);
return ret;
}
public static double momentCentralX(double[] a,int dim){
double mean = momentX(a,0,1);
double sigma = momentX(a,mean,2);
sigma = Math.sqrt(sigma);
//System.out.println("mean " + mean);
double ret = momentX(a,mean,dim);
return ret;
}
public static double momentX(double[] a,double m,int dim){
double ret = 0;
for(int i=0;i<a.length;i++){
double tmp = 0;
double pm =1;
if(a[i] != m){
if(a[i]>m){
//System.out.println("a[i] " + a[i]);
double tmp2 = Math.log(a[i]-m);
//System.out.println("tmp2 " + tmp2);
tmp = tmp2 * dim;

}else{
//System.out.println("a[i] " + a[i]);
double pm2 =-1;
double tmp2 = Math.log(-(a[i]-m));
//System.out.println("tmp2 " + tmp2);
tmp = tmp2 * dim;
for(int j=0;j<dim;j++){
//tmp+=tmp2;
pm*=pm2;
}
//System.out.println("pm " + pm2);
}
//System.out.println("tmp " + tmp);
double ttt = Math.exp(tmp)*pm;
//System.out.println("ttt " + ttt);
ret += Math.exp(tmp)*pm;			}

}
ret /= a.length;
return ret;
}

```