# Java验证辛钦大数定理-演道网

图一

import java.awt.Color;
import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.function.Function2D;
import org.jfree.data.function.NormalDistributionFunction2D;
import org.jfree.data.general.DatasetGroup;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class KhinchinBigDataTheorem {

/*********************************
*样本点集
********************************/
private static XYSeriesCollection dataset=new XYSeriesCollection();

/**********************************
* getXYSeriesCollection()
* 获得样本点XY坐标点集XYSeriesCollection
* @return
*********************************/
public static XYSeriesCollection getXYSeriesCollection(){
XYSeries series= new XYSeries("Khinchin");

int sampleSize=5000;                               //验证样本容量
int bin=10;                                         //以步长为bin进行样本概率统计
int poltSize=sampleSize/bin;                        //样本分成的区间数
double[] sampleProbability=new double[poltSize];    //每个区间内出现的点得数量的矩阵
double[] XAxis=new double[poltSize];                //每个区间所采取的Xi(X轴坐标点)的矩阵

for (int i = 0; i < XAxis.length; i++) {
sampleProbability[i]=0;
XAxis[i]=0;
}
/***************************************************
* 产生500000个(0,1)内均匀分布与(0-1)分布的样本点
* 画出样本数量从少到多的算术平均值趋向于均值的差距
***************************************************/
double u=0.5;                                       //样本服从的均值
double[] samplePoints=new double[sampleSize];       //分布的样本点
int su=0;
for (int i = 0; i < samplePoints.length; i++) {
//交替产生均匀分布与(0-1)分布样本点
if (i%2==0) {
samplePoints[i]=new Random().nextDouble();
}else {
samplePoints[i]=generator(0.5);
}
}

double sum=0;
for (int i = 0; i < samplePoints.length; i++) {
sum+=samplePoints[i];
if (i%bin==0) {
XAxis[i/bin]=i;
sampleProbability[i/bin]=sum/(i+1);
//System.out.println(sampleProbability[i/bin]);
}
}
for (int i = 0; i < poltSize ; i++) {
}

return dataset;
}

/**********************************************
* 产生概率为0.5的(0-1)分布点
* @param p
* @return
**********************************************/
public static int generator(double p){
Random random=new Random();
double g=random.nextDouble();
int i=0;
if(g