1 people like it.
Like the snippet!
Live chart of CNTK Error Rate
CNTK is Microsoft's deep learning toolkit. This snippets allows one to view the live error rate on a chart. It relies on FSharp.Charting and FSharp.Control.Reactive and a couple of other F# snippets the links for which are referenced in the code. Use 'track' function to start viewing live charts.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
|
#r @"..\packages\FSharp.Charting.0.90.14\lib\net40\FSharp.Charting.dll"
#r @"..\packages\System.Reactive.Core.3.0.0\lib\net45\System.Reactive.Core.dll"
#r @"..\packages\System.Reactive.Linq.3.0.0\lib\net45\System.Reactive.Linq.dll"
#r @"..\packages\System.Reactive.Interfaces.3.0.0\lib\net45\System.Reactive.Interfaces.dll"
#r @"..\packages\FSharp.Control.Reactive.3.5.0\lib\net45\FSharp.Control.Reactive.dll"
#r @"System.Windows.Forms.DataVisualization"
#load "ObservableExtensions.fs" // http://fssnip.net/nC
#load "CNTLLogParser.fs" // http://fssnip.net/7Rm
open CNTLLogParser
open System
open FSharp.Control.Reactive
open System.Windows.Forms
open FSharp.Charting
open System.IO
open FSharp.Control
module FsiAutoShow =
fsi.AddPrinter(fun (ch:FSharp.Charting.ChartTypes.GenericChart) -> ch.ShowChart() |> ignore; "(Chart)")
let private containerize ch = new ChartTypes.ChartControl(ch,Dock=DockStyle.Fill)
let show chlist =
let form = new Form()
form.Width <- 400
form.Height <- 300
form.Visible <- true
form.Text <- "CNTK Charts"
let grid = new TableLayoutPanel()
grid.AutoSize <- true
// grid.ColumnCount <- 2
// grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50.f)) |> ignore
// grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50.f)) |> ignore
grid.RowCount <- 2
grid.RowStyles.Add(new RowStyle(SizeType.Percent,50.f)) |> ignore
grid.RowStyles.Add(new RowStyle(SizeType.Percent,50.f)) |> ignore
grid.GrowStyle <- TableLayoutPanelGrowStyle.AddRows
grid.Dock <- DockStyle.Fill
chlist |> List.map containerize |> List.iter grid.Controls.Add
form.Controls.Add(grid)
form.Show()
let track file =
let cts = new System.Threading.CancellationTokenSource()
let obs,fPost = Observable.createObservableAgent 100 cts.Token
do tail tailFilterWihoutMB cts file fPost
let obsCntk = obs |> Observable.map cntkParse |> Observable.choose excludeUnk
let obsEE = obsCntk |> Observable.choose chooseEE
obsEE |> Observable.subscribe (printfn "%A") |> ignore
let c1 =
LiveChart.FastLineIncremental(obsEE |> Observable.map (fun x->x.Epoch,x.CE),Title="Epoch CE")
|> Chart.WithXAxis(Title="Epoch")
let c2 =
LiveChart.FastLineIncremental(obsEE |> Observable.map (fun x->x.Epoch,x.Err),Title="Epoch Err")
|> Chart.WithXAxis(Title="Epoch")
show [c1;c2]
cts
;;
(*
let ct1 = track @"C:\CNTK\Models\M1\err"
ct1.Cancel()
let ct2 = track @" track @"C:\CNTK\Models\M2\err"
ct2.Cancel()
*)
(* minibatch error rate display chart note use the 'tailFilterWithMB' filter to include data for this chart
let pctArray() = [|for i in 0 .. 9 -> i,0.|]
let collectMB (acc:(int*float)array) m1 = let i = int ((m1.Percent - 1. |> max 0.) * 0.1) % 10 in acc.[i] <- i,m1.CE; acc
let majorPctChanged (m1,m2) = floor (m1.Percent / 10.) <> floor (m2.Percent / 10.)
let obsMBP = obsCntk |> Observable.choose chooseMB
let obsMB = obsMBP |> Observable.scan collectMB (pctArray())
let every x i _ = i % !x = 0 //every 10th item
let updateEvery = ref 100 //updateEvery := 300
let obsMBCE = obsMB |> Observable.filteri (every updateEvery) |> Observable.map Array.copy
;;
LiveChart.FastLine (obsMBCE,Title="MB CE");;
*)
|
namespace System
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Control
namespace System.Windows
namespace System.Windows.Forms
namespace System.IO
val fsi : Compiler.Interactive.InteractiveSession
Full name: Microsoft.FSharp.Compiler.Interactive.Settings.fsi
member Compiler.Interactive.InteractiveSession.AddPrinter : ('T -> string) -> unit
val ch : obj
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
val private containerize : ch:'a -> 'b
Full name: Script.containerize
val ch : 'a
type DockStyle =
| None = 0
| Top = 1
| Bottom = 2
| Left = 3
| Right = 4
| Fill = 5
Full name: System.Windows.Forms.DockStyle
field DockStyle.Fill = 5
val show : chlist:'a list -> unit
Full name: Script.show
val chlist : 'a list
val form : Form
Multiple items
type Form =
inherit ContainerControl
new : unit -> Form
member AcceptButton : IButtonControl with get, set
member Activate : unit -> unit
member ActiveMdiChild : Form
member AddOwnedForm : ownedForm:Form -> unit
member AllowTransparency : bool with get, set
member AutoScale : bool with get, set
member AutoScaleBaseSize : Size with get, set
member AutoScroll : bool with get, set
member AutoSize : bool with get, set
...
nested type ControlCollection
Full name: System.Windows.Forms.Form
--------------------
Form() : unit
property Control.Width: int
property Control.Height: int
property Control.Visible: bool
property Form.Text: string
val grid : TableLayoutPanel
Multiple items
type TableLayoutPanel =
inherit Panel
new : unit -> TableLayoutPanel
member BorderStyle : BorderStyle with get, set
member CellBorderStyle : TableLayoutPanelCellBorderStyle with get, set
member ColumnCount : int with get, set
member ColumnStyles : TableLayoutColumnStyleCollection
member Controls : TableLayoutControlCollection
member GetCellPosition : control:Control -> TableLayoutPanelCellPosition
member GetColumn : control:Control -> int
member GetColumnSpan : control:Control -> int
member GetColumnWidths : unit -> int[]
...
Full name: System.Windows.Forms.TableLayoutPanel
--------------------
TableLayoutPanel() : unit
property Panel.AutoSize: bool
property TableLayoutPanel.RowCount: int
property TableLayoutPanel.RowStyles: TableLayoutRowStyleCollection
TableLayoutStyleCollection.Add(style: TableLayoutStyle) : int
TableLayoutRowStyleCollection.Add(rowStyle: RowStyle) : int
Multiple items
type RowStyle =
inherit TableLayoutStyle
new : unit -> RowStyle + 2 overloads
member Height : float32 with get, set
Full name: System.Windows.Forms.RowStyle
--------------------
RowStyle() : unit
RowStyle(sizeType: SizeType) : unit
RowStyle(sizeType: SizeType, height: float32) : unit
type SizeType =
| AutoSize = 0
| Absolute = 1
| Percent = 2
Full name: System.Windows.Forms.SizeType
field SizeType.Percent = 2
property TableLayoutPanel.GrowStyle: TableLayoutPanelGrowStyle
type TableLayoutPanelGrowStyle =
| FixedSize = 0
| AddRows = 1
| AddColumns = 2
Full name: System.Windows.Forms.TableLayoutPanelGrowStyle
field TableLayoutPanelGrowStyle.AddRows = 1
property Control.Dock: DockStyle
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val iter : action:('T -> unit) -> list:'T list -> unit
Full name: Microsoft.FSharp.Collections.List.iter
property TableLayoutPanel.Controls: TableLayoutControlCollection
Control.ControlCollection.Add(value: Control) : unit
TableLayoutControlCollection.Add(control: Control, column: int, row: int) : unit
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
Control.Show() : unit
Form.Show(owner: IWin32Window) : unit
val track : file:'a -> Threading.CancellationTokenSource
Full name: Script.track
val file : 'a
val cts : Threading.CancellationTokenSource
namespace System.Threading
Multiple items
type CancellationTokenSource =
new : unit -> CancellationTokenSource
member Cancel : unit -> unit + 1 overload
member Dispose : unit -> unit
member IsCancellationRequested : bool
member Token : CancellationToken
static member CreateLinkedTokenSource : [<ParamArray>] tokens:CancellationToken[] -> CancellationTokenSource + 1 overload
Full name: System.Threading.CancellationTokenSource
--------------------
Threading.CancellationTokenSource() : unit
val obs : IObservable<obj>
val fPost : obj
module Observable
from Microsoft.FSharp.Control
property Threading.CancellationTokenSource.Token: Threading.CancellationToken
val obsCntk : IObservable<obj>
val map : mapping:('T -> 'U) -> source:IObservable<'T> -> IObservable<'U>
Full name: Microsoft.FSharp.Control.Observable.map
val choose : chooser:('T -> 'U option) -> source:IObservable<'T> -> IObservable<'U>
Full name: Microsoft.FSharp.Control.Observable.choose
val obsEE : IObservable<obj>
val subscribe : callback:('T -> unit) -> source:IObservable<'T> -> IDisposable
Full name: Microsoft.FSharp.Control.Observable.subscribe
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val c1 : obj
val c2 : obj
More information