Example #1
0
        public AgentNetwork(AgentNetworkDefinition definition, ILayerInitializer initializer)
        {
            InputCoder = new AgentNetworkInputCoder(definition.ViewRadius);
            var lastLayer         = new NetworkLayerDefinition(definition.LastLayerActivationFunction, 1);
            var networkDefinition = new NetworkDefinition(InputCoder.EncodedSize, definition.Layers.Concat(new[] { lastLayer }));

            Network = NetworkBuilder.Build(networkDefinition, initializer);
        }
        public override void Deleting(IObject deletedObject)
        {
            if (IsCompletingOperation)
            {
                return;
            }

            IFeature deletedFeature = deletedObject as IFeature;

            if (NetworkDefinition.IsNetworkFeature(deletedFeature))
            {
                _deletedInOperation.Add(deletedFeature);

                NetworkFeatureFinder.TargetFeatureCandidates?.Remove(deletedFeature);
            }
        }
        public override void Creating(IObject newObject)
        {
            if (IsCompletingOperation)
            {
                return;
            }

            IFeature newFeature = newObject as IFeature;

            if (NetworkDefinition.IsNetworkFeature(newFeature))
            {
                _createdInOperation.Add(newFeature);

                NetworkFeatureFinder.TargetFeatureCandidates?.Add(newFeature);
            }
        }
        protected override NetworkDefinition<NeuralNode, NeuralConnection> CreateDefinition()
        {
            var networkDef = new NetworkDefinition<NeuralNode, NeuralConnection>();

            int nodeBeginIndex = InputInterfaceLength;
            int nodeEndIndex = nodeBeginIndex + NodeCount - 1;
            int maxConnectionIndex = InputInterfaceLength + NodeCount + OutputInterfaceLength - 1;

            // Nodes:
            for (int idx = nodeBeginIndex; idx <= nodeEndIndex; idx++)
            {
                networkDef.AddNode(idx, NodeFactory.Create());
            }

            // Input:
            for (int iidx = 0; iidx < nodeBeginIndex; iidx++)
            {
                for (int nidx = nodeBeginIndex; nidx <= nodeEndIndex; nidx++)
                {
                    networkDef.AddConnection(new ConnectionIndex(iidx, nidx), ConnectionFactory.Create());
                }
            }

            // Hidden:
            for (int nidx = nodeBeginIndex; nidx <= nodeEndIndex; nidx++)
            {
                for (int oidx = nidx + 1; oidx <= maxConnectionIndex; oidx++)
                {
                    networkDef.AddConnection(new ConnectionIndex(nidx, oidx), ConnectionFactory.Create());
                    if (Recurrent) networkDef.AddConnection(new ConnectionIndex(oidx, nidx), ConnectionFactory.Create());
                }
            }

            // Output:
            for (int idx = nodeEndIndex + 1; idx <= maxConnectionIndex; idx++)
            {
                networkDef.AddNode(idx, CollectorNodeFactory.Create());
                networkDef.AddConnection(new ConnectionIndex(idx, idx + OutputInterfaceLength), new NeuralConnection());
            }

            Debug.Assert(networkDef.MaxNodeIndex == maxConnectionIndex + OutputInterfaceLength);

            return networkDef;
        }
        public override void Updating(IObject objectToBeStored)
        {
            if (IsCompletingOperation)
            {
                return;
            }

            IFeature storedFeature = objectToBeStored as IFeature;

            if (!NetworkDefinition.IsNetworkFeature(storedFeature))
            {
                return;
            }

            if (_updatedInOperation.ContainsKey(Assert.NotNull(storedFeature)))
            {
                return;
            }

            if (_createdInOperation.Contains(storedFeature))
            {
                return;
            }

            if (!((IFeatureChanges)storedFeature).ShapeChanged)
            {
                return;
            }

            IGeometry originalShape = ((IFeatureChanges)storedFeature).OriginalShape;

            if (originalShape == null)
            {
                // ObjectClass events (on enterprise GDB) do not call OnCreate(), but OnChange() with null original
                _createdInOperation.Add(storedFeature);
            }
            else
            {
                _updatedInOperation.Add(storedFeature, originalShape);
            }
        }
