//Methods /// <summary> /// Adds the cluster into the chain. /// </summary> /// <param name="cluster">The cluster to be added into the chain.</param> public void AddCluster(TNRNetCluster cluster) { _clusterCollection.Add(cluster); return; }
/// <summary> /// Builds the cluster. /// </summary> /// <param name="dataBundle">The data bundle for training.</param> /// <param name="filters">The filters to be used to denormalize outputs.</param> public TNRNetCluster Build(VectorBundle dataBundle, FeatureFilterBase[] filters) { VectorBundle localDataBundle = dataBundle.CreateShallowCopy(); //Cluster of trained networks TNRNetCluster cluster = new TNRNetCluster(_clusterName, _clusterCfg.Output, _clusterCfg.TrainingGroupWeight, _clusterCfg.TestingGroupWeight, _clusterCfg.SamplesWeight, _clusterCfg.NumericalPrecisionWeight, _clusterCfg.MisrecognizedFalseWeight, _clusterCfg.UnrecognizedTrueWeight ); //Member's training ResetProgressTracking(); for (_repetitionIdx = 0; _repetitionIdx < _crossvalidationCfg.Repetitions; _repetitionIdx++) { //Data split to folds List <VectorBundle> foldCollection = localDataBundle.Folderize(_crossvalidationCfg.FoldDataRatio, _clusterCfg.Output == TNRNet.OutputType.Real ? double.NaN : cluster.OutputDataRange.Mid); _numOfFoldsPerRepetition = Math.Min(_crossvalidationCfg.Folds <= 0 ? foldCollection.Count : _crossvalidationCfg.Folds, foldCollection.Count); //Train the collection of networks for each processing fold. for (_testingFoldIdx = 0; _testingFoldIdx < _numOfFoldsPerRepetition; _testingFoldIdx++) { //Prepare training data bundle VectorBundle trainingData = new VectorBundle(); for (int foldIdx = 0; foldIdx < foldCollection.Count; foldIdx++) { if (foldIdx != _testingFoldIdx) { trainingData.Add(foldCollection[foldIdx]); } } for (_netCfgIdx = 0; _netCfgIdx < _clusterCfg.ClusterNetConfigurations.Count; _netCfgIdx++) { TNRNetBuilder netBuilder = new TNRNetBuilder(_clusterName, _clusterCfg.ClusterNetConfigurations[_netCfgIdx], _clusterCfg.Output, trainingData, foldCollection[_testingFoldIdx], _rand, _controller ); //Register notification netBuilder.NetworkBuildProgressChanged += OnNetworkBuildProgressChanged; //Build trained network. Trained network becomes to be the cluster member TNRNet tn = netBuilder.Build(); //Build an unique network scope identifier int netScopeID = _repetitionIdx * NetScopeDelimiterCoeff + _testingFoldIdx; //Add trained network to a cluster cluster.AddMember(tn, netScopeID, foldCollection[_testingFoldIdx], filters); } //netCfgIdx } //testingFoldIdx if (_repetitionIdx < _crossvalidationCfg.Repetitions - 1) { //Reshuffle the data localDataBundle.Shuffle(_rand); } }//repetitionIdx //Make the cluster operable cluster.FinalizeCluster(); //Return the built cluster return(cluster); }