我是F#的新手,爲了努力學習,認爲實現聚類算法會很有趣。 我有我需要迭代的列表輸入列表。對於這些輸入向量中的每一個,我需要應用更新權重並返回列表(權重矩陣)的函數。我可以通過newMatrix
函數來完成該部分。問題是,我需要在下一次迭代中使用更新的權重矩陣,並且我失去了如何執行此操作。這裏是重要的部分,爲簡潔起見省略了一些功能。如何遍歷列表並將函數結果傳遞給下一個迭代
let inputList = [[1; 1; 0; 0]; [0; 0; 0; 1]; [1; 0; 0; 0]; [0; 0; 1; 1;]]
let weights = [[.2; .6; .5; .9]; [.8; .4; .7; .3]]
let newMatrix xi matrix =
List.map2(fun w wi ->
if wi = (yiIndex xi) then (newWeights xi)
else w) matrix [0..matrix.Length-1]
printfn "%A" (newMatrix inputList.Head weights)
> >
[[0.2; 0.6; 0.5; 0.9]; [0.92; 0.76; 0.28; 0.32]]
所以我的問題是,我該如何遍歷inputList
計算newMatrix
使用以前newMatrix
結果每個inputVector?
編輯:加入僞算法:
for input vector 1
given weight matrix calculate new weight matrix
return weight matirx prime
for input vector 2
given weight matrix prime calculate new weight matrix
and so on...
...
題外話:我實現Kohonen SOM算法FOM this書。
@Ankur&@Tomas我在這個問題扔了你們的錯字。我在描述中引用'newWeights',我應該引用'newMatrix'。道歉。 – nathan