[{"data":1,"prerenderedAt":973},["ShallowReactive",2],{"content-query-wLWAAjRiGu":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":967,"_id":968,"_source":969,"_file":970,"_stem":971,"_extension":972},"/technology-blogs/zh/379","zh",false,"","MindSpore 首发：隐私保护的 Bandit 算法，实现电影推荐","本文将先简单介绍 Bandit 问题和本地差分隐私的相关背景，然后介绍基于本地差分隐私的 Bandit 算法，最后通过一个简单的电影推荐场景来验证 LDP LinUCB 算法。","2021-01-20","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/20/8f9eac6817ce4d80b2b1cc015b2460ea.png","technology-blogs",{"type":14,"children":15,"toc":962},"root",[16,24,34,61,65,72,77,82,90,143,151,239,246,251,258,316,349,373,392,421,428,438,479,486,491,523,534,541,555,563,597,607,622,629,639,646,651,661,672,680,685,696,704,709,717,724,729,744,751,762,785,796,812,819,835,840,849,854,861,874,879,887,892,897,905,912,920,950,955],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"mindspore-首发隐私保护的-bandit-算法实现电影推荐",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":17,"tag":29,"props":30,"children":33},"img",{"alt":31,"src":32},"image.png","https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/19/184439g6gl9sotairrlkdy.png",[],{"type":17,"tag":25,"props":35,"children":36},{},[37,39,45,47,52,54,59],{"type":23,"value":38},"老虎机（Bandit）问题是强化学习中一类重要的问题，由于它定义简洁且有大量的理论分析，因此被广泛应用于新闻推荐，医学试验等实际场景中。随着人类进入大数据时代，用户对自身数据的隐私性日益重视，这对机器学习算法的设计提出了新的挑战。",{"type":17,"tag":40,"props":41,"children":42},"strong",{},[43],{"type":23,"value":44},"为了在保护隐私的情况下解决 Bandit 这一经典问题",{"type":23,"value":46},"，北京大学和华为诺亚方舟实验室联合提出了",{"type":17,"tag":40,"props":48,"children":49},{},[50],{"type":23,"value":51},"基于本地差分隐私的 Bandit 算法",{"type":23,"value":53},"，论文已被 NeurIPS 2020 录用，",{"type":17,"tag":40,"props":55,"children":56},{},[57],{"type":23,"value":58},"代码已基于 MindSpore 开源首发",{"type":23,"value":60},"。",{"type":17,"tag":25,"props":62,"children":63},{},[64],{"type":23,"value":9},{"type":17,"tag":25,"props":66,"children":67},{},[68],{"type":17,"tag":29,"props":69,"children":71},{"alt":31,"src":70},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/19/184511aa8ji5uoozh3frsl.png",[],{"type":17,"tag":25,"props":73,"children":74},{},[75],{"type":23,"value":76},"大家都有过这样的经历，在我们刷微博或是读新闻的时候，经常会看到一些系统推荐的内容，这些推荐的内容是根据用户对过往推荐内容的点击情况以及阅读时长等反馈来产生的。在这个过程里，系统事先不知道用户对各种内容的偏好，通过不断地与用户进行交互（推荐内容 — 得到反馈），来慢慢学习到用户的偏好特征，不断提高推荐的精准性，从而最大化用户的价值，这就是一个典型的 Bandit 问题。",{"type":17,"tag":25,"props":78,"children":79},{},[80],{"type":23,"value":81},"Bandit 问题有 context-free 和 contextual 两种常见的设定，下面给出它们具体的数学定义。",{"type":17,"tag":25,"props":83,"children":84},{},[85],{"type":17,"tag":40,"props":86,"children":87},{},[88],{"type":23,"value":89},"【Context-Free Bandit】",{"type":17,"tag":25,"props":91,"children":92},{},[93,95,99,101,105,107,111,113,117,119,123,125,129,131,135,137,141],{"type":23,"value":94},"假设给定一个动作集合",{"type":17,"tag":29,"props":96,"children":98},{"alt":31,"src":97},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/132844iv9uogdzphazcvu8.png",[],{"type":23,"value":100},"，玩家跟环境的交互过程按轮进行。在每一轮",{"type":17,"tag":29,"props":102,"children":104},{"alt":31,"src":103},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1329100dlykky4bbnoufie.png",[],{"type":23,"value":106},"，玩家基于之前所有的观测结果选择一个动作",{"type":17,"tag":29,"props":108,"children":110},{"alt":31,"src":109},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/132926xhrerszb1plcl7n4.png",[],{"type":23,"value":112},"去执行，然后从环境观测到一个损失值",{"type":17,"tag":29,"props":114,"children":116},{"alt":31,"src":115},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1329425gkvlubswokkhsxg.png",[],{"type":23,"value":118},"，如此往复（有些文献中定义成 reward，那么 reward 的负数就对应此处的损失值）。我们定义累积 regret 函数为",{"type":17,"tag":29,"props":120,"children":122},{"alt":31,"src":121},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133009ju6ulo2tyivjmvg2.png",[],{"type":23,"value":124},"，问题目标是设计一个算法使得累积 regret 最小。其中",{"type":17,"tag":29,"props":126,"children":128},{"alt":31,"src":127},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133040j7qnrssz5tvi6sd4.png",[],{"type":23,"value":130},"既可以是 adversarial 也可以是 stochastic（只需让",{"type":17,"tag":29,"props":132,"children":134},{"alt":31,"src":133},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133057lri4xx3uxpn59m3i.png",[],{"type":23,"value":136},"，",{"type":17,"tag":29,"props":138,"children":140},{"alt":31,"src":139},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133111xja5xtogg2eq5mgl.png",[],{"type":23,"value":142},"是独立同分布的零均值噪声）。",{"type":17,"tag":25,"props":144,"children":145},{},[146],{"type":17,"tag":40,"props":147,"children":148},{},[149],{"type":23,"value":150},"【Contextual Bandit】",{"type":17,"tag":25,"props":152,"children":153},{},[154,156,160,162,166,168,172,174,178,180,184,186,190,192,196,198,202,204,208,210,214,216,220,222,226,228,232,233,237],{"type":23,"value":155},"顾名思义，Contextual Bandit 这类算法在做决策时考虑了上下文的信息，因而更加适合实际的个性化推荐场景。形式化地说，在每一轮",{"type":17,"tag":29,"props":157,"children":159},{"alt":31,"src":158},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1331592mm8rgbfqumwzovp.png",[],{"type":23,"value":161},"，系统观测到当前用户",{"type":17,"tag":29,"props":163,"children":165},{"alt":31,"src":164},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133221fmhyqfryg0cuqtg7.png",[],{"type":23,"value":167},"和每一个候选物品的联合特征的集合",{"type":17,"tag":29,"props":169,"children":171},{"alt":31,"src":170},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133240gizenm7mlhbntcee.png",[],{"type":23,"value":173},"（即上下文信息），然后基于之前所有的观测结果选择一个候选物品",{"type":17,"tag":29,"props":175,"children":177},{"alt":31,"src":176},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133301rsnawdas9gw9sx0s.png",[],{"type":23,"value":179},"（由于联合特征",{"type":17,"tag":29,"props":181,"children":183},{"alt":31,"src":182},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133323sjgjkdtftnlkum77.png",[],{"type":23,"value":185},"和候选物品一一对应，故此处用",{"type":17,"tag":29,"props":187,"children":189},{"alt":31,"src":188},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133330u2xnbvp9jybghmnj.png",[],{"type":23,"value":191},"代替）去推荐，并观测到一个奖励值",{"type":17,"tag":29,"props":193,"children":195},{"alt":31,"src":194},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133351vtcsgoa8u7jvqtbu.png",[],{"type":23,"value":197},"。通常，",{"type":17,"tag":29,"props":199,"children":201},{"alt":31,"src":200},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133407t5aiq3ampivzqt9b.png",[],{"type":23,"value":203},"可以建模成",{"type":17,"tag":29,"props":205,"children":207},{"alt":31,"src":206},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133423tfsyytnzmf7nmkwl.png",[],{"type":23,"value":209},"，其中",{"type":17,"tag":29,"props":211,"children":213},{"alt":31,"src":212},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133438asuxp0k6gp4greww.png",[],{"type":23,"value":215},"是待学习的真实参数，",{"type":17,"tag":29,"props":217,"children":219},{"alt":31,"src":218},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133507ks5awwo6cjswgbze.png",[],{"type":23,"value":221},"是零均值噪声，",{"type":17,"tag":29,"props":223,"children":225},{"alt":31,"src":224},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1335250xmmhuqmql5h24sz.png",[],{"type":23,"value":227},"是某个形式已知的函数。同样地，我们可以定义累积 regret 函数为",{"type":17,"tag":29,"props":229,"children":231},{"alt":31,"src":230},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133541uykhnui72gqbflve.png",[],{"type":23,"value":209},{"type":17,"tag":29,"props":234,"children":236},{"alt":31,"src":235},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133605fao3sfp0fxt0im9y.png",[],{"type":23,"value":238},"，问题目标是设计一个算法使得累积 regret 最小。",{"type":17,"tag":25,"props":240,"children":241},{},[242],{"type":17,"tag":29,"props":243,"children":245},{"alt":31,"src":244},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133645k0ygvysibshbkqxc.png",[],{"type":17,"tag":25,"props":247,"children":248},{},[249],{"type":23,"value":250},"传统的差分隐私技术（Differential Privacy，DP）是将用户数据集中到一个可信的数据中心，在数据中心对用户数据进行匿名化使其符合隐私保护的要求后，再分发给下游使用，我们将其称之为中心化差分隐私。但是，一个绝对可信的数据中心很难找到，因此人们提出了本地差分隐私技术（Local Differential Privacy，LDP），它直接在客户端进行数据的隐私化处理后再提交给数据中心，彻底杜绝了数据中心泄露用户隐私的可能。",{"type":17,"tag":25,"props":252,"children":253},{},[254],{"type":17,"tag":29,"props":255,"children":257},{"alt":31,"src":256},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133723wksmuemdm27smdvq.png",[],{"type":17,"tag":25,"props":259,"children":260},{},[261,263,267,269,273,275,279,281,285,287,291,292,296,298,302,304,308,310,314],{"type":23,"value":262},"本地差分隐私的定义：假设",{"type":17,"tag":29,"props":264,"children":266},{"alt":31,"src":265},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133827apcydqt6onkeavp0.png",[],{"type":23,"value":268},"是正实数，算法",{"type":17,"tag":29,"props":270,"children":272},{"alt":31,"src":271},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133844gatrxdff1rlalfsd.png",[],{"type":23,"value":274},"被称为满足",{"type":17,"tag":29,"props":276,"children":278},{"alt":31,"src":277},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133900u8xjlwokvudnfywp.png",[],{"type":23,"value":280},"-LDP，如果对任意两个数据",{"type":17,"tag":29,"props":282,"children":284},{"alt":31,"src":283},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133916hyqbzom9vkta0wyd.png",[],{"type":23,"value":286},"和任意子集",{"type":17,"tag":29,"props":288,"children":290},{"alt":31,"src":289},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133931wxkhw9utulqvp0oc.png",[],{"type":23,"value":136},{"type":17,"tag":29,"props":293,"children":295},{"alt":31,"src":294},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/133948ytxqceitpx8zix7g.png",[],{"type":23,"value":297},"。特别地，如果",{"type":17,"tag":29,"props":299,"children":301},{"alt":31,"src":300},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134007xlao10hzesznp6ws.png",[],{"type":23,"value":303},"满足",{"type":17,"tag":29,"props":305,"children":307},{"alt":31,"src":306},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134021k2l03vtgtxn9rzqq.png",[],{"type":23,"value":309},"-LDP，我们简称为",{"type":17,"tag":29,"props":311,"children":313},{"alt":31,"src":312},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134045c33zcxcjqwrhfseh.png",[],{"type":23,"value":315},"-LDP。",{"type":17,"tag":25,"props":317,"children":318},{},[319,321,325,327,331,333,337,338,342,344,348],{"type":23,"value":320},"可以看到，当",{"type":17,"tag":29,"props":322,"children":324},{"alt":31,"src":323},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134127uzw7l1ptmt3hgloq.png",[],{"type":23,"value":326},"和",{"type":17,"tag":29,"props":328,"children":330},{"alt":31,"src":329},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134140hm6kxfxbpq0fscl9.png",[],{"type":23,"value":332},"越小，说明",{"type":17,"tag":29,"props":334,"children":336},{"alt":31,"src":335},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134151b07pdzkgbsxjxqjx.png",[],{"type":23,"value":326},{"type":17,"tag":29,"props":339,"children":341},{"alt":31,"src":340},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134217jipirjbafsod7qfr.png",[],{"type":23,"value":343},"相似性越高，隐私保护程度也越好。 通常来说，对数据加噪声可以满足 LDP，两种常用的加噪声的方法：高斯噪声和拉普拉斯噪声。 给定一个函数",{"type":17,"tag":29,"props":345,"children":347},{"alt":31,"src":346},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134338jt4zio66mcwizdbk.png",[],{"type":23,"value":136},{"type":17,"tag":25,"props":350,"children":351},{},[352,357,359,363,365,369],{"type":17,"tag":40,"props":353,"children":354},{},[355],{"type":23,"value":356},"高斯机制",{"type":23,"value":358},"定义为",{"type":17,"tag":29,"props":360,"children":362},{"alt":31,"src":361},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134420wd2mtzyhaubmq2ez.png",[],{"type":23,"value":364},",其中",{"type":17,"tag":29,"props":366,"children":368},{"alt":31,"src":367},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134441uwjprux2aqtfm9gk.png",[],{"type":17,"tag":29,"props":370,"children":372},{"alt":31,"src":371},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134454fpcvqfzrmf3zfeub.png",[],{"type":17,"tag":25,"props":374,"children":375},{},[376,381,382,386,387,391],{"type":17,"tag":40,"props":377,"children":378},{},[379],{"type":23,"value":380},"拉普拉斯机制",{"type":23,"value":358},{"type":17,"tag":29,"props":383,"children":385},{"alt":31,"src":384},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134546o1oh5vpefllbvc8f.png",[],{"type":23,"value":209},{"type":17,"tag":29,"props":388,"children":390},{"alt":31,"src":389},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134603tlgzpqk7qirplady.png",[],{"type":23,"value":60},{"type":17,"tag":25,"props":393,"children":394},{},[395,397,401,403,407,409,413,415,419],{"type":23,"value":396},"可以证明，高斯机制能满足",{"type":17,"tag":29,"props":398,"children":400},{"alt":31,"src":399},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1346392vcvaoprms7pee7r.png",[],{"type":23,"value":402},"-LDP 性质，拉普拉斯机制能满足",{"type":17,"tag":29,"props":404,"children":406},{"alt":31,"src":405},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1347016eytfhvlbpgj7fht.png",[],{"type":23,"value":408},"-LDP 性质。因此，下文主要考虑",{"type":17,"tag":29,"props":410,"children":412},{"alt":31,"src":411},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134645rncrk5cfjdlp6pmr.png",[],{"type":23,"value":414},"-LDP 性质，将算法中的高斯机制替换成拉普拉斯机制可以得到对应的",{"type":17,"tag":29,"props":416,"children":418},{"alt":31,"src":417},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134708cmo9qptwqhlmokgn.png",[],{"type":23,"value":420},"-LDP 性质。",{"type":17,"tag":25,"props":422,"children":423},{},[424],{"type":17,"tag":29,"props":425,"children":427},{"alt":31,"src":426},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/134731hlbirhrctkjcjsnz.png",[],{"type":17,"tag":429,"props":430,"children":432},"h3",{"id":431},"context-free-bandit",[433],{"type":17,"tag":40,"props":434,"children":435},{},[436],{"type":23,"value":437},"Context-Free Bandit",{"type":17,"tag":25,"props":439,"children":440},{},[441,443,447,449,453,455,459,461,465,467,471,473,477],{"type":23,"value":442},"假定我们有一个非隐私保护的 Bandit 算法",{"type":17,"tag":29,"props":444,"children":446},{"alt":31,"src":445},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135436y9krwwlcwgym6jhn.png",[],{"type":23,"value":448},"，根据高斯机制，如果直接在每一轮回传的损失值",{"type":17,"tag":29,"props":450,"children":452},{"alt":31,"src":451},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135452pwwp93tc2ema6xhn.png",[],{"type":23,"value":454},"上注入噪声，那么该算法就可以满足",{"type":17,"tag":29,"props":456,"children":458},{"alt":31,"src":457},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1355086tqroamx2otwioaf.png",[],{"type":23,"value":460},"-LDP 性质。假设",{"type":17,"tag":29,"props":462,"children":464},{"alt":31,"src":463},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135534vf3ziytkngvk5j5q.png",[],{"type":23,"value":466},"是有界的，即",{"type":17,"tag":29,"props":468,"children":470},{"alt":31,"src":469},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135542xpwuzriaa9daro5m.png",[],{"type":23,"value":472},"，那么满足",{"type":17,"tag":29,"props":474,"children":476},{"alt":31,"src":475},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135554aqfac0phk6ndihbd.png",[],{"type":23,"value":478},"-LDP 的 Bandit 算法可以写成如下形式：",{"type":17,"tag":25,"props":480,"children":481},{},[482],{"type":17,"tag":29,"props":483,"children":485},{"alt":31,"src":484},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135609sjvmleir1hpksxyx.png",[],{"type":17,"tag":25,"props":487,"children":488},{},[489],{"type":23,"value":490},"我们可以证明，上述算法有如下的性能：",{"type":17,"tag":25,"props":492,"children":493},{},[494,499,501,505,507,511,513,517,519],{"type":17,"tag":40,"props":495,"children":496},{},[497],{"type":23,"value":498},"【定理】",{"type":23,"value":500}," 假设非隐私保护的 Bandit 算法",{"type":17,"tag":29,"props":502,"children":504},{"alt":31,"src":503},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135721nn8juew8j8rt1vh2.png",[],{"type":23,"value":506},"的 regret 上界是",{"type":17,"tag":29,"props":508,"children":510},{"alt":31,"src":509},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135752dodsjbl0scrajssu.png",[],{"type":23,"value":512},"，那么算法 1 有如下理论保证：",{"type":17,"tag":29,"props":514,"children":516},{"alt":31,"src":515},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135811hngiziosf6qhjvim.png",[],{"type":23,"value":518},"，有",{"type":17,"tag":29,"props":520,"children":522},{"alt":31,"src":521},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135821pgvgfak6b8o3d5gr.png",[],{"type":17,"tag":25,"props":524,"children":525},{},[526,528,532],{"type":23,"value":527},"根据上述定理，我们只需将任一非隐私保护的算法按照算法 1 进行改造，就立即可以得到对应的隐私保护版本的算法，且它的累积 regret 的理论上界和非隐私算法只相差一个",{"type":17,"tag":29,"props":529,"children":531},{"alt":31,"src":530},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135910zvcannsxmpb8jbxc.png",[],{"type":23,"value":533},"因子，因此算法 1 具有很强的通用性。我们将损失函数满足不同凸性和光滑性条件下的 regret 简单罗列如下：",{"type":17,"tag":25,"props":535,"children":536},{},[537],{"type":17,"tag":29,"props":538,"children":540},{"alt":31,"src":539},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/135921soruyd5sgwn0ergy.png",[],{"type":17,"tag":25,"props":542,"children":543},{},[544,546],{"type":23,"value":545},"上述算法和结论可以扩展到每一轮能观测多个动作损失值的情况，感兴趣的可以参见论文（",{"type":17,"tag":547,"props":548,"children":552},"a",{"href":549,"rel":550},"https://arxiv.org/abs/2006.00701%EF%BC%89%E3%80%82",[551],"nofollow",[553],{"type":23,"value":554},"https://arxiv.org/abs/2006.00701）。",{"type":17,"tag":25,"props":556,"children":557},{},[558],{"type":17,"tag":40,"props":559,"children":560},{},[561],{"type":23,"value":562},"Contextual Bandit",{"type":17,"tag":25,"props":564,"children":565},{},[566,568,572,574,578,580,584,585,589,591,595],{"type":23,"value":567},"这里我们只介绍一类最简单的线性的情况：",{"type":17,"tag":29,"props":569,"children":571},{"alt":31,"src":570},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140200hsuhc1vdytzoavm9.png",[],{"type":23,"value":573},"函数是恒等变换，即",{"type":17,"tag":29,"props":575,"children":577},{"alt":31,"src":576},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140221z8lgpcgzpczjxtjo.png",[],{"type":23,"value":579},"。LinUCB 是一个解决这种 linear contextual bandit 的经典算法。在 LinUCB 算法中，每一轮需要传输的是更新量是",{"type":17,"tag":29,"props":581,"children":583},{"alt":31,"src":582},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1402436bgwsesqkeomr0zg.png",[],{"type":23,"value":326},{"type":17,"tag":29,"props":586,"children":588},{"alt":31,"src":587},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140300wrfcp8fcwhl9bic2.png",[],{"type":23,"value":590},"，我们通过给这些变量加高斯噪声就可以保证",{"type":17,"tag":29,"props":592,"children":594},{"alt":31,"src":593},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140319gyrqqmp1h74uwu3n.png",[],{"type":23,"value":596},"-LDP，我们称之为 LDP LinUCB 算法，具体过程如下：",{"type":17,"tag":25,"props":598,"children":599},{},[600],{"type":17,"tag":40,"props":601,"children":602},{},[603],{"type":17,"tag":29,"props":604,"children":606},{"alt":31,"src":605},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140343dpbyjzejo3zdd7y0.png",[],{"type":17,"tag":25,"props":608,"children":609},{},[610,614,616,620],{"type":17,"tag":40,"props":611,"children":612},{},[613],{"type":23,"value":498},{"type":23,"value":615}," 依照至少为",{"type":17,"tag":29,"props":617,"children":619},{"alt":31,"src":618},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140422gpunegbc3fbsghyv.png",[],{"type":23,"value":621},"的概率，LDP LinUCB 算法的 regret 满足如",{"type":17,"tag":25,"props":623,"children":624},{},[625],{"type":17,"tag":29,"props":626,"children":628},{"alt":31,"src":627},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140439hdhfb5pknvslil5y.png",[],{"type":17,"tag":25,"props":630,"children":631},{},[632,634],{"type":23,"value":633},"上述算法和结论可以扩展到 gg 不是恒等变换的情况，感兴趣的可以参见论文（",{"type":17,"tag":547,"props":635,"children":637},{"href":549,"rel":636},[551],[638],{"type":23,"value":554},{"type":17,"tag":25,"props":640,"children":641},{},[642],{"type":17,"tag":29,"props":643,"children":645},{"alt":31,"src":644},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140527ymecgbuzkwcigmp9.png",[],{"type":17,"tag":25,"props":647,"children":648},{},[649],{"type":23,"value":650},"MovieLens 是一个包含多个用户对多部电影评分的公开数据集，我们可以用它来模拟电影推荐。我们通过src/dataset.py 来构建环境：我们从数据集中抽取一部分有电影评分数据的用户，然后将评分矩阵通过 SVD 分解来补全评分数据，并将分数归一化到[−1,+1]。在每次交互的时候，系统随机抽取一个用户，推荐算法获得特征，并选择一部电影进行推荐，MovieLensEnv会在打分矩阵中查询该用户对电影对评分并返回，从而模拟用户给电影打分。",{"type":17,"tag":652,"props":653,"children":655},"pre",{"code":654},"class MovieLensEnv:\n    def observation(self):\n        \"\"\"random select a user and return its feature.\"\"\"\n        sampled_user = random.randint(0, self._data_matrix.shape[0] - 1)\n        self._current_user = sampled_user\n        return Tensor(self._feature[sampled_user])\n    def current_rewards(self):\n        \"\"\"rewards for current user.\"\"\"\n        return Tensor(self._approx_ratings_matrix[self._current_user])\n",[656],{"type":17,"tag":657,"props":658,"children":659},"code",{"__ignoreMap":7},[660],{"type":23,"value":654},{"type":17,"tag":25,"props":662,"children":663},{},[664,666,670],{"type":23,"value":665},"LDP LinUCB 的算法位于src/linucb.py，参数如下，分别对应算法中的",{"type":17,"tag":29,"props":667,"children":669},{"alt":31,"src":668},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140715yymtlv6jvseqtnvt.png",[],{"type":23,"value":671},":",{"type":17,"tag":652,"props":673,"children":675},{"code":674},"import mindspore.nn as nn\n\nclass LinUCB(nn.Cell):\n    def __init__(self, context_dim, epsilon=100, delta=0.1, alpha=0.1, T=1e5):\n    ...\n        # Parameters\n        self._V = Tensor(np.zeros((context_dim, context_dim), dtype=np.float32))\n        self._u = Tensor(np.zeros((context_dim,), dtype=np.float32))\n        self._theta = Tensor(np.zeros((context_dim,), dtype=np.float32))\n",[676],{"type":17,"tag":657,"props":677,"children":678},{"__ignoreMap":7},[679],{"type":23,"value":674},{"type":17,"tag":25,"props":681,"children":682},{},[683],{"type":23,"value":684},"每来一个用户，LDP LinUCB 算法根据用户和电影的联合特征x基于当前的模型来选择最优的电影a_max做推荐，并传输带噪声的更新量：",{"type":17,"tag":25,"props":686,"children":687},{},[688,690,694],{"type":23,"value":689},"（算法中的",{"type":17,"tag":29,"props":691,"children":693},{"alt":31,"src":692},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/140859cvpg66loobbkqof9.png",[],{"type":23,"value":695},"）",{"type":17,"tag":652,"props":697,"children":699},{"code":698},"import mindspore.nn as nn\n\nclass LinUCB(nn.Cell):\n...\n    def construct(self, x, rewards):\n        \"\"\"compute the perturbed gradients for parameters.\"\"\"\n        # Choose optimal action\n        x_transpose = self.transpose(x, (1, 0))\n        scores_a = self.squeeze(self.matmul(x, self.expand_dims(self._theta, 1)))\n        scores_b = x_transpose * self.matmul(self._Vc_inv, x_transpose)\n        scores_b = self.reduce_sum(scores_b, 0)\n        scores = scores_a + self._beta * scores_b\n        max_a = self.argmax(scores)\n        xa = x[max_a]\n        xaxat = self.matmul(self.expand_dims(xa, -1), self.expand_dims(xa, 0))\n        y = rewards[max_a]\n        y_max = self.reduce_max(rewards)\n        y_diff = y_max - y\n        self._current_regret = float(y_diff.asnumpy())\n        self._regret += self._current_regret\n\n        # Prepare noise\n        B = np.random.normal(0, self._sigma, size=xaxat.shape)\n        B = np.triu(B)\n        B += B.transpose() - np.diag(B.diagonal())\n        B = Tensor(B.astype(np.float32))\n        Xi = np.random.normal(0, self._sigma, size=xa.shape)\n        Xi = Tensor(Xi.astype(np.float32))\n\n        # Add noise and update parameters\n        return xaxat + B, xa * y + Xi, max_a\n",[700],{"type":17,"tag":657,"props":701,"children":702},{"__ignoreMap":7},[703],{"type":23,"value":698},{"type":17,"tag":25,"props":705,"children":706},{},[707],{"type":23,"value":708},"系统收到更新量之后，更新模型参数如下：",{"type":17,"tag":652,"props":710,"children":712},{"code":711},"import mindspore.nn as nn\n\nclass LinUCB(nn.Cell):\n...\n    def server_update(self, xaxat, xay):\n        \"\"\"update parameters with perturbed gradients.\"\"\"\n        self._V += xaxat\n        self._u += xay\n        self.inverse_matrix()\n        theta = self.matmul(self._Vc_inv, self.expand_dims(self._u, 1))\n        self._theta = self.squeeze(theta)\n",[713],{"type":17,"tag":657,"props":714,"children":715},{"__ignoreMap":7},[716],{"type":23,"value":711},{"type":17,"tag":25,"props":718,"children":719},{},[720],{"type":17,"tag":29,"props":721,"children":723},{"alt":31,"src":722},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141034rrfwaohtwwnqzrcl.png",[],{"type":17,"tag":25,"props":725,"children":726},{},[727],{"type":23,"value":728},"我们测试不同的 \\varepsilonε 对累积 regret 对影响：",{"type":17,"tag":730,"props":731,"children":732},"ul",{},[733,739],{"type":17,"tag":734,"props":735,"children":736},"li",{},[737],{"type":23,"value":738},"x 轴：交互轮数",{"type":17,"tag":734,"props":740,"children":741},{},[742],{"type":23,"value":743},"y 轴：累积 regret",{"type":17,"tag":25,"props":745,"children":746},{},[747],{"type":17,"tag":29,"props":748,"children":750},{"alt":31,"src":749},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141057jq3nfpixgzqleij5.png",[],{"type":17,"tag":25,"props":752,"children":753},{},[754,756,760],{"type":23,"value":755},"可以看到，当固定隐私变量",{"type":17,"tag":29,"props":757,"children":759},{"alt":31,"src":758},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141133vvluogljadkjosmo.png",[],{"type":23,"value":761},"的时候，累积 regret 随着时间增加得越来越缓慢，意味着推荐的电影和用户最喜欢的电影越来越接近，即推荐变得越来越精准。",{"type":17,"tag":25,"props":763,"children":764},{},[765,767,771,773,777,779,783],{"type":23,"value":766},"同时，随着",{"type":17,"tag":29,"props":768,"children":770},{"alt":31,"src":769},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141140gwylluolfler52h9.png",[],{"type":23,"value":772},"的减小，隐私保护程度越好，但性能也会有所下降。由于测试用的数据量较小，因此此处",{"type":17,"tag":29,"props":774,"children":776},{"alt":31,"src":775},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141147ky6b1wdvgkycqwwy.png",[],{"type":23,"value":778},"设定的比较大。在真实商用场景中的数据量会远远大于此处模拟用的数据量，届时可以把",{"type":17,"tag":29,"props":780,"children":782},{"alt":31,"src":781},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141204hvgs8i6zsme2ufi3.png",[],{"type":23,"value":784},"定到 10以下。",{"type":17,"tag":25,"props":786,"children":787},{},[788,790,794],{"type":23,"value":789},"接着我们测试了 LDP LinUCB 和非隐私保护 LinUCB 的累积 regret 的比较（LinUCB 的累积 regret 是",{"type":17,"tag":29,"props":791,"children":793},{"alt":31,"src":792},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141220vvtdcxjohwrpfemx.png",[],{"type":23,"value":795},"）：",{"type":17,"tag":730,"props":797,"children":798},{},[799,803],{"type":17,"tag":734,"props":800,"children":801},{},[802],{"type":23,"value":738},{"type":17,"tag":734,"props":804,"children":805},{},[806,808],{"type":23,"value":807},"y 轴：累积 regret 除以",{"type":17,"tag":29,"props":809,"children":811},{"alt":31,"src":810},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141233dgd59esttiun8emi.png",[],{"type":17,"tag":25,"props":813,"children":814},{},[815],{"type":17,"tag":29,"props":816,"children":818},{"alt":31,"src":817},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/1412535c46w3lwqf5fgmrp.png",[],{"type":17,"tag":25,"props":820,"children":821},{},[822,824,828,830,834],{"type":23,"value":823},"可以看到 LDP LinUCB 的累积 regret 增长速度和近似，说明 LDP LinUCB 近乎是最优的算法。这也提示我们，论文中给出的 LDP LinUCB 的理论上界",{"type":17,"tag":29,"props":825,"children":827},{"alt":31,"src":826},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141350lyqwlskcsr0bbuzg.png",[],{"type":23,"value":829},"也许可以进一步改进到",{"type":17,"tag":29,"props":831,"children":833},{"alt":31,"src":832},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141351bylk0ngyy1ynmtgz.png",[],{"type":23,"value":60},{"type":17,"tag":25,"props":836,"children":837},{},[838],{"type":23,"value":839},"相关模型代码已上线 MindSpore Model Zoo：",{"type":17,"tag":25,"props":841,"children":842},{},[843],{"type":17,"tag":547,"props":844,"children":847},{"href":845,"rel":846},"https://gitee.com/mindspore/mindspore/tree/master",[551],[848],{"type":23,"value":845},{"type":17,"tag":25,"props":850,"children":851},{},[852],{"type":23,"value":853},"感兴趣的可自行体验。",{"type":17,"tag":25,"props":855,"children":856},{},[857],{"type":17,"tag":29,"props":858,"children":860},{"alt":31,"src":859},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141417w7prtrqfeg7v1dtn.png",[],{"type":17,"tag":25,"props":862,"children":863},{},[864,866,872],{"type":23,"value":865},"1. Kai Zheng, Tianle Cai, Weiran Huang, Zhenguo Li, Liwei Wang. \"Locally Differentially Private (Contextual) Bandits Learning.\" ",{"type":17,"tag":867,"props":868,"children":869},"em",{},[870],{"type":23,"value":871},"Advances in Neural Information Processing Systems",{"type":23,"value":873},". 2020.",{"type":17,"tag":25,"props":875,"children":876},{},[877],{"type":23,"value":878},"2. LDP LinUCB 代码：",{"type":17,"tag":25,"props":880,"children":881},{},[882],{"type":17,"tag":547,"props":883,"children":885},{"href":845,"rel":884},[551],[886],{"type":23,"value":845},{"type":17,"tag":25,"props":888,"children":889},{},[890],{"type":23,"value":891},"MindSpore两日集训营火热报名中！",{"type":17,"tag":25,"props":893,"children":894},{},[895],{"type":23,"value":896},"本期特邀6位MindSpore资深工程师为大家直播授课，参加集训的同学可通过使用MindSpore 实现一键部署在线推理服务、了解华为智慧终端的黑科技是什么、学习高效低功耗的单节点数据缓存模块、掌握快速定位模型精度问题的方法，讲解过后给大家留出时间消化内容、做作业，最后进行直播答疑，授课期间的任何疑问均能得到及时反馈！",{"type":17,"tag":25,"props":898,"children":899},{},[900],{"type":17,"tag":40,"props":901,"children":902},{},[903],{"type":23,"value":904},"扫码报名↓",{"type":17,"tag":25,"props":906,"children":907},{},[908],{"type":17,"tag":29,"props":909,"children":911},{"alt":31,"src":910},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141458xablnfmzbmhgcatk.png",[],{"type":17,"tag":25,"props":913,"children":914},{},[915],{"type":17,"tag":40,"props":916,"children":917},{},[918],{"type":23,"value":919},"*记得备注：集训",{"type":17,"tag":921,"props":922,"children":923},"blockquote",{},[924,929,940,945],{"type":17,"tag":25,"props":925,"children":926},{},[927],{"type":23,"value":928},"MindSpore官方资料",{"type":17,"tag":25,"props":930,"children":931},{},[932,934],{"type":23,"value":933},"GitHub : ",{"type":17,"tag":547,"props":935,"children":938},{"href":936,"rel":937},"https://github.com/mindspore-ai/mindspore",[551],[939],{"type":23,"value":936},{"type":17,"tag":25,"props":941,"children":942},{},[943],{"type":23,"value":944},"Gitee:https : //gitee.com/mindspore/mindspore",{"type":17,"tag":25,"props":946,"children":947},{},[948],{"type":23,"value":949},"官方QQ群 : 871543426",{"type":17,"tag":25,"props":951,"children":952},{},[953],{"type":23,"value":954},"扫描下方二维码加入MindSpore项目",{"type":17,"tag":25,"props":956,"children":957},{},[958],{"type":17,"tag":29,"props":959,"children":961},{"alt":31,"src":960},"https://bbs-img-cbc-cn.obs.cn-north-1.myhuaweicloud.com/data/attachment/forum/202101/20/141555dprpiebrkxu5ucqn.png",[],{"title":7,"searchDepth":963,"depth":963,"links":964},4,[965],{"id":431,"depth":966,"text":437},3,"markdown","content:technology-blogs:zh:379.md","content","technology-blogs/zh/379.md","technology-blogs/zh/379","md",1776506135275]