複数の検定でコントロールを共用にすること

メモ

> pool<-scan(file="B_pool.txt",sep="\t")
Read 17084 items
> pool<-scan(file="B_pool.txt",sep="\t")
Read 2050 items

> ind<-scan(file="B_ind.txt",sep="\t")
Read 2550 items
  
> indmat<-matrix(ind,nrow=50)

> persp(indmat,phi=0,theta=-45,shade=0.5,zlim=c(0,0.1),col="red")
> par(new=T)
> persp(poolmat,phi=0,theta=-45,shade=0.5,zlim=c(0,0.1),col="blue")
> 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class PoolVSRegular_2DplotSVG {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		/*
		 * 分割表
		 */
		
		int[][] M1={{50,50,100},{40,160},{200}};
		int[][][] M2={{{50,50},{20,80},{100}},{{50,50},{20,80},{100}}};
		
		
		
		int N=1;
		int numfiles=4;
		BufferedWriter[] bw = new BufferedWriter[numfiles];
		String[] suffix=new String[numfiles];
		suffix[0]="pool.svg";
		suffix[1]="ind.svg";
		String out = "D";
		
		suffix[2]="pool.txt";
		suffix[3]="ind.txt";
		
		
		
		
		
		for(int i=0;i<bw.length;i++){
			bw[i]=null;
			
		}
		for(int i=0;i<bw.length;i++){
			String tmp=out+"_"+suffix[i];
			bw[i] = new BufferedWriter(new FileWriter(tmp));
		}
		
		
		//for(int x=0;x<repeat;x++){
			
			int ncase = 50;
			int ncont = 50;
			int seed = (int)(Math.random()*100000000);
			Utils.MersenneTwisterFast mz=new Utils.MersenneTwisterFast(seed);
			double[][] chis = new double[N][4];
			
			for(int i=0;i<N;i++){
				int[][] t = new int[2][3];
				//double r = mz.nextDouble()*0.6+0.2;
				double r=0.5;
				double[] a ={r*r,r*r+2*r*(1-r),1};
				//a[0]=0.05;
				//a[1]=0.95;
				for(int j=0;j<ncase;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[0][k]++;
							break;
						}
					}
					
				}
				for(int j=0;j<ncont;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[1][k]++;
							break;
						}
					}
					
				}
				
				//int sum = mline[0]+mline[1];
				int sum=Math.max(M1[0][0], M1[1][0]);
				double[] size ={500,500};
				double[] viewBoxZero ={-1,-1};
				double[] viewBoxLength = {sum-viewBoxZero[0],sum-viewBoxZero[1]};
				/*
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
						*/
				/*
				 * 2x3 table Probを分離カラーリングするためのインデックス
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
				*/
				
				double[][] grad1={{2.772588722,5.545177445,8.317766167,11.09035489,13.86294361,16.63553233,19.40812106,22.18070978,24.9532985,27.72588722},
						{0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1},
						{0.001,0.005,0.01,0.03,0.05,0.06,0.07,0.08,0.1,1}};
				
				//String[] color ={"#FFFFFF","#DDDDDD","#CCCCCC","#AAAAAA","#999999","#777777","#555555","#444444","#222222","#000000"};
				String[] color ={"#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111","#000000"};
				String header = "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
				header += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
				header += "<svg width=\""+ size[0] +"\" height=\"" + size[1] +"\" viewBox=\"" + viewBoxZero[0] + " " + viewBoxZero[1] +" " + viewBoxLength[0] + " " + viewBoxLength[1] +"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
				String footer = "</svg>\n";
				
				for(int m=0;m<2;m++){
					BioBankPerm2.Run.out3File(bw[m],header);
				}
				
				double[] sl = StatUtilsX.Fisher.serialLogfact(M1[2][0]);
				/*
				 * pool
				 */
				int[][] pool=new int[3][2];
				double pr=0;
				double compool= sl[M1[0][0]]+sl[M1[0][1]]+sl[M1[0][2]]+sl[M1[1][0]]+sl[M1[1][1]]-sl[M1[2][0]];
				
				for(int x=0;x<M1[0][0];x++){
					for(int j=0;j<M1[1][0];j++){
						//System.out.println("x="+x+" j="+j);
						pool[0][0]=x;
						pool[1][0]=j;
						pool[0][1]=M1[0][0]-x;
						pool[1][1]=M1[0][1]-j;
						pool[2][0]=M1[1][0]-x-j;
						pool[2][1]=M1[0][2]-pool[2][0];
						boolean zero=true;
						double tmp =0;
						for(int k=0;k<pool.length;k++){
							for(int l=0;l<pool[k].length;l++){
								if(pool[k][l]<0){
									zero=false;
									//break;
								}else{
									tmp+=sl[pool[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							pr=Math.exp(compool-tmp);
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[0], ""+object);
								//BioBankPerm2.Run.out3File(bw[2], pr+"\t");
								//System.out.print(pr+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[2], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[0], "\n");
					BioBankPerm2.Run.out3File(bw[2], "\n");
				}
				/*
				 * independent
				 */
				double pr2=0;
				double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
				                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
				int[][] ind1=new int[2][2];
				int[][] ind2=new int[2][2];
				for(int x=0;x<M2[0][0][0];x++){
					ind1[0][0]=x;
					ind1[0][1]=M2[0][0][0]-x;
					ind1[1][0]=M2[0][1][0]-x;
					ind1[1][1]=M2[0][1][1]-ind1[0][1];
					for(int j=0;j<M2[1][0][0];j++){
						ind2[0][0]=j;
						ind2[0][1]=M2[1][0][0]-j;
						ind2[1][0]=M2[1][1][0]-j;
						ind2[1][1]=M2[1][1][1]-ind2[0][1];
						boolean zero=true;
						double tmp =0;
						for(int k=0;k<ind1.length;k++){
							for(int l=0;l<ind1[k].length;l++){
								if(ind1[k][l]<0 || ind2[k][l]<0){
									zero=false;
									//break;
								}else{
									tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							pr2=Math.exp(compool2-tmp);
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr2<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[1], ""+object);
								BioBankPerm2.Run.out3File(bw[3], pr2+"\t");
								//System.out.print(pr2+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[3], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[3], "\n");
				}
				
				
				
				for(int m=0;m<2;m++){
					BioBankPerm2.Run.out3File(bw[m],footer);
				}
				//System.out.print("\n");
				for(int m=0;m<bw.length;m++){
					bw[m].close();
				}
				
			}
			
	}

}
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class PoolVSRegular_2DplotSVG {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		/*
		 * 分割表
		 */
		
		int[][] M1={{50,50,50},{15,135},{150}};
		int[][][] M2={{{50,50},{10,90},{100}},{{50,50},{10,90},{100}}};
		String poolst="pooltestA";
		String indst="indtestA";
		double[][] prpool=prPool(M1);
		double[][] prind=prInd(M2);
		double tmpsum=0;
		for(int i=0;i<prpool.length;i++){
			for(int j=0;j<prpool[i].length;j++){
				//System.out.println(i + "\t"+j +"\t"+prpool[i][j]);
				tmpsum+=prpool[i][j];
			}
		}
		System.out.println("tmpsum=\t"+tmpsum);
		SVGpoolFromPr(M1,prpool,poolst);
		SVGindFromPr(M2,prind,indst);
		
		prpool=prind;
		
		
		double[][][] valuePool = valuePr(prpool);
		double[][] tmp3=probList2D(prpool,valuePool[3]);
		double[][] tmp0=probList2D(prpool,valuePool[0]);
		double[][] tmp1=probList2D(prpool,valuePool[1]);
		double[][] tmp2=probList2D(prpool,valuePool[2]);
		for(int i=0;i<tmp0.length;i++){
			for(int j=0;j<tmp0[i].length;j++){
				System.out.print(tmp0[i][j]+"\t");
				
			}
			System.out.println();
		}
		for(int i=0;i<tmp1.length;i++){
			for(int j=0;j<tmp1[i].length;j++){
				System.out.print(tmp1[i][j]+"\t");
				
			}
			System.out.println();
		}
		for(int i=0;i<tmp2.length;i++){
			for(int j=0;j<tmp2[i].length;j++){
				System.out.print(tmp2[i][j]+"\t");
				
			}
			System.out.println();
		}
		for(int i=0;i<tmp3.length;i++){
			for(int j=0;j<tmp3[i].length;j++){
				System.out.print(tmp3[i][j]+"\t");
				
			}
			System.out.println();
		}
		/*
		for(int i=0;i<valuePool.length;i++){
			System.out.println("i="+i);
			for(int j=0;j<valuePool[i].length;j++){
				for(int k=0;k<valuePool[i][j].length;k++){
					System.out.print(valuePool[i][j][k]+"\t");
				}
				System.out.println();
			}
			System.out.println();
		}
		/*
		double[][] Ppool = calcP2D(prpool,valuePool[3]);
		for(int i=0;i<Ppool.length;i++){
			for(int j=0;j<Ppool[i].length;j++){
				System.out.print(Ppool[i][j]+"\t");
			}
			System.out.println();
		}
		*/
		/*
		double[] V={0.1,0.2,0.3,0.3,0.2,0.3,0.4};
		double[] P={0.1,0.1,0.1,0.3,0.15,0.05,0.2};
		double[] x=calcP(P,V);
		for(int i=0;i<x.length;i++){
			System.out.println(V[i]+"\t"+x[i]);
		}
		double[][] tmp = probList(P,V);
		System.out.println("&&&");
		for(int i=0;i<tmp.length;i++){
			for(int j=0;j<tmp[i].length;j++){
				System.out.print(tmp[i][j]+"\t");
				
			}
			System.out.println();
		}
		*/	
	}
	public static double[][] pHolVertDiag(double[][] pr){
		double[][][] tmp = valuePr(pr);
		double[][] ret = {pHol(pr),pVert(pr),pDiag(pr),pDF2(pr),pTriple(pr)};
		
		return ret;
	}
	public static double[][] calcP2D(double[][] P, double[][] V){
		int[] size = new int[P.length];
		double[][] ret = new double[P.length][0];
		int N=0;
		for(int i=0;i<size.length;i++){
			size[i]=P[i].length;
			N+=P[i].length;
			ret[i]=new double[P[i].length];
		}
		double[] PL=new double[N];
		double[] VL=new double[N];
		int counter=0;
		for(int i=0;i<P.length;i++){
			for(int j=0;j<P[i].length;j++){
				PL[counter]=P[i][j];
				VL[counter]=V[i][j];
				counter++;
			}
		}
		double[] calcdP=calcP(PL,VL);
		counter=0;
		for(int i=0;i<ret.length;i++){
			for(int j=0;j<ret[i].length;j++){
				ret[i][j]=calcdP[counter];
				counter++;
			}
		}
		return ret;
		
	}
	public static double[] calcP(double[] P,double[] V){
		double[] ret = new double[V.length];
		
		for(int i=0;i<V.length;i++){
			for(int j=0;j<V.length;j++){
				if(V[i]>=V[j]){
					ret[i]+=P[j];
				}
			}
		}
		
		return ret;
	}
	public static double[][] probList(double[] P,double[] V){
		double[] tmp = calcP(P,V);
		double[] copyV=StatUtilsX.MiscUtil.DeepCopyDouble1(V);
		StatUtilsX.MiscUtil.quickSortDouble(tmp,0,tmp.length-1);
		StatUtilsX.MiscUtil.quickSortDouble(copyV,0,tmp.length-1);
		double[][] rettmp = new double[V.length][2];
		//System.out.println("%%%");
		//for(int i=0;i<tmp.length;i++){
			//System.out.println(tmp[i]+"\t"+copyV[i]);
		//}
		
		rettmp[0][0]=tmp[0];
		rettmp[0][1]=copyV[0];
		int counter=1;
		for(int i=1;i<tmp.length;i++){
			if(copyV[i]!=copyV[i-1]){
				rettmp[counter][0]=tmp[i];
				rettmp[counter][1]=copyV[i];
				counter++;
				//System.out.println("count");
			}
		}
		double[][] ret = new double[counter][2];
		for(int i=0;i<ret.length;i++){
			ret[i][0]=rettmp[i][0];
			ret[i][1]=rettmp[i][1];
		}
		return ret;
		
	}
	public static double[][] probList2D(double[][] P, double[][] V){
		int[] size = new int[P.length];
		double[][] ret = new double[P.length][0];
		int N=0;
		for(int i=0;i<size.length;i++){
			size[i]=P[i].length;
			N+=P[i].length;
			ret[i]=new double[P[i].length];
		}
		double[] PL=new double[N];
		double[] VL=new double[N];
		int counter=0;
		for(int i=0;i<P.length;i++){
			for(int j=0;j<P[i].length;j++){
				PL[counter]=P[i][j];
				VL[counter]=V[i][j];
				counter++;
			}
		}
		double[][] ret2 = probList(PL,VL);
		return ret2;
	}
	public static double[][][] valuePr(double[][] pr){
		double[][][] ret = new double[4][pr.length][pr[0].length];
		double[] hol=new double[pr.length];
		double[] vert=new double[pr[0].length];
		double[] diag=new double[pr.length+pr[0].length];
		
		for(int i=0;i<pr.length;i++){
			for(int j=0;j<pr[i].length;j++){
				hol[i]+=pr[i][j];
				vert[j]+=pr[i][j];
				diag[i+j]+=pr[i][j];
			}
		}
		double[] hol2=new double[pr.length];
		double[] vert2=new double[pr[0].length];
		double[] diag2=new double[pr.length+pr[0].length];
		for(int i=0;i<hol2.length;i++){
			for(int j=0;j<hol2.length;j++){
				if(hol[i]>=hol[j]){
					hol2[i]+=hol[j];
				}
			}
		}
		for(int i=0;i<vert2.length;i++){
			for(int j=0;j<vert2.length;j++){
				if(vert[i]>=vert[j]){
					vert2[i]+=vert[j];
				}
			}
		}
		for(int i=0;i<diag2.length;i++){
			for(int j=0;j<diag2.length;j++){
				if(diag[i]>=diag[j]){
					diag2[i]+=diag[j];
				}
			}
		}
		for(int i=0;i<pr.length;i++){
			for(int j=0;j<pr[i].length;j++){
				ret[0][i][j]=hol2[i];
				ret[1][i][j]=vert2[j];
				ret[2][i][j]=diag2[i+j];
				ret[3][i][j]=Math.min(ret[0][i][j],ret[1][i][j]);
				ret[3][i][j]=Math.min(ret[3][i][j],ret[2][i][j]);
			}
		}
		return ret;
	}
	public static double[] pHol(double[][] pr){
		double[] ret=new double[pr.length];
		
		return ret;
	}
	public static double[] pVert(double[][] pr){
		double[] ret=new double[pr[0].length];
		return ret;
	}
	public static double[] pDiag(double[][] pr){
		double[] ret=new double[pr.length+pr[0].length];
		return ret;
	}
	public static double[] pDF2(double[][] pr){
		double[] ret=new double[pr.length*pr[0].length];
		return ret;
	}
	public static double[] pTriple(double[][] pr){
		double[] ret=new double[pr.length+pr[0].length];
		return ret;
	}
	public static void SVGpoolFromPr(int[][] M1,double[][] prpool,String out)throws IOException{
//		int[][] M1={{50,50,100},{40,160},{200}};
		//int[][][] M2={{{50,50},{20,80},{100}},{{50,50},{20,80},{100}}};
		
		
		
		//int N=1;
		int numfiles=2;
		BufferedWriter[] bw = new BufferedWriter[numfiles];
		String[] suffix=new String[numfiles];
		suffix[0]="pool.svg";
		//suffix[1]="ind.svg";
		//String out = "D";
		
		suffix[1]="pool.txt";
		//suffix[3]="ind.txt";
		
		
		
		
		
		for(int i=0;i<bw.length;i++){
			bw[i]=null;
			
		}
		for(int i=0;i<bw.length;i++){
			String tmp=out+"_"+suffix[i];
			bw[i] = new BufferedWriter(new FileWriter(tmp));
		}
		
		
		//for(int x=0;x<repeat;x++){
			/*
			int ncase = 50;
			int ncont = 50;
			int seed = (int)(Math.random()*100000000);
			Utils.MersenneTwisterFast mz=new Utils.MersenneTwisterFast(seed);
			double[][] chis = new double[N][4];
			*/
			//for(int i=0;i<N;i++){
		/*
				int[][] t = new int[2][3];
				//double r = mz.nextDouble()*0.6+0.2;
				double r=0.5;
				double[] a ={r*r,r*r+2*r*(1-r),1};
				//a[0]=0.05;
				//a[1]=0.95;
				for(int j=0;j<ncase;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[0][k]++;
							break;
						}
					}
					
				}
				for(int j=0;j<ncont;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[1][k]++;
							break;
						}
					}
					
				}
				*/
				//int sum = mline[0]+mline[1];
				int sum=Math.max(M1[0][0], M1[1][0]);
				double[] size ={500,500};
				double[] viewBoxZero ={-1,-1};
				double[] viewBoxLength = {sum-viewBoxZero[0],sum-viewBoxZero[1]};
				/*
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
						*/
				/*
				 * 2x3 table Probを分離カラーリングするためのインデックス
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
				*/
				
				double[][] grad1={{2.772588722,5.545177445,8.317766167,11.09035489,13.86294361,16.63553233,19.40812106,22.18070978,24.9532985,27.72588722},
						{0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1},
						{0.001,0.005,0.01,0.03,0.05,0.06,0.07,0.08,0.1,1}};
				
				//String[] color ={"#FFFFFF","#DDDDDD","#CCCCCC","#AAAAAA","#999999","#777777","#555555","#444444","#222222","#000000"};
				String[] color ={"#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111","#000000"};
				String header = "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
				header += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
				header += "<svg width=\""+ size[0] +"\" height=\"" + size[1] +"\" viewBox=\"" + viewBoxZero[0] + " " + viewBoxZero[1] +" " + viewBoxLength[0] + " " + viewBoxLength[1] +"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
				String footer = "</svg>\n";
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],header);
				}
				
				//double[][] prpool=prPool(M1);
				//double[] sl = StatUtilsX.Fisher.serialLogfact(M1[2][0]);
				/*
				 * pool
				 */
				int[][] pool=new int[3][2];
				double pr=0;
				//double compool= sl[M1[0][0]]+sl[M1[0][1]]+sl[M1[0][2]]+sl[M1[1][0]]+sl[M1[1][1]]-sl[M1[2][0]];
				
				for(int x=0;x<M1[0][0];x++){
					for(int j=0;j<M1[0][1];j++){
						//System.out.println("x="+x+" j="+j);
						pool[0][0]=x;
						pool[1][0]=j;
						pool[0][1]=M1[0][0]-x;
						pool[1][1]=M1[0][1]-j;
						pool[2][0]=M1[1][0]-x-j;
						pool[2][1]=M1[0][2]-pool[2][0];
						boolean zero=true;
						
						//double tmp =0;
						for(int k=0;k<pool.length;k++){
							for(int l=0;l<pool[k].length;l++){
								if(pool[k][l]<0){
									zero=false;
									//break;
								}else{
									//tmp+=sl[pool[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						
						if(zero){
							//pr=Math.exp(compool-tmp);
							pr=prpool[x][j];
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[0], ""+object);
								BioBankPerm2.Run.out3File(bw[1], pr+"\t");
								//System.out.print(pr+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[1], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[0], "\n");
					BioBankPerm2.Run.out3File(bw[1], "\n");
				}
				/*
				 * independent
				 */
				/*
				double pr2=0;
				double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
				                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
				int[][] ind1=new int[2][2];
				int[][] ind2=new int[2][2];
				for(int x=0;x<M2[0][0][0];x++){
					ind1[0][0]=x;
					ind1[0][1]=M2[0][0][0]-x;
					ind1[1][0]=M2[0][1][0]-x;
					ind1[1][1]=M2[0][1][1]-ind1[0][1];
					for(int j=0;j<M2[1][0][0];j++){
						ind2[0][0]=j;
						ind2[0][1]=M2[1][0][0]-j;
						ind2[1][0]=M2[1][1][0]-j;
						ind2[1][1]=M2[1][1][1]-ind2[0][1];
						boolean zero=true;
						double tmp =0;
						for(int k=0;k<ind1.length;k++){
							for(int l=0;l<ind1[k].length;l++){
								if(ind1[k][l]<0 || ind2[k][l]<0){
									zero=false;
									//break;
								}else{
									tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							pr2=Math.exp(compool2-tmp);
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr2<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[1], ""+object);
								BioBankPerm2.Run.out3File(bw[3], pr2+"\t");
								//System.out.print(pr2+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[3], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[3], "\n");
				}
				*/
				
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],footer);
				}
				//System.out.print("\n");
				for(int m=0;m<bw.length;m++){
					bw[m].close();
				}
				
			//}
	}
	public static void SVGpool(int[][] M1,String out)throws IOException {
		//int[][] M1={{50,50,100},{40,160},{200}};
		//int[][][] M2={{{50,50},{20,80},{100}},{{50,50},{20,80},{100}}};
		
		
		
		//int N=1;
		int numfiles=2;
		BufferedWriter[] bw = new BufferedWriter[numfiles];
		String[] suffix=new String[numfiles];
		suffix[0]="pool.svg";
		//suffix[1]="ind.svg";
		//String out = "D";
		
		suffix[1]="pool.txt";
		//suffix[3]="ind.txt";
		
		
		
		
		
		for(int i=0;i<bw.length;i++){
			bw[i]=null;
			
		}
		for(int i=0;i<bw.length;i++){
			String tmp=out+"_"+suffix[i];
			bw[i] = new BufferedWriter(new FileWriter(tmp));
		}
		
		
		//for(int x=0;x<repeat;x++){
			/*
			int ncase = 50;
			int ncont = 50;
			int seed = (int)(Math.random()*100000000);
			Utils.MersenneTwisterFast mz=new Utils.MersenneTwisterFast(seed);
			double[][] chis = new double[N][4];
			*/
			//for(int i=0;i<N;i++){
		/*
				int[][] t = new int[2][3];
				//double r = mz.nextDouble()*0.6+0.2;
				double r=0.5;
				double[] a ={r*r,r*r+2*r*(1-r),1};
				//a[0]=0.05;
				//a[1]=0.95;
				for(int j=0;j<ncase;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[0][k]++;
							break;
						}
					}
					
				}
				for(int j=0;j<ncont;j++){
					double r2 = mz.nextDouble();
					for(int k=0;k<a.length;k++){
						if(r2<a[k]){
							t[1][k]++;
							break;
						}
					}
					
				}
				*/
				//int sum = mline[0]+mline[1];
				int sum=Math.max(M1[0][0], M1[1][0]);
				double[] size ={500,500};
				double[] viewBoxZero ={-1,-1};
				double[] viewBoxLength = {sum-viewBoxZero[0],sum-viewBoxZero[1]};
				/*
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
						*/
				/*
				 * 2x3 table Probを分離カラーリングするためのインデックス
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
				*/
				
				double[][] grad1={{2.772588722,5.545177445,8.317766167,11.09035489,13.86294361,16.63553233,19.40812106,22.18070978,24.9532985,27.72588722},
						{0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1},
						{0.001,0.005,0.01,0.03,0.05,0.06,0.07,0.08,0.1,1}};
				
				//String[] color ={"#FFFFFF","#DDDDDD","#CCCCCC","#AAAAAA","#999999","#777777","#555555","#444444","#222222","#000000"};
				String[] color ={"#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111","#000000"};
				String header = "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
				header += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
				header += "<svg width=\""+ size[0] +"\" height=\"" + size[1] +"\" viewBox=\"" + viewBoxZero[0] + " " + viewBoxZero[1] +" " + viewBoxLength[0] + " " + viewBoxLength[1] +"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
				String footer = "</svg>\n";
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],header);
				}
				
				double[][] prpool=prPool(M1);
				//double[] sl = StatUtilsX.Fisher.serialLogfact(M1[2][0]);
				/*
				 * pool
				 */
				int[][] pool=new int[3][2];
				double pr=0;
				//double compool= sl[M1[0][0]]+sl[M1[0][1]]+sl[M1[0][2]]+sl[M1[1][0]]+sl[M1[1][1]]-sl[M1[2][0]];
				
				for(int x=0;x<M1[0][0];x++){
					for(int j=0;j<M1[1][0];j++){
						//System.out.println("x="+x+" j="+j);
						pool[0][0]=x;
						pool[1][0]=j;
						pool[0][1]=M1[0][0]-x;
						pool[1][1]=M1[0][1]-j;
						pool[2][0]=M1[1][0]-x-j;
						pool[2][1]=M1[0][2]-pool[2][0];
						boolean zero=true;
						
						//double tmp =0;
						for(int k=0;k<pool.length;k++){
							for(int l=0;l<pool[k].length;l++){
								if(pool[k][l]<0){
									zero=false;
									//break;
								}else{
									//tmp+=sl[pool[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						
						if(zero){
							//pr=Math.exp(compool-tmp);
							pr=prpool[x][j];
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[0], ""+object);
								BioBankPerm2.Run.out3File(bw[1], pr+"\t");
								//System.out.print(pr+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[1], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[0], "\n");
					BioBankPerm2.Run.out3File(bw[1], "\n");
				}
				/*
				 * independent
				 */
				/*
				double pr2=0;
				double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
				                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
				int[][] ind1=new int[2][2];
				int[][] ind2=new int[2][2];
				for(int x=0;x<M2[0][0][0];x++){
					ind1[0][0]=x;
					ind1[0][1]=M2[0][0][0]-x;
					ind1[1][0]=M2[0][1][0]-x;
					ind1[1][1]=M2[0][1][1]-ind1[0][1];
					for(int j=0;j<M2[1][0][0];j++){
						ind2[0][0]=j;
						ind2[0][1]=M2[1][0][0]-j;
						ind2[1][0]=M2[1][1][0]-j;
						ind2[1][1]=M2[1][1][1]-ind2[0][1];
						boolean zero=true;
						double tmp =0;
						for(int k=0;k<ind1.length;k++){
							for(int l=0;l<ind1[k].length;l++){
								if(ind1[k][l]<0 || ind2[k][l]<0){
									zero=false;
									//break;
								}else{
									tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							pr2=Math.exp(compool2-tmp);
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr2<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[1], ""+object);
								BioBankPerm2.Run.out3File(bw[3], pr2+"\t");
								//System.out.print(pr2+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[3], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[3], "\n");
				}
				*/
				
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],footer);
				}
				//System.out.print("\n");
				for(int m=0;m<bw.length;m++){
					bw[m].close();
				}
				
			//}
	}

	public static void SVGind(int[][][] M2,String out)throws IOException {
		//int[][] M1={{50,50,100},{40,160},{200}};
		//int[][][] M2={{{50,50},{20,80},{100}},{{50,50},{20,80},{100}}};
		
		
		
		//int N=1;
		int numfiles=2;
		BufferedWriter[] bw = new BufferedWriter[numfiles];
		String[] suffix=new String[numfiles];
		suffix[0]="ind.svg";
		//suffix[1]="ind.svg";
		//String out = "D";
		
		suffix[1]="ind.txt";
		//suffix[3]="ind.txt";
		
		
		
		
		
		for(int i=0;i<bw.length;i++){
			bw[i]=null;
			
		}
		for(int i=0;i<bw.length;i++){
			String tmp=out+"_"+suffix[i];
			bw[i] = new BufferedWriter(new FileWriter(tmp));
		}
		
		
		
				//int sum = mline[0]+mline[1];
				int sum=Math.max(M2[0][0][0], M2[1][0][0]);
				double[] size ={500,500};
				double[] viewBoxZero ={-1,-1};
				double[] viewBoxLength = {sum-viewBoxZero[0],sum-viewBoxZero[1]};
				/*
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
						*/
				/*
				 * 2x3 table Probを分離カラーリングするためのインデックス
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
				*/
				
				double[][] grad1={{2.772588722,5.545177445,8.317766167,11.09035489,13.86294361,16.63553233,19.40812106,22.18070978,24.9532985,27.72588722},
						{0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1},
						{0.001,0.005,0.01,0.03,0.05,0.06,0.07,0.08,0.1,1}};
				
				//String[] color ={"#FFFFFF","#DDDDDD","#CCCCCC","#AAAAAA","#999999","#777777","#555555","#444444","#222222","#000000"};
				String[] color ={"#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111","#000000"};
				String header = "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
				header += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
				header += "<svg width=\""+ size[0] +"\" height=\"" + size[1] +"\" viewBox=\"" + viewBoxZero[0] + " " + viewBoxZero[1] +" " + viewBoxLength[0] + " " + viewBoxLength[1] +"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
				String footer = "</svg>\n";
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],header);
				}
				
				double[][] prInd=prInd(M2);
				//double[] sl = StatUtilsX.Fisher.serialLogfact(Math.max(M2[0][2][0],M2[1][2][0]));
				
				/*
				 * independent
				 */
				
				double pr2=0;
				/*
				double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
				                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
				*/
				int[][] ind1=new int[2][2];
				int[][] ind2=new int[2][2];
				for(int x=0;x<M2[0][0][0];x++){
					ind1[0][0]=x;
					ind1[0][1]=M2[0][0][0]-x;
					ind1[1][0]=M2[0][1][0]-x;
					ind1[1][1]=M2[0][1][1]-ind1[0][1];
					for(int j=0;j<M2[1][0][0];j++){
						ind2[0][0]=j;
						ind2[0][1]=M2[1][0][0]-j;
						ind2[1][0]=M2[1][1][0]-j;
						ind2[1][1]=M2[1][1][1]-ind2[0][1];
						boolean zero=true;
						//double tmp =0;
						for(int k=0;k<ind1.length;k++){
							for(int l=0;l<ind1[k].length;l++){
								if(ind1[k][l]<0 || ind2[k][l]<0){
									zero=false;
									//break;
								}else{
									//tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							//pr2=Math.exp(compool2-tmp);
							pr2=prInd[x][j];
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr2<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[0], ""+object);
								BioBankPerm2.Run.out3File(bw[1], pr2+"\t");
								//System.out.print(pr2+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[1], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[1], "\n");
				}
				
				
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],footer);
				}
				//System.out.print("\n");
				for(int m=0;m<bw.length;m++){
					bw[m].close();
				}
				
			//}
	}
	public static void SVGindFromPr(int[][][] M2,double[][] prInd,String out)throws IOException {
		//int[][] M1={{50,50,100},{40,160},{200}};
		//int[][][] M2={{{50,50},{20,80},{100}},{{50,50},{20,80},{100}}};
		
		
		
		//int N=1;
		int numfiles=2;
		BufferedWriter[] bw = new BufferedWriter[numfiles];
		String[] suffix=new String[numfiles];
		suffix[0]="ind.svg";
		//suffix[1]="ind.svg";
		//String out = "D";
		
		suffix[1]="ind.txt";
		//suffix[3]="ind.txt";
		
		
		
		
		
		for(int i=0;i<bw.length;i++){
			bw[i]=null;
			
		}
		for(int i=0;i<bw.length;i++){
			String tmp=out+"_"+suffix[i];
			bw[i] = new BufferedWriter(new FileWriter(tmp));
		}
		
		
		
				//int sum = mline[0]+mline[1];
				int sum=Math.max(M2[0][0][0], M2[1][0][0]);
				double[] size ={500,500};
				double[] viewBoxZero ={-1,-1};
				double[] viewBoxLength = {sum-viewBoxZero[0],sum-viewBoxZero[1]};
				/*
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
						*/
				/*
				 * 2x3 table Probを分離カラーリングするためのインデックス
				double[][] grad1={{0.0000000,0.1379857,0.2862017,0.4462871,0.6203099,0.8109302,1.0216512,1.2572173,1.5242801,1.8325815,2.1972246,2.6435117,3.2188758,4.0298060,5.4161004,36.8413615},
						{0.00000000,0.06666667,0.13333333,0.20000000,0.26666667,0.33333333
					,0.40000000,0.46666667,0.53333333,0.60000000,0.66666667,0.73333333
					,0.80000000,0.86666667,0.93333333,1},
						{0.00000000,0.00000001,0.0000001,0.000001,0.00001,0.0001
						,0.001,0.0013,0.005,0.01,0.015,0.016
						,0.06,0.09,0.1,0.15}};
				*/
				
				double[][] grad1={{2.772588722,5.545177445,8.317766167,11.09035489,13.86294361,16.63553233,19.40812106,22.18070978,24.9532985,27.72588722},
						{0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1},
						{0.001,0.005,0.01,0.03,0.05,0.06,0.07,0.08,0.1,1}};
				
				//String[] color ={"#FFFFFF","#DDDDDD","#CCCCCC","#AAAAAA","#999999","#777777","#555555","#444444","#222222","#000000"};
				String[] color ={"#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111","#000000"};
				String header = "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
				header += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
				header += "<svg width=\""+ size[0] +"\" height=\"" + size[1] +"\" viewBox=\"" + viewBoxZero[0] + " " + viewBoxZero[1] +" " + viewBoxLength[0] + " " + viewBoxLength[1] +"\" xmlns=\"http://www.w3.org/2000/svg\">\n";
				String footer = "</svg>\n";
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],header);
				}
				
				//double[][] prInd=prInd(M2);
				//double[] sl = StatUtilsX.Fisher.serialLogfact(Math.max(M2[0][2][0],M2[1][2][0]));
				
				/*
				 * independent
				 */
				
				double pr2=0;
				/*
				double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
				                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
				*/
				int[][] ind1=new int[2][2];
				int[][] ind2=new int[2][2];
				for(int x=0;x<M2[0][0][0];x++){
					ind1[0][0]=x;
					ind1[0][1]=M2[0][0][0]-x;
					ind1[1][0]=M2[0][1][0]-x;
					ind1[1][1]=M2[0][1][1]-ind1[0][1];
					for(int j=0;j<M2[1][0][0];j++){
						ind2[0][0]=j;
						ind2[0][1]=M2[1][0][0]-j;
						ind2[1][0]=M2[1][1][0]-j;
						ind2[1][1]=M2[1][1][1]-ind2[0][1];
						boolean zero=true;
						//double tmp =0;
						for(int k=0;k<ind1.length;k++){
							for(int l=0;l<ind1[k].length;l++){
								if(ind1[k][l]<0 || ind2[k][l]<0){
									zero=false;
									//break;
								}else{
									//tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
								}
							}
							if(!zero){
								//break;
							}
						}
						if(zero){
							//pr2=Math.exp(compool2-tmp);
							pr2=prInd[x][j];
							double[] position={x,j};
							int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
							//for(int m=0;m<16;m++){
								double[] rectsize ={1,1};
								String rectcolor="";
								for(int l=0;l<grad1[gradselect[7]].length;l++){
									if(pr2<=grad1[gradselect[7]][l]){
										if(gradselect[7]==0){
											rectcolor=color[l];
										}else{
											rectcolor=color[color.length-1-l];
										}
										
										break;
									}
								}
								String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
								BioBankPerm2.Run.out3File(bw[0], ""+object);
								BioBankPerm2.Run.out3File(bw[1], pr2+"\t");
								//System.out.print(pr2+"\t");
							//}
							
							//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
						}else{
							//BioBankPerm2.Run.out3File(bw[0], "\t");
							BioBankPerm2.Run.out3File(bw[1], "\t");
							//System.out.print("\t");
						}
					}
					//System.out.println();
					BioBankPerm2.Run.out3File(bw[1], "\n");
				}
				
				
				
				for(int m=0;m<1;m++){
					BioBankPerm2.Run.out3File(bw[m],footer);
				}
				//System.out.print("\n");
				for(int m=0;m<bw.length;m++){
					bw[m].close();
				}
				
			//}
	}
	public static double[][] prPool(int[][]M1){
		double[][] ret = new double[M1[0][0]][M1[0][1]];
		double[] sl = StatUtilsX.Fisher.serialLogfact(M1[2][0]);
		int[][] pool=new int[3][2];
		double pr=0;
		double compool= sl[M1[0][0]]+sl[M1[0][1]]+sl[M1[0][2]]+sl[M1[1][0]]+sl[M1[1][1]]-sl[M1[2][0]];
		
		for(int x=0;x<M1[0][0];x++){
			for(int j=0;j<M1[0][1];j++){
				//System.out.println("x="+x+" j="+j);
				pool[0][0]=x;
				pool[1][0]=j;
				pool[0][1]=M1[0][0]-x;
				pool[1][1]=M1[0][1]-j;
				pool[2][0]=M1[1][0]-x-j;
				pool[2][1]=M1[0][2]-pool[2][0];
				boolean zero=true;
				double tmp =0;
				for(int k=0;k<pool.length;k++){
					for(int l=0;l<pool[k].length;l++){
						if(pool[k][l]<0){
							zero=false;
							//break;
						}else{
							tmp+=sl[pool[k][l]];
						}
					}
					if(!zero){
						//break;
					}
				}
				if(zero){
					pr=Math.exp(compool-tmp);
					double[] position={x,j};
					int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
					//for(int m=0;m<16;m++){
						double[] rectsize ={1,1};
						String rectcolor="";
						/*
						for(int l=0;l<grad1[gradselect[7]].length;l++){
							if(pr<=grad1[gradselect[7]][l]){
								if(gradselect[7]==0){
									rectcolor=color[l];
								}else{
									rectcolor=color[color.length-1-l];
								}
								
								break;
							}
						}
						*/
						//String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
						//BioBankPerm2.Run.out3File(bw[0], ""+object);
						//BioBankPerm2.Run.out3File(bw[1], pr+"\t");
						ret[x][j]=pr;
						//System.out.print(pr+"\t");
					//}
					
					//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
				}else{
					//BioBankPerm2.Run.out3File(bw[0], "\t");
					//BioBankPerm2.Run.out3File(bw[1], "\t");
					//System.out.print("\t");
					ret[x][j]=0;
				}
			}
			//System.out.println();
			//BioBankPerm2.Run.out3File(bw[0], "\n");
			//BioBankPerm2.Run.out3File(bw[1], "\n");
		}
		return ret;
		
	}

	public static double[][] prInd(int[][][]M2){
		double[][] ret = new double[M2[0][0][0]][M2[1][0][0]];
		double[] sl = StatUtilsX.Fisher.serialLogfact(Math.max(M2[0][2][0],M2[1][2][0]));
		double pr2=0;
		double compool2= sl[M2[0][0][0]]+sl[M2[0][0][1]]+sl[M2[0][1][0]]+sl[M2[0][1][1]]-sl[M2[0][2][0]]
		                 +sl[M2[1][0][0]]+sl[M2[1][0][1]]+sl[M2[1][1][0]]+sl[M2[1][1][1]]-sl[M2[1][2][0]];
		int[][] ind1=new int[2][2];
		int[][] ind2=new int[2][2];
		for(int x=0;x<M2[0][0][0];x++){
			ind1[0][0]=x;
			ind1[0][1]=M2[0][0][0]-x;
			ind1[1][0]=M2[0][1][0]-x;
			ind1[1][1]=M2[0][1][1]-ind1[0][1];
			for(int j=0;j<M2[1][0][0];j++){
				ind2[0][0]=j;
				ind2[0][1]=M2[1][0][0]-j;
				ind2[1][0]=M2[1][1][0]-j;
				ind2[1][1]=M2[1][1][1]-ind2[0][1];
				boolean zero=true;
				double tmp =0;
				for(int k=0;k<ind1.length;k++){
					for(int l=0;l<ind1[k].length;l++){
						if(ind1[k][l]<0 || ind2[k][l]<0){
							zero=false;
							//break;
						}else{
							tmp+=sl[ind1[k][l]]+sl[ind2[k][l]];
						}
					}
					if(!zero){
						//break;
					}
				}
				if(zero){
					pr2=Math.exp(compool2-tmp);
					double[] position={x,j};
					int[] gradselect={0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2};
					//for(int m=0;m<16;m++){
						double[] rectsize ={1,1};
						String rectcolor="";
						/*
						for(int l=0;l<grad1[gradselect[7]].length;l++){
							if(pr2<=grad1[gradselect[7]][l]){
								if(gradselect[7]==0){
									rectcolor=color[l];
								}else{
									rectcolor=color[color.length-1-l];
								}
								
								break;
							}
						}
						*/
						//String object = DiscreteMathTools.PowerSet.StringRect(position, rectsize,rectcolor);
						//BioBankPerm2.Run.out3File(bw[0], ""+object);
						//BioBankPerm2.Run.out3File(bw[1], pr2+"\t");
						ret[x][j]=pr2;
						//System.out.print(pr2+"\t");
					//}
					
					//BioBankPerm2.Run.out3File(bw[0], pr+"\t");
				}else{
					//BioBankPerm2.Run.out3File(bw[0], "\t");
					//BioBankPerm2.Run.out3File(bw[1], "\t");
					ret[x][j]=0;
					//System.out.print("\t");
				}
			}
			//System.out.println();
			//BioBankPerm2.Run.out3File(bw[1], "\n");
		}
		return ret;
	}
}