Esempio n. 1
0
		public Probe(Neuron neuron, int width, Color color, int vOffset)
		{
			buffer = new List<int>();
			this.width = width;
			this.Neuron = neuron;
			this.vOffset = vOffset;
			dataPen = new Pen(color);
		}
Esempio n. 2
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. 3
0
		private void UpdateConnections(Neuron n, string val)
		{
			string[] connections = val.Split(',');
			n.Connections.Clear();

			foreach (string conn in connections)
			{
				int nidx = conn.LeftOf('(').to_i();
				int psap = conn.Between('(', ')').to_i() << 8;
				Neuron targetNeuron = rowNeuronMap[dvStudy[nidx - 1].Row];
				n.AddConnection(new Connection(targetNeuron, psap));
			}
		}
Esempio n. 4
0
		private void UpdateProperty(Neuron n, string propName, string newVal)
		{
			Type t = n.Config.GetType();
			object obj = n.Config;
			PropertyInfo pi = t.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance);
			pi.SetValue(obj, newVal.ToPotential());
		}
Esempio n. 5
0
		protected void UpdateNeuronProperty(Neuron n, DataRow row, int colIdx)
		{
			string[] colProps = new string[] 
			{
				"RestingPotential",
				"ActionPotentialThreshold",
				"ActionPotentialValue",
				"RefractoryRecoveryRate",
				"HyperPolarizationOvershoot",
				"RestingPotentialReturnRate",
			};

			string newVal = row[colIdx].ToString();

			switch (colIdx)
			{
				case 0:					// row index is not allowed to be changed
					break;

				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
					UpdateProperty(n, colProps[colIdx - 1], newVal);
					break;

				case 7:					// Leakage
					n.Leakage = newVal.ToPotential();
					break;

				case 8:					// probe color
					break;

				case 9:					// connections
					UpdateConnections(n, newVal);
					break;

				case 10:				// we don't support updating locations -- this should be a hidden column
					break;
			}
		}
Esempio n. 6
0
		protected void AddNeuron(Neuron n, DataTable dt, NeuronConfig cfg)
		{
			DataRow row = dt.NewRow();
			row["n"] = dt.Rows.Count + 1;
			row["RP"] = cfg.RestingPotential.ToDisplayValue();
			row["APT"] = cfg.ActionPotentialThreshold.ToDisplayValue();
			row["APV"] = cfg.ActionPotentialValue.ToDisplayValue();
			row["RRR"] = cfg.RefractoryRecoveryRate.ToDisplayValue();
			row["HPO"] = cfg.HyperPolarizationOvershoot.ToDisplayValue();
			row["RPRR"] = cfg.RestingPotentialReturnRate.ToDisplayValue();
			row["LKG"] = "0";
			row["PCOLOR"] = probeColors[probeColorIdx];
			row["Location"] = new Point(20 + probeColorIdx * 30, pnlNetwork.Height / 2);
			dt.Rows.Add(row);
			rowNeuronMap[row] = n;
		}
Esempio n. 7
0
		/// <summary>
		/// Add a study neuron using the default neuron config.
		/// </summary>
		private void btnAddNeuron_Click(object sender, EventArgs e)
		{
			Neuron n = new Neuron();
			AddNeuron(n, dtStudy, NeuronConfig.DefaultConfiguration);
			pnlScope.AddProbe(n, probeColors[probeColorIdx]);
			studyNeuronPlots.Add(new NeuronPlot() { Neuron = n, Location = new Point(20 + probeColorIdx * 30, pnlNetwork.Height / 2) });
			probeColorIdx = (probeColorIdx + 1) % probeColors.Length;
			pnlNetwork.SetPlots(studyNeuronPlots);
			pnlNetwork.Tick();
		}
Esempio n. 8
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);
			*/
		}
Esempio n. 9
0
		public Connection(Neuron targetNeuron, int psap = 20<<8)
		{
			Neuron = targetNeuron;
			postSynapticActionPotential = psap;
		}
Esempio n. 10
0
 public void RemoveProbe(Neuron n)
 {
     probes.Remove(probes.Single(p => p.Neuron == n));
 }
Esempio n. 11
0
 public void AddProbe(Neuron n, Color color)
 {
     probes.Add(new Probe(n, Width, color, vOffset));
 }
Esempio n. 12
0
		public void RemoveProbe(Neuron n)
		{
			probes.Remove(probes.Single(p => p.Neuron == n));
		}
Esempio n. 13
0
		public void AddProbe(Neuron n, Color color)
		{
			probes.Add(new Probe(n, Width, color, vOffset));
		}
Esempio n. 14
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);
             */
        }
Esempio n. 15
0
 public void Fire()
 {
     Neuron.PostSynapticAction(postSynapticActionPotential);
 }
Esempio n. 16
0
 public Connection(Neuron targetNeuron, int psap = 20 << 8)
 {
     Neuron = targetNeuron;
     postSynapticActionPotential = psap;
 }