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
#load "...\packages\MathNet.Numerics.FSharp.3.10.0\MathNet.Numerics.fsx" | |
open MathNet.Numerics.LinearAlgebra | |
open System.IO | |
let velocities = vector[23.;4.;5.;2.] | |
//let y = matrix [[1.;3.] | |
// [1.;5.] | |
// [1.;4.]] |
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.Text.RegularExpressions | |
type SentiWordNetEntry = {POS:string; ID:string; PositiveScore:string; NegativeScore:string; Words:string} | |
let sentiWordList = System.IO.File.ReadAllLines(@"SentiWordNet_3.0.0_20130122.txt") | |
|> Array.filter (fun line -> not (line.StartsWith("#"))) | |
|> Array.map (fun line -> line.Split '\t') | |
|> Array.map (fun lineTokens -> {POS = lineTokens.[0]; | |
ID = lineTokens.[1]; | |
PositiveScore = lineTokens.[2].Trim(); |
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
//Finds the median | |
let median numbers = | |
let sorted = List.sort numbers | |
let n = float numbers.Length | |
let x = int (n/2.) | |
let mutable result = 0.0 | |
if (float numbers.Length) % 2. = 0.0 then result <- float (numbers.[x] + | |
numbers.[x-1]) / 2.0 | |
else result <- float numbers.[x] | |
result |
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 | |
open System | |
open System.Windows.Forms | |
open System.Drawing | |
//The type that represents each row of the training | |
//or the test dataset | |
type Entry = {Label :string; Values : int list} | |
//Calculates Squared Euclidean distance between pixel |
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) |
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
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
// 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
//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)) | |