Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#I "../NeuralFish"
#load "NeuralFish_dev.fsx"
open NeuralFish.Types
open NeuralFish.Core
open NeuralFish.EvolutionChamber
type MsgType =
| Ham
| Spam
| NotSure
let data : TrainingAnswerAndDataSet<MsgType> =
let convertDataIntoVector (hamOrSpam, data) =
let convertDataIntoVector (data : string) =
data
|> Seq.map (fun x -> float x)
(hamOrSpam, data |> convertDataIntoVector)
let splitDataIntoTuple (data : string) =
let matchHamOrSpam (hamOrSpam : char array) =
match hamOrSpam with
| [|'h';'a';'m';_|] | [|'h';'a';'m'|] ->
Ham
| _ ->
Spam
let msgType =
data
|> Seq.take 4
|> Seq.toArray
|> matchHamOrSpam
let StringRemoveFirstFour (sequence : string) =
sequence
|> Seq.rev
|> Seq.take ((sequence |> Seq.length) - 4)
|> Seq.rev
(msgType, data |> StringRemoveFirstFour |> System.String.Concat )
sprintf "%s/SMSSpamCollection" __SOURCE_DIRECTORY__
|> System.IO.File.ReadAllLines
|> Array.Parallel.map splitDataIntoTuple
|> Array.Parallel.map convertDataIntoVector
let spamOrHamOutputHookId = 0
let (convertNetworkOutputToHamOrSpam : InterpretActuatorOutputFunction<MsgType>) =
(fun networkOutputMap ->
match networkOutputMap |> Map.tryFind spamOrHamOutputHookId with
| Some networkOutput ->
if (networkOutput > 0.99) then
NotSure
else if (networkOutput < 0.01) then
Ham
else
Spam
| None ->
NotSure
)
let (scoreAnswer : ScoreNeuralNetworkAnswerFunction<MsgType>) =
(fun correctAnswer guessedAnswer ->
if (guessedAnswer = correctAnswer) then
match correctAnswer with
| Spam ->
1.0
| Ham ->
2.0
| NotSure ->
0.0
else
match correctAnswer with
| Spam ->
-1.0
| Ham ->
-2.0
| NotSure ->
0.0
)
let scoredRecords =
let trainingProperties =
let outputHookIds = [spamOrHamOutputHookId]
let activationFunctions =
Map.empty
|> Map.add 0 sigmoid
let learningAlgorithm = NoLearning
let defaultTrainingProperties = getDefaultTrainingProperties data convertNetworkOutputToHamOrSpam scoreAnswer activationFunctions outputHookIds learningAlgorithm defaultInfoLog
{ defaultTrainingProperties with
ShuffleDataSet = false
MaximumMinds = 25
MaximumThinkCycles = 50
AmountOfGenerations = 50
DividePopulationBy = 5
}
trainSingleScopeProblem trainingProperties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment