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 Module instance 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 Module instance 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 Module instance 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 Module instance 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.element.avgPool1d(kernel_size)[source]
ecopann.element.avgPool2d(kernel_size)[source]
ecopann.element.avgPool3d(kernel_size)[source]
ecopann.element.celu()[source]
ecopann.element.dropout()[source]
ecopann.element.dropout2d()[source]
ecopann.element.dropout3d()[source]
ecopann.element.elu()[source]
ecopann.element.elu_1()[source]
ecopann.element.get_dropout(drouput_name='dropout')[source]

Get the dropout.

ecopann.element.leakyrelu()[source]
ecopann.element.logsigmoid()[source]
ecopann.element.maxPool1d(kernel_size)[source]
ecopann.element.maxPool2d(kernel_size)[source]
ecopann.element.maxPool3d(kernel_size)[source]
ecopann.element.pooling(pool_name='maxPool2d', kernel_size=2)[source]
ecopann.element.prelu()[source]
ecopann.element.relu()[source]
ecopann.element.relu6()[source]
ecopann.element.rrelu()[source]
ecopann.element.selu()[source]
ecopann.element.sigmoid()[source]
ecopann.element.sigmoid_1()[source]
ecopann.element.silu()[source]
ecopann.element.softplus()[source]
ecopann.element.softplus_1()[source]
ecopann.element.softplus_2()[source]
ecopann.element.softsign()[source]
ecopann.element.tanh()[source]
ecopann.element.tanhshrink()[source]

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:

list

ecopann.sequence

class ecopann.sequence.Activation[source]

Bases: object

Activation functions, to be used by class LinearSeq.

class ecopann.sequence.BatchNorm[source]

Bases: object

Batch Normalization, to be used by class LinearSeq.

class ecopann.sequence.Dropout[source]

Bases: object

Dropout, 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.Dropout

Sequence 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’
get_seq()[source]
class ecopann.sequence.Pooling[source]

Bases: object

Pooling, to be used by classes LinearSeq & Conv2dSeq

class ecopann.sequence.SeqName(module_name)[source]

Bases: object

The name of sequence, to be used by class LinearSeq.

seq_name()[source]

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.Module

Get 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 Module instance 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.Module

Get 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 Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ecopann.fcnet.split_nodes(nodes, weight=[])[source]

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
poly(decay_step=500, power=0.999, cycle=True)[source]

Polynomial decay.

Returns:(lr-lr_min) * (1 - iteration/decay_steps)^power +lr_min
Return type:float
step(stepsize=1000, gamma=0.3, auto_params=True)[source]

Let the learning rate decays step by step, similar to ‘exp’.

ecopann.train

class ecopann.train.SimilarityIdx(param_nums)[source]

Bases: object

simiIdx()[source]

calculate the parameter index surrounding a specific parameter

simiIdx_2()[source]

calculate the parameter index surrounding a specific parameter (using combination)

class ecopann.train.Train(net, loss_func='L1', iteration=10000, optimizer='Adam')[source]

Bases: object

Train the network.

call_GPU(prints=True)[source]
check_GPU()[source]
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.

train_1(inputs, target, repeat_n=1, set_seed=False, lr_decay=True, print_info=True, showIter_n=200)[source]

Training the training set (or a subsample of the training set).

transfer_data(device=None)[source]
transfer_net(use_DDP=False, device_ids=None, prints=True)[source]
ecopann.train.additional_loss(predicted, yy, simiIdx, reduction='mean')[source]
ecopann.train.additional_loss_2(predicted, yy, simiIdx, reduction='mean')[source]
ecopann.train.loss_funcs(name='L1')[source]

Some loss functions.

Parameters:name (str) – Abbreviation of loss function name. ‘L1’, ‘MSE’, or ‘SmoothL1’. Default: ‘L1’.
Returns:The corresponding loss function.
Return type:object

ecopann.models