Example #6
0
    public async Task Run(string identityEndpoint, string username, string password, string project, string region)
    {
        // Configure authentication
        var user = new CloudIdentityWithProject
        {
            Username    = username,
            Password    = password,
            ProjectName = project
        };
        var identity   = new OpenStackIdentityProvider(new Uri(identityEndpoint), user);
        var networking = new NetworkingService(identity, region);

        Console.WriteLine("Creating Sample Network... ");
        var networkDefinition = new NetworkDefinition {
            Name = "Sample"
        };
        var sampleNetwork = await networking.CreateNetworkAsync(networkDefinition);

        Console.WriteLine("Adding a subnet to Sample Network...");
        var subnetDefinition = new SubnetCreateDefinition(sampleNetwork.Id, IPVersion.IPv4, "192.0.2.0/24")
        {
            Name = "Sample"
        };
        var sampleSubnet = await networking.CreateSubnetAsync(subnetDefinition);

        Console.WriteLine("Attaching a port to Sample Network...");
        var portDefinition = new PortCreateDefinition(sampleNetwork.Id)
        {
            Name = "Sample"
        };
        var samplePort = await networking.CreatePortAsync(portDefinition);

        Console.WriteLine("Listing Networks...");
        var networks = await networking.ListNetworksAsync();

        foreach (Network network in networks)
        {
            Console.WriteLine($"{network.Id}\t\t\t{network.Name}");
        }

        Console.WriteLine();
        Console.WriteLine("Sample Network Information:");
        Console.WriteLine();
        Console.WriteLine($"Network Id: {sampleNetwork.Id}");
        Console.WriteLine($"Network Name: {sampleNetwork.Name}");
        Console.WriteLine($"Network Status: {sampleNetwork.Status}");
        Console.WriteLine();
        Console.WriteLine($"Subnet Id: {sampleSubnet.Id}");
        Console.WriteLine($"Subnet Name: {sampleSubnet.Name}");
        Console.WriteLine($"Subnet IPs: {sampleSubnet.AllocationPools.First().Start} - {sampleSubnet.AllocationPools.First().End}");
        Console.WriteLine();
        Console.WriteLine($"Port Id: {samplePort.Id}");
        Console.WriteLine($"Port Name: {samplePort.Name}");
        Console.WriteLine($"Port Address: {samplePort.MACAddress}");
        Console.WriteLine($"Port Status: {samplePort.Status}");
        Console.WriteLine();

        Console.WriteLine("Deleting Sample Network...");
        await networking.DeletePortAsync(samplePort.Id);

        await networking.DeleteNetworkAsync(sampleNetwork.Id);
    }
 /// <summary>
 /// Updates the specified network.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="networkId">The network identifier.</param>
 /// <param name="network">The updated network definition.</param>
 /// <returns>
 /// The updated network.
 /// </returns>
 public static Network UpdateNetwork(this NetworkingService networkingService, Identifier networkId, NetworkDefinition network)
 {
     return(networkingService.UpdateNetworkAsync(networkId, network).ForceSynchronous());
 }
 /// <summary>
 /// Creates a network.
 /// </summary>
 /// <param name="networkingService">The networking service.</param>
 /// <param name="network">The network definition.</param>
 /// <returns>
 /// The created network.
 /// </returns>
 public static Network CreateNetwork(this NetworkingService networkingService, NetworkDefinition network)
 {
     return(networkingService.CreateNetworkAsync(network).ForceSynchronous());
 }
Example #9
0
        public void LoadDBCFile(string filename)
        {
            string[] lines = System.IO.File.ReadAllLines(filename);

            const int VERSION    = 0;
            const int BS         = 1;
            const int BU         = 2;
            const int BO         = 3;
            const int SG         = 4;
            const int CM         = 5;
            const int BA_DEF     = 6;
            const int BA_DEF_DEF = 7;
            const int BA         = 8;
            const int VAL        = 9;
            const int VAL_TABLE  = 10;

            int parseState = -1;

            Configuration = new NetworkDefinition();

            foreach (string line in lines)
            {
                int marker = line.IndexOf(' ');
                if (marker < 3)
                {
                    marker = 3;
                }
                string checktag = line.Trim().Substring(0, marker);

                switch (checktag)
                {
                case "VERSION": parseState = VERSION; break;

                case "BS_": parseState = BS; break;

                case "BU_": parseState = BU; break;

                case "BO_": parseState = BO; break;

                case "SG_": parseState = SG; break;

                case "CM_": parseState = CM; break;

                case "BA_DEF_": parseState = BA_DEF; break;

                case "BA_DEF_DEF_": parseState = BA_DEF_DEF; break;

                case "BA_": parseState = BA; break;

                case "VAL_": parseState = VAL; break;

                case "VAL_TABLE_": parseState = VAL_TABLE; break;
                }

                switch (parseState)
                {
                case VERSION: Configuration.Document.version = line.Substring(9); break;

                case BS: Configuration.Bus[0].baudrate = line.Substring(4); break;

                case BU: break;

                case BO: break;

                case SG: break;

                case CM: break;

                case BA_DEF: break;

                case BA_DEF_DEF: break;

                case BA: break;

                case VAL: break;

                case VAL_TABLE: break;
                }
            }
        }
