Esempio n. 1
0
		//Keep track of nearest object by setting others to null.
		private void TrackNearestObject ( float distance, ref float nearestDistance, Cell returnedCell, ref Cell nearestCell, DistalSynapse returnedDistalSynapse, ref DistalSynapse nearestDistalSynapse, ProximalSynapse returnedProximalSynapse, ref ProximalSynapse nearestProximalSynapse )
		{
			if (distance < nearestDistance)
			{
				nearestDistance = distance;

				if (returnedCell != null)
				{
					nearestCell = returnedCell;
					nearestDistalSynapse = null;
					nearestProximalSynapse = null;
				}
				if (returnedDistalSynapse != null)
				{
					nearestCell = null;
					nearestDistalSynapse = returnedDistalSynapse;
					nearestProximalSynapse = null;
				}
				if (returnedProximalSynapse != null)
				{
					nearestCell = null;
					nearestDistalSynapse = null;
					nearestProximalSynapse = returnedProximalSynapse;
				}
			}
		}
Esempio n. 2
0
        /// <summary>
        /// Create a new synapse for this segment attached to the specified lateral cell.
        /// </summary>
        /// <param name="lateralCell">the lateral cell of the synapse to create.</param>
        /// <param name="initialPermanence">the initial permanence of the synapse.</param>
        internal void CreateSynapse(Cell lateralCell, float initialPermanence)
        {
            var newSynapse = new DistalSynapse(this, lateralCell, initialPermanence);

            this.Synapses.Add(newSynapse);
        }
Esempio n. 3
0
		/// <summary>
		/// Helper Method to get color from proximal synapse state
		/// </summary>
		/// <param name="distalSynapse"></param>
		/// <param name="color"></param>
		/// <param name="alphaValue"></param>
		private void  GetColorFromDistalSynapse ( DistalSynapse distalSynapse, out Color color, out float alphaValue )
		{
			color = this._dictionaryDistalSynapseColors[HtmDistalSynapseColors.Default].HtmColor;
			alphaValue = .1f; // All conditions can be false. 
			Simulation3DForm visualizerForm = Simulation3D.Form;

			//Color color = distalSynapse.IsActive ( Global.T ) ? Color.Black : Color.White;
			try
			{
				if (distalSynapse.IsActive ( Global.T ))
				{
					alphaValue = 1f;
					color = this._dictionaryDistalSynapseColors[HtmDistalSynapseColors.Active].HtmColor;
				}
				else	// Not Active.
				{
					alphaValue = 1f;
					color = this._dictionaryDistalSynapseColors[HtmDistalSynapseColors.Default].HtmColor;
				}

				//selected
				if (distalSynapse.mouseSelected)
				{
					color = selectedColor;
					alphaValue = 1f;
					//color = this._dictionaryProximalSynapseColors[HtmProximalSynapseColors.MouseSelected].HtmColor;
				}
				//mouseOver
				if (distalSynapse.mouseOver)
				{
					color = mouseOverColor;
					alphaValue = 1f;
					//color = this._dictionaryProximalSynapseColors[HtmProximalSynapseColors.MouseOver].HtmColor;
				}
			}
			catch (Exception)
			{

			}
		}
Esempio n. 4
0
		private float PickDistalSynapseConnections ( Ray ray, Column column, Cell cell, ref DistalSynapse returnedDistalSynapse )
		{
			float intersectDistance;
			float minDistance = float.MaxValue;

			returnedDistalSynapse = null;

			// Draw Connections if existing
			if (cell.IsDataGridSelected ||
				(Simulation3D.Form.ShowTemporalLearning && cell.PredictiveState[Global.T]))
			{
				Vector3 rayP1 = ray.Position;
				Vector3 rayP2 = rayP1 + ray.Direction;

				foreach (DistalSegment segment in cell.DistalSegments)
				{
					foreach (DistalSynapse synapse in segment.Synapses)
					{
						synapse.mouseOver = false;

						var distalSynapse = synapse as DistalSynapse;

						// Get the two vectors to draw line between
						var startPosition = new Vector3 ( column.PositionInRegion.X, cell.Index, column.PositionInRegion.Y + _zHtmRegion );

						// Get input source position
						int x = distalSynapse.InputSource.Column.PositionInRegion.X;
						int y = distalSynapse.InputSource.Index;
						int z = distalSynapse.InputSource.Column.PositionInRegion.Y;
						var endPosition = new Vector3 ( x, y, z + _zHtmPlane );

						bool intersect;
						Vector3 Line1ClosestPt = new Vector3 ();
						Vector3 Line2ClosestPt = new Vector3 ();
						intersect = Math3D.ClosestPointsLineSegmentToLine ( out Line1ClosestPt, out Line2ClosestPt, startPosition, endPosition, rayP1, rayP2, 0.1f, out intersectDistance );

						if (intersect && intersectDistance < minDistance)
						{
							minDistance = intersectDistance;
							returnedDistalSynapse = synapse;
						}
					}
				}
			}

			return minDistance;
		}
