示例#1
0
        public Dictionary <object, object> loadFrame(CreationFrame frame, int index)
        {
            Dictionary <object, object> result = new Dictionary <object, object>();
            Random random = new Random();
            bool   added  = false;

            Neuron neuron = frame.Neuron.Neuron;

            if (neurons.Find(k => k.Neuron == neuron) == null)
            {
                PointF         position = randomPoint(random);
                AnimatedNeuron an       = new AnimatedNeuron(neuron, position);
                CreatedNeuron  cn       = new CreatedNeuron(an);

                neurons.Add(an);
                result.Add(neuron, cn);
                added = true;
            }
            else
            {
                result.Add(neuron, true);
            }

            foreach (CreationData data in frame.Data)
            {
                if (data.Synapse.Changes.First <CreationData>() == data)
                {
                    AnimatedNeuron pre  = neurons.Find(k => data.Synapse.Pre == k.Neuron);
                    AnimatedNeuron post = neurons.Find(k => data.Synapse.Post == k.Neuron);

                    AnimatedSynapse synapse = synapses.Find(k => pre == k.Pre && post == k.Post);

                    if (synapse == null)
                    {
                        AnimatedSynapse syn = new AnimatedSynapse(pre, post, data.Synapse);
                        CreatedSynapse  cs  = new CreatedSynapse(syn);

                        synapses.Add(syn);
                        result.Add(syn.Synapse, cs);

                        if (syn.isDuplex())
                        {
                            result.Add(syn.Duplex, cs);
                        }
                    }
                    else
                    {
                        synapse.setDuplex(data.Synapse);
                    }
                }
            }

            if (added)
            {
                balance();
            }

            return(result);
        }
示例#2
0
        public CreationSequence addSentence(String sentence)
        {
            List <CreationFrame> frames   = new List <CreationFrame>();
            List <Neuron>        sequence = new List <Neuron>();

            String[] words = sentence.Split(' ');

            int index = 0;

            foreach (String word in words)
            {
                CreationFrame frame  = create(word, ++sentences);
                Neuron        neuron = frame.Neuron.Neuron;

                for (int i = 0; i < index; i++)
                {
                    Synapse synapse = neuron.Input.Find(k => k.Pre.Equals(sequence[i]));

                    if (synapse == null)
                    {
                        synapse = new Synapse(sequence[i], neuron);
                        synapses.Add(synapse);

                        neuron.Input.Add(synapse);
                        sequence[i].Output.Add(synapse);
                        frame.add(synapse);
                    }

                    synapse.Change += 1 / (float)(index - i);
                }

                foreach (Synapse synapse in neuron.Input)
                {
                    if (synapse.Change == 0)
                    {
                        continue;
                    }

                    float weight = synapse.Weight;
                    synapse.Factor += synapse.Change;
                    synapse.Weight  = (2 * synapse.Factor) / (neuron.Count + synapse.Factor);

                    CreationData data = new CreationData(synapse, frame, synapse.Change, weight, synapse.Weight);
                    synapse.Changes.Add(data);
                    frame.add(data);

                    synapse.Change = 0;
                }

                sequence.Add(neuron);
                frames.Add(frame);
                this.frames.Add(frame);

                index++;
            }

            return(new CreationSequence(frames));
        }
示例#3
0
        public CreationData(Synapse synapse, CreationFrame frame, float change, float start, float finish)
        {
            this.synapse = synapse;
            this.frame   = frame;
            this.change  = change;
            this.start   = start;
            this.finish  = finish;

            Height = 35;
            Width  = 160;
            initializeGraphics();

            MouseEnter += new EventHandler(mouseEnter);
            MouseLeave += new EventHandler(mouseLeave);
            background  = SystemColors.Control;
        }
示例#4
0
        public Creation(Display display) : base(display)
        {
            mapNeurons  = new Dictionary <Neuron, CreatedNeuron>();
            mapSynapses = new Dictionary <Synapse, CreatedSynapse>();
            mapHistory  = new Dictionary <AnimatedState, CreationHistory>();

            neurons  = new List <CreatedNeuron>();
            synapses = new List <CreatedSynapse>();

            CreationFrame.setDictionary(mapNeurons, mapSynapses);
            duplex = new List <Synapse>();

            tracking = new List <Tuple <int, int> >();
            tuple    = new Tuple <int, int>(-1, -1);
            tracking.Add(tuple);

            display.add(this);
            count = 0;
        }
示例#5
0
        public CreationFrame add(Brain brain, int index)
        {
            if (builder == null)
            {
                return(null);
            }

            CreationFrame  frame  = brain.add(this, builder, index);
            SequenceNeuron neuron = frame.Neuron;

            neuron.Top  = 8;
            neuron.Left = builder.Left;
            neuron.changeType(SequenceElementType.Normal);
            position = neuron.Right + 10;

            builder = null;
            sequence.Add(neuron);
            frames.Add(frame);
            return(frame);
        }
示例#6
0
        void changeFrame(CreationFrame cf, bool change = false)
        {
            if (frame != null)
            {
                frame.create();
                frame.Neuron.changeType(SequenceElementType.Normal);
            }

            frame = cf;
            frame.Neuron.changeType(SequenceElementType.Active);

            if (change)
            {
                frame.change();
            }

            if (animation)
            {
                frame.step();
            }
        }
示例#7
0
 public Dictionary <object, object> loadFrame(CreationFrame frame, int index)
 {
     return(animation.loadFrame(frame, index));
 }
示例#8
0
 public void remove(CreationFrame frame)
 {
 }
示例#9
0
        public CreationFrame add(CreationSequence sequence, BuiltElement element, int frame)
        {
            CreationFrame result = create(element.Name, frame);
            Neuron        neuron = result.Neuron.Neuron;
            int           index  = sequence.Frames.Count;

            for (int i = 0; i < index; i++)
            {
                Neuron  previous = sequence.Frames[i].Neuron.Neuron;
                Synapse synapse  = neuron.Input.Find(k => k.Pre.Equals(previous));

                if (synapse == null)
                {
                    synapse = new Synapse(previous, neuron);
                    synapses.Add(synapse);

                    neuron.Input.Add(synapse);
                    previous.Output.Add(synapse);
                    result.add(synapse);
                }

                synapse.Change += 1 / (float)(index - i);
            }

            foreach (Synapse synapse in neuron.Input)
            {
                if (synapse.Change == 0)
                {
                    continue;
                }

                int   count  = 0;
                float start  = 0;
                float weight = 0;

                List <CreationData> changes = synapse.Changes;
                synapse.Factor = 0;

                foreach (CreationData cd in changes)
                {
                    if (cd.Frame > frame)
                    {
                        break;
                    }

                    count++;
                    start           = cd.Weight;
                    synapse.Factor += cd.Change;
                }

                synapse.Factor += synapse.Change;
                weight          = (2 * synapse.Factor) / (synapse.Factor + count + 1);

                CreationData data = new CreationData(synapse, result, synapse.Change, start, weight);

                changes.Insert(count, data);
                result.add(data);
                start = weight;

                for (int i = count; i < changes.Count; i++)
                {
                    synapse.Factor += changes[i].Change;
                    weight          = (2 * synapse.Factor) / (synapse.Factor + i + 1);

                    changes[i].Start  = start;
                    changes[i].Weight = weight;

                    start = synapse.Weight;
                }

                synapse.Weight = weight;
                synapse.Change = 0;
            }

            for (int i = frame; i < frames.Count; i++)
            {
                frames[i].Frame = i;
            }

            frames.Insert(result.Frame, result);
            return(result);
        }