Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            CustomizableNode other = (CustomizableNode)obj;

            if (other == null)
            {
                return(false);
            }
            if (combinationFunction != other.combinationFunction)
            {
                return(false);
            }
            if (activationFunction != other.activationFunction)
            {
                return(false);
            }

            if (Weights.Length != other.Weights.Length)
            {
                return(false);
            }
            for (int i = 0; i < Weights.Length; i++)
            {
                if (Weights[i] != other.Weights[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an object for a specified datatype
        /// </summary>
        /// <typeparam name="TObject">Interface that will be implimented and returned</typeparam>
        /// <param name="objectName">The name of the data type that will be instantiated
        /// and returned.</param>
        /// <param name="buildParam">The paramater that will be used to create the object</param>
        /// <returns>Returns a finished object instance</returns>
        public TObject CreateUserObject <TObject>(
            string objectName, Dictionary <string, string> buildParam)
        {
            switch (objectName)
            {
            case "BasicNode":
                string[] rawModifiers = ParseList(buildParam["combinationWeights"]);
                float[]  modifiers    = new float[rawModifiers.Length];

                for (int i = 0; i < rawModifiers.Length; i++)
                {
                    float.TryParse(rawModifiers[i], out modifiers[i]);
                }
                BasicNode node = new BasicNode();
                node.MetaData = buildParam;
                node.Weights  = modifiers;
                if (buildParam.ContainsKey("activationFunction"))
                {
                    node.ActivationFunc = getActivationFunction(buildParam["activationFunction"]);
                }
                INode tempNode = node;
                return((TObject)tempNode);

            case "CustomizableNode":
                rawModifiers = ParseList(buildParam["combinationWeights"]);
                modifiers    = new float[rawModifiers.Length];

                for (int i = 0; i < rawModifiers.Length; i++)
                {
                    float.TryParse(rawModifiers[i], out modifiers[i]);
                }
                CustomizableNode custNode = new CustomizableNode();
                custNode.MetaData = buildParam;
                custNode.Weights  = modifiers;
                if (buildParam.ContainsKey("activationFunction"))
                {
                    custNode.ActivationFunc =
                        getActivationFunction(buildParam["activationFunction"]);
                }
                if (buildParam.ContainsKey("combinationFunction"))
                {
                    custNode.ComboFunction =
                        getCombinationFunction(buildParam["combinationFunction"]);
                }
                tempNode = custNode;
                return((TObject)tempNode);

            case "BasicInputLayer":
                BasicInputLayer input = new BasicInputLayer();
                input.MetaData = buildParam;
                string[] rawValues = ParseList(buildParam["inputIndexes"]);
                int[]    values    = new int[rawValues.Length];
                for (int i = 0; i < rawValues.Length; i++)
                {
                    int.TryParse(rawValues[i], out values[i]);
                }
                input.ValueIndexes = values;
                IInputLayer tempIn = input;
                return((TObject)tempIn);

            case "BasicOutputLayer":
                IOutputLayer tempOut = new BasicOutputLayer();
                tempOut.MetaData = buildParam;
                return((TObject)tempOut);

            case "BasicLayer":
                int count;
                int.TryParse(buildParam["nodeCount"], out count);
                IHiddenLayer tempHidden = new BasicLayer(new INode[count]);
                tempHidden.MetaData = buildParam;
                return((TObject)tempHidden);

            case "ThreadedHiddenLayer":
                int.TryParse(buildParam["nodeCount"], out count);
                tempHidden          = new ThreadedHiddenLayer(new INode[count]);
                tempHidden.MetaData = buildParam;
                return((TObject)tempHidden);

            case "HillClimbAlgo":
                ITrainingAlgorithm algo = new HillClimbAlgo();
                return((TObject)algo);

            default:
                return(default(TObject));
            }
        }