- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这道题原本是我的作业,但是我的答案是错误的,我很好奇这道题的最佳解法是什么。
目标是使用 4 个 map reduce 步骤计算“推荐系统引导算法”的关键方面。我的问题出在第 3 步,所以我只会提供它的详细信息。
input: records of the form:
1. (population id, item, number of rating users, sum of ratings, sum of ratings squared)
2. (population id, splitter item, likers/dislikers, item, number of rating users, sum of ratings, sum of ratings squared)
第二种形式与第一种形式非常相似,但每个形式都有一个记录(拆分器、喜欢者/不喜欢者)——其中喜欢者/不喜欢者是一个 bool 值。
这意味着(我认为)有 2^|items| records of the seconds form for each record from the 1st form...(很多同学做错了(又一次,我认为..)假设有相同数量的 1st 和 2nd form 记录)
任务描述:
This step will compute, per splitter movie, the squared error (SE) induced by each movie.
提示:
assume that there exists a string that precedes (in the system’s sort order) any splitter movie id.
这必须在一个 mapreduce 步骤内完成!
其他背景:
这是在“The Netflix Challange”的背景下了解到的
SE 定义:
编辑:有关该问题的其他 Material [关于 netflix 挑战的一些描述和有关该问题的数学信息] 可以在 this link 中找到。 [特别是幻灯片 12-24]
EDIT2:请注意,由于我们使用的是 map/reduce,因此我们不能假设任何有关 ORDER 记录的信息都会被处理 [在 map 和 reduce 中]。
最佳答案
我不确定我是否理解您的问题。
您最终想要的是 SE(U)。在幻灯片 23 和 24 的一些数学细节之后,它是“简单地”用\sum_{i} SE(U)_i
计算的您自己已经了解,9 月 4 日和最后一个是 map reduce 以获得此总和。
第三步是map reduce得到(LaTeX风格)
SE(U)_i = \sum_{u in U_i} (r_{u,i} - r_i)^2
在 Python 中这可能是这样的:
def map(Ui):
''' Ui is the list of user who have rated the film i'''
for user in Ui:
results.append((user,(r_{u,i} - r_i)^2))
def reduce(results):
''' Returns a final pair (item, SE(U)_i ) '''
return (item, sum([value for user,value in results]))
编辑:我原来的回答不完整。让我再解释一下。
您最终想要的是每个分离器的 SE(U)。
步骤 a 准备一些关于项目的有用数据。发出的条目定义为:
key = (population_id, item)
value =
number: |U_i|,
sum_of_ratings: \sum_{u \ in U_i} r_{u,i}
sum_of_squared_ratings: \sum_{u \in U_i} r_{u,i} ^2
现在,对于任何给定的分割电影 M:
U_M = U_{+M} + U_{-M} + U_{M?}
步骤 b 显式计算每个 split 器 M 的小子种群 M+ 和 M- 的统计数据。
NB 喜欢/不喜欢不是 bool 值本身,它是子群体标识符“+”或“-”
每个拆分器项有 2 个新条目:
key = (population_id, item, M, '+')
value =
number: |U_i(+)|
sum_of_ratings: \sum_{u \ in U_i(+)} r_{u,i}
sum_of_squared_ratings: \sum_{u \in U_i(+)} r_{u,i} ^2
Same thing for '-'
或者如果你更喜欢 dis/likers 符号
key = (population_id, item, M, dis/likers)
value =
number: |U_i(dis/likers)|
sum_of_ratings: \sum_{u \ in U_i(dis/likers)} r_{u,i}
sum_of_squared_ratings: \sum_{u \in U_i(dis/likers)} r_{u,i} ^2
cf 幻灯片 24 的中间
注意如果你认为每部电影都可能是一个分离器,那么第二种形式有 2x |item|^2 个项目;那是因为 item -> (boolean, item, splitter) -- 这远远小于你的 2^|item|你还没有解释的评估。
步骤 c 为每个分离器 M 计算每部电影的估计 SE,即 SE(U_M)_i
因为总和可以分配给不同的成员:
U_M = U_{+M} + U_{-M} + U_{M?}
SE(U_M)_i = SE(U_M?)_i + SE(U_+M) + SE(U_-M)
使用 SE(U_{+M})
使用此映射函数显式计算:
def map(key, value):
'''
key = (population_id, item, M, dis/likers)
'''
value =
count: 1
dist: (r_u,i - r_i)^2
emit key, value
def reduce(key, values):
'''
This function explicitly computes the SE for dis/likers
key = (population_id, item, M, dis/likers)
value= count, dist
'''
emit key, sum(count, sum(dist))
现在我们只需要SE(U_{M?})_i
,这是幻灯片 24 中给出的“简单”计算:
SE(?)_i = \sum_{u \in U_i(?)}{r_{u,i}^2} - (\sum r)^2 / |U_i(?)|
当然,我们不会做这么大的加法,而是使用讲座上面的评论,以及步骤 a 中已经计算的数据(这是我从幻灯片 24 的最后 3 个等式中得出的结论)
SE(?)_i = \sum_{u \in U_i}{r_{u,i}^2} - \sum_{u \in U_i('+'/'-')}{r_{u,i}^2} - (...)/ (|U_i| - |U_i('+'/'-'))
所以这一步甚至不是 Map/Reduce,它只是最后一步:
def finalize(key, values):
for [k in keys if k match key]:
''' From all entries get
# from step a
key = (population_id, item) value=(nb_ratings, sum_ratings, sum_ratings_squared)
# from step b
key = (population_id, item, M, '+') value=(nb_ratings_likers, sum_ratings_likers, sum_ratings_squared_likers)
key = (population_id, item, M, '-') value=(nb_ratings_dislikers, sum_ratings_dislikers, sum_ratings_squared_dislikers)
# from step c
key = (population_id, item, M, '+') value=(se_likers)
key = (population_id, item, M, '-') value=(se_dislikers)
'''
se_other = sum_rating_squared - sum_ratings_squared_likers - sum_ratins_squared_dislikers - sum_ratings_likers / (nb_ratings - (nb_ratings_likers)) - sum_ratins_squared_dislikers - sum_ratings_likers / (nb_ratings - (nb_ratings_likers))
emit
key: (population_id, splitter, item)
value : se_likers + se_dislikers + se_other
步骤 d 最后,最后的步骤计算 U_M 的 SE。它只是先前条目的总和,以及一个简单的 Map/Reduce:
对于分离器 M:
SE(U_M) = \sum_i SE(U_M)_i = \sum_i SE(U_M?)_i + \sum_i SE(U_+M) + \sum_i SE(U_-M)
关于algorithm - 使用 Map/Reduce 计算自举算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5392709/
我不知道如何从 reducerRegister.js 中的 reducerForm.js reducer 访问 bool 值 isLoading 标志。我使用了 combineReducers() 并
我正在尝试找到一种理想的方法来更新我的状态树上的几个顶级字段,同时仍然维护拆分 reducer 。 这是我想出的一个简单的解决方案。 var state = { fileOrder: [0],
如果我们想按相同的键(第一个 reducer 的输出)分组,是否可以将 reducer 的输出直接发送到另一个 reducer 有时在链接时我发现我正在使用一个映射器来读取输入并将其复制到输出。因此想
我有一个如下所示的 reducer : const chart = combineReducers({ data, fetchProgress, fetchError,
当Map Reduce代码中有多个reduce时,它们之间没有任何形式的通信。但是,当执行诸如聚合之类的操作时,所有化简器共同产生单个最终输出。当它们之间没有通信时,聚合如何发生?是通过写入上下文吗?
我在 hive 中有一个表,我想从中获取所有数据。问题是: select * from tbl; 给我的结果与以下情况截然不同: select count(*) from tbl; 这是为什么?第二个
假设我有一个带有两个 reducer 的应用程序 - 使用 combineReducers() 组合的 tables 和 footer。 当我点击某个按钮时,将分派(dispatch)两个操作 - 一
我正在学习更深入的 redux,并且在处理高阶 reducer 时遇到一些麻烦。 我试图使用一个简单的分页示例来了解它是如何工作的。 NB:下面的代码只是 Nodejs 上下文中 redux 的一个快
我调用 RSS 提要并使用解析器对其进行解析。我收到一个数组。我现在想在最后创建一个对象,看起来像这样: { "2019-06-13": { "rates": { "usd":
我有一份学生列表,我的应用程序始终显示当时的一个学生,即 activePupil。到目前为止我有两个 reducer 。其中一个包含并默认返回所有子项的列表(以数组的形式): [ { id:
我有一个叫做 animals 的特征缩减器(切片缩减器)。我想将这些 reducer 拆分为哺乳动物、鸟类、鱼类等。这部分很简单,因为我可以简单地使用 ActionReducerMap。 现在假设哺乳
空数组上的简单reduce会抛出: 线程“main”java.lang.UnsupportedOperationException 中的异常:无法减少空的可迭代对象。 链接时同样的异常: val a
我有一些 25k 文档(原始 json 中为 4 GB)的数据,我想对其执行一些 javascript 操作,以使我的最终数据使用者 (R) 更容易访问这些数据,并且我想通过为每个更改添加一个新集合来
我只是想验证我对这些参数及其关系的理解,如果我错了请通知我。 mapreduce.reduce.shuffle.input.buffer.percent 告诉分配给 reducer 的整个洗牌阶段的内
我想将 redux 状态的值从 reducer 传递到另一个 reducer。在我的例子中,我想将 groups 的值从 groupReducer.js 中的状态传递到 scheduleReducer
所以,我有一个应用程序,它有多个 reducer ,因此有多个关联的 Action 创建者。 有一段时间,我的一个 reducer 更新了状态(由于编辑),因此,我必须确保其他 reducer 看到此
我有一个 reducer ,可以在调度操作时重新调整适当的状态。现在我定期调用 API,因此结果会一次又一次地触发操作。所以我想要的是,如果 reducer 状态已经有数据,那么另一个 reducer
当我尝试执行来自 here 的 DISTINCT reduce 时,出现错误。我已经在啤酒 sample 桶上重现了这个错误,所以这应该很容易重现。我没有在 mapreduce_errors.txt
在以下语法的简单优先级解析(分解)中,我们存在 shift-reduce 和 reduce-reduce 冲突。 X 是开始符号,X'-->$X$ 是添加规则。另外+和下符号是终结符。 X'-->$X
我需要编写一个连续调用两个reducer的Mapreduce程序。即,第一个 reducer 的输出将是第二个 reducer 的输入。我如何实现这一目标? 到目前为止我发现的内容表明我需要在我的驱动
我是一名优秀的程序员,十分优秀!