(威尼斯人娱乐城) python运行报错 RuntimeWarning: invalid value in double_scalars
威尼斯人娱乐城
威尼斯人娱乐城
当前位置 : 威尼斯人娱乐城 > 威尼斯人娱乐城

(威尼斯人娱乐城) python运行报错 RuntimeWarning: invalid value in double_scalars

我就搞不懂了,为什么运行老是会报类似于RuntimeWarning: overflow encountered in multiply的这种错误,这个应该不是代码逻辑的问题吧
部分代码如下:

 #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @File    : TrustMF.py
    
    from baseclass.SocialRecommender import SocialRecommender
    import numpy as np
    from tool import config
    
    
    class TrustMFSocialRecommender:

    def __init__self, conf,trainingSet=None,testSet=None,relation=list,fold=[1]:
        superTrustMF, self.__init__conf,trainingSet,testSet,relation,fold

    def initModelself:
        superTrustMF, self.initModel
        self.Br = np.random.randself.dao.trainingSize[0], self.k  # latent user matrix
        self.Wr = np.random.randself.dao.trainingSize[0], self.k  # latent item matrix
        self.Vr = np.random.randself.dao.trainingSize[1], self.k  # latent item matrix
        self.Be = np.random.randself.dao.trainingSize[0], self.k  # latent user matrix
        self.We = np.random.randself.dao.trainingSize[0], self.k  # latent item matrix
        self.Ve = np.random.randself.dao.trainingSize[1], self.k  # latent item matrix

    def readConfigurationself:
        superTrustMF, self.readConfiguration
        regular = config.LineConfigself.config[reg.lambda]
        self.regB = floatregular[-b]
        self.regT = floatregular[-t]

    def printAlgorConfigself:
        superTrustMF,self.printAlgorConfig
        print Regularization parameter:  regT %.3f % self.regT
        print = * 80

    def buildModelself:
        # If necessary, you can fix the parameter in ./config/Trust.conf
        iteration = 0
        while iteration < self.maxIter:
            self.loss = 0
            self.trusterModel
            self.trusteeModel
            iteration += 1
            self.isConvergediteration

    def trusterModelself:
        for entry in self.dao.trainingData:
            u, i, r = entry
            mbu = lenself.sao.getFolloweesu
            uid = self.dao.getUserIdu
            iid = self.dao.getItemIdi
            error = self.truserPredictu, i - r
            nbu = lenself.dao.userRatedu[0]
            nvi = lenself.dao.itemRatedi[0]
            self.loss += error**2 + self.regB * mbu + nbu * self.Br[uid].dotself.Br[uid] + nvi * self.Vr[iid].dotself.Vr[iid]
            self.Vr[iid] = self.Vr[iid] - self.lRate * error * self.Br[uid] + self.regB * nvi * self.Vr[iid]

            relations = self.sao.getFolloweesu
            if lenrelations!=0:
                for followee in relations.iterkeys:
                    weight = relations[followee]
                    uf = self.dao.getUserIdfollowee
                    if uf != -1 and self.dao.containsUserfollowee:  # followee is in rating set
                        error1 = self.Br[uid].dotself.Wr[uf] - weight
                        mwk = lenself.sao.getFollowersfollowee
                        self.loss += self.regT * error1**2 + self.regB * mwk * self.Wr[uf].dotself.Wr[uf]
                        self.Br[uid] = self.Br[uid] - self.lRate * error * self.Vr[iid] + self.regB * mbu + nbu * self.Br[uid] + self.regT * self.Br[uid].dotself.Wr[uf] - weight * self.Wr[uf]
                        self.Wr[uf] = self.Wr[uf] - self.lRate * self.regT * error1 * self.Br[uid] + self.regB * mwk * self.Wr[uf]

    def trusteeModelself:
        for entry in self.dao.trainingData:
            u, i, r = entry
            mwu = lenself.sao.getFollowersu
            uid = self.dao.getUserIdu
            iid = self.dao.getItemIdi
            error = self.truseePredictu, i - r
            nwu = lenself.dao.userRatedu[0]
            nvi = lenself.dao.itemRatedi[0]
            self.loss += error**2 + self.regB * mwu + nwu * self.We[uid].dotself.We[uid] + nvi * self.Ve[iid].dotself.Ve[iid]
            self.Ve[iid] = self.Ve[iid] - self.lRate * error * self.We[uid] + self.regB * nvi * self.Ve[iid]

            relations = self.sao.getFollowersu
            if lenrelations != 0:
                for follower in relations.iterkeys:
                    weight = relations[follower]
                    uf = self.dao.getUserIdfollower
                    if uf != -1 and self.dao.containsUserfollower:  # follower is in rating set
                        error1 = self.Be[uf].dotself.We[uid] - weight
                        mbk = lenself.sao.getFolloweesfollower
                        self.loss += self.regT * error1**2 + self.regB * mbk * self.Be[uf].dotself.Be[uf]
                        self.We[uid] = self.We[uid] - self.lRate * error * self.Vr[iid] + self.regB * mwu + nwu * self.We[uid] + self.regT * error1 * self.Be[uf]
                        self.Be[uf] = self.Be[uf] - self.lRate * self.regT * error1 * self.We[uid] + self.regB * mbk * self.Be[uf]

    def truserPredictself, u, i:
        if self.dao.containsUseru and self.dao.containsItemi:
            u = self.dao.getUserIdu
            i = self.dao.getItemIdi
            return self.Br[u].dotself.Vr[i]
        else:
            return self.dao.globalMean

    def truseePredictself, u, i:
        if self.dao.containsUseru and self.dao.containsItemi:
            u = self.dao.getUserIdu
            i = self.dao.getItemIdi
            return self.We[u].dotself.Ve[i]
        else:
            return self.dao.globalMean

    def predictself, u, i:
        if self.dao.containsUseru and self.dao.containsItemi:
            u = self.dao.getUserIdu
            i = self.dao.getItemIdi
            return self.Br[u] + self.We[u].dotself.Vr[i] + self.Ve[i] * 0.25
        else:
            return self.dao.globalMean

我就写了个trustMF方法,用到梯度下降法,就给我报一大堆runtimeerror,我真的不知道到底哪里出错了
报错如下:

C:\Users\123\Documents\GitHub\RecQ\algorithm\rating\TrustMF.py:65: RuntimeWarning: overflow encountered in multiply
  self.Br[uid] = self.Br[uid] - self.lRate * error * self.Vr[iid] + self.regB * mbu + nbu * self.Br[uid] + self.regT * self.Br[uid].dotself.Wr[uf] - weight * self.Wr[uf]
C:\Users\123\Documents\GitHub\RecQ\algorithm\rating\TrustMF.py:65: RuntimeWarning: invalid value encountered in add
  self.Br[uid] = self.Br[uid] - self.lRate * error * self.Vr[iid] + self.regB * mbu + nbu * self.Br[uid] + self.regT * self.Br[uid].dotself.Wr[uf] - weight * self.Wr[uf]
C:\Users\123\Documents\GitHub\RecQ\algorithm\rating\TrustMF.py:64: RuntimeWarning: invalid value encountered in double_scalars
  self.loss += self.regT * error1**2 + self.regB * mwk * self.Wr[uf].dotself.Wr[uf]
C:\Users\123\Documents\GitHub\RecQ\algorithm\rating\TrustMF.py:54: RuntimeWarning: invalid value encountered in double_scalars
  self.loss += error**2 + self.regB * mbu + nbu * self.Br[uid].dotself.Br[uid] + nvi * self.Vr[iid].dotself.Vr[iid]

求解,在线等

栏目列表

广告位

威尼斯人娱乐城