Ejemplo n.º 1
0
        // LISTNET COMMAND
        public void ListNets()
        {
            if (network == null)
            {
                // NO NETWORK CREATED - CREATING NEW
                network = ANNetwork.NewNetwork(new int[] { 1 }, 1);
            }

            network.ShowFileList();
        }
Ejemplo n.º 2
0
        // LOAD NETWORK COMMAND
        public string LoadNetwork(string tmpString, ref ANNetwork externalNetworkLink)
        {
            if (network == null)
            {
                // NO NETWORK CREATED - CREATING NEW
                network             = ANNetwork.NewNetwork(new int[] { 1 }, 1);
                externalNetworkLink = network;
            }

            string result = network.LoadFromFile(tmpString);

            if (result.Length > 0)
            {
                return(result);
            }

            return("");
        }
Ejemplo n.º 3
0
        ////////// *******************************************************************************************************************************
        ////////// *******************************************************************************************************************************
        ////////// NETWORK FUNCTIONS

        // CREATE NEW NETWORK
        public string CreateNewANN(string tmpString, ref ANNetwork externalNetworkLink)
        {
            /* newANN <inputsNumber> <layersNumber> <L1NeuronNumber>...
             * (<alpha> <CostFunctionIndex> {<L1ActivationFunctionIndex>...} {<L1LowerBoundary>... <L1UpperBoundary>...} <scaleBoolean>)*/

            bool   isLast = true;
            string result = "";

            // PARSING INPUTS NUMBER
            if (tmpString.Length == 0)
            {
                return("\n-> Error creating new network: no <inputsNumber> argument entered.");
            }

            int inputsNumber = -1;

            result = Parsing.ParseInt(ref tmpString, ref inputsNumber, ref isLast, "inputsNumber", Parsing.AfterParsingCheck.Positive);

            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if (isLast)
            {
                return("\n-> Error creating new network: no <layersNumber> argument entered.");
            }


            // PARSING LAYER NUMBER
            int layersNumber = -1;

            result = Parsing.ParseInt(ref tmpString, ref layersNumber, ref isLast, "inputsNumber", Parsing.AfterParsingCheck.Positive);

            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            // PARSING LAYER NEURONS NUMBER FOR EACH LAYER
            int[] neuronNumbers = new int[layersNumber];
            for (int layerInd = 0; layerInd < layersNumber; layerInd++)
            {
                result = Parsing.ParseInt(ref tmpString, ref neuronNumbers[layerInd], ref isLast, "<LxNeuronNumber>", Parsing.AfterParsingCheck.Positive);
                if (result.Length > 0)
                {
                    return("\n-> Error creating new network. " + result);
                }

                if ((isLast) && (layerInd < layersNumber - 1))
                {
                    return("\n-> Error creating new network: no <LxNeuronNumber> for layer " + layerInd.ToString() + " .");
                }
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber);
                externalNetworkLink = network;
                return("");
            }

            // PARSING TRAINING SPEED IF ABLE
            float learningSpeed = -1;

            result = Parsing.ParseFloat(ref tmpString, ref learningSpeed, ref isLast, "trainingSpeed", Parsing.AfterParsingCheck.Positive);
            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed);
                externalNetworkLink = network;
                return("");
            }

            // PARSING ALPHA IF ABLE
            float alpha = -1;

            result = Parsing.ParseFloat(ref tmpString, ref alpha, ref isLast, "alpha", Parsing.AfterParsingCheck.Positive);
            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha);
                externalNetworkLink = network;
                return("");
            }

            // PARSING LYAMBDA IF ABLE
            float lyambda = -1;

            result = Parsing.ParseFloat(ref tmpString, ref lyambda, ref isLast, "lyambda", Parsing.AfterParsingCheck.NonNegative);
            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha, lyambda);
                externalNetworkLink = network;
                return("");
            }

            // PARSING COST FUNCTION
            CFTypeBase CFType = null;

            result = Parsing.ParseCFType(ref tmpString, ref CFType, ref isLast);

            if (result.Length > 0)
            {
                return(result);
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha, lyambda, CFType);
                externalNetworkLink = network;
                return("");
            }

            // PARSING ACTIVATION FUNCTIONS FOR ALL LAYERS
            AFTypeBase[] AFTypes = new AFTypeBase[layersNumber];
            result = Parsing.ParseAFTypesArray(ref tmpString, ref AFTypes, ref isLast);

            if (result.Length > 0)
            {
                return(result);
            }

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha, lyambda, CFType, AFTypes);
                externalNetworkLink = network;
                return("");
            }

            // PARSING INIT SCALE
            bool initScale;
            int  initScaleInt = -1;

            result = Parsing.ParseInt(ref tmpString, ref initScaleInt, ref isLast, "scaleBoolean", Parsing.AfterParsingCheck.NonNegative);
            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if ((initScaleInt != 0) && (initScaleInt != 1))
            {
                return("\n-> Error creating new network: non-boolean initScale " + initScaleInt.ToString() + " .");
            }

            initScale = initScaleInt == 0 ? false : true;

            if (isLast)
            {
                network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha, lyambda, CFType, AFTypes, initScale);
                externalNetworkLink = network;
                return("");
            }

            // PARSING LOWER BOUNDARY AND UPPER BOUNDARY
            float[] lowerBoundaries = new float[layersNumber];
            result = Parsing.ParseFloatArray(ref tmpString, ref lowerBoundaries, ref isLast, "lower boundaries", Parsing.AfterParsingCheck.NoCheck);

            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            if (isLast)
            {
                return("\n-> Error creating new network: no text for upper boundaties ");
            }

            float[] upperBoundaries = new float[layersNumber];
            result = Parsing.ParseFloatArray(ref tmpString, ref upperBoundaries, ref isLast, "upper boundaries", Parsing.AfterParsingCheck.NoCheck);

            if (result.Length > 0)
            {
                return("\n-> Error creating new network. " + result);
            }

            network             = ANNetwork.NewNetwork(neuronNumbers, inputsNumber, learningSpeed, alpha, lyambda, CFType, AFTypes, initScale, lowerBoundaries, upperBoundaries);
            externalNetworkLink = network;

            return("");
        }