public override bool Equals(object obj) { BasicNode other = (BasicNode)obj; if (other == null) { 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); }
private void SetUpBaseTopology() { BasicInputLayer input = new BasicInputLayer(); input.ValueIndexes = new int[] { 0, 1, 2, 3 }; baseTopology.InputLayer = input; baseTopology.OutputLayer = new BasicOutputLayer(); baseTopology.PreProcessor = objectFactory["TestBinary"]. CreateUserObject<IPreProcessor>( "BasicPreProcessor", new Dictionary<string, string>()); baseTopology.PostProcessor = objectFactory["TestBinary"]. CreateUserObject<IPostProcessor>( "BasicPostProcessor", new Dictionary<string, string>()); BasicNode[][] nodes = new BasicNode[2][]; nodes[0] = new BasicNode[3]; nodes[1] = new BasicNode[3]; for (int i = 0; i < 3; i++) { nodes[0][i] = new BasicNode( new float[] { 0.4f, 0.3f, 0.2f, 0.6f }, SigmoidFunctions.Logistic); nodes[1][i] = new BasicNode( new float[] { 0.4f, 0.3f, 0.2f }, SigmoidFunctions.Logistic); } baseTopology.HiddenLayers = new BasicLayer[] { new BasicLayer(nodes[0]), new BasicLayer(nodes[1]) }; baseTopology.TrainingAlgorithm = new HillClimbAlgo(); baseTopology.TrainingPreProcessor = objectFactory["TestBinary"]. CreateUserObject<ITrainingPreProcessor>( "BasicPreProcessor", new Dictionary<string, string>()); }
/// <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)); } }