ANN models

refann.element

refann.element.activation(active_name='relu')[source]
refann.element.elu()[source]
refann.element.leakyrelu()[source]
refann.element.prelu()[source]
refann.element.relu()[source]
refann.element.rrelu()[source]

refann.hpmodel

refann.hpmodel.default()[source]
refann.hpmodel.models(key)[source]

Hyperparameter models.

Parameters:key (str) – Hyperparameter model that contains hyperparameters (such as activation function, batch normalization, dropout, etc.) used in the network. It can be ‘rec_1’ (no batch normalization) or ‘rec_2’ (with batch normalization).
Returns:Hyperparameter model.
Return type:object
refann.hpmodel.nuisance_hp(hparams)[source]

The hyperparameters that could be set to deterministic values.

refann.hpmodel.rec_1()[source]
refann.hpmodel.rec_2()[source]

refann.nodeframe

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

refann.nodeframe.triangleNode_1(node_in=1, node_mid=1024, node_out=2, hidden_layer=5)[source]

A neural network structure that the number of neurons in each hidden layer is increased proportionally and then decreased proportionally, the number of nodes in the hidden layers is symmetrical.

Parameters:
  • node_in (int) – The number of nodes in the input layer.
  • node_out (int) – The number of nodes in the output layer.
  • node_mid (int) – The number of nodes in the middle (hidden) layer.
  • hidden_layer (int) – The number of the hidden layers.
Returns:

A list that contains the number of nodes in each layer.

Return type:

list

refann.sequence

class refann.sequence.Activation[source]

Bases: object

Activation functions, to be used by class LinearSeq

class refann.sequence.BatchNorm[source]

Bases: object

Batch Normalization, to be used by class LinearSeq

class refann.sequence.Dropout[source]

Bases: object

Dropout, to be used by class LinearSeq

class refann.sequence.LinearSeq(nodes, mainBN=True, finalBN=False, mainActive='relu', finalActive='None', mainDropout='None', finalDropout='None')[source]

Bases: refann.sequence.SeqName, refann.sequence.BatchNorm, refann.sequence.Activation, refann.sequence.Dropout

Sequence of Linear

get_seq()[source]
class refann.sequence.Pooling[source]

Bases: object

Pooling, to be used by class LinearSeq

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

Bases: object

The name of sequence, to be used by class LinearSeq

seq_name()[source]

refann.fcnet

class refann.fcnet.FcNet(nodes, mainActive='relu', finalActive='None', mainBN=False, finalBN=False, mainDropout='None', finalDropout='None')[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.

refann.fcnet.get_FcNet(node_in=2000, node_out=6, hidden_layer=3, nodes=None, hparams={})[source]

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]
  • hparams (dict) – A dictionary of hyperparameters (or hidden parameters, such as the activation function, the batch normalization, and the dropout) of the netwowrk. See models().

refann.optimize

class refann.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’

Parameters:auto_params (bool) – If True, gamma is set automatically.

refann.train

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

Bases: object

call_GPU(prints=True)[source]
train_0(xx, yy, iter_mid, repeat_n=3, lr_decay=True)[source]
train_1(inputs, target, repeat_n=1, set_seed=False, lr_decay=True, print_info=True, showIter_n=200)[source]
transfer_data(device=None)[source]
transfer_net(use_DDP=False, device_ids=None, prints=True)[source]
refann.train.loss_funcs(name='L1')[source]

refann.data_process

class refann.data_process.InverseNormalize(x1, statistic={}, norm_type='z_score')[source]

Bases: object

Inverse transformation of class Normalize.

inverseNorm()[source]
mean()[source]
minmax()[source]
z_score()[source]
class refann.data_process.Normalize(x, statistic={}, norm_type='z_score')[source]

Bases: object

Normalize data.

mean()[source]

mean normalization

minmax()[source]

min-max normalization

Rescaling the range of features to scale the range in [0, 1] or [a,b] https://en.wikipedia.org/wiki/Feature_scaling

norm()[source]
z_score()[source]

standardization/z-score/zero-mean normalization

class refann.data_process.Statistic(x)[source]

Bases: object

Statistics of an array.

mean
statistic()[source]
std
xmax
xmin
refann.data_process.cuda2numpy(data)[source]
refann.data_process.cuda2torch(data)[source]
refann.data_process.numpy2cuda(data, device=None)[source]
refann.data_process.numpy2torch(data)[source]
refann.data_process.torch2cuda(data, device=None)[source]
refann.data_process.torch2numpy(data)[source]