Exemplo n.º 1
0
 /// <summary>
 /// Stores new input data to be processed.
 /// </summary>
 /// <param name="inputVector">An external input vector.</param>
 public void StoreNewData(double[] inputVector)
 {
     //Reset input data
     ResetInputProcessingQueue();
     //Store new data
     if (_encoderCfg.FeedingCfg.FeedingType == InputFeedingType.Continuous)
     {
         //Add single vector into the processing queue
         _inputDataQueue.Add(AddInternalInputs(inputVector));
     }
     else
     {
         //Split steady and varying data
         SplitSteadyAndVaryingInputData(inputVector, out _steadyData, out double[] varyingVector);
         //Check length of the external varying data vector
         ValidateExtInputVectorLength(varyingVector.Length);
         //Reset input neurons to initial state
         ResetInputNeurons(false);
         //Prepare input pattern
         FeedingPatternedSettings feedingCfg   = (FeedingPatternedSettings)_encoderCfg.FeedingCfg;
         InputPattern             inputPattern = new InputPattern(varyingVector,
                                                                  _encoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count,
                                                                  feedingCfg.VarSchema,
                                                                  feedingCfg.UnificationCfg.Detrend,
                                                                  feedingCfg.UnificationCfg.UnifyAmplitude,
                                                                  feedingCfg.UnificationCfg.ResamplingCfg.SignalBeginThreshold,
                                                                  feedingCfg.UnificationCfg.ResamplingCfg.SignalEndThreshold,
                                                                  feedingCfg.UnificationCfg.ResamplingCfg.UniformTimeScale,
                                                                  NumOfTimePoints == VariableNumOfTimePoints ? ResamplingSettings.AutoTargetTimePointsNum : NumOfTimePoints
                                                                  );
         _inputDataQueue.AddRange(CompleteInputPattern(inputPattern));
     }
     return;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes the input encoder and its feature filters from the specified samples data bundle.
 /// </summary>
 /// <param name="inputBundle">Sample input data</param>
 public void Initialize(VectorBundle inputBundle)
 {
     //Full reset
     Reset();
     if (_encoderCfg.FeedingCfg.FeedingType == InputFeedingType.Continuous)
     {
         //Continuous feeding
         //Fixed lengths
         _varyingDataVectorLength = inputBundle.InputVectorCollection[0].Length;
         NumOfTimePoints          = 1;
         //Add internal inputs and initialize feature filters
         UpdateFeatureFilters(AddInternalInputs(inputBundle.InputVectorCollection));
     }
     else
     {
         //Patterned feeding
         FeedingPatternedSettings feedingPatternedCfg = (FeedingPatternedSettings)_encoderCfg.FeedingCfg;
         //Input pattern length constraint and number of time-points
         NumOfTimePoints = feedingPatternedCfg.UnificationCfg.ResamplingCfg.TargetTimePoints != ResamplingSettings.AutoTargetTimePointsNum ? feedingPatternedCfg.UnificationCfg.ResamplingCfg.TargetTimePoints : VariableNumOfTimePoints;
         if (NumOfTimePoints == VariableNumOfTimePoints && (_routedVaryingFieldCollection.Count > 0 || feedingPatternedCfg.Slices > 1))
         {
             //because no resampling, length of external input vector must be fixed to keep consistent data
             _varyingDataVectorLength = inputBundle.InputVectorCollection[0].Length - _numOfSteadyFields;
             //Number of time-points must be also fixed
             NumOfTimePoints = _varyingDataVectorLength / _varyingFields.Count;
         }
         //Convert input vectors to InputPatterns
         foreach (double[] orgVector in inputBundle.InputVectorCollection)
         {
             //Split steady and varying data
             SplitSteadyAndVaryingInputData(orgVector, out double[] steadyVector, out double[] varyingVector);
             //Check length of the external varying data vector
             ValidateExtInputVectorLength(varyingVector.Length);
             //Convert external vector to pattern
             FeedingPatternedSettings feedingCfg   = (FeedingPatternedSettings)_encoderCfg.FeedingCfg;
             InputPattern             inputPattern = new InputPattern(varyingVector,
                                                                      _encoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count,
                                                                      feedingCfg.VarSchema,
                                                                      feedingCfg.UnificationCfg.Detrend,
                                                                      feedingCfg.UnificationCfg.UnifyAmplitude,
                                                                      feedingCfg.UnificationCfg.ResamplingCfg.SignalBeginThreshold,
                                                                      feedingCfg.UnificationCfg.ResamplingCfg.SignalEndThreshold,
                                                                      feedingCfg.UnificationCfg.ResamplingCfg.UniformTimeScale,
                                                                      NumOfTimePoints == VariableNumOfTimePoints ? ResamplingSettings.AutoTargetTimePointsNum : NumOfTimePoints
                                                                      );
             List <double[]> inputPatternVectors = CompleteInputPattern(inputPattern);
             UpdateFeatureFilters(inputPatternVectors);
         }
     }
     //Number of routed input values
     NumOfRoutedValues = _routedSteadyFieldIndexCollection.Count;
     if (_routedVaryingFieldCollection.Count > 0)
     {
         NumOfRoutedValues += _routedVaryingFieldCollection.Count * NumOfTimePoints;
     }
     return;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns collection of input field names to be routed to readout layer as the predictors
        /// </summary>
        public List <string> GetRoutedFieldNames()
        {
            List <string> names = new List <string>();

            //Steady fields
            if (FeedingCfg.FeedingType == InputEncoder.InputFeedingType.Patterned)
            {
                FeedingPatternedSettings patternedCfg = (FeedingPatternedSettings)FeedingCfg;
                if (patternedCfg.SteadyFieldsCfg != null)
                {
                    //There are steady fields defined
                    foreach (SteadyFieldSettings sf in patternedCfg.SteadyFieldsCfg.FieldCfgCollection)
                    {
                        if (sf.RouteToReadout)
                        {
                            names.Add(sf.Name);
                        }
                    }
                }
            }
            //Varying fields
            if (VaryingFieldsCfg.RouteToReadout)
            {
                foreach (ExternalFieldSettings fieldCfg in VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
                {
                    if (fieldCfg.RouteToReadout)
                    {
                        names.Add(fieldCfg.Name);
                    }
                }
                if (VaryingFieldsCfg.TransformedFieldsCfg != null)
                {
                    foreach (TransformedFieldSettings fieldCfg in VaryingFieldsCfg.TransformedFieldsCfg.FieldCfgCollection)
                    {
                        if (fieldCfg.RouteToReadout)
                        {
                            names.Add(fieldCfg.Name);
                        }
                    }
                }
                if (VaryingFieldsCfg.GeneratedFieldsCfg != null)
                {
                    foreach (GeneratedFieldSettings fieldCfg in VaryingFieldsCfg.GeneratedFieldsCfg.FieldCfgCollection)
                    {
                        if (fieldCfg.RouteToReadout)
                        {
                            names.Add(fieldCfg.Name);
                        }
                    }
                }
            }
            return(names);
        }
Exemplo n.º 4
0
        //Methods
        /// <summary>
        /// Checks consistency
        /// </summary>
        protected override void Check()
        {
            //Uniqueness of all input field names
            if (FeedingCfg.FeedingType == InputEncoder.InputFeedingType.Patterned)
            {
                FeedingPatternedSettings patternedCfg = (FeedingPatternedSettings)FeedingCfg;
                if (patternedCfg.SteadyFieldsCfg != null)
                {
                    //There are steady fields defined
                    foreach (SteadyFieldSettings sf in patternedCfg.SteadyFieldsCfg.FieldCfgCollection)
                    {
                        if (VaryingFieldsCfg.GetFieldID(sf.Name, false) != -1)
                        {
                            throw new InvalidOperationException($"Steady field name {sf.Name} found among varying fields.");
                        }
                    }
                }
            }

            return;
        }
Exemplo n.º 5
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="inputEncoderCfg">The configuration of the input encoder.</param>
        public InputEncoder(InputEncoderSettings inputEncoderCfg)
        {
            _encoderCfg = (InputEncoderSettings)inputEncoderCfg.DeepClone();
            //Steady fields
            _numOfSteadyFields = 0;
            _routedSteadyFieldIndexCollection = new List <int>();
            if (_encoderCfg.FeedingCfg.FeedingType == InputFeedingType.Patterned)
            {
                FeedingPatternedSettings fps = (FeedingPatternedSettings)_encoderCfg.FeedingCfg;
                if (fps.SteadyFieldsCfg != null)
                {
                    _numOfSteadyFields = fps.SteadyFieldsCfg.FieldCfgCollection.Count;
                    for (int i = 0; i < fps.SteadyFieldsCfg.FieldCfgCollection.Count; i++)
                    {
                        if (fps.SteadyFieldsCfg.FieldCfgCollection[i].RouteToReadout)
                        {
                            _routedSteadyFieldIndexCollection.Add(i);
                        }
                    }
                }
            }
            //Varying fields
            _varyingFields = new List <InputField>(_encoderCfg.VaryingFieldsCfg.TotalNumOfFields);
            int[] coordinates         = _encoderCfg.CoordinatesCfg.GetCoordinates();
            int   fieldIdx            = _numOfSteadyFields;
            int   inputNeuronStartIdx = 0;

            //External fields
            foreach (ExternalFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                _varyingFields.Add(new InputField(fieldCfg.Name,
                                                  fieldIdx++,
                                                  coordinates,
                                                  Interval.IntN1P1,
                                                  fieldCfg.FeatureFilterCfg,
                                                  _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                  (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                  inputNeuronStartIdx
                                                  ));
                inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
            }
            //Internal input transformers and fields
            _internalInputTransformerCollection = new List <ITransformer>();
            if (_encoderCfg.VaryingFieldsCfg.TransformedFieldsCfg != null)
            {
                List <string> names = _encoderCfg.VaryingFieldsCfg.GetNames();
                foreach (TransformedFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.TransformedFieldsCfg.FieldCfgCollection)
                {
                    _internalInputTransformerCollection.Add(TransformerFactory.Create(names, fieldCfg.TransformerCfg));
                    _varyingFields.Add(new InputField(fieldCfg.Name,
                                                      fieldIdx++,
                                                      coordinates,
                                                      Interval.IntN1P1,
                                                      fieldCfg.FeatureFilterCfg,
                                                      _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                      (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                      inputNeuronStartIdx
                                                      ));
                    inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
                }
            }
            //Internal input generators and fields
            _internalInputGeneratorCollection = new List <IGenerator>();
            if (_encoderCfg.VaryingFieldsCfg.GeneratedFieldsCfg != null)
            {
                foreach (GeneratedFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.GeneratedFieldsCfg.FieldCfgCollection)
                {
                    _internalInputGeneratorCollection.Add(GeneratorFactory.Create(fieldCfg.GeneratorCfg));
                    _varyingFields.Add(new InputField(fieldCfg.Name,
                                                      fieldIdx++,
                                                      coordinates,
                                                      Interval.IntN1P1,
                                                      fieldCfg.FeatureFilterCfg,
                                                      _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                      (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                      inputNeuronStartIdx
                                                      ));
                    inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
                }
            }
            _routedVaryingFieldCollection = new List <InputField>(_varyingFields.Count);
            foreach (InputField field in _varyingFields)
            {
                if (field.RouteToReadout)
                {
                    _routedVaryingFieldCollection.Add(field);
                }
            }
            _varyingDataVectorLength = NonFixedVaryingDataVectorLength;
            NumOfTimePoints          = VariableNumOfTimePoints;
            NumOfRoutedValues        = 0;
            //Input processing queue
            _inputDataQueue = new List <double[]>();
            ResetInputProcessingQueue();
            return;
        }
Exemplo n.º 6
0
 /// <summary>
 /// The deep copy constructor.
 /// </summary>
 /// <param name="source">The source instance.</param>
 public FeedingPatternedSettings(FeedingPatternedSettings source)
     : this(source.Slices, source.Bidir, source.VarSchema, source.UnificationCfg, source.SteadyFieldsCfg)
 {
     return;
 }