Exemple #1
0
        // CHANGE COST FUNCTION
        public string SetCFType(string tmpString)
        {
            // CHECKING NETWORK
            if (network == null)
            {
                return(noNetworkMessage);
            }

            // CHECKING INPUTED STRING
            if (tmpString.Length == 0)
            {
                return("\n-> Error changing network's cost function type: no input text.");
            }

            CFTypeBase newCFType = null;
            bool       isLast    = false;

            string answer = Parsing.ParseCFType(ref tmpString, ref newCFType, ref isLast);

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

            network.SetCFType(newCFType);
            return("\n-> Cost function type set successful.");
        }
Exemple #2
0
        /// <summary>
        /// Parses inputed string, trying to read array of indexes of cost functions (see CFTypeBase class and its subclasses), passed as a reference.
        /// </summary>
        /// <param name="tmpString">Input string argument to be parsed.</param>
        /// <param name="resultCFType">Reference on result array with subclass objects.</param>
        /// <param name="isLast">Reference on a variable, indicating on success if read array was last in inputed string or not.</param>
        /// <returns>Empty string on success or error message.</returns>
        public static string ParseCFType(ref string tmpString, ref CFTypeBase resultCFType, ref bool isLast)
        {
            int    CFTypeInd = -1;
            string result    = ParseInt(ref tmpString, ref CFTypeInd, ref isLast, "CFType index", AfterParsingCheck.Positive);

            if (result.Length > 0)
            {
                return("\n-> Error parsing CFType index. " + result);
            }

            // DETERMINING THE TYPE OF COST FAUNCTION SUBCLASS
            switch (CFTypeInd)
            {
            case 1:
                resultCFType = new CFTypeQuadratic();
                break;

            case 2:
                resultCFType = new CFTypeCrossEntropy();
                break;

            case 3:
                resultCFType = new CFTypeLogLikelihood();
                break;

            default:
                return("\n-> Error parsing CFType index: unknown CFType index (" + CFTypeInd.ToString() + ").");
            }

            return("");
        }
Exemple #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("");
        }