Python interface to C Deeply's neural network generators
Put cdeeply_neural_network.py into a reachable directory, then:
- Create a class instance: myNN = cdeeply_neural_network.CDNN()
- Call
myNN.tabular_regressor(...)ormyNN.tabular_encoder(...)to train a neural network in supervised or unsupervised mode. This step requires an internet connection! as the training is done server-side. - Call
output = myNN.runSample(input)as many times as you want to process new data samples -- one sample per function call.
Function definitions:
trainingSampleOutputs = myNN.tabular_regressor(trainingSamples, sampleTableTranspose,
outputRowOrColumnList, importances=[],
maxWeights="NO_MAX", maxHiddenNeurons="NO_MAX", maxLayers="NO_MAX",
maxWeightDepth="NO_MAX", maxActivationRate=1.,
maxWeightsHardLimit=True, maxHiddenNeuronsHardLimit=True, maxActivationsHardLimit=True,
allowedAFs=[True,True,True,True,True],
ifQuantizeWeights=False, wQuantBits=0, wQuantZeroInt=0, wQuantRange=1.,
ifQuantizeActivations=False, yQuantBits=0, yQuantZeroInt=0, yQuantRange=1.,
sparseWeights=False, allowNegativeWeights=True, hasBias=True, allowIOconnections=True)
Generates a x->y prediction network using supervised training on trainingSamples.
trainingSampleshas dimensionsnumFeaturesandnumSamples, containing both inputs and target outputs.- Set
sampleTableTransposeto"FEATURE_SAMPLE_ARRAY"fortrainingSamples[feature, sample]array ordering, or"SAMPLE_FEATURE_ARRAY"fortrainingSamples[sample, feature]array ordering. - The rows/columns in
trainingSamplescorresponding to the target outputs are specified byoutputRowOrColumnList.
- Set
- The optional
importancesargument weights the cost function of the target outputs. If passed, it has dimensionsnumTargetOutputsandnumSamples(ordered according tosampleTableTranspose). - Optional integer parameters
maxWeights,maxHiddenNeuronsandmaxLayerslimit the size of the neural network, andmaxWeightDepthlimits the depth of layer-to-layer connections. The correspondingmaxWeightsHardLimitandmaxHiddenNeuronsHardLimitparameters should be eitherTrueorFalse. allowedAFsis a length-5 Boolean vector corresponding to the allowed activation functions: (step, ReLU, ReLU1, sigmoid, tanh). Set each Boolean according to whether the activation function should be considered for a given layer of the network.To quantize weights or neural activations, setifQuantizeWeightsorifQuantizeActivationstoTrueand give values to the following three fields; otherwise set the respectiveifQuantizetoFalse`.- Set
sparseWeightsto eitherTrueorFalse, depending on whether we are generating sparse weight matrices. - The parameter
maxActivationRateshould be set to1.unless sparsifying the neural activations, in which case this can be a lower positive value. Sparse activations do not work with sigmoid or tanh activation functions. SetmaxActivationsHardLimitto eitherTrueorFalse. - The
allowNegativeWeightsandifNNhasBiasparameters are eitherTrueorFalse. The bias is a constant input to each neuron. - Set
allowIOconnectionstoFalseto forbid the input layer from feeding directly into the output layer. (Outliers in new input data might cause wild outputs). trainingSampleOutputshas dimensionsnumTargetOutputsandnumSamples, and stores the training output as calculated by the server. This is mainly a check that the data went through the pipes OK. If you don't care, ignore the return value.
trainingSampleOutputs = myNN.tabular_encoder(trainingSamples, sampleTableTranspose, importances=[],
doEncoder=True, doDecoder=True, numEncodingFeatures=1,
numVariationalFeatures=0, variationalDistribution="NORMAL_DIST",
maxWeights="NO_MAX", maxHiddenNeurons="NO_MAX", maxLayers="NO_MAX",
maxWeightDepth="NO_MAX", maxActivationRate=1.,
maxWeightsHardLimit=True, maxHiddenNeuronsHardLimit=True, maxActivationsHardLimit=True,
allowedAFs=[True,True,True,True,True],
ifQuantizeWeights=False, wQuantBits=0, wQuantZeroInt=0, wQuantRange=1.,
ifQuantizeActivations=False, yQuantBits=0, yQuantZeroInt=0, yQuantRange=1.,
sparseWeights=False, allowNegativeWeights=True, ifNNhasBias=True)
Generates an autoencoder (or an encoder or decoder) using unsupervised training on trainingSamples.
trainingSampleshas dimensionsnumFeaturesandnumSamples, in the order determined bysampleTableTranspose.sampleTableTransposeandimportancesare set the same way as fortabular_regressor(...).- The size of the encoding is determined by
numEncodingFeatures.- So-called variational features are extra randomly-distributed inputs used by the decoder, analogous to the extra degrees of freedom a variational autoencoder generates.
variationalDistributionis set to"UNIFORM_DIST"if the variational inputs are uniformly-(0, 1)-distributed, or"NORMAL_DIST"if they are normally distributed (zero mean, unit variance).
- Set
doEncodertoFalsefor a decoder-only network. - Set
doDecodertoFalsefor an encoder-only network. - The remaining parameters are set the same way as for
tabular_regressor(...).
sampleOutput = myNN.runSample(sampleInput, sampleVariationalInput=[])
Runs the neural network on a single sample, and returns the network output.
- If it's an autoencoder (encoder+decoder),
length(sampleInput)andlength(sampleOutput)equal the number of features in the training sample space. If it's just an encoder,length(sampleOutput)equalsnumEncodingFeatures; if decoder only,length(sampleInput)must equalnumEncodingFeatures. - If it's a decoder or autoencoder network with variational features, sample the variational features from the appropriate distribution and pass them as a second argument.
- The return value is simply a reference to the last layer of the network
myNN.y[myNN.numLayers]. Note that this may overwrite the output of a prior sample unless a copy is made of the output data.