代码之家  ›  专栏  ›  技术社区  ›  Harshit

在C++ 11中调用“AdvestAtNETHyFug”没有匹配函数

  •  1
  • Harshit  · 技术社区  · 8 年前

    我正在做一个深度学习项目,我写了一些测试来评估神经网络中的净权重。代码是这样的 evaluate_net_weight

    /*! Compute the loss of the net as a function of the weight at index (i,j) in
     *  layer l. dx is added as an offset to the current value of the weight. */
    //______________________________________________________________________________
    template <typename Architecture>
    auto evaluate_net_weight(TDeepNet<Architecture> &net, std::vector<typename Architecture::Matrix_t> & X,
                             const typename Architecture::Matrix_t &Y, const typename Architecture::Matrix_t &W, size_t l,
                             size_t k, size_t i, size_t j, typename Architecture::Scalar_t xvalue) ->
       typename Architecture::Scalar_t
    {
        using Scalar_t = typename Architecture::Scalar_t;
    
        Scalar_t prev_value = net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j);
        net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j) = xvalue;
        Scalar_t res = net.Loss(X, Y, W, false, false);
        net.GetLayerAt(l)->GetWeightsAt(k).operator()(i,j) = prev_value;
        //std::cout << "compute loss for weight  " << xvalue << "  " << prev_value << " result " << res << std::endl;
        return res;
    }
    

    函数的调用方式如下:

    // Testing input gate: input weights k = 0
        auto &Wi = layer->GetWeightsAt(0);
        auto &dWi = layer->GetWeightGradientsAt(0);
        for (size_t i = 0; i < (size_t) Wi.GetNrows(); ++i) {
            for (size_t j = 0; j < (size_t) Wi.GetNcols(); ++j) {
                auto f = [&lstm, &XArch, &Y, &weights, i, j](Scalar_t x) {
                    return evaluate_net_weight(lstm, XArch, Y, weights, 0, 0, i, j, x);
                };
                ROOT::Math::Functor1D func(f);
                double dy = deriv.Derivative1(func, Wi(i,j), 1.E-5);
                Double_t dy_ref = dWi(i,j);
    
                // Compute relative error if dy != 0
                Double_t error;
                std::string errorType;
                if (std::fabs(dy_ref) > 1e-15) {
                    error = std::fabs((dy - dy_ref) / dy_ref);
                    errorType = "relative";
                } else {
                    error = std::fabs(dy - dy_ref);
                    errorType = "absolute";
                }
    
                if (debug) std::cout << "Input Gate: input weight gradients (" << i << "," << j << ") : (comp, ref) " << dy << ", " << dy_ref << std::endl;
    
                if (error >= maximum_error) {
                    maximum_error = error;
                    maxErrorType = errorType;
                }
            }
        }
    

    XArch 是我的意见, Y lstm 指网络类型。这些都已经定义好了。

    当我尝试使用cmake构建程序时,通常会出现以下错误:

    /Users/harshitprasad/Desktop/gsoc-rnn/root/tmva/tmva/test/DNN/RNN/TestLSTMBackpropagation.h:385:24: error: 
          no matching function for call to 'evaluate_net_weight'
                    return evaluate_net_weight(lstm, XArch, Y, weights, 0, 2, i, j, x);
                           ^~~~~~~~~~~~~~~~~~~
    /Users/harshitprasad/Desktop/gsoc-rnn/root/tmva/tmva/test/DNN/RNN/TestLSTMBackpropagation.h:67:6: note: 
          candidate function [with Architecture = TMVA::DNN::TReference<double>] not viable: no known
          conversion from 'Scalar_t' (aka 'TMatrixT<double>') to 'typename TReference<double>::Scalar_t'
          (aka 'double') for 9th argument
    auto evaluate_net_weight(TDeepNet<Architecture> &net, std::vector<typename Architecture::Matr...
    

    我不明白为什么会发生这个错误?如果有人能帮我解决这个问题那就太好了。谢谢!

    1 回复  |  直到 8 年前
        1
  •  0
  •   gsamaras a Data Head    8 年前

    您可能对自定义类型有不同且相互冲突的定义 Scalar_t ,在不同的范围内。

    从错误消息中,我们可以看到函数需要 typename TReference<double>::Scalar_t double ),但实际上传递了类型为的参数 标量 (可能是在全局范围的某个地方定义的),相当于 TMatrixT<double> ,这导致了错误,正如一些程序员所说。