In fact, it is difficult for you to give an answer. Perhaps this would be a better match for viewing the stackoverflow subdirectory code ?
, :
. - / ,
for((k,v)<-map) {
...
}
for(k<-map.keySet) { val value = map.get(k).get;
...
}
, . ,
def gradient(p: DataPoint, w: Broadcast[Vector]) : Vector = {
def h(w: Broadcast[Vector], x: SparserVector): Double = {
val wb = w.value
val features = x.elements
var s = 0.0
for((k,v)<-features)
s += v * wb(k)
1 / (1 + Math.exp(-p.y * s))
}
p.x * (-(1 - p.y *h(w, p.x)))
}
, , SparseVector, Map [Int, Double]. , , Array [Int] Array [Double] -
( , SortedMap [Int, Double] )
class SparseVector(val indices: Array[Int], val values: Array[Double]) {
require(indices.length == values.length)
def *(scale: Double): Vector = {
var x = new Array[Double](dimNum)
var i = 0
while(i < indices.length) {
x(indices(i)) = scale * values(i)
i += 1
}
Vector(x)
}
}
, , , .