Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import logging | |
from contextlib import contextmanager | |
from typing import Optional | |
@contextmanager | |
def timer(name: str, logger: Optional[logging.Logger] = None): | |
t0 = time.time() | |
msg = f"[{name}] start" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
def get_logger(out_file=None): | |
logger = logging.getLogger() | |
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") | |
logger.handlers = [] | |
logger.setLevel(logging.INFO) | |
stream_handler = logging.StreamHandler() | |
stream_handler.setFormatter(formatter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import numpy as np | |
import torch | |
def set_seed(seed: int = 42): | |
random.seed(seed) | |
np.random.seed(seed) | |
os.environ["PYTHONHASHSEED"] = str(seed) | |
torch.manual_seed(seed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LayeredFoldWrapper(Dataset): | |
def __init__(self, dataset, n_splits=5, fold=0, valid=False): | |
self.dataset = dataset | |
self.n_splits = n_splits | |
self.fold = fold | |
self.valid = valid | |
self.valid_index = list(self._valid_index(len(dataset), n_splits, fold)) | |
self.train_index = list(set(range(len(dataset))) - set(self.valid_index)) | |
def __len__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
MIT License | |
Copyright (c) 2017-2020 Packt, grouns0state | |
https://github.com/PacktPublishing/Artificial-Intelligence-with-Python/blob/master/LICENSE | |
""" | |
from sklearn.cluster import KMeans | |
from sklearn import metrics | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.datasets import make_blobs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
MIT License | |
Copyright (c) 2017-2020 Packt, grouns0state | |
https://github.com/PacktPublishing/Artificial-Intelligence-with-Python/blob/master/LICENSE | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.cluster import MeanShift, estimate_bandwidth | |
from itertools import cycle | |
from sklearn.datasets import make_blobs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
喜多 一,『プログラミング演習 Python 2019( コラム編 )』, 2020-02-13, http://hdl.handle.net/2433/245698 | |
LISENCE: CC-BY-NC-ND | |
[参考資料] | |
桂田 祐史:Python を使った WAVE ファイルの処理、 http://nalab.mind.meiji.ac.jp/~mk/lecture/fourier-2018/python-sound/ (2018/12/3 アクセ ス) | |
""" | |
import numpy as np | |
import wave |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://org-technology.com/posts/power-spectral-density.html | |
""" | |
適当な信号を作成して periodogram と welch で PSD を推定してみます。 | |
下の例ではセグメント長 nseg はデフォルトで 256 なので、 | |
ちょうど n/4 の長さです。 | |
いくつかセグメント長を変えて推定した結果をプロットしています。 | |
なおオーバーラップ noverlap はデフォルトのままで nseg/2、 | |
つまり 50% オーバーラップして計算しています。 | |
periodogramでは窓関数はデフォルトではなし(Boxcar と同じ)、 | |
welch では Hanning です。 |
NewerOlder