Example #10
0
 public void LoadConfig(string filename)
 {
     Configuration = NetworkDefinition.LoadFromFile(filename);
 }
Example #11
0
 /// <inheritdoc cref="OpenStack.Synchronous.NetworkingServiceExtensions.CreateNetwork"/>
 public static Network CreateNetwork(this CloudNetworkService cloudNetworkService, NetworkDefinition network)
 {
     return(cloudNetworkService.CreateNetworkAsync(network).ForceSynchronous());
 }
 private IEnumerable <IFeature> GetJunctionFeatures([NotNull] IEnumerable <IFeature> fromList)
 {
     return(fromList.Where(f => NetworkDefinition.IsJunctionFeature(f)));
 }
 protected bool Equals(LinearNetworkEditAgent other)
 {
     return(NetworkDefinition.Equals(other.NetworkDefinition));
 }
 public override int GetHashCode()
 {
     return(NetworkDefinition.GetHashCode());
 }
        private NetworkDefinition<NeuralNode, NeuralConnection> Build()
        {
            var networkDef = new NetworkDefinition<NeuralNode, NeuralConnection>();
            
            int currentNodeIndex = InputInterfaceLength;
            var nodeLayerInfos = new Dictionary<int, IntRange>();
            nodeLayerInfos.Add(0, IntRange.CreateExclusive(0, InputInterfaceLength));

            int entryCount = Definition.NodeCount;

            int entryIdx = 0; 
            foreach (var nodeEntry in Definition.NodeEntries)
            {
                // Info
                var currentInfo = IntRange.CreateExclusive(currentNodeIndex, currentNodeIndex + nodeEntry.Node.NodeCount);
                nodeLayerInfos.Add(nodeEntry.Index, currentInfo);
                currentNodeIndex += nodeEntry.Node.NodeCount;

                // Upper
                foreach (var conn in Definition.GetUpperConnections(nodeEntry.Index))
                {
                    IntRange prevInfo;
                    if (!nodeLayerInfos.TryGetValue(conn.Index.UpperNodeIndex, out prevInfo))
                    {
                        throw GetArchitectureBuildingErrorEx("Node layer definition at '" + conn.Index.UpperNodeIndex + "' doesn't exists.");
                    }

                    for (int uidx = prevInfo.MinValue; uidx <= prevInfo.MaxValue; uidx++)
                    {
                        for (int lidx = currentInfo.MinValue; lidx <= currentInfo.MaxValue; lidx++)
                        {
                            networkDef.AddConnection(new ConnectionIndex(uidx, lidx), conn.Connection.ConnectionFactory.Create());
                        }
                    }
                }

                // Nodes
                for (int idx = currentInfo.MinValue; idx <= currentInfo.MaxValue; idx++)
                {
                    networkDef.AddNode(idx, nodeEntry.Node.NodeFactory.Create());
                }

                var selfConnDef = nodeEntry.Node.SelfConnectionDefinition;

                if (selfConnDef != null)
                {
                    for (int uidx = currentInfo.MinValue; uidx < currentInfo.MaxValue; uidx++)
                    {
                        for (int lidx = uidx + 1; lidx <= currentInfo.MaxValue; lidx++)
                        {
                            networkDef.AddConnection(new ConnectionIndex(uidx, lidx), selfConnDef.ConnectionFactory.Create());
                        }
                    }
                }

                // Output:
                if (entryIdx == entryCount - 1)
                {
                    if (currentInfo.Size != OutputInterfaceLength)
                    {
                        throw GetArchitectureBuildingErrorEx("Last node layer output size must be same as OutputInterfaceLength.");
                    }

                    for (int uidx = currentInfo.MinValue; uidx <= currentInfo.MaxValue; uidx++)
                    {
                        int lidx = uidx + OutputInterfaceLength;
                        networkDef.AddConnection(new ConnectionIndex(uidx, lidx), new NeuralConnection());
                    }
                }

                entryIdx++;
            }

            return networkDef;
        }
