public static void CreateConnection(INeuronPermitsToAddOutputsConnections source, INeuronPermitsToAddInputsConnections destination)
        {
            var connection = new NeuronConnection(source, destination);

            source.AddOutputConnection(connection);
            destination.AddInputConnections(connection);
        }
Esempio n. 2
0
 private void Start()
 {
     if (Connect)
     {
         _instance = NeuronConnection.Connect(IpAddress, Port, -1, NeuronConnection.SocketType.TCP);
     }
 }
 public void OnApplicationQuit()
 {
     for (int i = 0; i < sources.Count; ++i)
     {
         NeuronConnection.Disconnect(sources[i]);
     }
 }
 void OnEnable()
 {
     // Connect to target machine
     source = NeuronConnection.Connect(address, port, commandServerPort, socketType);
     // Get first actor from source
     actor = source.AcquireActor(0);
 }
Esempio n. 5
0
        public override void ConstructConnectionsAndRandonizeWeights()
        {
            List <BaseLayer> allLayers = new List <BaseLayer>();

            allLayers.Add(this.InputLayer);
            allLayers.AddRange(this.HiddenLayers);
            allLayers.Add(this.OutputLayer);

            for (var layerIndex = 0; layerIndex < allLayers.Count - 1; layerIndex++)
            {
                foreach (var curLayerNeuron in allLayers[layerIndex].Neurons)
                {
                    foreach (var nextLayerNeuron in allLayers[layerIndex + 1].Neurons)
                    {
                        var connection = new NeuronConnection(curLayerNeuron, Utils.Utils.GenerateRandomValue());
                        nextLayerNeuron.IncomeConnections.Add(connection);
                    }
                }
            }

            allLayers.ForEach(layer => {
                layer.Neurons.ForEach(neuron => {
                    if (neuron.B != null)
                    {
                        neuron.B.Weight = Utils.Utils.GenerateRandomValue();
                        neuron.B.Value  = 1;
                    }
                });
            });
        }
 void OnEnable()
 {
     _source = NeuronConnection.Connect(_address, _port, _socketType);
     if (_source != null)
     {
         _actor = _source.AcquireActor(_actorID);
     }
 }
 void OnDisable()
 {
     if (_source != null)
     {
         NeuronConnection.Disconnect(_source);
     }
     _source = null;
     _actor  = null;
 }
Esempio n. 8
0
        public void ProjectTest()
        {
            Neuron           testNeuron     = new Neuron(0.5D);
            NeuronConnection testConnection = new NeuronConnection(0.2D);
            var gid = Guid.NewGuid();

            testConnection.Project(gid, ref testNeuron, 0.4D);
            Assert.AreEqual(0.58D, testNeuron.Value, 0.1);
            Assert.AreEqual(gid, testNeuron.InputsIDs.First());
        }
		public NeuronSource( string address, int port, int commandServerPort, NeuronConnection.SocketType socketType, IntPtr socketReference, IntPtr commandSocketReference )
		{
			this.address = address;
			this.port = port;
			this.socketType = socketType;
			this.socketReference = socketReference;
			this.commandSocketReference = commandSocketReference;
			this.referenceCounter = 0;
			
			QueryNumOfActors();
		}
	public bool Connect( string address, int port, int commandServerPort, NeuronConnection.SocketType socketType )
	{
		NeuronSource source =  NeuronConnection.Connect( address, port, commandServerPort, socketType );
		if( source != null )
		{
			source.RegisterResumeActorCallback( OnResumeActor );
			source.RegisterSuspendActorCallback( OnSuspendActor );
			sources.Add( source );
		}
		return true;
	}
    public void DiconnectAll()
    {
        for (int i = 0; i < sources.Count; ++i)
        {
            NeuronSource source = sources[i];
            OnDisconnect(source);
            NeuronConnection.Disconnect(source);
        }
        sources.Clear();

        ClearAllInstances();
    }
    public bool Connect(string address, int port, int commandServerPort, NeuronConnection.SocketType socketType)
    {
        NeuronSource source = NeuronConnection.Connect(address, port, commandServerPort, socketType);

        if (source != null)
        {
            source.RegisterResumeActorCallback(OnResumeActor);
            source.RegisterSuspendActorCallback(OnSuspendActor);
            sources.Add(source);
        }
        return(true);
    }
Esempio n. 13
0
        public void GetNeuronConnectionByNodeIdTest()
        {
            Neuron[] testNeuronList = new Neuron[3] {
                new Neuron(0.3, null), new Neuron(0.5, null), new Neuron(0.7, null)
            };
            NeuronConnection[] testConnections = new NeuronConnection[3] {
                new NeuronConnection(0.2), new NeuronConnection(0.4), new NeuronConnection(0.9)
            };
            Neuron testNeuron = new Neuron(0.3d, new List <NeuronConnection>(testConnections));

            testNeuron.Output = 0.1;

            testNeuron.ProjectConnections(ref testNeuronList);
            Assert.AreEqual(0.2D, testNeuron.GetNeuronConnectionByNodeId(testNeuronList[0].id).Weight);
        }
