public void AssignPinToInputChannelsOfTheXCell(Pin pin)
        {
            var channel = new Channel(pin);

            channel.XCellDestiny = this;
            ListOfInputChannels.Add(channel);
        }
        /// <summary>
        /// ID=a<x<w~a<x<b,c<x<d,...,z<x<w
        /// </summary>
        /// <param name="ID">The identifier.</param>
        private void Explode(string ID)
        {
            var IDoldIDnew = ID.Split('~');

            if (IDoldIDnew.Count() == 2)
            {
                var inputChannelOfTheOriginalXCellOrToExplodeToReconnect = ListOfInputChannels.FirstOrDefault(channel => channel.XCellOrigin.Id == IDoldIDnew[0]);
                if (inputChannelOfTheOriginalXCellOrToExplodeToReconnect != null)
                {
                    var newXCellOrExplode = new XCellORExplode(IDoldIDnew[1], Layer);
                    inputChannelOfTheOriginalXCellOrToExplodeToReconnect.XCellOrigin = newXCellOrExplode;
                    newXCellOrExplode.ListOfOutputChannels.Add(inputChannelOfTheOriginalXCellOrToExplodeToReconnect);

                    var newRegions = IDoldIDnew[1].Split(',');
                    foreach (var region in newRegions)
                    {
                        var channelConnectedToAnXceldaFuzzy = Layer.ListOfInputChannels.FirstOrDefault(channel => channel.XCellOrigin.Id == region);
                        if (channelConnectedToAnXceldaFuzzy != null)
                        {
                            var newInputChannelForNewXCellOrExplode = new Channel();
                            newInputChannelForNewXCellOrExplode.XCellDestiny = newXCellOrExplode;
                            newInputChannelForNewXCellOrExplode.XCellOrigin  = channelConnectedToAnXceldaFuzzy.XCellOrigin;
                            newXCellOrExplode.ListOfInputChannels.Add(newInputChannelForNewXCellOrExplode);
                        }
                    }

                    newXCellOrExplode.AssignLevel();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Atomización
        /// </summary>
        /// <param name="idSequence">id=id1&id2&...&idn</param>
        public void Atomice(string idSequence)
        {
            var ids = idSequence.Split('&');

            if (ids.Count() >= HyperParameters.W)
            {
                var newXCellAND = ((ANDLayer)Layer).CreateAnXCellANDGivenItsIDInTemporalList(idSequence);
                var outputChannelFornewXCeldaANDConnectedToInputOfOldXCellAND = new Channel();
                outputChannelFornewXCeldaANDConnectedToInputOfOldXCellAND.XCellDestiny = this;
                outputChannelFornewXCeldaANDConnectedToInputOfOldXCellAND.XCellOrigin  = newXCellAND;
                newXCellAND.ListOfOutputChannels.Add(outputChannelFornewXCeldaANDConnectedToInputOfOldXCellAND);
                foreach (var id in ids)
                {
                    var inputChannel = ListOfInputChannels.FirstOrDefault(channel => channel.XCellOrigin.Id == id);
                    if (inputChannel != null)
                    {
                        inputChannel.XCellDestiny = newXCellAND;
                        newXCellAND.ListOfInputChannels.Add(inputChannel);
                        ListOfInputChannels.Remove(inputChannel); //Al eliminar este inputChannel de la lista, se elimina tb el inputChannel???
                    }
                }

                newXCellAND.AssignLevel();
                ListOfInputChannels.Add(newXCellAND.ListOfOutputChannels[0]);
            }
        }
 public void AssignChannelsToInputChannelsOfTheXCell(List <Channel> listOfChannels)
 {
     foreach (var channel in listOfChannels)
     {
         channel.XCellDestiny = this;
         ListOfInputChannels.Add(channel);
     }
 }
 public void AssignPinsToInputChannelsOfTheXCell(List <Pin> listOfPins)
 {
     foreach (var pin in listOfPins)
     {
         var channel = new Channel(pin);
         channel.XCellDestiny = this;
         ListOfInputChannels.Add(channel);
     }
 }
        public override void GetInputDataSync() //Diastole
        {
            PatternToSendInOutputChannels = string.Empty;

            var activeChannels = ListOfInputChannels.Where(inputChannel => inputChannel.IsActive).OrderBy(inputChannel => inputChannel.XCellOrigin.Id).ToList();
            var activeChannelsWithoutXCellDestiny = activeChannels.Where(activeChannel => activeChannel.XCellDestiny == null).ToList();

            foreach (var activeChannelWithoutXCellDestiny in activeChannelsWithoutXCellDestiny)
            {
                var xCellDP_I = new XCellDP_I(activeChannelWithoutXCellDestiny.XCellOrigin.Id, this);
                activeChannelWithoutXCellDestiny.XCellDestiny = xCellDP_I;
                xCellDP_I.ListOfInputChannels.Add(activeChannelWithoutXCellDestiny);
                ListOfXCellsDPI.Add(xCellDP_I);
            }

            foreach (var xCellDPI in ListOfXCellsDPI)
            {
                xCellDPI.GetInputData();
                xCellDPI.SendOutputData();
            }

            foreach (var xCellDPI in ListOfXCellsDPI.Where(xCelldpI => xCelldpI.ListOfOutputChannels[0].IsActive).OrderBy(xCelldpI => xCelldpI.ListOfOutputChannels[0].PatternToSendToAnXCell).ToList())
            {
                PatternToSendInOutputChannels = $"{PatternToSendInOutputChannels}{xCellDPI.ListOfOutputChannels[0].PatternToSendToAnXCell}&";
            }
            PatternToSendInOutputChannels = PatternToSendInOutputChannels.TrimEnd('&');

            var c1 = activeChannels.Count();
            var c2 = activeChannelsWithoutXCellDestiny.Count();

            if (c1 == c2 && c1 > 0)
            {
                if (!string.IsNullOrEmpty(PatternToSendInOutputChannels))
                {
                    var xCellAND = ((ANDLayer)LayerUp).CreateAnXCellANDGivenItsID(PatternToSendInOutputChannels);
                    //Crear una XCellAND con los canales de entrada igual a los canales de salida de las XCellDP_I creadas
                    foreach (var activeChannelWithoutXCell in activeChannelsWithoutXCellDestiny)
                    {
                        xCellAND.ListOfInputChannels.Add(activeChannelWithoutXCell.XCellDestiny.ListOfOutputChannels[0]);
                    }
                }
            }

            foreach (var xCellDPI in ListOfXCellsDPI)
            {
                xCellDPI.GetInputData();
            }

            foreach (var xCellDPI in ListOfXCellsDPI)
            {
                xCellDPI.ListOfInputChannels[0].PatternToSendToAnXCell = null;
                xCellDPI.ListOfInputChannels[0].Aij      = double.NaN;
                xCellDPI.ListOfInputChannels[0].IsActive = false;
            }
        }
示例#7
0
        public override void AssignLevel()
        {
            var Lj = double.MaxValue;
            var Lh = 0.0;

            if (ListOfInputChannels.Count() == 0)
            {
                Lh = Layer.LayerDown.LayerNumber;
            }
            else
            {
                foreach (var inputChannel in ListOfInputChannels)
                {
                    var LhTemp = 0.0;
                    if (inputChannel.XCellOrigin == null)
                    {
                        LhTemp = Layer.LayerNumber - 1;
                    }
                    else
                    {
                        LhTemp = inputChannel.XCellOrigin.Li;
                    }
                    if (LhTemp > Lh)
                    {
                        Lh = LhTemp;
                    }
                }
            }

            if (ListOfOutputChannels.Count == 0)
            {
                Lj = Layer.LayerUp.LayerNumber;
            }
            else
            {
                foreach (var outputChannel in ListOfOutputChannels)
                {
                    var LjTemp = 0.0;
                    if (outputChannel.XCellDestiny == null)
                    {
                        LjTemp = Layer.LayerNumber + 1;
                    }
                    else
                    {
                        LjTemp = outputChannel.XCellDestiny.Li;
                    }
                    if (LjTemp < Lj)
                    {
                        Lj = LjTemp;
                    }
                }
            }

            Li = (Lj + Lh) / 2;
        }
        public string CreateIdOfAllInActiveInputs()
        {
            var id = string.Empty;
            var listOfInActiveInputs = ListOfInputChannels.Where(input => input.Pin.Value < Threshold);

            foreach (var activeInput in listOfInActiveInputs)
            {
                id = $"{id}{activeInput.Pin.Id}|";
            }
            return(id.TrimEnd('|'));
        }
        public string CreateIdOfAllInactiveInputs()
        {
            var id = string.Empty;
            var listOfInActiveInputs = ListOfInputChannels.Where(inputChannel => inputChannel.Aij < Threshold);

            foreach (var activeChannelInput in listOfInActiveInputs)
            {
                id = $"{id}{activeChannelInput.XCellOrigin.Id}&";
            }
            return(id.TrimEnd('&'));
        }
        public virtual void ActivateOutputChannelsAndGenerateOutputValue()
        {
            var outputValue = 0.0;

            foreach (var inputChannelActive in ListOfInputChannels.Where(inputChannel => inputChannel.IsActive))
            {
                outputValue += (inputChannelActive.Nijpos - inputChannelActive.Nijneg) * inputChannelActive.Pin.Value / Nii;
            }

            foreach (var outputChannel in ListOfOutputChannels)
            {
                outputChannel.Pin.Value = outputValue;
                outputChannel.IsActive  = outputChannel.Pin.Value >= 0; //el caso =0 es para asegurar la difusión (maximiza la entropía en caso de duda)
            }
        }
        public XCellORExplode(string id, Layer layer) : base(id, layer)
        {
            var newInputChannel = new Channel();

            newInputChannel.XCellDestiny = this;
            var channelForInputFoundInLayerAsInputChannel = layer.ListOfInputChannels.FirstOrDefault(channel => channel.XCellOrigin.Id == id);

            if (channelForInputFoundInLayerAsInputChannel != null)
            {
                newInputChannel.XCellOrigin = channelForInputFoundInLayerAsInputChannel.XCellOrigin;
            }
            ListOfInputChannels.Add(newInputChannel);

            var newOutputChannel = new Channel();

            newOutputChannel.XCellOrigin = this;
            ListOfOutputChannels.Add(newOutputChannel);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XCellInput"/> class.
        /// </summary>
        /// <param name="id">id=id1</param>
        /// <param name="layer">The layer.</param>
        public XCellInput(string id, Layer layer) : base(id, layer)
        {
            var minMaxRValues = ((INPUTLayer)Layer).MinAndMaxValuesForInputHeaderID[id];

            MaxInputValue   = minMaxRValues.maxValue;
            MinInputValue   = minMaxRValues.minValue;
            R               = minMaxRValues.R;
            CounterOfValues = new uint[R];
            if (!layer.ListOfInputChannels.Any(channel => channel.XCellOrigin?.Id == id))
            {
                var newInputChannel = new Channel();
                newInputChannel.XCellDestiny = this;
                ListOfInputChannels.Add(newInputChannel);

                var newOutputChannel = new Channel();
                newOutputChannel.XCellOrigin = this;
                ListOfOutputChannels.Add(newOutputChannel);
            }
        }
示例#13
0
        public override void ActivateOutputChannelsAndGenerateOutputValue()
        {
            var outputValue = double.MaxValue;

            foreach (var inputChannelActive in ListOfInputChannels.Where(inputChannel => inputChannel.IsActive))
            {
                var value = (inputChannelActive.Nijpos - inputChannelActive.Nijneg) * inputChannelActive.Aij / Nii;
                if (value < outputValue)
                {
                    outputValue = value;
                }
            }

            foreach (var outputChannel in ListOfOutputChannels)
            {
                outputChannel.Aij      = outputValue;
                outputChannel.IsActive = outputChannel.Aij >= 0; //el caso =0 es para asegurar la difusión (maximiza la entropía en caso de duda)
            }
        }
示例#14
0
        public override void GetInputDataSync() //Diastole
        {
            var listOfInputChannelsActive = ListOfInputChannels.Where(inputChannel => inputChannel.IsActive == true).ToList();

            if (listOfInputChannelsActive != null)
            {
                foreach (var inputChannelActive in listOfInputChannelsActive)
                {
                    if (inputChannelActive.XCellDestiny == null)
                    {
                        var xCellFuzzyMaster = new XCellFuzzyMaster(inputChannelActive.XCellOrigin.Id, this, ((XCellInput)(inputChannelActive.XCellOrigin)).R);
                        xCellFuzzyMaster.AssignLevel();
                        xCellFuzzyMaster.ListOfInputChannels.Add(inputChannelActive);
                        inputChannelActive.XCellDestiny = xCellFuzzyMaster;
                        ListOfXCellsFuzzyMaster.Add(xCellFuzzyMaster);
                        xCellFuzzyMaster.ORExplodeLayer.ConnectThisLayerWithOutputLayer(this);
                    }
                    inputChannelActive.XCellDestiny.GetInputData();
                }
            }
        }
示例#15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XCellOR"/> class.
        /// </summary>
        /// <param name="idSequence">id=id1|id2|...|idn</param>
        /// <param name="layer">The layer.</param>
        public XCellOR(string idSequence, Layer layer) : base(idSequence, layer)
        {
            var ids = idSequence.Split('|');

            foreach (var id in ids)
            {
                var newInputChannel = new Channel();
                newInputChannel.XCellDestiny = this;
                var channelForInputFoundInLayerAsInputChannel = layer.ListOfInputChannels.FirstOrDefault(channel => channel.XCellOrigin.Id == id);
                if (channelForInputFoundInLayerAsInputChannel != null)
                {
                    newInputChannel.XCellOrigin = channelForInputFoundInLayerAsInputChannel.XCellOrigin;
                }
                ListOfInputChannels.Add(newInputChannel);
            }

            var newOutputChannel = new Channel();

            newOutputChannel.XCellOrigin = this;
            ListOfOutputChannels.Add(newOutputChannel);
        }
示例#16
0
        /// <summary>
        /// Hacer la atomización o la autogénesis al leer los datos de entrada para generar la estructura que se usará para hacer SendOutputData
        /// </summary>
        public override void GetInputData() //Diastole
        {
            var splittedIds            = Id.Split('&');
            var concatenatedRestingIDs = string.Empty;
            var idsOfActiveChannels    = string.Empty;

            var listOfActiveChannels = ListOfInputChannels.Where(inputChannel => inputChannel.IsActive).ToList();

            foreach (var inputChannel in listOfActiveChannels)
            {
                var patternToSendToAnXCell = inputChannel.PatternToSendToAnXCell;

                foreach (var splittedId in splittedIds)
                {
                    inputChannel.PatternToSendToAnXCell = inputChannel.PatternToSendToAnXCell.Trim(splittedId.ToCharArray()).Replace("&&", string.Empty);
                }
                if (!string.IsNullOrEmpty(inputChannel.PatternToSendToAnXCell) && !string.IsNullOrEmpty(concatenatedRestingIDs))
                {
                    concatenatedRestingIDs = $"{concatenatedRestingIDs}{inputChannel.PatternToSendToAnXCell}&";
                }

                if (inputChannel.IsActive && !string.IsNullOrEmpty(inputChannel.XCellOrigin.Id) && !string.IsNullOrEmpty(idsOfActiveChannels))
                {
                    idsOfActiveChannels = $"{idsOfActiveChannels}{inputChannel.XCellOrigin.Id}&";
                }
            }
            concatenatedRestingIDs = concatenatedRestingIDs.TrimEnd('&');
            idsOfActiveChannels    = idsOfActiveChannels.TrimEnd('&');

            if (listOfActiveChannels.Count() == ListOfInputChannels.Count()) //Han llegado patrones por todos los canales
            {
                if (concatenatedRestingIDs.Length == 0)                      //Se han eliminado todos los IDs en los InP
                {
                    var kk = 0;
                    //AuxPattern = string.Empty;
                    //AuxIsActive = false;
                    //double minValue = double.MaxValue;
                    //foreach (var inputChannel in ListOfInputChannels)
                    //{
                    //    if (inputChannel.IsActive)
                    //    {
                    //        AuxIsActive = true;
                    //        if (inputChannel.Aij < minValue)
                    //        {
                    //            minValue = inputChannel.Aij;
                    //        }
                    //        if (!string.IsNullOrEmpty(inputChannel.PatternToSendToAnXCell))
                    //        {
                    //            AuxPattern = $"{AuxPattern}{inputChannel.PatternToSendToAnXCell}|";
                    //        }
                    //    }
                    //}
                    //AuxPattern = AuxPattern.TrimEnd('|');
                    //IN = minValue;
                }
                else //Quedan IDs en los InP
                {
                    var splittedConcatenatedRestingIDs = concatenatedRestingIDs.Split('&');
                    var messageWasSent = false;
                    foreach (var outputChannel in ListOfOutputChannels)
                    {
                        foreach (var restingID in splittedConcatenatedRestingIDs)
                        {
                            if (outputChannel.XCellDestiny.Id.Contains(restingID))
                            {
                                //calcular la AND de los valores de entrada y dejar el valor preparado
                                //IN=
                                //foreach
                                messageWasSent = true;
                            }
                        }
                    }
                    if (!messageWasSent)
                    {
                        var kk = 0;
                        //Autogenesis(concatenatedRestingIDs);
                    }
                }
            }
            else //Han llegado patrones sólo por algunos canales
            {
                var kk = 0;
                //Atomice(idsOfActiveChannels);
            }
        }
 public void AssignChannelToInputChannelsOfTheXCell(Channel channel)
 {
     channel.XCellDestiny = this;
     ListOfInputChannels.Add(channel);
 }