This file contains 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 random | |
from copy import deepcopy | |
from deap import base, creator, tools | |
def eval_one_max(individual) -> tuple: | |
return sum(individual), | |
def main(): | |
# creator.FitnessMax クラスと、creator.Individual クラスを作成 | |
creator.create("FitnessMax", base.Fitness, weights=(1.0,)) |
This file contains 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 numpy as np | |
import scipy.stats | |
# %matplotlib inline | |
import matplotlib.pyplot as plt | |
from matplotlib import mlab | |
plt.style.use("ggplot") | |
plt.rcParams["font.size"] = 16 | |
plt.rcParams["figure.figsize"] = 10, 8 |
This file contains 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 numpy as np | |
from sklearn.model_selection import train_test_split | |
from sklearn.utils import shuffle | |
import tensorflow as tf | |
from tensorflow.examples.tutorials.mnist import input_data | |
def salt_and_pepper_noise(x, ratio): | |
x_noise = x.copy() |
This file contains 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 numpy as np | |
def intersect2d(x, y): | |
_, ncols = x.shape | |
dtype = { | |
"names": [f"f{i}" for i in range(ncols)], | |
"formats": ncols * [predict.dtype], | |
} | |
This file contains 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
from IPython.display import clear_output, Image, display, HTML | |
import tensorflow as tf | |
import numpy as np | |
def strip_consts(graph_def, max_const_size=32): | |
"""Strip large constant values from graph_def.""" | |
strip_def = tf.GraphDef() | |
for n0 in graph_def.node: | |
n = strip_def.node.add() | |
n.MergeFrom(n0) |
This file contains 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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
# for matplotlib | |
plt.style.use("ggplot") | |
plt.rcParams["font.size"] = 13 | |
plt.rcParams["figure.figsize"] = 10, 8 |
This file contains 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 datetime | |
from logging import getLogger, Formatter, FileHandler, StreamHandler, DEBUG | |
today = datetime.date.today() | |
today = today.strftime("%Y%m%d") | |
# Specify a path to log file which will be written log messages | |
path_to_log = f"log/{today}.log" | |
fmt = "%(asctime)s %(name)s %(lineno)d [%(levelname)s][%(funcName)s] %(message)s" | |
log_fmt = Formatter(fmt) |
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import animation | |
plt.style.use("ggplot") | |
plt.rcParams["font.size"] = 13 | |
plt.rcParams["figure.figsize"] = 16, 8 | |
class GradientDescent(object): | |
def __init__(self, f, grad, init_x, n_iter=100, learning_ratio=0.01, delta=0.1**8): |
This file contains 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 pandas as pd | |
cols = ['col1', 'col2'] | |
df = pd.DataFrame(index=[], columns=cols) | |
record = pd.Series(['hoge', 'fuga'], index=df.columns) | |
for _ in range(5): | |
df = df.append(record, ignore_index=True) | |
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
plt.style.use("ggplot") | |
plt.rcParams["font.size"] = 13 | |
plt.rcParams["figure.figsize"] = 16, 12 | |
class Newton(object): | |
def __init__(self, f, d1f, d2f, f2): | |
self.f = f |
NewerOlder