Skip to content

Commit 3fca0e7

Browse files
author
Aragorn
committed
poisson process added.
1 parent 6ebaa3a commit 3fca0e7

File tree

4 files changed

+176
-102
lines changed

4 files changed

+176
-102
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# 《数理统计》课程代码
2-
该项目中主要包含上海对外经贸大学司继春《数理统计》课程的相关代码,主要包括讲义中的示意性代码以及Python、Julia语言的Jupyter Notebook。
1+
# 《数理统计》、《随机过程》课程代码
2+
该项目中主要包含上海对外经贸大学司继春《数理统计》课程以及《随机过程》的相关代码,主要包括讲义中的示意性代码以及Python、Julia语言的Jupyter Notebook。
33
## 讲义中代码
44
讲义中的代码主要包含在以下地址中:[Code in Notes](https://github.com/sijichun/MathStatsCode/tree/master/code_in_notes),其中Stata数据文件包含在以下地址中:[Datasets](https://github.com/sijichun/MathStatsCode/tree/master/code_in_notes/datasets)
55
## Python Notebook
@@ -9,5 +9,6 @@
99
* [大数定律与中心极限定律](https://github.com/sijichun/MathStatsCode/blob/master/notebook_python/LLN_CLT.ipynb)
1010
* [矩估计、极大似然估计与区间估计](https://github.com/sijichun/MathStatsCode/blob/master/notebook_python/estimation.ipynb)
1111
* [假设检验](https://github.com/sijichun/MathStatsCode/blob/master/notebook_python/Testing.ipynb)
12+
* [泊松过程](https://github.com/sijichun/MathStatsCode/blob/master/notebook_python/Poisson_Process.ipynb)
1213
## Julia Notebook
1314
* [Julia介绍](https://github.com/sijichun/MathStatsCode/blob/master/notebook_julia/Julia.ipynb)

notebook_python/Numpy+Matplotlib+random.ipynb

Lines changed: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {
6-
"deletable": true,
7-
"editable": true
8-
},
5+
"metadata": {},
96
"source": [
107
"# Python的安装\n",
118
"由于我们会使用到一些Python的非标准库,比如NumPy, SciPy, Matplotlib等,在Windows系统上安装这些包比较繁琐,所以推荐直接安装Anaconda使用,下载地址:https://www.continuum.io/downloads 。对于Mac用户,可以安装Anaconda,也可以自行安装Python并使用pip安装所需要的包。Linux用户可以安装Anaconda,也可以使用apt-get, rpm等安装所需的包。\n",
@@ -19,9 +16,6 @@
1916
"cell_type": "code",
2017
"execution_count": 1,
2118
"metadata": {
22-
"collapsed": false,
23-
"deletable": true,
24-
"editable": true,
2519
"scrolled": false
2620
},
2721
"outputs": [
@@ -51,22 +45,15 @@
5145
},
5246
{
5347
"cell_type": "markdown",
54-
"metadata": {
55-
"deletable": true,
56-
"editable": true
57-
},
48+
"metadata": {},
5849
"source": [
5950
"如果我们需要生成一个服从分布函数$F: R\\rightarrow [0,1]$的随机数,那么只要首先生成一个$(0,1)$的随机数$u$,并令$x=F^{-1}(u)$,那么新生成的$x$即服从$F$的分布。比如,指数分布的分布函数为$1-e^{-\\frac{1}{b}\\cdot x}$,其中b为一个参数,因而我们可以使用$x=-b\\cdot \\ln(u)$来生成服从指数分布的随机数。"
6051
]
6152
},
6253
{
6354
"cell_type": "code",
6455
"execution_count": 2,
65-
"metadata": {
66-
"collapsed": false,
67-
"deletable": true,
68-
"editable": true
69-
},
56+
"metadata": {},
7057
"outputs": [
7158
{
7259
"name": "stdout",
@@ -94,22 +81,15 @@
9481
},
9582
{
9683
"cell_type": "markdown",
97-
"metadata": {
98-
"deletable": true,
99-
"editable": true
100-
},
84+
"metadata": {},
10185
"source": [
10286
"我们可以使用经验分布函数(Empirical distribution function)与理论的分布函数比较,来判断我们生成的随机数是否满足某一分布。经验分布函数的定义为:$\\hat{F}(x)=\\frac{1}{N}\\cdot \\sum_{i=1}^N 1\\{X_i \\leq x\\}$,也就是给定一个$x$,其经验分布函数的值为样本中小于等于$x$的比例,比如:"
10387
]
10488
},
10589
{
10690
"cell_type": "code",
10791
"execution_count": 3,
108-
"metadata": {
109-
"collapsed": false,
110-
"deletable": true,
111-
"editable": true
112-
},
92+
"metadata": {},
11393
"outputs": [
11494
{
11595
"name": "stdout",
@@ -205,10 +185,7 @@
205185
},
206186
{
207187
"cell_type": "markdown",
208-
"metadata": {
209-
"deletable": true,
210-
"editable": true
211-
},
188+
"metadata": {},
212189
"source": [
213190
"# 使用NumPy\n",
214191
"虽然Python自带了一些基本的数学函数以及列表、元组等数据结构,然而并没有对向量运算的天然支持,因而我们需要NumPy这个包来支持Python中的向量运算。https://docs.scipy.org/doc/numpy-dev/user/quickstart.html 提供了一个简单的教程。\n",
@@ -219,9 +196,6 @@
219196
"cell_type": "code",
220197
"execution_count": 4,
221198
"metadata": {
222-
"collapsed": false,
223-
"deletable": true,
224-
"editable": true,
225199
"scrolled": true
226200
},
227201
"outputs": [
@@ -278,22 +252,15 @@
278252
},
279253
{
280254
"cell_type": "markdown",
281-
"metadata": {
282-
"deletable": true,
283-
"editable": true
284-
},
255+
"metadata": {},
285256
"source": [
286257
"下面展示如何使用NumPy操作矩阵:"
287258
]
288259
},
289260
{
290261
"cell_type": "code",
291262
"execution_count": 5,
292-
"metadata": {
293-
"collapsed": false,
294-
"deletable": true,
295-
"editable": true
296-
},
263+
"metadata": {},
297264
"outputs": [
298265
{
299266
"name": "stdout",
@@ -381,22 +348,15 @@
381348
},
382349
{
383350
"cell_type": "markdown",
384-
"metadata": {
385-
"deletable": true,
386-
"editable": true
387-
},
351+
"metadata": {},
388352
"source": [
389353
"此外,NumPy还支持很多常用函数的向量运算,比如:"
390354
]
391355
},
392356
{
393357
"cell_type": "code",
394358
"execution_count": 6,
395-
"metadata": {
396-
"collapsed": false,
397-
"deletable": true,
398-
"editable": true
399-
},
359+
"metadata": {},
400360
"outputs": [
401361
{
402362
"name": "stdout",
@@ -419,22 +379,15 @@
419379
},
420380
{
421381
"cell_type": "markdown",
422-
"metadata": {
423-
"deletable": true,
424-
"editable": true
425-
},
382+
"metadata": {},
426383
"source": [
427384
"最后,NumPy中的random模块也可以用来生成随机数:"
428385
]
429386
},
430387
{
431388
"cell_type": "code",
432389
"execution_count": 7,
433-
"metadata": {
434-
"collapsed": false,
435-
"deletable": true,
436-
"editable": true
437-
},
390+
"metadata": {},
438391
"outputs": [
439392
{
440393
"name": "stdout",
@@ -463,22 +416,15 @@
463416
},
464417
{
465418
"cell_type": "markdown",
466-
"metadata": {
467-
"deletable": true,
468-
"editable": true
469-
},
419+
"metadata": {},
470420
"source": [
471421
"使用NumPy,上面的指数分布的例子可以改写成如下更加简洁的方式:"
472422
]
473423
},
474424
{
475425
"cell_type": "code",
476426
"execution_count": 8,
477-
"metadata": {
478-
"collapsed": false,
479-
"deletable": true,
480-
"editable": true
481-
},
427+
"metadata": {},
482428
"outputs": [
483429
{
484430
"name": "stdout",
@@ -573,10 +519,7 @@
573519
},
574520
{
575521
"cell_type": "markdown",
576-
"metadata": {
577-
"deletable": true,
578-
"editable": true
579-
},
522+
"metadata": {},
580523
"source": [
581524
"# 使用matplotlib画图\n",
582525
"在Python中,可以方便的是用matplotlib画图。在使用前应该使用(sudo) pip install matplotlib进行安装,Python3可能需要使用pip3 install。matplotlib地址:http://matplotlib.org/2.0.0/index.html ,教程地址:http://www.labri.fr/perso/nrougier/teaching/matplotlib/ 。\n",
@@ -587,9 +530,6 @@
587530
"cell_type": "code",
588531
"execution_count": 9,
589532
"metadata": {
590-
"collapsed": false,
591-
"deletable": true,
592-
"editable": true,
593533
"scrolled": false
594534
},
595535
"outputs": [
@@ -621,22 +561,15 @@
621561
},
622562
{
623563
"cell_type": "markdown",
624-
"metadata": {
625-
"deletable": true,
626-
"editable": true
627-
},
564+
"metadata": {},
628565
"source": [
629566
"除此之外,matplotlib的图类型非常多,比如常见的直方图:"
630567
]
631568
},
632569
{
633570
"cell_type": "code",
634571
"execution_count": 10,
635-
"metadata": {
636-
"collapsed": false,
637-
"deletable": true,
638-
"editable": true
639-
},
572+
"metadata": {},
640573
"outputs": [
641574
{
642575
"data": {
@@ -660,22 +593,15 @@
660593
},
661594
{
662595
"cell_type": "markdown",
663-
"metadata": {
664-
"deletable": true,
665-
"editable": true
666-
},
596+
"metadata": {},
667597
"source": [
668598
"以及散点图:"
669599
]
670600
},
671601
{
672602
"cell_type": "code",
673603
"execution_count": 11,
674-
"metadata": {
675-
"collapsed": false,
676-
"deletable": true,
677-
"editable": true
678-
},
604+
"metadata": {},
679605
"outputs": [
680606
{
681607
"data": {
@@ -701,10 +627,7 @@
701627
},
702628
{
703629
"cell_type": "markdown",
704-
"metadata": {
705-
"deletable": true,
706-
"editable": true
707-
},
630+
"metadata": {},
708631
"source": [
709632
"可以参考matplotlib的官方网站以及教程,组合使用这些图形可以画出各种符合自己要求的图像。"
710633
]
@@ -726,7 +649,7 @@
726649
"name": "python",
727650
"nbconvert_exporter": "python",
728651
"pygments_lexer": "ipython3",
729-
"version": "3.5.1"
652+
"version": "3.6.5"
730653
},
731654
"latex_envs": {
732655
"LaTeX_envs_menu_present": true,
@@ -747,5 +670,5 @@
747670
}
748671
},
749672
"nbformat": 4,
750-
"nbformat_minor": 0
673+
"nbformat_minor": 1
751674
}

0 commit comments

Comments
 (0)