Giter Club home page Giter Club logo

Comments (4)

Coder-Yu avatar Coder-Yu commented on May 26, 2024

你好,因为算法库由多人维护,所以难免出现纰漏,我们会尽快修复bug. LOCABAL当时那一版写的有问题,后来便直接删除了。有时间会不断添加新算法的。感兴趣也可以关注另一个库Yue,里面也包含了不少Item Ranking的方法。

from qrec.

flyxu avatar flyxu commented on May 26, 2024

你好,SoReg.py 里的代码除了我说的少了一项外,还有一个问题是第60行for user in self.dao.user:应该删掉。不需要在这儿写一个循环。
此外,我看到您在ratings文件夹下的所有算法的loss计算方式都是一边读数据一边累加loss,然后最后再加上正则项的loss.我认为这样是有问题的,因为你累加的loss是在P,Q更新之间的loss,但最后加的正则项的loss是P,Q更新后的loss,这两个loss能否直接相加?我认为应该在P,Q更新后再累加loss,然后最后加上更新后的正则项loss.我觉的是这样,不知道对不对。

from qrec.

flyxu avatar flyxu commented on May 26, 2024

这是重写的SoReg.py。您看看对不对吧

# encoding:utf-8
from baseclass.SocialRecommender import SocialRecommender
from tool import config
from tool import qmath


class SoReg_D(SocialRecommender):
    def __init__(self,conf,trainingSet=None,testSet=None,relation=list(),fold='[1]'):
        super(SoReg_D, self).__init__(conf,trainingSet,testSet,relation,fold)

    def readConfiguration(self):
        super(SoReg_D, self).readConfiguration()
        alpha = config.LineConfig(self.config['SoReg'])
        self.alpha = float(alpha['-alpha'])

    def printAlgorConfig(self):
        super(SoReg_D, self).printAlgorConfig()
        print 'Specified Arguments of',self.config['recommender']+':'
        print 'alpha: %.3f' %self.alpha
        print '='*80

    def initModel(self):
        super(SoReg_D, self).initModel()
        # compute similarity
        from collections import defaultdict
        self.Sim = defaultdict(dict)
        print 'constructing similarity matrix...'

        for user in self.dao.user:
            for f in self.sao.getFollowees(user):
                if self.Sim.has_key(user) and self.Sim[user].has_key(f):
                    pass
                else:
                    self.Sim[user][f]=self.sim(user,f)
                    self.Sim[f][user]=self.Sim[user][f]


    def sim(self,u,v):
        return (qmath.pearson_sp(self.dao.sRow(u), self.dao.sRow(v))+self.sao.weight(u,v))/2.0

    def buildModel(self):
        iteration = 0
        while iteration < self.maxIter:
            self.loss = 0
            for entry in self.dao.trainingData:
                user, item, rating = entry
                uid = self.dao.user[user]
                vid = self.dao.item[item]

                # add the followees' influence

                error = rating - self.P[uid].dot(self.Q[vid])
                p = self.P[uid]
                q = self.Q[vid]

                #self.loss += error**2

                #update latent vectors
                self.P[uid] += self.lRate*(error*q - self.regU * p)
                self.Q[vid] += self.lRate*(error*p - self.regI * q)


                simSumf1 = 0
                #simloss = 0
                uid = self.dao.user[user]
                for f in self.sao.getFollowees(user):
                    if self.dao.containsUser(f):
                        fid = self.dao.user[f]
                        simSumf1 += self.Sim[user][f] * (self.P[uid] - self.P[fid])
                        #simloss += self.Sim[user][f] * ((self.P[uid] - self.P[fid]).dot(self.P[uid] - self.P[fid]))
                        #self.loss += simloss

                #缺失的第二项
                simSumf2 = 0
                for g in self.sao.getFollowers(user):
                    if self.dao.containsUser(g):
                        gid=self.dao.user[g]
                        simSumf2 += self.Sim[g][user] * (self.P[uid]-self.P[gid])

                self.P[uid] += self.lRate * (- self.alpha * (simSumf1+simSumf2))

                #P,Q更新后再计算loss
                e=rating - self.P[uid].dot(self.Q[vid])
                self.loss += e**2
                simloss=0
                uid = self.dao.user[user]
                for f in self.sao.getFollowees(user):
                    if self.dao.containsUser(f):
                        fid = self.dao.user[f]
                        simloss += self.Sim[user][f] * ((self.P[uid] - self.P[fid]).dot(self.P[uid] - self.P[fid]))
                        self.loss += simloss

            self.loss += self.regU*(self.P*self.P).sum() + self.regI*(self.Q*self.Q).sum()
            iteration += 1
            if self.isConverged(iteration):
                break

from qrec.

Coder-Yu avatar Coder-Yu commented on May 26, 2024

非常感谢您的细心,loss的那个地方我觉得都是可行的。至于SoReg, 是一个不太会写代码的同学贡献的,后来我也没有认真检查这个算法,只是大概看了下改了改。谢谢您的更新,如果方便的话,您可以直接在源文件上修改,然后pull request,我会把您加到contributor里面的。这个库整体的代码还有一些问题,后面有时间会整体重构一下的。后来在这个基础上改的音乐推荐的库Yue的代码质量有所提高,有兴趣可以关注。再次感谢

from qrec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.