Esempio n. 14
0
    private void OnApplicationQuit()
    {
        if (bDebugLog)
        {
            Debug.Log("AutoMotionCaptureDevicesSelecter.OnApplicationQuit");
        }
        // Perception Neuron(1-5)
        int i = 0;

        foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
        {
            if (sNeuronConnection.sNeuronSource != null)
            {
                NeuronConnection.DestroyConnection(sNeuronConnection.sNeuronSource);
                if (bDebugLog)
                {
                    Debug.Log("[Perception Neuron_" + (i + 1) + "] DestroyConnection");
                }
            }
            i++;
        }
        // Kinect1
        NativeMethods.NuiShutdown();
        if (bDebugLog)
        {
            Debug.Log("[Kinect1] KinectSensor Shutdown");
        }
        // Kinect2
        Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (_Sensor.IsOpen)
            {
                _Sensor.Close();
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Close");
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Closed");
                }
            }
        }
    }
    public void Update()
    {
        NeuronConnection.OnUpdate();

        for (int i = 0; i < actorsToInstantiate.Count; ++i)
        {
            SpawnInstance(actorsToInstantiate[i]);
        }
        actorsToInstantiate.Clear();

        for (int i = 0; i < instancesToDestroy.Count; ++i)
        {
            KillInstance(instancesToDestroy[i]);
        }
        instancesToDestroy.Clear();
    }
Esempio n. 16
0
        public void ProjectConnectionsTest()
        {
            Neuron[] testNeuronList = new Neuron[3] {
                new Neuron(0.3, null), new Neuron(0.5, null), new Neuron(0.7, null)
            };
            NeuronConnection[] testConnections = new NeuronConnection[3] {
                new NeuronConnection(0.2), new NeuronConnection(0.4), new NeuronConnection(0.9)
            };
            Neuron testNeuron = new Neuron(0.3d, new List <NeuronConnection>(testConnections));

            testNeuron.Output = 0.1;

            testNeuron.ProjectConnections(ref testNeuronList);

            Assert.AreEqual(0.38D, testNeuronList[0].Value, 0.01);
            Assert.AreEqual(0.67D, testNeuronList[1].Value, 0.01);
            Assert.AreEqual(1.08D, testNeuronList[2].Value, 0.01);
        }
Esempio n. 17
0
        public void ResetConnectionsTest()
        {
            Neuron[] testNeuronList = new Neuron[3] {
                new Neuron(0.3, null), new Neuron(0.5, null), new Neuron(0.7, null)
            };
            NeuronConnection[] testConnections = new NeuronConnection[3] {
                new NeuronConnection(0.2), new NeuronConnection(0.4), new NeuronConnection(0.9)
            };
            Neuron testNeuron = new Neuron(0.3d, new List <NeuronConnection>(testConnections));

            testNeuron.Output = 0.1;

            testNeuron.ProjectConnections(ref testNeuronList);
            Assert.AreEqual(1, testNeuronList[0].Inputs.Count);
            Assert.AreEqual(1, testNeuronList[0].InputsIDs.Count);
            testNeuronList[0].ResetConnections();
            Assert.AreEqual(0, testNeuronList[0].Inputs.Count);
            Assert.AreEqual(0, testNeuronList[0].InputsIDs.Count);
        }
Esempio n. 18
0
        public override void ConstructConnectionsAndRandonizeWeights()
        {
            List <BaseLayer> allLayers = new List <BaseLayer>();

            allLayers.Add(this.InputLayer);
            allLayers.Add(this.OutputLayer);

            for (var layerIndex = 0; layerIndex < allLayers.Count - 1; layerIndex++)
            {
                foreach (var curLayerNeuron in allLayers[layerIndex].Neurons)
                {
                    foreach (var nextLayerNeuron in allLayers[layerIndex + 1].Neurons)
                    {
                        var connection = new NeuronConnection(curLayerNeuron, Utils.Utils.GenerateRandomValue());
                        nextLayerNeuron.IncomeConnections.Add(connection);
                    }
                }
            }
        }
    public void Disconnect(string address, int port)
    {
        NeuronSource source = null;

        for (int i = 0; i < sources.Count; ++i)
        {
            if (address == sources[i].address && port == sources[i].port)
            {
                source = sources[i];
                break;
            }
        }

        if (source != null)
        {
            sources.Remove(source);
            OnDisconnect(source);
            NeuronConnection.Disconnect(source);
        }

        ClearAllInstances();
    }
