/// <summary> /// Creates the instance and initializes it from given xml element. /// This is the preferred way to instantiate ReadoutLayer settings. /// </summary> /// <param name="elem"> /// Xml data containing ReadoutLayer settings. /// Content of xml element is always validated against the xml schema. /// </param> public ReadoutLayerSettings(XElement elem) { //Validation ElemValidator validator = new ElemValidator(); Assembly assemblyRCNet = Assembly.GetExecutingAssembly(); validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.ReadoutLayerSettings.xsd"); validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd"); XElement readoutLayerSettingsElem = validator.Validate(elem, "rootElem"); //Parsing TestDataRatio = double.Parse(readoutLayerSettingsElem.Attribute("testDataRatio").Value, CultureInfo.InvariantCulture); NumOfFolds = readoutLayerSettingsElem.Attribute("folds").Value == "Auto" ? 0 : int.Parse(readoutLayerSettingsElem.Attribute("folds").Value); //Readout unit XElement readoutUnitElem = readoutLayerSettingsElem.Descendants("readoutUnit").First(); ReadoutUnitCfg = new ReadoutUnitSettings(readoutUnitElem); //Output fields XElement outputFieldsElem = readoutLayerSettingsElem.Descendants("outputFields").First(); OutputFieldNameCollection = new List <string>(); foreach (XElement outputFieldElem in outputFieldsElem.Descendants("field")) { OutputFieldNameCollection.Add(outputFieldElem.Attribute("name").Value); } return; }
/// <summary> /// Creates the readout layer configuration. /// </summary> /// <param name="foldDataRatio">Specifies what part of available data to be used as the fold data.</param> /// <param name="numOfAttempts">Number of regression attempts. Each readout network will try to learn numOfAttempts times.</param> /// <param name="numOfEpochs">Number of training epochs within an attempt.</param> ReadoutLayerSettings CreateReadoutLayerCfg(double foldDataRatio, int numOfAttempts, int numOfEpochs) { //For each output field we will use prediction of two networks //First network having only Identity output neuron and associated the resilient back propagation trainer FeedForwardNetworkSettings ffNet1Cfg = new FeedForwardNetworkSettings(new AFAnalogIdentitySettings(), null, new RPropTrainerSettings(numOfAttempts, numOfEpochs) ); //Second network having Identity output neuron, hidden layer consisting of 5 LeakyReLU neurons //and associated the resilient back propagation trainer HiddenLayerSettings hiddenLayerCfg = new HiddenLayerSettings(5, new AFAnalogLeakyReLUSettings()); FeedForwardNetworkSettings ffNet2Cfg = new FeedForwardNetworkSettings(new AFAnalogIdentitySettings(), new HiddenLayersSettings(hiddenLayerCfg), new RPropTrainerSettings(numOfAttempts, numOfEpochs) ); //Create the cluster chain configuration for the forecast and the default configuration for the forecast task. CrossvalidationSettings crossvalidationCfg = new CrossvalidationSettings(foldDataRatio); TNRNetClusterRealNetworksSettings networksCfg = new TNRNetClusterRealNetworksSettings(ffNet1Cfg, ffNet2Cfg); TNRNetClusterRealSettings realClusterCfg = new TNRNetClusterRealSettings(networksCfg, new TNRNetClusterRealWeightsSettings()); TNRNetClusterChainRealSettings realClusterChainCfg = new TNRNetClusterChainRealSettings(crossvalidationCfg, new TNRNetClustersRealSettings(realClusterCfg)); TaskDefaultsSettings taskDefaultsCfg = new TaskDefaultsSettings(null, realClusterChainCfg); //Create readout unit configurations. We will forecast next High and Low prices. ReadoutUnitSettings highReadoutUnitCfg = new ReadoutUnitSettings("High", new ForecastTaskSettings()); ReadoutUnitSettings lowReadoutUnitCfg = new ReadoutUnitSettings("Low", new ForecastTaskSettings()); //Create readout layer configuration ReadoutLayerSettings readoutLayerCfg = new ReadoutLayerSettings(taskDefaultsCfg, new ReadoutUnitsSettings(highReadoutUnitCfg, lowReadoutUnitCfg ), null ); return(readoutLayerCfg); }
/// <summary> /// Creates readout layer configuration /// </summary> /// <param name="testDataRatio">Specifies what part of available data to be used as test data</param> /// <param name="numOfAttempts">Number of regression attempts. Each readout network will try to learn numOfAttempts times</param> /// <param name="numOfEpochs">Number of training epochs within an attempt</param> ReadoutLayerSettings CreateReadoutLayerCfg(double testDataRatio, int numOfAttempts, int numOfEpochs) { //For each output field we will use prediction of two networks //First network having only Identity output neuron and associated the resilient back propagation trainer FeedForwardNetworkSettings ffNet1Cfg = new FeedForwardNetworkSettings(new IdentitySettings(), null, new RPropTrainerSettings(numOfAttempts, numOfEpochs) ); //Second network having Identity output neuron, hidden layer consisting of 5 LeakyReLU neurons //and associated the resilient back propagation trainer HiddenLayerSettings hiddenLayerCfg = new HiddenLayerSettings(5, new LeakyReLUSettings()); FeedForwardNetworkSettings ffNet2Cfg = new FeedForwardNetworkSettings(new IdentitySettings(), new HiddenLayersSettings(hiddenLayerCfg), new RPropTrainerSettings(numOfAttempts, numOfEpochs) ); //Create default networks configuration for forecasting DefaultNetworksSettings defaultNetworksCfg = new DefaultNetworksSettings(null, new ForecastNetworksSettings(ffNet1Cfg, ffNet2Cfg)); //Create readout units. We will forecast next High and Low prices. Both fields are real numbers. ReadoutUnitSettings highReadoutUnitCfg = new ReadoutUnitSettings("High", new ForecastTaskSettings(new RealFeatureFilterSettings())); ReadoutUnitSettings lowReadoutUnitCfg = new ReadoutUnitSettings("Low", new ForecastTaskSettings(new RealFeatureFilterSettings())); //Create readout layer configuration ReadoutLayerSettings readoutLayerCfg = new ReadoutLayerSettings(new ReadoutUnitsSettings(highReadoutUnitCfg, lowReadoutUnitCfg ), testDataRatio, ReadoutLayerSettings.AutoFolds, ReadoutLayerSettings.DefaultRepetitions, defaultNetworksCfg ); return(readoutLayerCfg); }
//Constructors /// <summary> /// Creates an uninitialized instance. /// </summary> public ReadoutLayerSettings() { //Default settings TestDataRatio = 0; NumOfFolds = 0; ReadoutUnitCfg = new ReadoutUnitSettings(); OutputFieldNameCollection = new List <string>(); return; }
//Constructors /// <summary> /// Creates an uninitialized instance. /// </summary> /// <param name="unitCfg">The configuration of the readout unit.</param> /// <param name="unitIndex">An index of the readout unit within the readout layer.</param> /// <param name="memberIndex">An index within the "One Takes All" group.</param> public MemberErrorStat(ReadoutUnitSettings unitCfg, int unitIndex, int memberIndex) { UnitCfg = (ReadoutUnitSettings)unitCfg.DeepClone(); UnitIndex = unitIndex; MemberIndex = memberIndex; ErrStat = new BasicStat(); NumOfCorrectButBellowBorderSelections = 0; NumOfOverbeatedAboveBorderRawProbabilities = 0; return; }
//Constructor /// <summary> /// Creates an unitialized instance /// </summary> /// <param name="index">The zero-based index of the readout unit.</param> /// <param name="readoutUnitCfg">The configuration of the readout unit.</param> public ReadoutUnitErrorStat(int index, ReadoutUnitSettings readoutUnitCfg) { Name = readoutUnitCfg.Name; Index = index; Task = readoutUnitCfg.TaskCfg.Type; ErrorStat = new BasicStat(); if (Task == ReadoutUnit.TaskType.Classification) { BinErrorStat = new BinErrStat(0.5d); } return; }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) { return(false); } ReadoutUnitSettings cmpSettings = obj as ReadoutUnitSettings; if (NetType != cmpSettings.NetType || !Equals(NetSettings, cmpSettings.NetSettings) || RegressionAttempts != cmpSettings.RegressionAttempts || RegressionAttemptEpochs != cmpSettings.RegressionAttemptEpochs ) { return(false); } return(true); }
/// <summary> /// Copy constructor /// </summary> /// <param name="source">Source instance</param> public ReadoutUnitSettings(ReadoutUnitSettings source) { NetType = source.NetType; NetSettings = null; if (source.NetSettings != null) { if (source.NetSettings.GetType() == typeof(FeedForwardNetworkSettings)) { NetSettings = ((FeedForwardNetworkSettings)source.NetSettings).DeepClone(); } else { NetSettings = ((ParallelPerceptronSettings)source.NetSettings).DeepClone(); } } RegressionAttempts = source.RegressionAttempts; RegressionAttemptEpochs = source.RegressionAttemptEpochs; return; }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (MapperCfg != null && NeuralPreprocessorCfg == null) { throw new ArgumentException($"Mapper can not be specified when neural preprocessor is not defined.", "MapperCfg"); } if (MapperCfg != null) { foreach (ReadoutUnitMapSettings map in MapperCfg.MapCfgCollection) { ReadoutUnitSettings rus = ReadoutLayerCfg.ReadoutUnitsCfg.GetReadoutunitCfg(map.ReadoutUnitName); //Pools if (map.AllowedPoolsCfg != null) { foreach (AllowedPoolSettings aps in map.AllowedPoolsCfg.AllowedPoolCfgCollection) { ReservoirInstanceSettings ris = NeuralPreprocessorCfg.ReservoirInstancesCfg.GetReservoirInstanceCfg(aps.ReservoirInstanceName); ReservoirStructureSettings rss = NeuralPreprocessorCfg.ReservoirStructuresCfg.GetReservoirStructureCfg(ris.StructureCfgName); rss.PoolsCfg.GetPoolID(aps.PoolName); } } //Input fields if (map.AllowedInputFieldsCfg != null) { string[] routedFieldNames = NeuralPreprocessorCfg.InputEncoderCfg.GetRoutedFieldNames().ToArray(); foreach (AllowedInputFieldSettings aifs in map.AllowedInputFieldsCfg.AllowedInputFieldCfgCollection) { if (Array.IndexOf(routedFieldNames, aifs.Name) == -1) { throw new ArgumentException($"Specified input field {aifs.Name} to be allowed for readout unit {map.ReadoutUnitName} is not among fields routed to readout layer.", "MapperCfg"); } } } } } return; }