//Constructor /// <summary> /// Creates an initialized instance /// </summary> /// <param name="dataVector">Vector of values corresponding to readout units</param> /// <param name="unitsAllSubResults">All sub-predictions</param> /// <param name="rl">Readout layer object</param> public ReadoutData(double[] dataVector, List <double[]> unitsAllSubResults, ReadoutLayer rl) { //Alone units DataVector = dataVector; ReadoutUnitDataCollection = new Dictionary <string, ReadoutUnitData>(); for (int i = 0; i < rl.Settings.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count; i++) { ReadoutUnitSettings rus = rl.Settings.ReadoutUnitsCfg.ReadoutUnitCfgCollection[i]; ReadoutUnitDataCollection.Add(rus.Name, new ReadoutUnitData() { Name = rus.Name, Index = i, Task = rus.TaskCfg.Type, SubPredictions = unitsAllSubResults[i], DataValue = DataVector[i] }); } //One Winner groups OneWinnerDataCollection = new Dictionary <string, OneWinnerGroupData>(); foreach (string oneWinnerGroupName in rl.Settings.ReadoutUnitsCfg.OneWinnerGroupCollection.Keys) { //There is One Winner group int winningUnitIndex = rl.DecideOneWinner(oneWinnerGroupName, dataVector, out int[] membersIndexes, out double[] membersWeightedDataVector, out int memberWinningIndex); OneWinnerDataCollection.Add(oneWinnerGroupName, new OneWinnerGroupData() { GroupName = oneWinnerGroupName, WinningReadoutUnitName = rl.Settings.ReadoutUnitsCfg.ReadoutUnitCfgCollection[winningUnitIndex].Name, WinningReadoutUnitIndex = winningUnitIndex, MemberWinningIndex = memberWinningIndex, MemberReadoutUnitIndexes = membersIndexes, MemberProbabilities = membersWeightedDataVector }); } return; }
//Constructors /// <summary> /// Creates an itialized instance. /// </summary> /// <param name="index">An index of this readout unit within the readout layer.</param> /// <param name="readoutUnitCfg">The configuration of the readout unit.</param> /// <param name="taskDefaultsCfg">The tasks defaults configuration.</param> public ReadoutUnit(int index, ReadoutUnitSettings readoutUnitCfg, TaskDefaultsSettings taskDefaultsCfg ) { Index = index; Name = readoutUnitCfg.Name; Task = readoutUnitCfg.TaskCfg.Type; if (readoutUnitCfg.TaskCfg.GetType() == typeof(ForecastTaskSettings)) { _clusterChainCfg = (ITNRNetClusterChainSettings)((ForecastTaskSettings)readoutUnitCfg.TaskCfg).ClusterChainCfg?.DeepClone(); if (_clusterChainCfg == null) { _clusterChainCfg = taskDefaultsCfg.ForecastClusterChainCfg; } } else { _clusterChainCfg = (ITNRNetClusterChainSettings)((ClassificationTaskSettings)readoutUnitCfg.TaskCfg).ClusterChainCfg?.DeepClone(); { if (_clusterChainCfg == null) { _clusterChainCfg = taskDefaultsCfg.ClassificationClusterChainCfg; } } } _clusterChain = null; return; }
/// <summary> /// Resets the readout layer to its initial untrained state. /// </summary> public void Reset() { _predictorFeatureFilterCollection = null; _outputFeatureFilterCollection = null; _predictorsMapper = null; _readoutUnitCollection = new ReadoutUnit[ReadoutLayerCfg.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count]; for (int i = 0; i < ReadoutLayerCfg.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count; i++) { ReadoutUnitSettings cfg = ReadoutLayerCfg.ReadoutUnitsCfg.ReadoutUnitCfgCollection[i]; _readoutUnitCollection[i] = new ReadoutUnit(i, cfg, ReadoutLayerCfg.TaskDefaultsCfg); } _oneTakesAllGroupCollection = null; if (ReadoutLayerCfg.OneTakesAllGroupsCfg != null) { _oneTakesAllGroupCollection = new OneTakesAllGroup[ReadoutLayerCfg.OneTakesAllGroupsCfg.OneTakesAllGroupCfgCollection.Count]; for (int i = 0; i < ReadoutLayerCfg.OneTakesAllGroupsCfg.OneTakesAllGroupCfgCollection.Count; i++) { OneTakesAllGroupSettings cfg = ReadoutLayerCfg.OneTakesAllGroupsCfg.OneTakesAllGroupCfgCollection[i]; _oneTakesAllGroupCollection[i] = new OneTakesAllGroup(i, cfg, ReadoutLayerCfg.GetOneTakesAllGroupMemberRUnitIndexes(cfg.Name)); } } Trained = false; ResetProgressTracking(); return; }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) { return(false); } ReadoutUnitSettings cmpSettings = obj as ReadoutUnitSettings; if (Name != cmpSettings.Name || TaskType != cmpSettings.TaskType || NetType != cmpSettings.NetType || !Equals(NetSettings, cmpSettings.NetSettings) || !Equals(OutputRange, cmpSettings.OutputRange) ) { return(false); } return(true); }
/// <summary> /// Copy constructor /// </summary> /// <param name="source">Source instance</param> public ReadoutUnitSettings(ReadoutUnitSettings source) { Name = source.Name; TaskType = source.TaskType; NetType = source.NetType; NetSettings = null; OutputRange = null; if (source.NetSettings != null) { if (source.NetSettings.GetType() == typeof(FeedForwardNetworkSettings)) { NetSettings = ((FeedForwardNetworkSettings)(source.NetSettings)).DeepClone(); } else { NetSettings = ((ParallelPerceptronSettings)(source.NetSettings)).DeepClone(); } OutputRange = source.OutputRange.DeepClone(); } return; }
/// <summary> /// The copy constructor. /// </summary> /// <param name="source">The source instance.</param> public ReadoutUnitSettings(ReadoutUnitSettings source) : this(source.Name, source.TaskCfg) { return; }