0.1.56
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
				
			|||||||
[metadata]
 | 
					[metadata]
 | 
				
			||||||
# replace with your username:
 | 
					# replace with your username:
 | 
				
			||||||
name = guan
 | 
					name = guan
 | 
				
			||||||
version = 0.1.55
 | 
					version = 0.1.56
 | 
				
			||||||
author = guanjihuan
 | 
					author = guanjihuan
 | 
				
			||||||
author_email = guanjihuan@163.com
 | 
					author_email = guanjihuan@163.com
 | 
				
			||||||
description = An open source python package
 | 
					description = An open source python package
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
Metadata-Version: 2.1
 | 
					Metadata-Version: 2.1
 | 
				
			||||||
Name: guan
 | 
					Name: guan
 | 
				
			||||||
Version: 0.1.55
 | 
					Version: 0.1.56
 | 
				
			||||||
Summary: An open source python package
 | 
					Summary: An open source python package
 | 
				
			||||||
Home-page: https://py.guanjihuan.com
 | 
					Home-page: https://py.guanjihuan.com
 | 
				
			||||||
Author: guanjihuan
 | 
					Author: guanjihuan
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,13 @@
 | 
				
			|||||||
# Module: machine_learning
 | 
					# Module: machine_learning
 | 
				
			||||||
import guan
 | 
					import guan
 | 
				
			||||||
model_class = None  # 把类定义成全局的,防止保存完整模型时,无法访问函数中的类
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 全连接神经网络模型(包含一个隐藏层)
 | 
					# 全连接神经网络模型(包含一个隐藏层)
 | 
				
			||||||
@guan.function_decorator
 | 
					@guan.function_decorator
 | 
				
			||||||
def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_size=10, output_size=1, activation='relu'):
 | 
					def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_size=10, output_size=1, activation='relu'):
 | 
				
			||||||
    import torch
 | 
					    import torch
 | 
				
			||||||
    global model_class
 | 
					    # 如果在函数中定义模型类,尽量定义成全局的,这样可以防止在保存完整模型到文件时,无法访问函数中的模型类。
 | 
				
			||||||
    class model_class(torch.nn.Module):
 | 
					    global model_class_of_fully_connected_neural_network_with_one_hidden_layer
 | 
				
			||||||
 | 
					    class model_class_of_fully_connected_neural_network_with_one_hidden_layer(torch.nn.Module):
 | 
				
			||||||
        def __init__(self):
 | 
					        def __init__(self):
 | 
				
			||||||
            super().__init__()
 | 
					            super().__init__()
 | 
				
			||||||
            self.hidden_layer = torch.nn.Linear(input_size, hidden_size)
 | 
					            self.hidden_layer = torch.nn.Linear(input_size, hidden_size)
 | 
				
			||||||
@@ -25,15 +25,15 @@ def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_si
 | 
				
			|||||||
                hidden_output = self.hidden_layer(x)
 | 
					                hidden_output = self.hidden_layer(x)
 | 
				
			||||||
            output = self.output_layer(hidden_output)
 | 
					            output = self.output_layer(hidden_output)
 | 
				
			||||||
            return output
 | 
					            return output
 | 
				
			||||||
    model = model_class()
 | 
					    model = model_class_of_fully_connected_neural_network_with_one_hidden_layer()
 | 
				
			||||||
    return model
 | 
					    return model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 全连接神经网络模型(包含两个隐藏层)
 | 
					# 全连接神经网络模型(包含两个隐藏层)
 | 
				
			||||||
@guan.function_decorator
 | 
					@guan.function_decorator
 | 
				
			||||||
def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, output_size=1, activation_1='relu', activation_2='relu'):
 | 
					def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, output_size=1, activation_1='relu', activation_2='relu'):
 | 
				
			||||||
    import torch
 | 
					    import torch
 | 
				
			||||||
    global model_class
 | 
					    global model_class_of_fully_connected_neural_network_with_two_hidden_layers
 | 
				
			||||||
    class model_class(torch.nn.Module):
 | 
					    class model_class_of_fully_connected_neural_network_with_two_hidden_layers(torch.nn.Module):
 | 
				
			||||||
        def __init__(self):
 | 
					        def __init__(self):
 | 
				
			||||||
            super().__init__()
 | 
					            super().__init__()
 | 
				
			||||||
            self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1)
 | 
					            self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1)
 | 
				
			||||||
@@ -64,15 +64,15 @@ def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_s
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            output = self.output_layer(hidden_output_2)
 | 
					            output = self.output_layer(hidden_output_2)
 | 
				
			||||||
            return output
 | 
					            return output
 | 
				
			||||||
    model = model_class()
 | 
					    model = model_class_of_fully_connected_neural_network_with_two_hidden_layers()
 | 
				
			||||||
    return model
 | 
					    return model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 全连接神经网络模型(包含三个隐藏层)
 | 
					# 全连接神经网络模型(包含三个隐藏层)
 | 
				
			||||||
@guan.function_decorator
 | 
					@guan.function_decorator
 | 
				
			||||||
def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, hidden_size_3=10, output_size=1, activation_1='relu', activation_2='relu', activation_3='relu'):
 | 
					def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, hidden_size_3=10, output_size=1, activation_1='relu', activation_2='relu', activation_3='relu'):
 | 
				
			||||||
    import torch
 | 
					    import torch
 | 
				
			||||||
    global model_class
 | 
					    global model_class_of_fully_connected_neural_network_with_three_hidden_layers
 | 
				
			||||||
    class model_class(torch.nn.Module):
 | 
					    class model_class_of_fully_connected_neural_network_with_three_hidden_layers(torch.nn.Module):
 | 
				
			||||||
        def __init__(self):
 | 
					        def __init__(self):
 | 
				
			||||||
            super().__init__()
 | 
					            super().__init__()
 | 
				
			||||||
            self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1)
 | 
					            self.hidden_layer_1 = torch.nn.Linear(input_size, hidden_size_1)
 | 
				
			||||||
@@ -115,7 +115,7 @@ def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            output = self.output_layer(hidden_output_3)
 | 
					            output = self.output_layer(hidden_output_3)
 | 
				
			||||||
            return output
 | 
					            return output
 | 
				
			||||||
    model = model_class()
 | 
					    model = model_class_of_fully_connected_neural_network_with_three_hidden_layers()
 | 
				
			||||||
    return model
 | 
					    return model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 使用优化器训练模型
 | 
					# 使用优化器训练模型
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user