SLNeuralNetworkConfig.sleela
lib/neural-nets/SLNeuralNetworkConfig.sleela · 55 line(s) · sleela
<< Language-level configuration mirror of slnn_network_config. The 32-bit
SLeeLa seed is widened to the native uint64_t field by the host adapter. >>
#sleela 3.0
material;
class SLNeuralNetworkConfig {
static final int ACTIVATION_LINEAR = 0;
static final int ACTIVATION_RELU = 1;
static final int ACTIVATION_TANH = 2;
static final int ACTIVATION_SIGMOID = 3;
static final int ABI_VERSION = 1;
int[] layerSizes;
int hiddenActivation = ACTIVATION_RELU;
int outputActivation = ACTIVATION_LINEAR;
int seed = 0;
int layerCount = 0;
void setLayerSizes(int[] sizes) {
if (sizes == null) {
layerSizes = null;
layerCount = 0;
return;
}
int[] copy = new int[sizes.length];
for (int i = 0; i < sizes.length; i++) { copy[i] = sizes[i]; }
layerSizes = copy;
layerCount = copy.length - 1;
}
int[] getLayerSizes() {
if (layerSizes == null) { return null; }
int[] copy = new int[layerSizes.length];
for (int i = 0; i < layerSizes.length; i++) { copy[i] = layerSizes[i]; }
return copy;
}
int getLayerCount() { return layerCount; }
void setHiddenActivation(int value) { hiddenActivation = value; }
int getHiddenActivation() { return hiddenActivation; }
void setOutputActivation(int value) { outputActivation = value; }
int getOutputActivation() { return outputActivation; }
void setSeed(int value) { seed = value; }
int getSeed() { return seed; }
boolean valid() {
if (layerSizes == null || layerCount < 1 || layerSizes.length != layerCount + 1) { return false; }
if (hiddenActivation < ACTIVATION_LINEAR || hiddenActivation > ACTIVATION_SIGMOID) { return false; }
if (outputActivation < ACTIVATION_LINEAR || outputActivation > ACTIVATION_SIGMOID) { return false; }
for (int i = 0; i < layerSizes.length; i++) {
if (layerSizes[i] < 1) { return false; }
}
return true;
}
}