RNN<LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::RNN(LayerType &&network, OutputType &&outputLayer, const arma::mat& predictors, const arma::mat& responses, InitializationRuleType initializeRule, PerformanceFunction performanceFunction) : network(std::forward<LayerType>(network)), outputLayer(std::forward<OutputType>(outputLayer)), performanceFunc(std::move(performanceFunction)), inputSize(0), outputSize(0) { static_assert(std::is_same<typename std::decay<LayerType>::type, LayerTypes>::value, "The type of network must be LayerTypes."); static_assert(std::is_same<typename std::decay<OutputType>::type, OutputLayerType>::value, "The type of outputLayer must be OutputLayerType."); initializeRule.Initialize(parameter, NetworkSize(this->network), 1); NetworkWeights(parameter, this->network); Train(predictors, responses); }
FFN<LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::FFN(LayerType &&network, OutputType &&outputLayer, const arma::mat& predictors, const arma::mat& responses, OptimizerType<NetworkType>& optimizer, InitializationRuleType initializeRule, PerformanceFunction performanceFunction) : network(std::forward<LayerType>(network)), outputLayer(std::forward<OutputType>(outputLayer)), performanceFunc(std::move(performanceFunction)), predictors(predictors), responses(responses), numFunctions(predictors.n_cols) { static_assert(std::is_same<typename std::decay<LayerType>::type, LayerTypes>::value, "The type of network must be LayerTypes."); static_assert(std::is_same<typename std::decay<OutputType>::type, OutputLayerType>::value, "The type of outputLayer must be OutputLayerType."); initializeRule.Initialize(parameter, NetworkSize(this->network), 1); NetworkWeights(parameter, this->network); // Train the model. Timer::Start("ffn_optimization"); const double out = optimizer.Optimize(parameter); Timer::Stop("ffn_optimization"); Log::Info << "FFN::FFN(): final objective of trained model is " << out << "." << std::endl; }
typename std::enable_if< HasWeightsCheck<T, arma::mat&(T::*)()>::value, size_t>::type LayerWeights(InitializationRuleType& initializeRule, T& layer, arma::mat& weights, size_t offset, arma::mat& /* output */) { layer.Weights() = arma::mat(weights.memptr() + offset, layer.Weights().n_rows, layer.Weights().n_cols, false, false); initializeRule.Initialize(layer.Weights(), layer.Weights().n_rows, layer.Weights().n_cols); return layer.Weights().n_elem; }
FFN<LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction >::FFN(LayerType &&network, OutputType &&outputLayer, InitializationRuleType initializeRule, PerformanceFunction performanceFunction) : network(std::forward<LayerType>(network)), outputLayer(std::forward<OutputType>(outputLayer)), performanceFunc(std::move(performanceFunction)) { static_assert(std::is_same<typename std::decay<LayerType>::type, LayerTypes>::value, "The type of network must be LayerTypes."); static_assert(std::is_same<typename std::decay<OutputType>::type, OutputLayerType>::value, "The type of outputLayer must be OutputLayerType."); initializeRule.Initialize(parameter, NetworkSize(this->network), 1); NetworkWeights(parameter, this->network); }