Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Tech Days Paris Intoduction F# and Collective Intelligence
1. F# on the Road to Visual Studio
2010
Robert Pickering – LexiFi (ALTi)
With thanks to Don Syme, Leon
“secretGeek” Bambrick, Chris Smith
and the puppies
2. Session Overview
• Why was F# created? Why learn F#?
• A taste of the F# language
– Especially the functional side!
• See a complete working F# “Collective
Intelligence” application
8. I'll let you in on a secret: I'm doing F# simply
because it's lots and lots of fun. In a very broad
sense of the word: functional programming is
fun, OO programming with F# is fun, watching
people use F# is fun.
One of the wonderful things about F# is that you
can actually end up working in your domain. In
the zone. With F#, you're not necessarily quot;justquot; a
programmer! You're likely to also be a
probabilistic modeller, or an AutoCAD
engineer, or a finance engineer, or a symbolic
programmer, or one of many other things.
- Don Syme,
F#’s creator
9. F# is unique amongst both imperative and
declarative languages in that it is the golden
middle road where these two extremes converge.
F# takes the best features of both paradigms and
tastefully combines them in a highly productive
and elegant language that both scientists and
developers identify with. F# makes programmers
better mathematicians and mathematicians
better programmers.
- Eric Meijer,
Forward to Expert F#
10. A Few Words From …
Julien Laugel
Head of Research & Development
EuroPerformance
11. F#: Combining Paradigms
I've been coding in F# lately, for a production task.
F# allows you to move smoothly in your programming style... I start
with pure functional code, shift slightly towards an object-oriented
style, and in production code, I sometimes have to do some
imperative programming.
I can start with a pure idea, and still finish my project with realistic
code. You're never disappointed in any phase of the project!
Julien Laugel, Head of Research & Development, EuroPerformance
13. Road Map
• Current Release: September CTP for VS 2008
• Next Release: as part of VS 2010 beta 1
• Plugin for VS Shell and CodePlex release in VS
2010 timeframe
• More:
http://blogs.msdn.com/dsyme/archive/2008/12/10/fsharp-to-ship-as-part-of-visual-studio-2010.aspx
14. Part 2
F# the Language ...
... and the Functional
Point of View
15. Code!
//F# //C#
open System using System;
let a = 2
namespace ConsoleApplication1
Console.WriteLine a {
class Program
{
static int a()
{
return 2;
}
static void Main(string[] args)
{
Console.WriteLine(a);
}
}
}
17. Let Bindings & Literals
Declaration
An identifier A comment
of a binding
let aString = quot;Stringyquot; // a string
Like “var” in
A literal
C#
18. Lists
Let binding
The empty
// the empty list
let emptyList = [] list
Literal Concatenate
The empty
list
// adding to a list
let conact = quot;Onequot; :: []
19. Lists
let list = 1 :: 2 :: 3 :: []
These are
the same
let list = [1; 2; 3]
20. Functions
Parameter
// a function
let addTen = fun x -> x + 10
Let binding Result
21. Functions
Parameter
// shorter version
let addTen x = x + 10
Let binding Result
22. Functions
Let binding Parameters
// multi parameters and
// intermediate results
let addThenTimesTwo x y =
let temp = x + y Intermediate
temp * 2 Value
Whitespace
Sensitive Result
23. Pattern Matching
// simple pattern matching
let matching n =
match n with
| 1 -> quot;Onequot;
Pattern | 2 -> quot;Twoquot; Result
| _ -> quot;Otherquot;
24. Pattern Matching
// pattern matching Recursive
// over lists
let rec addOne list = function
Pattern match list with
| head :: tail ->
head + 1 :: addOne tail
| [] -> []
Result Recursive call
// more pattern matching
// over lists
let rec subOne list =
match list with
| head :: tail ->
head - 1 :: subOne tail
| [] -> []
26. Functions as Parameters
// pattern matching Function
// over lists
let rec map func list = parameter
match list with
| head :: tail ->
Call function func head :: map tail
| [] -> []
let addOne list = List.map (fun x -> x + 1) list
let subOne list = List.map (fun x -> x + 1) list
28. Representing a Blog
• A blog can be represented by the frequency
that words appear in it
• Most and least common words are cut
– words like “the” are ignored
– words like “woah” are ignored
Phone Email Book People Affiliate
Heckler Spray 0 0 1 2 0
Shiny Shiny 3 0 0 5 0
Chris Garret on New Media 1 75 12 60 24
30. Measuring “Closeness” of Blogs
• Pervious slide shows “Euclidean Distance”
• While this could be use we use “Pearson
correlation”
– “Pearson correlation” corrects for the problem
that some blogs are longer than others
where
31. Pearson correlation in F#
let pearson (wc1: seq<float>) (wc2: seq<float>) =
let sum = PSeq.reduce (+)
let sum1 = sum wc1
let sum2 = sum wc2
let sumSq1 = sum (Seq.map (fun x -> x * x) wc1)
let sumSq2 = sum (Seq.map (fun x -> x * x) wc2)
let pSum = sum (Seq.map2 (fun x y -> x * y) wc1 wc2)
let len = float (Seq.length wc1)
let num = pSum - ((sum1 * sum2) / len)
let den = sqrt ((sumSq1 - (sum1 * sum1) / len)
* (sumSq2 - (sum2 * sum2) / len))
if den = 0. then 0. else num / den
34. How we implement hierarchical clustering efficiently in F#
THE ALGORITHM
35. Map Reduce
Fetch Data Process Data Build Tree
Start End
Clean Data
Calculate Words Used
Split Data
Make HTTP Request Build Tree
Count Word
Create Master Word List
36. Map Reduce
Fetch Data Process Data Build Tree
Start End
Parallelized by the
Parallelized by Asynchronous Workflows
Parallel Task Library
37. 3 Layer Architecture
Data Access – dataAccess.fs
Helpers
extentions.fs
Business Logic – algo.fs
UI – Program.fs Tests – test.fsx
40. Other Things To Cluster
• Any other kind of text:
– Books from project Gutenberg
– Twitter!
– Messages boards or other web pages
• People in social networks
• Reviewers on Amazon
• Companies based on metrics