-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
61 lines (49 loc) · 1.59 KB
/
Copy pathsample.py
File metadata and controls
61 lines (49 loc) · 1.59 KB
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
51
52
53
54
55
56
57
58
59
60
61
import numpy as np
from population import Population
class Sample:
def __init__(self, population: Population, size: int) -> None:
"""
Sampleオブジェクトを初期化する。
Args:
population (Population): 母集団オブジェクト
size (int): サンプルサイズ
"""
self.sample = np.random.choice(population.get_population(), size)
self.mean = np.mean(self.sample)
self.variance = np.var(self.sample)
self.size = size
def get_mean(self) -> float:
"""
サンプルの平均値を取得する。
Returns:
float: サンプルの平均値
"""
return self.mean
def get_variance(self) -> float:
"""
サンプルの分散を取得する。
Returns:
float: サンプルの分散
"""
return self.variance
def get_unbiased_variance(self) -> float:
"""
不偏分散を取得する。
Returns:
float: 不偏分散
"""
return self.variance * self.size / (self.size - 1)
def get_size(self) -> int:
"""
サンプルのサイズを取得する。
Returns:
int: サンプルのサイズ
"""
return self.size
def get_sample(self) -> np.ndarray:
"""
サンプルを取得する。
Returns:
numpy.ndarray: サンプル
"""
return self.sample