This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Superman Returns': 3.5, 'The Night Listener': 4.0}, | |
'Claudia Puig': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0, | |
'The Night Listener': 4.5, 'Superman Returns': 4.0, | |
'You, Me and Dupree': 2.5}, | |
'Mick LaSalle': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0, | |
'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0, | |
'You, Me and Dupree': 2.0}, | |
'Jack Matthews': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0, | |
'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5}, | |
'Toby': {'Snakes on a Plane':4.5,'You, Me and Dupree':1.0,'Superman Returns':4.0}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
let critics = | |
Map.of_list [("Lisa Rose", | |
Map.of_list [("Lady in the Water", 2.5);("Snakes on a Plane", 3.5); | |
("Just My Luck", 3.0);("Superman Returns", 3.5); | |
("You, Me and Dupree", 2.5);("The Night Listener", 3.0)];); | |
("Gene Seymour", | |
Map.of_list [("Lady in the Water", 3.0);("Snakes on a Plane", 3.5); | |
("Just My Luck", 1.5);("Superman Returns", 5.0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
let critics = | |
Map.of_list [("Lisa Rose", | |
Map.of_list [("Lady in the Water", 2.5);("Snakes on a Plane", 3.5); | |
("Just My Luck", 3.0);("Superman Returns", 3.5); | |
("You, Me and Dupree", 2.5);("The Night Listener", 3.0)];); | |
("Gene Seymour", | |
Map.of_list [("Lady in the Water", 3.0);("Snakes on a Plane", 3.5); | |
("Just My Luck", 1.5);("Superman Returns", 5.0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets recommendations for a person by using a weighted average | |
# of every other user's rankings | |
def getRecommendations(prefs,person,similarity=sim_pearson): | |
totals={} | |
simSums={} | |
for other in prefs: | |
# don't compare me to myself | |
if other==person: continue | |
sim=similarity(prefs,person,other) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
module Map = | |
let insertWith (f:'a -> 'a -> 'a) (k:'tkey) (v:'a) (m:Map<'tkey, 'a>) = | |
match Map.tryfind k m with | |
| None -> Map.add k v m | |
| Some x -> let res = f v x | |
Map.add k res m | |
// Gets recommendations for a person by using a weighted average |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prefs = Map String (Map String Double) | |
def transformPrefs(prefs): | |
result={} | |
for person in prefs: | |
for item in prefs[person]: | |
result.setdefault(item,{}) | |
# Flip item and person | |
result[item][person]=prefs[person][item] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// F# | |
let transformPrefs | |
(prefs:Map<string, Map<string, float>>) = | |
let add k1 k2 v m = | |
let curInner = | |
match Map.tryfind k1 m with | |
| None -> Map.empty | |
| Some x -> x | |
m |> Map.add k1 (Map.add k2 v curInner) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
module Option = | |
let some (n:'b) (f:'a -> 'b) (opt:'a option) : 'b = | |
match n, f, opt with | |
| n, _, None -> n | |
| _, f, Some x -> f x | |
module Map = | |
/// Inserts into the Map with the given function if already exists, else adds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
module Option = | |
let some (n:'b) (f:'a -> 'b) (opt:'a option) : 'b = | |
match n, f, opt with | |
| n, _, None -> n | |
| _, f, Some x -> f x | |
module Map = | |
let insertWith (f:'a -> 'a -> 'a) (k:'tkey) (v:'a) (m:Map<'tkey, 'a>) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#light | |
module SeqMonad = | |
let bindS l f = Seq.concat (Seq.map f l) | |
let returnS l = seq { yield l } | |
type SeqBuilder() = | |
member x.Delay(f) = f() | |
member x.Bind(l, f) = bindS l f | |
member x.Return(l) = returnS l |