This file contains hidden or 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
//Average rating for all other rated items by the user | |
//except the item "except" | |
let rBaru(u:float list)(except:int)= | |
let filtered = u |> List.mapi(fun i j -> if i <> except then j else 0.0) | |
|> List.filter(fun t -> t <> 0.0) | |
float ( List.sum filtered ) / float filtered.Length | |
//The following function finds the common item indices | |
let commonItemIndices (ratings:(float list)list)(a:int)(u:int)= |
This file contains hidden or 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
let SimuDot (ratings :(float list)list) (a:int)(u:int)= | |
let num = List.zip ratings.[a] ratings.[u] | |
|> List.sumBy (fun item -> fst item * snd item) | |
let d1 = ratings.[a] |> List.sumBy (fun item -> item * item ) | |
let d2 = ratings.[u] |> List.sumBy (fun item -> item * item ) | |
if d1 = 0.0 || d2 = 0.0 then 0.0 else num / (sqrt d1 * sqrt d2) | |
let ratings = [[4.;0.;5.;5.];[4.;2.;1.;0.];[3.;0.;2.;4.];[4.;4.;0.;0.];[2.;1.;3.;5.]] | |
SimuDot ratings 0 1 |
This file contains hidden or 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
//Mean Absolute Error | |
let mae (ratings:float list)(predictions:float list) = | |
(List.zip ratings predictions |> List.sumBy (fun t -> abs (fst t - snd t))) | |
/float ratings.Length | |
//Normalized Mean Absolute Error | |
let nmae (ratings:float list)(predictions:float list) = | |
let rMax = ratings |> List.max | |
let rMin = ratings |> List.min | |
(mae ratings predictions )/(rMax - rMin) |
This file contains hidden or 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
//Calculates the standard deviation | |
let stddev(list:float list)= | |
sqrt (List.fold (fun acc elem -> acc + (float elem - List.average list) ** 2.0 ) 0.0 | |
list / float list.Length) | |
let trueRanks = [1.;2.;3.;4.;5.;5.;7.;8.;9.;10.] | |
let predictedRanks = [1.;2.;3.;4.;6.;7.;5.;8.;10.;9.] | |
let uBar = trueRanks |> List.average | |
let upBar = predictedRanks |> List.average |
This file contains hidden or 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
//Non personalized baseline predictor | |
let baseline (ratings:(float list)list) = | |
let mu = ratings |> List.map ( fun ra -> [for i in 0 .. ra.Length - 1 -> ra.[i]] | |
|> List.filter (fun t -> t <> 0.0) | |
|> List.average) | |
|> List.average | |
let mutable bu = ratings |> List.sumBy (fun rating -> [for i in 0 .. rating.Length - 1 -> rating.[i]] | |
|> List.filter (fun ri -> ri <> 0.0) | |
|> List.sumBy (fun ri -> ri - mu)) | |
This file contains hidden or 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
// Learn more about F# at http://fsharp.org | |
// See the 'F# Tutorial' project for more help. | |
//Comprehensive coverage of Collaborative Filtering Techniques | |
//http://www.hindawi.com/journals/aai/2009/421425/ | |
module confusion = | |
let TP (matches : int [] []) = | |
matches |> Array.mapi( fun i j -> matches.[i].[i]) |> Array.sum |
This file contains hidden or 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
let sentence1 = "this is a a sample" | |
let sentence2 = "this is another another example example example" | |
let word = "example" | |
let numberOfDocs = 2. | |
let tf1 = sentence1.Split ' ' |> Array.filter ( fun t -> t = word) | |
|> Array.length | |
let tf2 = sentence2.Split ' ' |> Array.filter ( fun t -> t = word) | |
|> Array.length |
This file contains hidden or 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
namespace IRLib | |
module asymSimilarity = | |
let private getABCD (first :string list)(second : string list) = | |
let all = Set.union (first |> Set.ofList) (second |> Set.ofList) |> Set.toList | |
let firstMatches = all |> List.map (fun t -> first |> List.contains t ) | |
let secondMatches = all |> List.map (fun t -> second |> List.contains t ) |
This file contains hidden or 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
open System.IO | |
let image = System.Drawing.Image.FromFile(@"C:\personal\rose.jpg") | |
let image2 = System.Drawing.Image.FromFile(@"C:\personal\potato.jpg") | |
let ms = new MemoryStream() | |
image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg) | |
let bytes = ms.ToArray() |> Array.map int |> List.ofArray | |
let ms2 = new MemoryStream() | |
image2.Save(ms2,System.Drawing.Imaging.ImageFormat.Jpeg) |