Example #16
0
        /// <summary>
        /// Create a network definition by querying the provided IBlackBox (typically a CPPN) with the
        /// substrate connection endpoints.
        /// </summary>
        /// <param name="blackbox">The HyperNEAT CPPN that defines the strength of connections between nodes on the substrate.</param>
        /// <param name="lengthCppnInput">Optionally we provide a connection length input to the CPPN.</param>
        public INetworkDefinition CreateNetworkDefinition(IBlackBox blackbox, bool lengthCppnInput)
        {
            // Get the sequence of substrate connections. Either a pre-built list or a dynamically
            // generated sequence.
            IEnumerable <SubstrateConnection> connectionSequence = _connectionList ?? GetConnectionSequence();

            // Iterate over substrate connections. Determine each connection's weight and create a list
            // of network definition connections.
            ISignalArray   inputSignalArr  = blackbox.InputSignalArray;
            ISignalArray   outputSignalArr = blackbox.OutputSignalArray;
            ConnectionList networkConnList = new ConnectionList(_connectionCountHint);
            int            lengthInputIdx  = _dimensionality + _dimensionality;

            foreach (SubstrateConnection substrateConn in connectionSequence)
            {
                // Assign the connection's endpoint position coords to the CPPN/blackbox inputs. Note that position dimensionality is not fixed.
                for (int i = 0; i < _dimensionality; i++)
                {
                    inputSignalArr[i] = substrateConn._srcNode._position[i];
                    inputSignalArr[i + _dimensionality] = substrateConn._tgtNode._position[i];
                }

                // Optional connection length input.
                if (lengthCppnInput)
                {
                    inputSignalArr[lengthInputIdx] = CalculateConnectionLength(substrateConn._srcNode._position, substrateConn._tgtNode._position);
                }

                // Reset blackbox state and activate it.
                blackbox.ResetState();
                blackbox.Activate();

                // Read connection weight from output 0.
                double weight = outputSignalArr[0];

                // Skip connections with a weight magnitude less than _weightThreshold.
                double weightAbs = Math.Abs(weight);
                if (weightAbs > _weightThreshold)
                {
                    // For weights over the threshold we re-scale into the range [-_maxWeight,_maxWeight],
                    // assuming IBlackBox outputs are in the range [-1,1].
                    weight = (weightAbs - _weightThreshold) * _weightRescalingCoeff * Math.Sign(weight);

                    // Create network definition connection and add to list.
                    networkConnList.Add(new NetworkConnection(substrateConn._srcNode._id,
                                                              substrateConn._tgtNode._id, weight));
                }
            }

            // Additionally we create connections from each hidden and output node to a bias node that is not defined at any
            // position on the substrate. The motivation here is that a each node's input bias is independent of any source
            // node (and associated source node position on the substrate). That we refer to a bias 'node' is a consequence of how input
            // biases are handled in NEAT - with a specific bias node that other nodes can be connected to.
            int setCount = _nodeSetList.Count;

            for (int i = 1; i < setCount; i++)
            {
                SubstrateNodeSet nodeSet = _nodeSetList[i];
                foreach (SubstrateNode node in nodeSet.NodeList)
                {
                    // Assign the node's position coords to the blackbox inputs. The CPPN inputs for source node coords are set to zero when obtaining bias values.
                    for (int j = 0; j < _dimensionality; j++)
                    {
                        inputSignalArr[j] = 0.0;
                        inputSignalArr[j + _dimensionality] = node._position[j];
                    }

                    // Optional connection length input.
                    if (lengthCppnInput)
                    {
                        inputSignalArr[lengthInputIdx] = CalculateConnectionLength(node._position);
                    }

                    // Reset blackbox state and activate it.
                    blackbox.ResetState();
                    blackbox.Activate();

                    // Read bias connection weight from output 1.
                    double weight = outputSignalArr[1];

                    // Skip connections with a weight magnitude less than _weightThreshold.
                    double weightAbs = Math.Abs(weight);
                    if (weightAbs > _weightThreshold)
                    {
                        // For weights over the threshold we re-scale into the range [-_maxWeight,_maxWeight],
                        // assuming IBlackBox outputs are in the range [-1,1].
                        weight = (weightAbs - _weightThreshold) * _weightRescalingCoeff * Math.Sign(weight);

                        // Create network definition connection and add to list. Bias node is always ID 0.
                        networkConnList.Add(new NetworkConnection(0, node._id, weight));
                    }
                }
            }

            // Check for no connections.
            // If no connections were generated then there is no point in further evaulating the network.
            // However, null is a valid response when decoding genomes to phenomes, therefore we do that here.
            if (networkConnList.Count == 0)
            {
                return(null);
            }

            // Construct and return a network definition.
            NetworkDefinition networkDef = new NetworkDefinition(_inputNodeCount, _outputNodeCount,
                                                                 _activationFnLibrary, _netNodeList, networkConnList);

            // Check that the definition is valid and return it.
            Debug.Assert(networkDef.PerformIntegrityCheck());
            return(networkDef);
        }
