-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathmodel.py
executable file
·50 lines (42 loc) · 1.4 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env python
#! -*- coding=utf-8 -*-
# Project: Lihang
# Filename: model
# Date: 10/21/18
# Author: 😏 <smirk dot cao at gmail dot com>
import numpy as np
import argparse
import logging
import warnings
class TripleCoin(object):
def __init__(self, pi=0, p=0, q=0):
self.pi = pi
self.p = p
self.q = q
def sample(self,
n=10):
"""
e9.1, 三硬币模型数据
:param n:
:return:
"""
rst = np.empty(1)
for n_iter in range(n):
pi_ = np.random.binomial(1, self.pi, 1)
if pi_:
rst = np.hstack((rst, np.random.binomial(1, self.p, 1)))
else:
rst = np.hstack((rst, np.random.binomial(1, self.q, 1)))
return rst[1:]
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", required=False, help="path to input data file")
args = vars(ap.parse_args())
else:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", required=False, help="path to input data")
args = vars(ap.parse_args())