Ejemplo n.º 1
0
        /// <summary>
        /// Return the current panel, resized to (Width, Height)
        /// </summary>
        /// <param name="width">The width of the panel to return</param>
        /// <param name="height">The height of the panel to return</param>
        /// <returns>The current panel</returns>
        public NNPanel current(int width, int height)
        {
            NNPanel currentPanel = this.panels[this.currentPanelIndex];

            currentPanel.resize(width, height);

            return(currentPanel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns to the previous screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void previousButton_Click(object sender, EventArgs e)
        {
            NNPanel nextPanel = this.wc.previous(this.mainPanel.Width, this.mainPanel.Height);

            this.visualizeButton.Visible = (nextPanel is SaveControl);

            this.setNextButtonText(nextPanel);

            this.mainPanel.Controls.Clear();
            this.mainPanel.Controls.Add(nextPanel);
            this.Invalidate();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the previous screen to display to the user
        /// </summary>
        /// <param name="width">The width at which to display the screen</param>
        /// <param name="height">The height at which to display the screen</param>
        /// <returns></returns>
        public NNPanel previous(int width, int height)
        {
            NNPanel currentPanel  = this.pc.current();
            NNPanel previousPanel = this.pc.previous(width, height);

            if (currentPanel is SaveControl || currentPanel is WeightsAndPrecision || currentPanel is ThankYou || currentPanel is NetworkSetup)
            {
                this.pc.clearToEnd(this.pc.currentPanelIndex + 1); //the .previous() call above decrements the currentPannelIndex
            }

            return(previousPanel);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Advances to the next screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nextButton_Click(object sender, EventArgs e)
        {
            NNPanel nextPanel = this.wc.next(this.mainPanel.Width, this.mainPanel.Height);

            this.visualizeButton.Visible = (nextPanel is SaveControl);

            if (nextPanel == null)
            {
                this.Close();
                return;
            }

            this.setNextButtonText(nextPanel);

            this.mainPanel.Controls.Clear();
            this.mainPanel.Controls.Add(nextPanel);
            this.Invalidate();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// A method to set the text of the "next" button.
 /// On the final screens, we want the text "next ->" to be replaced by "Generate" or "Finish"
 /// </summary>
 /// <param name="np"></param>
 private void setNextButtonText(NNPanel np)
 {
     if (np is Welcome || np is NetworkSetup || np is LayerSetup || np is WeightsAndPrecision || np is SyncOrAsync)
     {
         this.nextButton.Text = "next ->";
     }
     else if (np is SaveControl)
     {
         this.nextButton.Text = "Generate";
     }
     else if (np is ThankYou)
     {
         this.nextButton.Text = "Finish";
     }
     else
     {
         throw new Exception("Unrecognized form");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the next screen to show the user
        /// </summary>
        /// <param name="width">The width at which to display the form</param>
        /// <param name="height">The height at which to display the form</param>
        /// <returns></returns>
        public NNPanel next(int width, int height)
        {
            NNPanel currentPanel = this.pc.current();

            if (!currentPanel.verify())
            {
                return(currentPanel);
            }

            /*Take action based upon current panel*/
            if (currentPanel is SyncOrAsync)
            {
                this.isSynchronousNetwork = ((SyncOrAsync)currentPanel).isSynchronousNetwork();
                this.pc.panels.Add(new NetworkSetup(DEFAULT_HIDDEN_LAYERS));
                return(this.pc.advance(width, height));
            }

            if (currentPanel is Welcome)
            {
                return(this.pc.advance(width, height));
            }

            if (currentPanel is NetworkSetup)
            {
                NetworkSetup _currentPanel = (NetworkSetup)currentPanel;

                /*Resize rest of list*/
                if (this.pc.panels.Count > 3)
                {
                    this.pc.panels.RemoveRange(3, this.pc.panels.Count - 3);
                }
                int numLayers = _currentPanel.numHiddenLayers;

                /*Re-init if the lengths have changed*/
                if (this.neuronCounts == null || numLayers - 2 != this.neuronCounts.Length)
                {
                    this.neuronCounts         = new int[numLayers + 2]; //account for input and output layer
                    this.biasValues           = new double[numLayers + 1];
                    this.asyncActivationTypes = new AsyncNeuron.NeuronActivationType[numLayers + 1];
                    this.syncActivationTypes  = new TransferFunctionWrapper.MemoryActivationType[numLayers + 1];

                    for (int i = 0; i < numLayers + 1; i++)
                    {
                        this.neuronCounts[i]         = 1;
                        this.biasValues[i]           = 0;
                        this.asyncActivationTypes[i] = AsyncNeuron.NeuronActivationType.SIGMOID_POLY_APPROX;
                        this.syncActivationTypes[i]  = TransferFunctionWrapper.MemoryActivationType.LINEAR;
                    }
                    this.neuronCounts[numLayers + 1] = 1;
                }

                for (int i = 0; i < this.neuronCounts.Length; i++)
                {
                    if (!this.isSynchronousNetwork)
                    {
                        if (i == 0)
                        {
                            this.pc.panels.Add(new LayerSetup("Input layer", true, this.biasValues[0], this.neuronCounts[i], false, AsyncNeuron.NeuronActivationType.SIGMOID_POLY_APPROX, TransferFunctionWrapper.MemoryActivationType.LINEAR, false, false));
                        }
                        else if (i == this.neuronCounts.Length - 1)
                        {
                            this.pc.panels.Add(new LayerSetup("Output layer", false, 0, this.neuronCounts[i], true, this.asyncActivationTypes[i - 1], TransferFunctionWrapper.MemoryActivationType.LINEAR, false, true));
                        }
                        else
                        {
                            this.pc.panels.Add(new LayerSetup(String.Format("Hidden layer {0}", i), true, this.biasValues[i], this.neuronCounts[i], true, this.asyncActivationTypes[i - 1], TransferFunctionWrapper.MemoryActivationType.LINEAR, false, false));
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            this.pc.panels.Add(new LayerSetup("Input layer", true, this.biasValues[0], this.neuronCounts[i], false, AsyncNeuron.NeuronActivationType.LINEAR, TransferFunctionWrapper.MemoryActivationType.LINEAR, true, false));
                        }
                        else if (i == this.neuronCounts.Length - 1)
                        {
                            this.pc.panels.Add(new LayerSetup("Output layer", false, 0, this.neuronCounts[i], true, AsyncNeuron.NeuronActivationType.LINEAR, this.syncActivationTypes[i - 1], true, true));
                        }
                        else
                        {
                            this.pc.panels.Add(new LayerSetup(String.Format("Hidden layer {0}", i), true, this.biasValues[i], this.neuronCounts[i], true, AsyncNeuron.NeuronActivationType.LINEAR, this.syncActivationTypes[i - 1], true, false));
                        }
                    }
                }

                return(this.pc.advance(width, height));
            }

            if (currentPanel is LayerSetup)
            {
                LayerSetup _currentPanel = (LayerSetup)currentPanel;
                int        layerIndex    = this.pc.currentPanelIndex - 3;

                this.neuronCounts[layerIndex] = _currentPanel.numNeurons;

                if (layerIndex < this.biasValues.Length)
                {
                    this.biasValues[layerIndex] = _currentPanel.biasValue;
                }

                if (layerIndex != 0)
                {
                    if (!this.isSynchronousNetwork)
                    {
                        this.asyncActivationTypes[layerIndex - 1] = _currentPanel.asyncActivationType;
                    }
                    else
                    {
                        this.syncActivationTypes[layerIndex - 1] = _currentPanel.syncActivationType;
                    }
                }

                if (this.pc.isEnd())
                {
                    int numWeightsExpected = 0;
                    for (int i = 0; i < this.neuronCounts.Length - 1; i++)
                    {
                        numWeightsExpected += ((this.neuronCounts[i] + 1) * this.neuronCounts[i + 1]); //+1 -> bias node
                    }

                    /*Save weather this is a classifier or not*/
                    this.isClassifier = _currentPanel.isClassifier;
                    if (this.isClassifier)
                    {
                        this.classifierThresholds = (double[])_currentPanel.classifierThresholds.Clone();
                    }

                    /*Generate new weights form*/
                    this.pc.panels.Add(new WeightsAndPrecision(numWeightsExpected, 0, 0, ""));
                }

                return(this.pc.advance(width, height));
            }

            if (currentPanel is WeightsAndPrecision)
            {
                WeightsAndPrecision _currentPanel = (WeightsAndPrecision)currentPanel;

                this.numIntBits       = _currentPanel.maxIntBits;
                this.numFracBits      = _currentPanel.maxFracBits;
                this.numWeightIntBits = _currentPanel.maxIntBits; //TODO: Weights?
                this.weights          = _currentPanel.weights;

                this.pc.panels.Add(new SaveControl(saveControl_Persistant_Path, saveControl_Valid));

                this.initNN();

                return(this.pc.advance(width, height));
            }

            if (currentPanel is SaveControl)
            {
                SaveControl sc = (SaveControl)currentPanel;

                if (!this.generateNN(sc.filePath))
                {
                    MessageBox.Show("Error in writing the neural network.");
                    return(currentPanel);
                }

                this.pc.panels.Add(new ThankYou());
                return(this.pc.advance(width, height));
            }

            if (currentPanel is ThankYou)
            {
                return(null);
            }

            throw new Exception("ERROR: Unrecognized form type");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Return the current panel without resizing
        /// </summary>
        /// <returns>The current panel</returns>
        public NNPanel current()
        {
            NNPanel currentPanel = this.panels[this.currentPanelIndex];

            return(currentPanel);
        }