1 people like it.

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: 
#r @"..\packages\FSharp.Charting\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 FSharp.Charting
open System.IO
open FSharp.Control

module FsiAutoShow = 
    fsi.AddPrinter(fun (ch:FSharp.Charting.ChartTypes.GenericChart) -> ch.ShowChart() |> ignore; "(Chart)")

let file = @"C:\< cntk log file reference>"

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
LiveChart.FastLineIncremental(obsEE |> Observable.map (fun x->x.Epoch,x.CE),Title="Epoch CE")
|> Chart.WithXAxis(Title="Epoch");;

(*
cts.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
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
Multiple items
namespace FSharp.Control

--------------------
namespace Microsoft.FSharp.Control
namespace FSharp.Control.Reactive
namespace FSharp.Charting
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 : ChartTypes.GenericChart
module ChartTypes

from FSharp.Charting
Multiple items
type GenericChart =
  inherit obj
  new : chartType:SeriesChartType -> GenericChart
  member ApplyToChart : fn:(Chart -> unit) -> GenericChart
  member CopyAsBitmap : unit -> Image
  member CopyChartToClipboard : unit -> unit
  member CopyChartToClipboardEmf : control:Control -> unit
  member private ForceLegend : unit -> Legend
  member private ForceTitle : unit -> Title
  member private GetCustomProperty : name:string * def:'T -> 'T
  member SaveChartAs : filename:string * format:ChartImageFormat -> unit
  ...

Full name: FSharp.Charting.ChartTypes.GenericChart

--------------------
new : chartType:Windows.Forms.DataVisualization.Charting.SeriesChartType -> ChartTypes.GenericChart
member ChartTypes.GenericChart.ShowChart : unit -> Windows.Forms.Form
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val file : string

Full name: Script.file
val cts : Threading.CancellationTokenSource

Full name: Script.cts
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>

Full name: Script.obs
val fPost : obj

Full name: Script.fPost
Multiple items
module Observable

from Microsoft.FSharp.Control

--------------------
module Observable

from FSharp.Control.Reactive
property Threading.CancellationTokenSource.Token: Threading.CancellationToken
val obsCntk : IObservable<obj>

Full name: Script.obsCntk
Multiple items
val map : mapping:('T -> 'U) -> source:IObservable<'T> -> IObservable<'U>

Full name: Microsoft.FSharp.Control.Observable.map

--------------------
val map : f:('a -> 'b) -> source:IObservable<'a> -> IObservable<'b>

Full name: FSharp.Control.Reactive.Observable.map
val choose : chooser:('T -> 'U option) -> source:IObservable<'T> -> IObservable<'U>

Full name: Microsoft.FSharp.Control.Observable.choose
val obsEE : IObservable<obj>

Full name: Script.obsEE
type LiveChart =
  static member Area : data:IObservable<#seq<'a1 * 'a2>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart (requires 'a1 :> key and 'a2 :> value)
  static member Bar : data:IObservable<#seq<'a1 * 'a2>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart (requires 'a1 :> key and 'a2 :> value)
  static member Bubble : data:IObservable<#seq<'a1 * 'a2 * 'a3>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart (requires 'a1 :> key and 'a2 :> value and 'a3 :> value)
  static member BubbleIncremental : data:IObservable<#key * #value * #value> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart
  static member Candlestick : data:IObservable<#seq<'a1 * 'a2 * 'a3 * 'a4 * 'a5>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart (requires 'a1 :> key and 'a2 :> value and 'a3 :> value and 'a4 :> value and 'a5 :> value)
  static member Candlestick : data:IObservable<seq<#value * #value * #value * #value>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
  static member CandlestickIncremental : data:IObservable<#key * #value * #value * #value * #value> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
  static member CandlestickIncremental : data:IObservable<'a0 * #value * #value * #value> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart (requires 'a0 :> key and 'a0 :> value)
  static member Column : data:IObservable<#seq<'a1 * 'a2>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?ColumnWidth:float -> GenericChart (requires 'a1 :> key and 'a2 :> value)
  static member ColumnIncremental : data:IObservable<#key * #value> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?ColumnWidth:float -> GenericChart
  ...

Full name: FSharp.Charting.LiveChart
static member LiveChart.FastLineIncremental : data:IObservable<#key * #value> * ?Name:string * ?Title:string * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
val x : obj
type Chart =
  static member Area : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
  static member Area : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
  static member Bar : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
  static member Bar : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
  static member BoxPlotFromData : data:seq<#key * #seq<'a2>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?Percentile:int * ?ShowAverage:bool * ?ShowMedian:bool * ?ShowUnusualValues:bool * ?WhiskerPercentile:int -> GenericChart (requires 'a2 :> value)
  static member BoxPlotFromStatistics : data:seq<#key * #value * #value * #value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?Percentile:int * ?ShowAverage:bool * ?ShowMedian:bool * ?ShowUnusualValues:bool * ?WhiskerPercentile:int -> GenericChart
  static member Bubble : data:seq<#value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart
  static member Bubble : data:seq<#key * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart
  static member Candlestick : data:seq<#value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
  static member Candlestick : data:seq<#key * #value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
  ...

Full name: FSharp.Charting.Chart
static member Chart.WithXAxis : ?Enabled:bool * ?Title:string * ?Max:float * ?Min:float * ?Log:bool * ?ArrowStyle:ChartTypes.AxisArrowStyle * ?LabelStyle:ChartTypes.LabelStyle * ?IsMarginVisible:bool * ?MajorGrid:ChartTypes.Grid * ?MinorGrid:ChartTypes.Grid * ?MajorTickMark:ChartTypes.TickMark * ?MinorTickMark:ChartTypes.TickMark * ?TitleAlignment:Drawing.StringAlignment * ?TitleFontName:string * ?TitleFontSize:float * ?TitleFontStyle:Drawing.FontStyle * ?TitleColor:Drawing.Color * ?ToolTip:string -> ('a0 -> 'a0) (requires 'a0 :> ChartTypes.GenericChart)
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/7Rn
Posted:7 years ago
Author:Faisal Waris
Tags: cntk , fsharp.charting