def test_tanh(self): """ tanh函数显示. """ print('{} test_tanh {}'.format('-'*15, '-'*15)) data_x = torch.arange(-8.0, 8.0, 0.1, requires_grad=True) data_y = data_x.tanh() show_x_y_axis(data_x.detach().numpy(), data_y.detach().numpy(), title='tanh') # 直接弹出图片
def test_show_x_y_axis(self): """ 显示x、y坐标系. """ print('{} test_show_x_y_axis {}'.format('-' * 15, '-' * 15)) data_x = np.arange(0, 10) data_y = 2 * data_x + 5 show_x_y_axis(data_x, data_y) # 直接弹出图片
def test_sigmoid(self): """ sigmoid函数显示. """ print('{} test_sigmoid {}'.format('-'*15, '-'*15)) data_x = torch.arange(-8.0, 8.0, 0.1, requires_grad=True) data_y = data_x.sigmoid() show_x_y_axis(data_x.detach().numpy(), data_y.detach().numpy(), title='sigmoid') # 直接弹出图片
def test_ReLU(self): """ ReLU函数显示. """ print('{} test_ReLU {}'.format('-'*15, '-'*15)) data_x = torch.arange(-8.0, 8.0, 0.1, requires_grad=True) data_y = data_x.relu() show_x_y_axis(data_x.detach().numpy(), data_y.detach().numpy(), title='ReLU') # 直接弹出图片
def test_tanh_grad(self): """ tanh函数梯度显示. """ print('{} test_tanh_grad {}'.format('-'*15, '-'*15)) data_x = torch.arange(-8.0, 8.0, 0.1, requires_grad=True) data_x.tanh().sum().backward() data_y = data_x.grad show_x_y_axis(data_x.detach().numpy(), data_y.detach().numpy(), title='tanh grad') # 直接弹出图片
def test_saddle_point(self): """ 鞍点. """ print('{} test_saddle_point {}'.format('-' * 15, '-' * 15)) data_x = np.arange(-2.0, 2.0, 0.1) data_y = data_x**3 annotates = [{ 'text': 'saddle point', 'xy': (0, -0.2), 'xytext': (-0.52, -5.0), 'arrowstyle': '->' }] show_x_y_axis(data_x, data_y, title='saddle point', annotates=annotates) # 直接弹出图片
def test_local_minimum(self): """ 局部最小值显示. """ print('{} test_local_minimum {}'.format('-' * 15, '-' * 15)) data_x = np.arange(-1.0, 2.0, 0.1) data_y = data_x * np.cos(np.pi * data_x) annotates = [{ 'text': 'local minimum', 'xy': (-0.3, -0.25), 'xytext': (-0.7, -1.0), 'arrowstyle': '->' }, { 'text': 'global minimum', 'xy': (1.1, -0.95), 'xytext': (0.6, 0.8), 'arrowstyle': '->' }] show_x_y_axis(data_x, data_y, title='local minimum', annotates=annotates) # 直接弹出图片