Example #17
0
        /// <summary>
        /// Create a network definition by querying the provided IBlackBox (typically a CPPN) with the
        /// substrate connection endpoints.
        /// </summary>
        /// <param name="blackbox">The HyperNEAT CPPN that defines the strength of connections between nodes on the substrate.</param>
        /// <param name="lengthCppnInput">Optionally we provide a connection length input to the CPPN.</param>
        public INetworkDefinition CreateNetworkDefinition(IBlackBox blackbox, bool lengthCppnInput)
        {
            // Iterate over substrate connections. Determine each connection's weight and create a list
            // of network definition connections.
            ISignalArray   inputSignalArr  = blackbox.InputSignalArray;
            ISignalArray   outputSignalArr = blackbox.OutputSignalArray;
            ConnectionList networkConnList = new ConnectionList(_connectionCountHint);
            int            lengthInputIdx  = Dimensionality + Dimensionality;

            for (int i = 0; i < N; i++)
            {
                foreach (var substrateConnection in _connectionList[i])
                {
                    for (int j = 0; j < Dimensionality; j++)
                    {
                        inputSignalArr[j] = substrateConnection._srcNode._position[j];
                        inputSignalArr[j + Dimensionality] = substrateConnection._tgtNode._position[j];
                    }
                    // Optional connection length input.
                    if (lengthCppnInput)
                    {
                        inputSignalArr[lengthInputIdx] = CalculateConnectionLength(substrateConnection._srcNode._position, substrateConnection._tgtNode._position);
                    }
                    blackbox.ResetState();
                    blackbox.Activate();
                    double weight = outputSignalArr[i];

                    //if LEO is toggled query for expression
                    double expressionWeight = -0.1;
                    if (Leo)
                    {
                        expressionWeight = outputSignalArr[i + M + N];
                    }
                    // Skip connections with a weight magnitude less than _weightThreshold.
                    double weightAbs = Math.Abs(weight);
                    if (!Leo && weightAbs > _weightThreshold || Leo && expressionWeight >= 0.0)
                    {
                        // For weights over the threshold we re-scale into the range [-_maxWeight,_maxWeight],
                        // assuming IBlackBox outputs are in the range [-1,1].
                        weight = (weightAbs - _weightThreshold) * _weightRescalingCoeff * Math.Sign(weight);

                        // Create network definition connection and add to list.
                        networkConnList.Add(new NetworkConnection(substrateConnection._srcNode._id,
                                                                  substrateConnection._tgtNode._id, weight));
                    }
                }
            }
            var biasOutputIdx = N;

            foreach (var nodeSet in _outputLayers.Concat(_hiddenLayers))
            {
                foreach (var node in nodeSet.NodeList)
                {
                    // Assign the node's position coords to the blackbox inputs. The CPPN inputs for source node coords are set to zero when obtaining bias values.
                    for (int j = 0; j < Dimensionality; j++)
                    {
                        inputSignalArr[j] = 0.0;
                        inputSignalArr[j + Dimensionality] = node._position[j];
                    }

                    // Optional connection length input.
                    if (lengthCppnInput)
                    {
                        inputSignalArr[lengthInputIdx] = CalculateConnectionLength(node._position);
                    }

                    // Reset blackbox state and activate it.
                    blackbox.ResetState();
                    blackbox.Activate();

                    // Read bias connection weight from output 1.
                    double weight = outputSignalArr[biasOutputIdx];
                    // Skip connections with a weight magnitude less than _weightThreshold.
                    double weightAbs = Math.Abs(weight);
                    if (weightAbs > _weightThreshold)
                    {
                        // For weights over the threshold we re-scale into the range [-_maxWeight,_maxWeight],
                        // assuming IBlackBox outputs are in the range [-1,1].
                        weight = (weightAbs - _weightThreshold) * _weightRescalingCoeff * Math.Sign(weight);

                        // Create network definition connection and add to list. Bias node is always ID 0.
                        networkConnList.Add(new NetworkConnection(0, node._id, weight));
                    }
                }
                biasOutputIdx++;
            }

            // Check for no connections.
            // If no connections were generated then there is no point in further evaulating the network.
            // However, null is a valid response when decoding genomes to phenomes, therefore we do that here.
            if (networkConnList.Count == 0)
            {
                return(null);
            }

            // Construct and return a network definition.
            NetworkDefinition networkDef = new NetworkDefinition(_inputLayers.Sum(x => x.NodeList.Count), _outputLayers.Sum(x => x.NodeList.Count),
                                                                 _activationFnLibrary, _netNodeList, networkConnList);

            // Check that the definition is valid and return it.
            Debug.Assert(networkDef.PerformIntegrityCheck());
            return(networkDef);
        }