Esempio n. 5
0
 /// <summary>
 /// Create a new synapse for this segment attached to the specified lateral cell.
 /// </summary>
 /// <param name="lateralCell">the lateral cell of the synapse to create.</param>
 /// <param name="initialPermanence">the initial permanence of the synapse.</param>
 internal void CreateSynapse(Cell lateralCell, float initialPermanence)
 {
     var newSynapse = new DistalSynapse(this, lateralCell, initialPermanence);
     this.Synapses.Add(newSynapse);
 }
			public DistalSynapseChange(DistalSynapse synapse, Cell outputCell,
									   EDistalSynapseChange change, string changeText)
			{
				this.Synapse = synapse;
				this.OutputCell = outputCell;
				this.ChangeType = change;
				this.ChangeText = changeText;
			}
			public DistalSynapseComparisonCopy(Cell outputCell,
											   DistalSynapse originalSynapse, DistalSynapse savedSynapse)
			{
				this.OutputCell = outputCell;
				this.OriginalSynapse = originalSynapse;
				this.SavedSynapse = savedSynapse;
			}
		private void DrawConnectionBetweenColumns(Graphics grpOnBitmap, Column outputColumn,
			DistalSynapse synapse, Color color)
		{
			// Note that the start and end points are from the center of the
			// Column rectangle, that's why we add COLUMN_SIZE_VIRTUAL / 2
			// To the start points of the column rectangles.
			SizeF columnSizeVirtual;
			PointF columnStartPointVirtual, columnEndPointVirtual;
			this.GetColumnVirtualPointAndSize(synapse.InputSource.Column,
											  out columnStartPointVirtual, out columnSizeVirtual);
			this.GetColumnVirtualPointAndSize(outputColumn,
											  out columnEndPointVirtual, out columnSizeVirtual);

			Point pntConnectionStart = this.ConvertViewPointToDisplayPoint(new PointF(
																			   columnStartPointVirtual.X + columnSizeVirtual.Width / 2,
																			   columnStartPointVirtual.Y + columnSizeVirtual.Height / 2));
			Point pntConnectionEnd = this.ConvertViewPointToDisplayPoint(new PointF(
																			 columnEndPointVirtual.X + columnSizeVirtual.Width / 2,
																			 columnEndPointVirtual.Y + columnSizeVirtual.Height / 2));

			grpOnBitmap.DrawLine(new Pen(color, 5.0f),
								 pntConnectionStart, pntConnectionEnd);
		}
Esempio n. 9
0
        public void TestSynapse()
        {
            this.DefaultSynapseValues();

            var cell = new Cell(null, 0);
            cell.ActiveState[Global.T] = true;
            cell.LearnState[Global.T] = true;

            Synapse syn = new DistalSynapse(cell, Synapse.ConnectedPermanence);
            Assert.Equal(true, syn.IsConnected());

            Assert.Equal(true, syn.IsActive(Global.T));
            Assert.Equal(false, syn.IsActive(Global.T - 1));
            Assert.Equal(false, syn.IsActiveFromLearning(Global.T - 1));

            syn.DecreasePermanence();
            Assert.Equal(false, syn.IsConnected());
            Assert.Equal(true, syn.IsActive(Global.T));

            cell.ActiveState[Global.T] = false;
            Assert.Equal(false, syn.IsActive(Global.T));
        }