Fully Responsive Theme
Resize your Browser to see the Effect
Parallax Effect
Scroll and Notice the Header Image

A New Year Resolution: F# Practice – Frequency chart, some graphics

2014 will be the year I get stuck into F# and more – so the grand plan:

  • The basics, starting with the sample below
  • Computation expressions and Async/Parallel basics
  • Digging into Deedle/R
  • Hadoop
  • MongoDB and Neo4j

The projects at time of writing will start as simple as the one below, however the current plan is:

  • DNA-Ribosome string simulator – this will require parallel and agent based coding to enable it to handle hundreds of thousands of bases, compile them into actual protein lists. This relies on external data such as http://www.ncbi.nlm.nih.gov/Taxonomy/taxonomyhome.html/index.cgi?chapter=tgencodes
  • Simple Gene expression programming – this will allow me to get the hang of code quotations and splicing, may lead to the next project
  • Neural networking – this may be combined with the above project as both subjects I’ve only got a beginner’s view of!** Like a few bloggers, I am finding that my own site is a good place to review code solutions that I’ve puzzled out for myself. As I’m not a fan of the cut n paste via google method, I’ve got to wrestle with syntax line by line. So here is where I’ll keep the results. Today is a couple of hours foundation work using charts, pattern matching and a few other basic ideas – the chart below is something useful to budding cryptography students: it shows the most commonly occurring letters in a sample of text. The next stage is to make the functions work as parallel units for multi file reading.

frequency chart

open FSharp.Charting
open System.Windows.Forms
open System.Drawing

let counter(str:string,ch:char) = str.ToCharArray() 
                                    |> Array.sumBy(fun s ->
                                                        let x = 0
                                                        match s with 
                                                        | c when ch = s-> x + 1
                                                        | _ -> x)

let chrs = ['e';'a';'o';'s';'t'] 
let sample = "tesqatetweafwefwlvuioneuiounrv;onr;rvoian;c;oi;oijewrrfaa"
let character = chrs |> List.map(fun x-> counter (sample ,x)) 
                                        |> List.zip chrs 
                                        |> List.map (fun (a, b)-> string a,b)

let frequencyChart = character |> Chart.Bar

let form = new Form(Visible = true , 
                    TopMost = true,
                    Width = 700, 
                    Height = 500)

form.Controls.Add( new ChartTypes.ChartControl(frequencyChart, 
                                               Dock = DockStyle.Fill))

For a diversion, I had a play with an idea I had to do with a thing I saw in Logo years ago:


open System.Windows.Forms
open System.Drawing

let showForm() =
    let form = new Form(TopMost = true, ClientSize = new Size(600,400))
    form.Paint.Add(fun pe -> pe.Graphics.Clear(Color.White)
                             for i in 0 .. 40 do
                             pe.Graphics.DrawLine(Pens.DarkMagenta, 1, 1, 300 , i*10)
                             pe.Graphics.DrawLine(Pens.Black,1,400,300,i * 10)
                             pe.Graphics.DrawLine(Pens.Red, 600,400,300, i* 10)
                             pe.Graphics.DrawLine(Pens.Green, 600,1, 300,i* 10)