有这个代码:
let errorChanged = new Event<(int * float)>()
let learn error data w w_ iter =
let rec learning error data w w_ i icount =
//recursive(loop) fire event
errorChanged.Trigger(i, e) //trigger event for chart update
if (/**/) then
learning /*params*/
else
/*do else*/
let plot = LiveChart.PointIncremental(errorChanged.Publish |> Event.every 5)
plot.ShowChart()
learning error data w w_ 0 iter
当我运行它时,我看到点图窗口,它没有响应(也没有更新)。根据代码示例,这应该可以正常工作,但是......我该如何解决这个问题?
更新:
如果我做:
let rec learning error data w w_ i icount = async {
let e = Seq.fold (fun s x ->
s + errorPart w w_ x x) 0.0 data
errorChanged.Trigger(i, e)
if (e > error && i <= iter) then
printfn "[iter] = %d of %d. [e] = %f" i icount e
let (w, w_) = Seq.fold (fun (w, w_) x ->
learnPart w w_ x x) (w, w_) data
return! learning error data (normalize w) (normalize w_) (i + 1) icount
else
let resultData = Seq.map (fun x -> calculatePart w w_ x) data
let y = resultData
|> Seq.map (fun (y, _) -> y)
|> Seq.concat
let x_ = resultData
|> Seq.map (fun (_, x_) -> x_)
|> Seq.concat
return (w, w_, e, y, x_) }
let plot = LiveChart.PointIncremental(errorChanged.Publish |> Event.every 5)
plot.ShowChart()
async { return! learning error data w w_ 0 iter}
|> Async.RunSynchronously
我得到异常:跨线程操作无效。好像我需要类似的东西Dispatcher
。