ANN models¶
ecopann.element¶
-
class
ecopann.element.ELU_1[source]¶ Bases:
torch.nn.modules.module.Module-
forward(x)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
ecopann.element.Sigmoid_1[source]¶ Bases:
torch.nn.modules.module.Module-
forward(x)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
ecopann.element.Softplus_1[source]¶ Bases:
torch.nn.modules.module.Module-
forward(x)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
class
ecopann.element.Softplus_2[source]¶ Bases:
torch.nn.modules.module.Module-
forward(x)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
-
ecopann.element.activation(activation_name='rrelu')[source]¶ Activation functions.
Parameters: activation_name (str, optional) – The name of activation function, which can be ‘relu’, ‘leakyrelu’, ‘prelu’, ‘rrelu’, ‘relu6’, ‘elu’, ‘celu’, ‘selu’, ‘silu’, ‘sigmoid’, ‘logsigmoid’, ‘tanh’, ‘tanhshrink’, ‘softsign’, or ‘softplus’. Default: ‘rrelu’ Returns: Activation functions. Return type: object Note
Although many activation functions are available, the recommended activation function is ‘rrelu’.
ecopann.hpmodel¶
ecopann.nodeframe¶
-
ecopann.nodeframe.decreasingNode(node_in=1970, node_out=5, hidden_layer=3, get_allNode=True)[source]¶ A network structure that the number of neurons in each hidden layer is decreased proportionally.
Parameters: - node_in (int) – The number of nodes in the input layer.
- node_out (int) – The number of nodes in the output layer.
- hidden_layer (int) – The number of the hidden layers.
- get_allNode (bool) – If True, return the number of all nodes, otherwise, only return the number of nodes of hidden layers. Default: True
Returns: A list that contains the number of nodes in each layer.
Return type:
ecopann.sequence¶
-
class
ecopann.sequence.Activation[source]¶ Bases:
objectActivation functions, to be used by class
LinearSeq.
-
class
ecopann.sequence.BatchNorm[source]¶ Bases:
objectBatch Normalization, to be used by class
LinearSeq.
-
class
ecopann.sequence.LinearSeq(nodes, mainBN=True, finalBN=False, mainActive='rrelu', finalActive='None', mainDropout='None', finalDropout='None')[source]¶ Bases:
ecopann.sequence.SeqName,ecopann.sequence.BatchNorm,ecopann.sequence.Activation,ecopann.sequence.DropoutSequence of Linear.
Parameters: - nodes (list) – A list that contains the number of nodes in each layer.
- mainBN (bool, optional) – If True, the network will contain batch normalization layer in its main part. Default: True
- finalBN (bool, optional) – If True, the network will contain batch normalization layer in its last layer. Default: False
- mainActive (str, optional) – The activation function used in the main part of the network. See
activation()for the available activation functions. Default: ‘rrelu’ - finalActive (str, optional) – The activation function used in the last layer of the network. See
activation()for the available activation functions. Default: ‘None’ - mainDropout (str, optional) – The dropout used in the main part of the network, ‘None’ or ‘dropout’. Default: ‘None’
- finalDropout (str, optional) – The dropout used in the final layer of the network, ‘None’ or ‘dropout’. Default: ‘None’
ecopann.fcnet¶
-
class
ecopann.fcnet.FcNet(node_in=2000, node_out=6, hidden_layer=3, nodes=None, activation_func='rrelu')[source]¶ Bases:
torch.nn.modules.module.ModuleGet a fully connected network.
Parameters: - node_in (int) – The number of the input nodes.
- node_out (int) – The number of the output nodes.
- hidden_layer (int) – The number of the hidden layers.
- nodes (None or list) – If list, it should be a collection of nodes of the network, e.g. [node_in, node_hidden1, node_hidden2, …, node_out]
- activation_func (str) – Activation function.
-
forward(x)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
class
ecopann.fcnet.MultiBranchFcNet(nodes_in=[100, 100, 20], node_out=6, branch_hiddenLayer=1, trunk_hiddenLayer=3, nodes_all=None, activation_func='rrelu')[source]¶ Bases:
torch.nn.modules.module.ModuleGet a multibranch network.
Parameters: - nodes_in (list) – The number of the input nodes for each branch. e.g. [node_in_branch1, node_in_branch2, …]
- node_out (int) – The number of the output nodes.
- branch_hiddenLayer (int) – The number of the hidden layers for the branch part.
- trunk_hiddenLayer (int) – The number of the hidden layers for the trunk part.
- nodes_all (list) – The number of nodes of the multibranch network. e.g. [nodes_branch1, nodes_branch2, …, nodes_trunk]
-
forward(x_all)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
ecopann.optimize¶
-
class
ecopann.optimize.LrDecay(iter_mid, iteration=10000, lr=0.1, lr_min=1e-06)[source]¶ Let the learning rate decay with iteration.
-
exp(gamma=0.999, auto_params=True)[source]¶ Exponential decay.
Parameters: auto_params (bool) – If True, gamma is set automatically. Returns: lr * gamma^iteration Return type: float
-
ecopann.train¶
-
class
ecopann.train.Train(net, loss_func='L1', iteration=10000, optimizer='Adam')[source]¶ Bases:
objectTrain the network.
-
train_0(xx, yy, iter_mid, repeat_n=3, lr_decay=True)[source]¶ Training batch samples.
Parameters: - xx (torch tensor) – The input of the network.
- yy (torch tensor) – The target of the network.
- iter_mid (int) – The i-th iteration.
- repeat_n (int, optional) – The number of iterations using the same batch of data during network training, which is usually set to 1 or 3. Default: 3
- lr_decay (bool, optional) – If True, the learning rate will decrease with the iteration, otherwise, the learning rate will not change.
Returns: - float – The loss.
- Tensor – The predicted values.
-