java   apache-commons-math   zipf

温馨提示:将鼠标放在语句上可以显示对应的英文。   或者   切换至中英文显示

我想基于遵循Zipf分布的单词(来自字典)创建数据源(Java)。 因此,我来谈谈 Apache commons库的ZipfDistribution和NormalDistribution 。 不幸的是,很少有关于如何使用这些类的信息。 我尝试进行一些测试,但不确定是否以正确的方式使用它。 我只关注每个构造函数的文档中写的内容。 但是结果似乎并不“分布均匀”。

import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.distribution.ZipfDistribution;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;public class ZipfDistributionDataSource extends RichSourceFunction<String> {private static final String DISTINCT_WORDS_URL = "https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt";public static void main(String[] args) throws Exception {ZipfDistributionDataSource zipfDistributionDataSource = new ZipfDistributionDataSource();StringBuffer stringBuffer = new StringBuffer(zipfDistributionDataSource.readDataFromResource());String[] words = stringBuffer.toString().split("\n");System.out.println("size: " + words.length);System.out.println("Normal Distribution");NormalDistribution normalDistribution = new NormalDistribution(words.length / 2, 1);for (int i = 0; i < 10; i++) {int sample = (int) normalDistribution.sample();System.out.print("sample[" + sample + "]: ");System.out.println(words[sample]);}System.out.println();System.out.println("Zipf Distribution");ZipfDistribution zipfDistribution = new ZipfDistribution(words.length - 1, 1);for (int i = 0; i < 10; i++) {int sample = zipfDistribution.sample();System.out.print("sample[" + sample + "]: ");System.out.println(words[sample]);}}private String readDataFromResource() throws Exception {URL url = new URL(DISTINCT_WORDS_URL);InputStream in = url.openStream();BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));StringBuilder builder = new StringBuilder();String line;try {while ((line = bufferedReader.readLine()) != null) {builder.append(line + "\n");}bufferedReader.close();} catch (IOException ioe) {ioe.printStackTrace();} catch (Exception e) {e.printStackTrace();}return builder.toString();}
}

输出

size: 370103
Normal Distribution
sample[185049]: metathesize
sample[185052]: metathetically
sample[185051]: metathetical
sample[185050]: metathetic
sample[185049]: metathesize
sample[185050]: metathetic
sample[185052]: metathetically
sample[185050]: metathetic
sample[185052]: metathetically
sample[185050]: metatheticZipf Distribution
sample[11891]: anaphasic
sample[314]: abegge
sample[92]: abandoner
sample[3]: aah
sample[36131]: blepharosynechia
sample[218]: abbozzo
sample[8]: aalii
sample[5382]: affing
sample[6394]: agoraphobia
sample[4360]: adossed

java apache-commons-math zipf

1 个回复

按投票数排序按时间排序

如何在Java中正确使用Apache Commons数学库中的ZipfDistribution?相关推荐

  1. intellij中出現java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration解決方案

    完整报错如下: Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties 19/03/06 19: ...

  2. Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

    1.错误叙述性说明 2014-7-12 0:38:57 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplica ...

  3. 【报错笔记】使用MultipartFile 出现异常:java.lang.ClassNotFoundException: org.apache.commons.fileupload...

    使用MultipartFile出现异常:java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory ...

  4. hive执行drop卡死一例:java.lang.NoSuchMethodError: org.apache.commons.lang3.StringUtils.isAnyBlank

    环境: 组件 版本 Hadoop 3.1.2 Hive 2.3.4 故障复现操作: hive中尝试drop table卡死,然后去hadoop的yarn界面发现如下报错 完整报错: org.apach ...

  5. Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/BasePoolableObjectFactory

    摘要:异常信息解决过程记录 一:异常信息: Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/BasePoolabl ...

  6. 『Java CVE』CVE-2022-33980: Apache Commons Configuration 读文件RCE

    文章目录 影响版本 漏洞原理(机翻自CVE页面) 漏洞复现 环境配置 jdk版本 pom.xml 基本使用demo PoC 代码审计 对生产环境的影响 漏洞修复 参考 完 影响版本 Apache Co ...

  7. java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法

    java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法 只需把这三个commons-pool.jar ...

  8. java.lang.NoClassDefFoundError: org/apache/commons/pool2/PooledObjectFactory

    用GenericObjectPool来连接postgres数据库,在pom.xml中也加入了依赖 <!-- https://mvnrepository.com/artifact/org.apac ...

  9. VSCrawler 爬虫 java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory 解决方案

    长长的报错信息如下: 13:39:15.345 [main] WARN c.v.vscrawler.core.event.EventLoop - 程序已停止 13:39:15.376 [main] I ...

最新文章

  1. “前”方有坑,绕道而行(一)-- H5 CSS
  2. GOF设计模式之桥接模式
  3. 11、Libgdx的音频
  4. x86构架之-Intel8042键盘控制器简介
  5. 进阶Java架构师必看书:大型架构+框架+性能优化+中间件+分布式
  6. 计算机系统结构开设学校,计算机系统结构专业介绍及考研院校排名
  7. python工资一般多少西安-在西安为什么对Python编程需求这么大?工资这么高?
  8. matlab画交通标志,基于MATLAB的交通标志设计方法研究
  9. 三种常用的数字数据编码方式
  10. DOORS和Reqtify — 需求管理和需求追溯工具
  11. echarts年龄饼图_echarts饼图
  12. KNIME的学习使用心得
  13. 伴随着我娃成长的运维平台(持续开源..)
  14. 如何重现难以重现的bug
  15. 数字商标能注册商标吗?
  16. 360手机n4s骁龙版 html,高通骁龙机型 360N4S骁龙版_360 手机N4S_手机市场-中关村在线...
  17. iOS(Swift)学习笔记之SwiftyJSON的使用
  18. 《痞子衡嵌入式半月刊》 第 55 期
  19. 解决M1芯片版本安装Sketch问题 M1芯片安装那个Sketch版本?Sketch已完美支持M1芯片安装 支持big sur系统
  20. 【数据可视化应用】绘制类别插值地图(附Python代码)

热门文章

  1. 数据结构与算法(b站老甲鱼)
  2. Sketch 浅谈(一)
  3. java 对音频文件降噪_如何有效的对录音文件进行降噪处理?
  4. 教师进修学校计算机老师工作计划,★2015年教师进修学校工作计划
  5. 自动取款机流程模拟C语言的实现
  6. 多行省略号(使用碰到问题解决)
  7. 2018开门红,格力电器1月大涨28.01%,怒送1个涨停
  8. linux下接扫描枪问题
  9. VOS中开启媒体转发功能后,计算几种常用编码所需占用的带宽量
  10. 插入排序与选择排序的比较