<jupyter_start><jupyter_text>5章　対数関数と指数関数<jupyter_code># 必要ライブラリの宣言
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
# PDF出力用
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png', 'pdf')
# fig05-01
#　指数関数のグラフ
x = np.linspace(-2, 2, 200)
y = 2**x
x1 = np.linspace(-2, 2, 9)
y1 = 2**x1
plt.figure(figsize=(8,8))
plt.plot(x, y, c='b')
plt.xticks(size=18)
plt.yticks(size=18)
plt.grid(which='major',linestyle='-', lw=2)
plt.scatter(x1, y1, s=50, c='k')
plt.xlabel("$x$", fontsize=20) 
plt.ylabel("$2^x$", fontsize=20)
plt.show()
# fig05-02
# 指数関数のグラフ　その2
x = np.linspace(-2, 2, 200)
y = (1/2)**x
x1 = np.linspace(-2, 2, 9)
y1 = (1/2)**x1
plt.figure(figsize=(8,8))
plt.plot(x, y, c='b')
plt.scatter(x1, y1, s=50, c='k')
plt.xticks(size=18)
plt.yticks(size=18)
plt.grid(which='major',linestyle='-', lw=2)
plt.xlabel("$x$", fontsize=20) 
plt.ylabel(r'$\left(\frac{1}{2}\right)^x$', fontsize=20)
plt.show()
# fig05-05
# 対数のグラフ
x = np.linspace(0, 4, 200)
xx = np.linspace(-2, 2, 200)
x0 = np.delete(x, 0)
y0 = np.log2(x0)
x1 = np.linspace(0, 4, 9)
x2 = np.delete(x1, 0)
y2 = np.log2(x2)
plt.figure(figsize=(8,8))
plt.plot(x0, y0, c='b', label='$y=\log_{2}x$',lw=2)
plt.plot(xx, 2**xx, c='k', label='$y=2^x$',lw=2)
plt.plot([-2,4],[-2,4], linestyle='-.', label='$y=x$', lw=2)
plt.plot([-2,4],[0,0],lw=2,c='k')
plt.plot([0,0],[-2,4],lw=2,c='k')
plt.scatter(x2, y2, s=50, c='b')
plt.scatter(y2, x2, s=30, c='k')
plt.xticks(size=20)
plt.yticks(size=20)
plt.ylim(-2,4)
plt.grid(which='major',linestyle='-',lw=2)
plt.xlabel("$x$", fontsize=18) 
plt.ylabel("$y$", fontsize=18)
plt.legend(fontsize=18)
plt.show()
# 対数関数の応用
sell_list = [[9984, 8901004], [9987, 2126993], [9983, 1861917], [1333, 873295], [1332, 635953], 
             [9989, 528394], [1417, 283236], [1301, 236561], [9974, 193566], [9994, 167334], 
             [1419, 157001], [9997, 146083], [9993, 114111], [9977, 105954], [1413, 105007], 
             [9991, 98729], [9982, 77952], [9995, 77581], [1352, 73761], [9979, 63957], 
             [1379, 63119], [1377, 61844], [1376, 57848], [9990, 56747], [1420, 55504], 
             [1414, 53250], [9996, 48505], [9967, 34353], [9976, 33591], [1407, 32753], 
             [9978, 29919], [9966, 21387], [1430, 20948], [1418, 19082], [1381, 18802], 
             [1429, 18052], [1384, 15982], [9972, 15173], [9980, 13401], [1408, 10599], 
             [9969, 8791], [9992, 7281], [9986, 6944], [9973, 5420], [1380, 5399], 
             [1383, 4623], [1431, 3765], [1382, 3722], [1401, 2660], [1400, 2355]]
