Example #1
0
        private static List <List <KeyValuePair <double, double> > > getActivatedSignal(Signal signal, Network network)
        {
            List <List <KeyValuePair <double, double> > > activatedSignal = new List <List <KeyValuePair <double, double> > >();

            List <Signal> weightedSum = new List <Signal>();

            Signal input = new Signal(signal);

            for (int i = 0; i < network.Count; i++)
            {
                weightedSum.Add(Layer.GetWeightedSum(input, network[i]));

                activatedSignal.Add(new List <KeyValuePair <double, double> >());

                for (int j = 0; j < weightedSum[i].Count; j++)
                {
                    activatedSignal[i].Add(new KeyValuePair <double, double>(LogisticFunction(weightedSum[i][j]), LogisticFunctionDerivative(weightedSum[i][j])));
                }

                input.Clear();
                foreach (KeyValuePair <double, double> pair in activatedSignal[i])
                {
                    input.Add(pair.Key);
                }
            }

            return(activatedSignal);
        }
Example #2
0
        static void Main(string[] args)
        {
            Network network = new Network();
            Layer   layer2  = new Layer();
            Layer   layer3  = new Layer();
            Node    node1   = new Node(2);
            Node    node2   = new Node(2);
            Node    node3   = new Node(2);

            layer2.Add(node1);
            layer2.Add(node2);
            layer3.Add(node3);

            network.Add(layer2);
            network.Add(layer3);

            Dictionary <Signal, Signal> trainingSet = new Dictionary <Signal, Signal>();
            Signal signalFF = new Signal();
            Signal signalFT = new Signal();
            Signal signalTF = new Signal();
            Signal signalTT = new Signal();
            Signal signalF  = new Signal();
            Signal signalT  = new Signal();

            signalFF.Add(0.0); signalFF.Add(0.0);
            signalFT.Add(0.0); signalFT.Add(1.0);
            signalTF.Add(1.0); signalTF.Add(0.0);
            signalTT.Add(1.0); signalTT.Add(1.0);

            signalF.Add(0.0);
            signalT.Add(1.0);

            trainingSet.Add(signalFF, signalF);
            trainingSet.Add(signalFT, signalT);
            trainingSet.Add(signalTF, signalT);
            trainingSet.Add(signalTT, signalF);

            network.Train(trainingSet);

            Console.WriteLine("OutputFF: " + signalFF * network);
            Console.WriteLine("OutputFT: " + signalFT * network);
            Console.WriteLine("OutputTF: " + signalTF * network);
            Console.WriteLine("OutputTT: " + signalTT * network);

            Console.ReadLine();
        }