Esempio n. 1
0
        protected void ShowNeuronBasedOnState(FastPixel fp, NeuronPlot np)
        {
            Color color = Color.Black;

            switch (np.Neuron.ActionState)
            {
            case Neuron.State.Integrating:
                int offset  = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.CurrentMembranePotential;
                int range   = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.Config.RestingPotential;
                int percent = 255 - (offset * 255 / range);
                int cval    = percent.Min(0).Max(255);
                color = Color.FromArgb(0, cval, 0);
                break;

            case Neuron.State.Firing:
                color = Color.White;
                break;

            case Neuron.State.RefractoryStart:
            case Neuron.State.AbsoluteRefractory:
                color = Color.FromArgb(255, 64, 64);
                break;

            case Neuron.State.RelativeRefractory:
                color = Color.Yellow;
                break;
            }

            Plot(fp, np.Location, color);
        }
Esempio n. 2
0
		protected void ShowNeuronBasedOnState(FastPixel fp, NeuronPlot np)
		{
			Color color = Color.Black;

			switch (np.Neuron.ActionState)
			{
				case Neuron.State.Integrating:
					int offset = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.CurrentMembranePotential;
					int range = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.Config.RestingPotential;
					int percent = 255 - (offset * 255 / range);
					int cval = percent.Min(0).Max(255);
					color = Color.FromArgb(0, cval, 0);
					break;

				case Neuron.State.Firing:
					color = Color.White;
					break;

				case Neuron.State.RefractoryStart:
				case Neuron.State.AbsoluteRefractory:
					color = Color.FromArgb(255, 64, 64);
					break;

				case Neuron.State.RelativeRefractory:
					color = Color.Yellow;
					break;
			}

			Plot(fp, np.Location, color);
		}
Esempio n. 3
0
 protected void UpdateLocations()
 {
     foreach (DataRow row in dtStudy.Rows)
     {
         Neuron     n  = rowNeuronMap[row];
         NeuronPlot np = studyNeuronPlots.Single(p => p.Neuron == n);
         row["Location"] = np.Location;
     }
 }
Esempio n. 4
0
        protected void ShowNeuronBasedOnFiredCountDown(FastPixel fp, NeuronPlot np)
        {
            if (np.Neuron.ActionState == Neuron.State.Firing)
            {
                np.FiredCountDown = 11;
            }

            if (np.FiredCountDown > 0)
            {
                --np.FiredCountDown;
                Color color = countDownColor[np.FiredCountDown];
                Plot(fp, np.Location, color);
            }
        }
Esempio n. 5
0
		protected void ShowNeuronBasedOnFiredCountDown(FastPixel fp, NeuronPlot np)
		{
			if (np.Neuron.ActionState == Neuron.State.Firing)
			{
				np.FiredCountDown = 11;
			}

			if (np.FiredCountDown > 0)
			{
				--np.FiredCountDown;
				Color color = countDownColor[np.FiredCountDown];
				Plot(fp, np.Location, color);
			}
		}
Esempio n. 6
0
		public override void SelectObject(Point pos, List<NeuronPlot> plots)
		{
			foreach (NeuronPlot np in plots)
			{
				if ((np.Location.X - 5 < pos.X) &&
					 (np.Location.X + 5 > pos.X) &&
					 (np.Location.Y - 5 < pos.Y) &&
					 (np.Location.Y + 5 > pos.Y))
				{
					selectedNeuron = np;
					NeuronSelected.Fire(this, new SelectedNeuronEventArgs() { Neuron = selectedNeuron.Neuron });
					break;
				}
			}
		}
Esempio n. 7
0
        protected int TestNeuronFiring(NeuronPlot np)
        {
            int idx = -1;

            if (np.Neuron.ActionState == Neuron.State.Firing)
            {
                np.FiredCountDown = 11;
            }

            if (np.FiredCountDown > 0)
            {
                --np.FiredCountDown;
                idx = np.FiredCountDown;
            }

            return(idx);
        }
Esempio n. 8
0
 public override void SelectObject(Point pos, List <NeuronPlot> plots)
 {
     foreach (NeuronPlot np in plots)
     {
         if ((np.Location.X - 5 < pos.X) &&
             (np.Location.X + 5 > pos.X) &&
             (np.Location.Y - 5 < pos.Y) &&
             (np.Location.Y + 5 > pos.Y))
         {
             selectedNeuron = np;
             NeuronSelected.Fire(this, new SelectedNeuronEventArgs()
             {
                 Neuron = selectedNeuron.Neuron
             });
             break;
         }
     }
 }