import numpy as np
import matplotlib.pyplot as plt
sell_np = np.array(sell_list)
sell_np = np.array(sell_list)
index = range(sell_np.shape[0])
sc_label = ['' for x in sell_np[:,1]]
# fig05-06
# 通常スケールでの棒グラフ
plt.figure(figsize=(10,6))
plt.bar(index,sell_np[:,1], tick_label=sc_label, color='b')
#plt.bar(index,sell_np[:,1], color='b')
plt.grid(lw=2)
plt.xticks([])
plt.yticks(size=16)
plt.show()
# fig-5-07
# logスケールでの棒グラフ
plt.figure(figsize=(10,6))
plt.bar(index, np.log(sell_np[:,1]), tick_label=sc_label, color='b')
plt.ylim(7,17)
plt.grid(lw=2)
plt.xticks([])
plt.yticks(size=16)
plt.show()<jupyter_output><empty_output><jupyter_text>コラム　ネイピア数<jupyter_code>import numpy as np
np.set_printoptions(precision=10)
x = np.logspace(0, 11, 12, base=0.1, dtype='float64')
y = np.power(1+x, 1/x)
for i in range(11):
    print( 'x = %12.10f y = %12.10f' % (x[i], y[i]))<jupyter_output><empty_output><jupyter_text>対数グラフの重ね書き<jupyter_code>xx =  np.linspace(0.2, 2.0, 100)
yy1 = np.log(xx) / np.log(2.0)
yy2 = np.log(xx)
yy3 = np.log(xx) / np.log(6.0)
# fig05-09
plt.figure(figsize=(6,6))
plt.ylim(-1.0, 1.0)
plt.xlim(0.2, 2.0)
plt.xlabel('$x$', fontsize=18)
plt.ylabel('$y$',fontsize=18)
plt.grid(lw=2)
plt.plot([0.2,2.0], [-0.8,1.0], 'b-', lw=2, c='black')
plt.plot(xx, yy1, linestyle='dotted', c='black',lw=2, label='$log_{2}x$')
plt.plot(xx, yy2, linestyle='solid', c='b', lw=2, label='$log_{e}x$')
plt.plot(xx, yy3, linestyle='dashed', c='black',lw=2, label='$log_{6}x$')
plt.scatter(1.0, 0.0, s=50)
plt.xticks(size=16)
plt.yticks(size=16)
plt.legend(fontsize=18)
plt.show()<jupyter_output><empty_output><jupyter_text>シグモイド関数<jupyter_code>xx =  np.linspace(-6, 6, 500)
yy = 1 / (np.exp(-xx) + 1)
# fig05-10
plt.figure(figsize=(8,6))
plt.ylim(0.0, 1.0)
plt.xlim(-6, 6)
plt.xlabel('x', fontsize=18)
plt.ylabel('y', fontsize=18)
plt.xticks(size=18)
plt.yticks(size=18)
plt.grid(lw=2)
plt.plot(xx, yy, c='b',lw=2, label=r'$\frac{1}{1+\exp{(-x)}}$')
plt.legend(fontsize=20)
plt.show()
plt.figure(figsize=(8,6))
plt.ylim(-3, 3)
plt.xlim(-3, 3)
plt.xticks(np.linspace(-3,3,13))
plt.yticks(np.linspace(-3,3,13))
plt.xlabel('x', fontsize=14)
plt.ylabel('y', fontsize=14)
plt.xticks(size=16)
plt.yticks(size=16)
plt.grid()
plt.plot(xx, yy, c='b', label=r'$\dfrac{1}{1+\exp{(-x)}}$', lw=1)
plt.plot(xx, xx, c='k', label=r'$y = x$', lw=1)
plt.plot([-3,3], [0,0], c='k')
plt.plot([0,0], [-3,3],c='k')
plt.plot([-3,3],[1,1],linestyle='-.',c='k')
plt.legend(fontsize=18)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.25446251487504956, 'fraction_numerical': 0.15628718762395874, 'mean_word_length': 5.311639549436796, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '325890', 'license': 'Apache-2.0', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2574, 'n_words': 418, 'path': 'notebooks/ch05-exp-log.ipynb', 'repo_name': 'kjmatsuda/math_dl_book_info', 'size': '5042'}