Skip to content

Instantly share code, notes, and snippets.

View 1pha's full-sized avatar
💦
I may be slow to respond.

Daehyun Cho 1pha

💦
I may be slow to respond.
View GitHub Profile
This file has been truncated, but you can view the full file.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1 Distribution Analysis\n",
"\n",
"약물 투여 여부를 중심으로 연구를 진행하게 되었다. 기존 근시 환자의 내방 이후 최종 검진 시 SE값을 예측하는 예측모델에 그쳤다면, 여기에 더 나아가 약물사용이 어떻게 모델 예측에 영향력을 미치는지 살펴보는 방향을 진행한다. "
]
@1pha
1pha / 1_distribution.ipynb
Created August 13, 2023 11:36
1_distribution_analysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@1pha
1pha / multiprocessing_global_variable.py
Created January 12, 2023 00:42
How to access global variable when using multiprocessing in python
import multiprocessing as mp
def add(val):
list_proxy.append(val)
print(list_proxy)
if __name__=="__main__":
man = mp.Manager()
list_proxy = man.list()
@1pha
1pha / dataclass.py
Created October 19, 2022 12:19
Dataclass and Attributes
# Explanations will further be attached.
from dataclasses import dataclass, field
@dataclass
class A:
d: int = 3
_e: int = 5
_g: list = field(default_factory=list)
def __post_init__(self):
self._f = 6
@1pha
1pha / count_params.py
Created October 19, 2022 01:02
Count Pytorch Model Parameters
# Reference
# https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/8
def count_parameters(model):
return sum(p.numel() for p in model.parameters() if p.requires_grad)
from io import BytesIO, StringIO
from urllib.request import urlopen
from zipfile import ZipFile
import pandas as pd
def download_and_unzip(url, extract_to='.'):
http_response = urlopen(url)
zipfile = ZipFile(BytesIO(http_response.read()))
return zipfile
@1pha
1pha / torch_collate_fn.py
Created May 28, 2021 05:10
Understanding collate_fn
import torch
from torch.utils.data import Dataset, DataLoader
import numpy as np
class MyDataset(Dataset):
def __init__(self):
x = np.random.randint(10, size=[1000, 3]) # 1000 3-dim samples
self.x = [x[i].tolist() for i in range(1000)]
y = np.random.randint(low=0, high=2, size=(1000,))
self.y = [y[i] for i in range(1000)]
@1pha
1pha / seed_everything.py
Created May 25, 2021 07:28
Source code for setting every seed same.
import os
import random
import numpy as np
import torch
def seed_everything(seed=42):
os.environ['PYTHONHASHSEED'] = str(seed)
random.seed(seed)
@1pha
1pha / depth_firth_search.py
Last active April 15, 2021 09:21
DFS algorithm for graph search theories.
def recursive_dfs(v, discovered=[]):
discovered.append(v)
for w in graph[v]: # for the graph of adjacent matrix
if w not in discovered:
discovered = recursive_dfs(w, discovered)
return discovered # will return the nodes searched in order
def iterative_dfs(start_v):
@1pha
1pha / kill_desktop_ini.py
Created April 7, 2021 01:44
Killing desktop.ini with python function. I'm sick of deleting these .ini files through Windows explorer and made this..
import os
def kill_desktop_ini(root_dir):
for (root, dirs, files) in os.walk(root_dir):
if len(files) > 0:
for file_name in files:
if file_name.endswith('.ini'):
os.remove(f'{root}/{file_name}')