在JAVA中运用正态分布
  Ou9C1GfddcUF 2023年12月23日 66 0

概述:

正态分布是统计学中常用的一种概率分布。当数据量足够大时,很多分布近似于正态分布,因此它是常用的一种分布。这里主要是介绍,在Java中我们可以使用一些库和方法来实现正态分布。

1.正态分布在Java中的运行要求:

除了正常的Java运行环境外,需要下载以下工具包;

Apache Commons Statistics

Numbers – Apache Commons Numbers

RNG – Commons RNG;


2.具体的实现方法:

下面以一段代码来介绍:

package NormalDistribution;

import org.apache.commons.statistics.distribution.*;

public class NorDisExample {
	
	    public static void main(String[] args) {
	    	
	        normalDistribution( 0.0, 1.0);
	        
	    }
	   
	 	 /**
	     * @param mean              均值
	     * @param sd				 标准差 Standard Deviation
	     * @param x                 需要计算的点
	     */
	    
	    public static void normalDistribution(Double mean, Double sd) {
	 
	    	NormalDistribution normalDistribution = NormalDistribution.of (mean, sd);

	    	// 设定需要计算的某点	    	
	    	double x= 1.0;
	    	
	    	// 设定需要计算的概率区间
	    	double x0= 0.0;
	    	double x1= 3.0;
	    	
	    	// 计算某点概率密度(PDF)
	    	double pdf =  normalDistribution.density(x);
	        System.out.println("PDF: " + pdf);
	    	       
	    	// 计算某区间累积概率(CDF)  
	    	double cdf =  normalDistribution.probability( x0, x1) ;
	        System.out.println("CDF: " + pdf);

	    }
	    
	}	

//验算方法:区间[0,3]的累积概率加上0.5应该等于0.9987左右。

引入类包:

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.statistics.distribution;

import org.apache.commons.numbers.gamma.Erfc;
import org.apache.commons.numbers.gamma.InverseErfc;
import org.apache.commons.numbers.gamma.ErfDifference;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.distribution.GaussianSampler;
import org.apache.commons.rng.sampling.distribution.ZigguratSampler;


运算结果截图:

在JAVA中运用正态分布_Apache


3.结语:

之前有人使用Apache Commons Math3的库来计算正态分布函数,在Math4时,采用Apache Commons Statistics来处理,用Numbers – Apache Commons Numbers和RNG – Commons RNG配合使用。



4.参考资料:

[Apache Commons 官方文档]

java正态分布函数_mob64ca12d06991的技术博客_51CTO博客 [原创] https://blog.51cto.com/u_16213300/6957923

正态分布和Java实现   小鱼干换酒钱 [原创] http://t.csdnimg.cn/gBzhg

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月23日 0

暂无评论

推荐阅读