/// <summary> /// Create a VisualizerLayer /// </summary> /// <param name="_numNeurons">The number of neurons in the layer</param> /// <param name="_asyncActivationType">For an asynchronous network, the activation type. Ignored for synchronous networks</param> /// <param name="_syncActivationType">For a synchronous network, the activation type. Ignored for asynchronous networks</param> /// <param name="_isSynchronous">A flag determining whether the network is synchronous or not</param> /// <param name="_layerName">The name of the layer</param> /// <param name="_isFirstLayer">A flag representing whether this layer is the first layer in the network. Used to mask the activation type</param> public VisualizerLayer(int _numNeurons, AsyncNeuron.NeuronActivationType _asyncActivationType, TransferFunctionWrapper.MemoryActivationType _syncActivationType, bool _isSynchronous, string _layerName, bool _isFirstLayer) { InitializeComponent(); /*Prevent resizing*/ this.MaximumSize = this.Size; this.MinimumSize = this.Size; this.numNeurons = _numNeurons; this.asyncActivationType = _asyncActivationType; this.syncActivationType = _syncActivationType; this.isSynchronous = _isSynchronous; this.layerName = _layerName; this.isFirstLayer = _isFirstLayer; if (!this.isFirstLayer) { if (!this.isSynchronous) { this.activationType_string = Utilities.GetDescription <AsyncNeuron.NeuronActivationType>(this.asyncActivationType); } else { this.activationType_string = Utilities.GetDescription <TransferFunctionWrapper.MemoryActivationType>(this.syncActivationType); } } this.layerNameLabel.Text = String.Format("{0}", this.layerName); this.numNeuronLabel.Text = String.Format("{0} neurons", this.numNeurons); if (this.isSynchronous) { this.syncLabel.Text = "Synchronous"; } else { this.syncLabel.Text = "Asynchronous"; } if (this.isFirstLayer) { this.activationTypeLabel.Text = ""; } else { this.activationTypeLabel.Text = String.Format("Activation type: {0}", this.activationType_string); } this.label_padding = this.Height - this.layerNameLabel.Height - this.numNeuronLabel.Height - this.activationTypeLabel.Height - this.syncLabel.Height; this.label_padding /= 5; return; }
/// <summary> /// Construct the layer setup form /// </summary> /// <param name="_titleString">The string to display in the title</param> /// <param name="_biasEnabled">The seed value for whether the bias node is enabled for this layer or not</param> /// <param name="_biasValue">The seed value for the bias value for this layer</param> /// <param name="_numNeuron">The seed value for the number of neurons in the layer</param> /// <param name="_thresholdingEnabled">A flag for determing whether thresholding is enabled in this layer</param> /// <param name="_asyncType">For asynchronous networks, the seed value for the activation type. This parameter is ingored for synchronous networks</param> /// <param name="_syncType">For synchronous networks, the seed value for the activation type. This parameter is ignored for the asynchronous networks</param> /// <param name="_isSyncLayer">A flag for setting whether this layer is synchronous or asynchronous</param> /// <param name="_isLastLayer">A flag for setting whether this is the last layer in the network or not</param> public LayerSetup(string _titleString, bool _biasEnabled, double _biasValue, int _numNeuron, bool _thresholdingEnabled, AsyncNeuron.NeuronActivationType _asyncType, TransferFunctionWrapper.MemoryActivationType _syncType, bool _isSyncLayer, bool _isLastLayer) { InitializeComponent(); this.TitleLabel.Text = _titleString; this.biasEnabled = _biasEnabled; this.thresholdingEnabled = _thresholdingEnabled; this.isSyncLayer = _isSyncLayer; this.isLastLayer = _isLastLayer; this.biasValue = _biasValue; this.biasValueTB.Text = this.biasValue.ToString(); this.numNeurons = _numNeuron; this.numNeuronsTB.Text = _numNeuron.ToString(); this.validAsyncActivationTypes = new List <AsyncNeuron.NeuronActivationType>(); this.validSyncActivationTypes = new List <TransferFunctionWrapper.MemoryActivationType>(); this.activationComboBox.Items.Clear(); if (!this.isSyncLayer) { if (this.thresholdingEnabled) { int index = 0; var actTypes = Enum.GetValues(typeof(AsyncNeuron.NeuronActivationType)).Cast <AsyncNeuron.NeuronActivationType>(); foreach (AsyncNeuron.NeuronActivationType type in actTypes) { if (type != AsyncNeuron.NeuronActivationType.NONE) { this.activationComboBox.Items.Add(Utilities.GetDescription <AsyncNeuron.NeuronActivationType>(type)); this.validAsyncActivationTypes.Add(type); if (type == _asyncType) { this.activationComboBox.SelectedIndex = index; } index++; } } } else { this.activationComboBox.Items.Add(Utilities.GetDescription <AsyncNeuron.NeuronActivationType>(AsyncNeuron.NeuronActivationType.NONE)); this.activationComboBox.SelectedIndex = 0; } } else { int index = 0; var actTypes = Enum.GetValues(typeof(TransferFunctionWrapper.MemoryActivationType)).Cast <TransferFunctionWrapper.MemoryActivationType>(); foreach (TransferFunctionWrapper.MemoryActivationType type in actTypes) { this.activationComboBox.Items.Add(Utilities.GetDescription <TransferFunctionWrapper.MemoryActivationType>(type)); this.validSyncActivationTypes.Add(type); if (type == _syncType) { this.activationComboBox.SelectedIndex = index; } index++; } } this.biasValueTB.Visible = this.biasEnabled; this.biasLabel.Visible = this.biasEnabled; this.activationComboBox.Visible = this.thresholdingEnabled; this.thresholdingLabel.Visible = this.thresholdingEnabled; if (!this.isLastLayer) { this.binaryClassificationRadioButton.Visible = false; this.realValuedRadioButton.Visible = false; this.OutputTypeLabel.Visible = false; this.browseForThresholdInputsButton.Visible = false; this.thresholdLabel.Visible = false; this.thresholdInputFileTextBox.Visible = false; } }
private void testNN_Click(object sender, EventArgs e) { int[] neuronCounts = new int[3] { 3, 2, 1 }; double[] biasValues = new double[2] { 0, 0 }; AsyncNeuron.NeuronActivationType[] activations = new AsyncNeuron.NeuronActivationType[2] { AsyncNeuron.NeuronActivationType.SIGMOID_POLY_APPROX, AsyncNeuron.NeuronActivationType.SIGMOID_POLY_APPROX }; int numIntBits = 4; int numFracBits = 4; int numWeightUpperBits = 4; bool isClassifier = true; double[] classifierThresholds = new double[1]; classifierThresholds[0] = 0.5; List <double> weights = new List <double>(); weights.Add(0.0); weights.Add(1.0); weights.Add(-1.0); weights.Add(0.0); weights.Add(1.0); weights.Add(-1.0); AsyncNeuralNetwork nn = new AsyncNeuralNetwork(neuronCounts, biasValues, activations, numIntBits, numFracBits, numWeightUpperBits, isClassifier, classifierThresholds, weights); string outFile = Directory.GetCurrentDirectory() + "\\testOne\\"; System.IO.FileInfo f = new FileInfo(outFile); f.Directory.Create(); if (!(nn.writeVHDL(outFile))) { MessageBox.Show("Error in writing nn"); return; } /*File.Copy throws an exception if the file already exists. Delete it if it does*/ string fft_filepath = outFile + "\\fixed_float_types.vhd"; string fpkg_filepath = outFile + "\\fixed_pkg.vhd"; if (File.Exists(fft_filepath)) { File.Delete(fft_filepath); } if (File.Exists(fpkg_filepath)) { File.Delete(fpkg_filepath); } if (!File.Exists(outFile + "\\fixed_pkg.vhd")) { File.Copy("fixed_float_types.vhd", outFile + "\\fixed_float_types.vhd"); File.Copy("fixed_pkg.vhd", outFile + "\\fixed_pkg.vhd"); } MessageBox.Show("Files successfully written."); return; }