Esempio n. 20
0
        public void NeuronConnectionTest()
        {
            NeuronConnection testConnection = new NeuronConnection(0.1D);

            Assert.AreEqual(0.1D, testConnection.Weight);
        }
 void OnDisable()
 {
     // Disconnect from the target machine, because multiple instances that require mocap data might connect to the same source.
     // We use a simple reference counter to handle connections, so each connection must have be paired with a disconnection.
     NeuronConnection.Disconnect(source);
 }
	public NeuronAnimatorInstance( Animator animator, string address, int port, int commandServerPort, NeuronConnection.SocketType socketType, int actorID )
		:base( address, port, commandServerPort, socketType, actorID )
	{
		boundAnimator = animator;
		UpdateOffset();
	}
		public NeuronInstance( string address, int port, int commandServerPort, NeuronConnection.SocketType socketType, int actorID )
		{
			standalone = true;
		}
	static NeuronSource CreateConnection( string address, int port, int commandServerPort, NeuronConnection.SocketType socketType )
	{	
		NeuronSource source = null;
		IntPtr socketReference = IntPtr.Zero;
		IntPtr commandSocketReference = IntPtr.Zero;
		
		if( socketType == NeuronConnection.SocketType.TCP )
		{
			socketReference = NeuronDataReader.BRConnectTo( address, port );
			if( socketReference != IntPtr.Zero )
			{
				if (bDebugLog) Debug.Log( string.Format( "[NeuronConnection] Connected to {0}:{1}.", address, port ) );
			}
			else
			{
				if (bDebugLog) Debug.LogError( string.Format( "[NeuronConnection] Connecting to {0}:{1} failed.", address, port ) );
			}
		}
		else
		{
			socketReference = NeuronDataReader.BRStartUDPServiceAt( port );
			if( socketReference != IntPtr.Zero )
			{
				if (bDebugLog) Debug.Log( string.Format( "[NeuronConnection] Start listening at {0}.", port ) );
			}
			else
			{
				if (bDebugLog) Debug.LogError( string.Format( "[NeuronConnection] Start listening at {0} failed.", port ) );
			}
		}
		
		if( socketReference != IntPtr.Zero )
		{
			if( commandServerPort > 0 )
			{
				// connect to command server
				commandSocketReference = NeuronDataReader.BRConnectTo( address, commandServerPort );
				if( commandSocketReference != IntPtr.Zero )
				{
					if (bDebugLog) Debug.Log( string.Format( "[NeuronConnection] Connected to command server {0}:{1}.", address, commandServerPort ) );
				}
				else
				{
					if (bDebugLog) Debug.LogError( string.Format( "[NeuronConnection] Connected to command server {0}:{1} failed.", address, commandServerPort ) );
				}
			}

			source = new NeuronSource( address, port, commandServerPort, socketType, socketReference, commandSocketReference );
		}
		
		return source;
	}
Esempio n. 25
0
    void Start()
    {
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation            = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }
        else
        {
            if (GameObject.Find(strFBXExporterForUnity) != null)
            {
                sFBXExporterForUnity = GameObject.Find(strFBXExporterForUnity).GetComponent <FBXExporterForUnity>();
            }
        }

        switch (eAutoMotionCaptureDevicesSelecter)
        {
        case EAutoMotionCaptureDevicesSelecter.eAuto:
        {
            // Perception Neuron(1-5)
            int iSelect = 0;
            foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
            {
                sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnection.address, sNeuronConnection.port, sNeuronConnection.commandServerPort, sNeuronConnection.socketType);
                if (sNeuronConnections[iSelect].sNeuronSource != null)
                {
                    eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                    NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                    }
                    return;
                }
                iSelect++;
            }

            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }

            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                //if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_2:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_3:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_4:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_5:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_6:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_7:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_8:
        {
            // Perception Neuron(1-5)
            int iSelect = (int)eAutoMotionCaptureDevicesSelecter - (int)EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1;
            sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnections[iSelect].address, sNeuronConnections[iSelect].port, sNeuronConnections[iSelect].commandServerPort, sNeuronConnections[iSelect].socketType);
            if (sNeuronConnections[iSelect].sNeuronSource != null)
            {
                eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect1:
        {
            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect2:
        {
            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
                else
                {
                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Kinect2] -Sensor Opened-");
                    }
                    return;
                }
            }
            break;
        }
        }
        eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eNone;
    }
		public NeuronTransformsInstance( string address, int port, int commandServerPort, NeuronConnection.SocketType socketType, int actorID )
			:base( address, port, commandServerPort, socketType, actorID )
		{
		}
		public NeuronTransformsInstance( Transform root, string prefix, string address, int port, int commandServerPort, NeuronConnection.SocketType socketType, int actorID )
			:base( address, port, commandServerPort, socketType, actorID )
		{
			Bind( root, prefix );
		}