Esempio n. 9
0
        public override bool Draw(FastPixel fp, Graphics gr, List <NeuronPlot> plots)
        {
            gr.Clear(Color.White);

            foreach (NeuronPlot np in plots)
            {
                int colorIdx = TestNeuronFiring(np);
                Pen pen      = np == selectedNeuron ? penGreen : penBlack;

                // Draw the neuron circle as a border if not firing, otherwise as a solid circle on a fire event and post-fire countdown.
                if (colorIdx == -1)
                {
                    gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                }
                else
                {
                    gr.FillEllipse(brushCountDown[colorIdx], new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                    gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                }

                // If no connections, just draw a vertical "no connection" endpoint
                if (np.Neuron.Connections.Count == 0)
                {
                    Point endpoint = np.Location - new Size(0, 45);
                    DrawSynapse(pen, gr, np.Location, endpoint, Connection.CMode.Excitatory);
                }
                else
                {
                    foreach (Connection conn in np.Neuron.Connections)
                    {
                        NeuronPlot npConn   = plots.Single(p => p.Neuron == conn.Neuron);
                        Point      endpoint = npConn.Location;
                        DrawSynapse(pen, gr, np.Location, endpoint, conn.Mode);
                    }
                }
            }

            return(false);
        }
Esempio n. 10
0
        protected void UpdateStudyPlot(DataTable dt)
        {
            rowNeuronMap.Clear();
            studyNeuronPlots.Clear();
            pnlScope.ClearProbes();
            probeColorIdx = 0;

            foreach (DataRow row in dt.Rows)
            {
                Neuron n = new Neuron();
                rowNeuronMap[row] = n;

                for (int colIdx = 1; colIdx <= 7; ++colIdx)
                {
                    UpdateNeuronProperty(n, row, colIdx);
                }
                n.Leakage = row["LKG"].ToString().ToPotential();

                pnlScope.AddProbe(n, probeColors[probeColorIdx]);
                NeuronPlot np = new NeuronPlot()
                {
                    Neuron = n, Location = new Point(20 + probeColorIdx * 30, pnlNetwork.Height / 2)
                };

                if (row["Location"] != DBNull.Value)
                {
                    string pos = row["Location"].ToString();
                    np.Location = new Point(pos.Between('=', ',').to_i(), pos.RightOf(',').Between('=', '}').to_i());
                }

                studyNeuronPlots.Add(np);
                probeColorIdx = (probeColorIdx + 1) % probeColors.Length;
            }

            pnlNetwork.SetPlots(studyNeuronPlots);
            pnlNetwork.Tick();
        }
Esempio n. 11
0
		protected void UpdateStudyPlot(DataTable dt)
		{
			rowNeuronMap.Clear();
			studyNeuronPlots.Clear();
			pnlScope.ClearProbes();
			probeColorIdx = 0;

			foreach (DataRow row in dt.Rows)
			{
				Neuron n = new Neuron();
				rowNeuronMap[row] = n;

				for (int colIdx = 1; colIdx <= 7; ++colIdx)
				{
					UpdateNeuronProperty(n, row, colIdx);
				}
				n.Leakage = row["LKG"].ToString().ToPotential();

				pnlScope.AddProbe(n, probeColors[probeColorIdx]);
				NeuronPlot np = new NeuronPlot() { Neuron = n, Location = new Point(20 + probeColorIdx * 30, pnlNetwork.Height / 2) };

				if (row["Location"] != DBNull.Value)
				{
					string pos = row["Location"].ToString();
					np.Location = new Point(pos.Between('=', ',').to_i(), pos.RightOf(',').Between('=', '}').to_i());
				}

				studyNeuronPlots.Add(np);
				probeColorIdx = (probeColorIdx + 1) % probeColors.Length;
			}

			pnlNetwork.SetPlots(studyNeuronPlots);
			pnlNetwork.Tick();
		}
Esempio n. 12
0
 public override void DeselectObject()
 {
     selectedNeuron = null;
 }
Esempio n. 13
0
		public override void DeselectObject()
		{
			selectedNeuron = null;
		}
Esempio n. 14
0
		protected int TestNeuronFiring(NeuronPlot np)
		{
			int idx = -1;

			if (np.Neuron.ActionState == Neuron.State.Firing)
			{
				np.FiredCountDown = 11;

			}

			if (np.FiredCountDown > 0)
			{
				--np.FiredCountDown;
				idx = np.FiredCountDown;
			}

			return idx;
		}
Esempio n. 15
0
        protected void CreateNetwork()
        {
            Cursor             = Cursors.WaitCursor;
            networkNeuronPlots = new List <NeuronPlot>();

            int mx = pnlNetwork.Width / 4;
            int my = pnlNetwork.Height / 4;
            int c  = NetworkConfig.DefaultConfiguration.NumConnections;                                 // # of connections each neuron makes
            int d  = NetworkConfig.DefaultConfiguration.MaxDistance;                                    // max distance of each connection.			Must be multiple of 2
            int r  = NetworkConfig.DefaultConfiguration.Radius;                                         // radius (as a square) of connections.		Must be multiple of 2
            int p  = NetworkConfig.DefaultConfiguration.Pacemakers;                                     // # of pacemaker neurons

            // Initialize an mx x my array of neurons.  The edges wrap top-bottom / left-right.
            for (int x = 0; x < mx; x++)
            {
                for (int y = 0; y < my; y++)
                {
                    Neuron n = new Neuron();
                    networkNeuronPlots.Add(new NeuronPlot()
                    {
                        Neuron = n, Location = new Point(x * 4, y * 4)
                    });
                }
            }

            // Each neuron connects to c other neurons in a localized r x r region at a maximum distance of d from the originating neuron.
            foreach (NeuronPlot np in networkNeuronPlots)
            {
                int x = np.Location.X / 4;
                int y = np.Location.Y / 4;

                // Note: rnd.Next(min,max) is inclusive of the lower bound and exclusive of the upper bound.
                // To avoid introducing bias, we add 1 to the upper bound.

                // Target location:
                int targetx = x + rnd.Next(-d / 2, (d / 2) + 1);
                int targety = y + rnd.Next(-d / 2, (d / 2) + 1);

                for (int i = 0; i < c; i++)
                {
                    // Connection location around the target.
                    int adjx = targetx + rnd.Next(-r / 2, (r / 2) + 1);
                    int adjy = targety + rnd.Next(-r / 2, (r / 2) + 1);

                    if (adjx < 0)
                    {
                        adjx += mx;
                    }
                    if (adjy < 0)
                    {
                        adjy += my;
                    }

                    int qx = adjx % mx;
                    int qy = adjy % my;

                    // Find the neuron at this location
                    NeuronPlot npTarget = networkNeuronPlots.Single(np2 => np2.Location.X == qx * 4 & np2.Location.Y == qy * 4);
                    np.Neuron.AddConnection(new Connection(npTarget.Neuron));
                }
            }

            // Pick p neurons to be pacemakers at different rates.
            for (int i = 0; i < p; i++)
            {
                Neuron n = networkNeuronPlots[rnd.Next(mx * my)].Neuron;
                // You get more interesting patterns when the leakage is randomized so that pacemaker neurons do not all
                // fire synchronously.
                n.Leakage = 256 + rnd.Next(256);

/*
 *                              if (i == 0)
 *                              {
 *                                      pnlScope.AddProbe(n, Color.LightBlue);
 *                                      // Pick the first connecting neuron for a second trace.
 *                                      pnlScope.AddProbe(n.Connections[0].Neuron, Color.Red);
 *                              }
 */
                Cursor = Cursors.Arrow;
            }


            pnlNetwork.SetPlots(networkNeuronPlots);

            /*
             * pacemakerNeuron = new Neuron();
             * pacemakerNeuron.Leakage = 2 << 8;
             * pacemakerNeuron.Integration = 0;
             *
             * receiverNeuron = new Neuron();
             *
             * pacemakerNeuron.AddConnection(new Connection(receiverNeuron));
             *
             * neuronPlots.Add(new NeuronPlot() { Neuron = pacemakerNeuron, Location = new Point(pnlNetwork.Width / 2, pnlNetwork.Height / 2) });
             * neuronPlots.Add(new NeuronPlot() { Neuron = receiverNeuron, Location = new Point(pnlNetwork.Width / 2 + 20, pnlNetwork.Height / 2) });
             *
             * pnlScope.AddProbe(pacemakerNeuron, Color.LightBlue);
             * pnlScope.AddProbe(receiverNeuron, Color.Red);
             */
        }