Wykład przeznaczony jest dla studentów stopnia studiów informatycznych na Wydziale Podstawowych Problemów Techniki. Odbywa się w czwartki w godz. - (sala 131/C13). Na stronie tej znajdziesz informacje o zasadach zaliczenia, realizowanym materiale, literaturze oraz listę zadań.
val T = "ALA ma kota. ALA ma psa. Ala ma kota i kanarka"
val t = T.toLowerCase
var G = t.filterNot(x=>".;".contains(x)).split("\\s+").map(x=>(x,1))
val A = G.groupBy(x=>x._1).mapValues(x=>x.length)
var X = A.toSeq
X.sortWith((x,y)=>x._2>y._2)
val macierz = List(
(1,1,2.0),
(1,2,1.0),
(2,1,3.0),
(2,2,1.0)
)
import scala.collection.mutable.ListBuffer
def mapper(mat:List[(Int,Int,Double)],x:Array[Double]) : Map[Int,ListBuffer[(Int, Double)]] = {
var B = ListBuffer[(Int,Double)]()
def emit(keyVal:(Int,Double)) : Unit = {
B += keyVal
}
for ((i,j,m) <- mat) {
var b = (i, m*x(j-1))
emit(b)
}
B.groupBy(t=>t._1)
}
def uruchom(X : Map[Int,ListBuffer[(Int, Double)]]) : Unit = {
for ((key,v) <- X) {
reducer(key, v.map(x=>x._2))
}
}
def reducer(key:Int, L:ListBuffer[Double]) : Unit = {
def emit(key:Int,value:Double){
println(s"y${key} = ${value}")
}
emit(key,L.sum)
}
Przykładowe użycie:
val X = mapper(macierz,Array(1.0,2.0)) uruchom(X)
map (a,b) { emit(a->("to",b)); emit(b->("from",a)) }
reduce(x->L) {
pogrupuj L: ["from" -> L1, "to" -> L2]
forall(a <- L1; c <- L2)
emit((a,c) -> (a,c))
}
map ("X", x, y) { if ("X" == "R") emit(y->(1,x)) else emit(x->(2,y)) }
reduce(x->L) {
pogrupuj L: [1 -> L1, 2 -> L2]
forall(a <- L1; c <- L2)
emit((a, x, c) -> (a, x, c))
}
STEP I:
map ("X", i, j, x) { if ("X" == "M") emit(j -> (1,i,x)) else emit(i->(2,j,x)) }
reduce(x->L) {
pogrupuj L: [1 -> L1, 2 -> L2]
forall((1,i,x) <- L1; (2,k,y) <- L2)
emit((i, k) -> x*y)
}
STEP II : mapper = identity
reduce ((i,k) ->L) {emit ((i,j) -> Sum(L))}