library(rmr2)
## @knitr LLS-data
X = matrix(rnorm(2000), ncol = 10)
X.index = to.dfs(cbind(1:nrow(X), X))
y = as.matrix(rnorm(200))
## @knitr LLS-sum
Sum =
function(., YY)
keyval(1, list(Reduce('+', YY)))
## @knitr LLS-XtX
XtX =
values(
from.dfs(
mapreduce(
input = X.index,
map =
function(., Xi) {
Xi = Xi[,-1]
keyval(1, list(t(Xi) %*% Xi))},
reduce = Sum,
combine = TRUE)))[[1]]
## @knitr LLS-Xty
Xty =
values(
from.dfs(
mapreduce(
input = X.index,
map = function(., Xi) {
yi = y[Xi[,1],]
Xi = Xi[,-1]
keyval(1, list(t(Xi) %*% yi))},
reduce = Sum,
combine = TRUE)))[[1]]
## @knitr LLS-solve
solve(XtX, Xty)
## @knitr end
基于RHadoop的linear-least-squares算法
最新推荐文章于 2023-06-28 17:13:54 发布