public static bool SuccessConditionLadderPrint(List <double> predicted, List <double> actual, string print) { var phLadder = Numbery.Denormalise(predicted[0], Util.MaxLadderPoints); var paLadder = Numbery.Denormalise(predicted[1], Util.MaxLadderPoints); var ahLadder = Numbery.Denormalise(actual[0], Util.MaxLadderPoints); var aaLadder = Numbery.Denormalise(actual[1], Util.MaxLadderPoints); if (print == "") { Console.WriteLine("[{0}, {1} Vs {2}, {3}] Suggested Bet: ${8:0.00}", phLadder, paLadder, ahLadder, aaLadder); } else if (!string.IsNullOrEmpty(print)) { Filey.Save(string.Format("[{0}, {1} Vs {2}, {3}] Suggested Bet: ${8:0.00}", phLadder, paLadder, ahLadder, aaLadder), print); } if (phLadder > paLadder && ahLadder > aaLadder) { return(true); } if (phLadder < paLadder && ahLadder < aaLadder) { return(true); } if (phLadder == paLadder && ahLadder == aaLadder) { return(true); } return(false); }
public static Data GetMatchDataBetween(List <Season> seasons, RoundShell fromRoundShell, RoundShell toRoundShell, DataInterpretation interpretation = null) { var data = new Data(); //TODO: It's a little messy to new this up here var league = new League(seasons); var rounds = league.GetRounds(0, 0, toRoundShell.Year, toRoundShell.Number).Where(x => x.Matches.Count > 0).ToList(); var matches = rounds.Where(r => (r.EffectiveId() > fromRoundShell.EffectiveId())) .SelectMany(r => r.Matches); foreach (var m in matches) { var dataPoint = new DataPoint(); var history = rounds.Where(r => !r.Matches.Any(rm => rm.Date >= m.Date)).SelectMany(r => r.Matches).ToList(); dataPoint.Inputs = (BuildInputs(history, m, interpretation)); dataPoint.Outputs = (new List <double>() { Numbery.Normalise(m.HomeScore().Total(), Util.MaxScore), Numbery.Normalise(m.AwayScore().Total(), Util.MaxScore) }); dataPoint.Reference = m.ToTuple(); data.DataPoints.Add(dataPoint); } return(data); }
public void TestNormaliser_For_Positive_Offset_Result() { var result = Numbery.Normalise(50, new double[] { 0, 100 }, new double[] { 100, 200 }, Numbery.NormalisationMethod.Normal); Assert.AreEqual(150, result); }
public void DecodeDNA() { var currentDNACount = 0; NumHiddenLayers = (int) Numbery.DenormaliseObsolete(DNA[currentDNACount], NumHiddenLayersRange.Lower, NumHiddenLayersRange.Upper, 0, 1); currentDNACount++; NumInHidden = new List <int>(); for (var i = 0; i < NumInHiddenCount; i++)//TODO: how do I know how many of these there are? { NumInHidden.Add( (int) Numbery.DenormaliseObsolete(DNA[currentDNACount], NumInHiddenRange.Lower, NumInHiddenRange.Upper, 0, 1)); currentDNACount++; } RangeSize = (int)Numbery.DenormaliseObsolete(DNA[currentDNACount], RangeSizeRange.Lower, RangeSizeRange.Upper, 0, 1); currentDNACount++; Epochs = (int)Numbery.DenormaliseObsolete(DNA[currentDNACount], EpochsRange.Lower, EpochsRange.Upper, 0, 1); currentDNACount++; Facade = new List <bool>(); for (var i = 0; i < FacadeRangeCount; i++)//TODO: how do I know how many of these there are? { Facade.Add(Numbery.DenormaliseObsolete(DNA[currentDNACount], FacadeRange.Lower, FacadeRange.Upper, 0, 1) > 0.5 ? true : false); currentDNACount++; } }
public void TestNormaliser_For_Negative_Offset_Result() { var result = Numbery.Normalise(25, new double[] { -25, 75 }, new double[] { -100, 0 }, Numbery.NormalisationMethod.Normal); Assert.AreEqual(-50, result); }
public static double BetReturnGoalAndPoints(List <double> predicted, List <double> actual, double homeOdds, double awayOdds) { var phGoals = Numbery.Denormalise(predicted[0], Util.MaxGoals); var phPoints = Numbery.Denormalise(predicted[1], Util.MaxPoints); var paGoals = Numbery.Denormalise(predicted[2], Util.MaxGoals); var paPoints = Numbery.Denormalise(predicted[3], Util.MaxPoints); var phScore = phGoals * 6 + phPoints; var paScore = paGoals * 6 + paPoints; var ahGoals = Numbery.Denormalise(actual[0], Util.MaxGoals); var ahPoints = Numbery.Denormalise(actual[1], Util.MaxPoints); var aaGoals = Numbery.Denormalise(actual[2], Util.MaxGoals); var aaPoints = Numbery.Denormalise(actual[3], Util.MaxPoints); var ahScore = ahGoals * 6 + ahPoints; var aaScore = aaGoals * 6 + aaPoints; //Console.WriteLine("[{0}, {1} Vs {2}, {3}]", phScore, paScore, ahScore, aaScore); if (phScore > paScore && ahScore > aaScore) { return(homeOdds); } if (phScore < paScore && ahScore < aaScore) { return(awayOdds); } if (phScore == paScore && ahScore == aaScore) { return(1.00); } return(0.00); }
public override dynamic Decode() { var index = (int)Numbery.DenormaliseObsolete(Encoded, Min, Max, 0, 1); Decoded = AllowedCharacters[index]; return(Decoded); }
public override double Encode() { var index = AllowedCharacters.IndexOf(Decoded); Encoded = Numbery.Normalise(index, Min, Max, 0, 1); return(Encoded); }
public static bool SuccessConditionTotalPrint(List <double> predicted, List <double> actual, string print = "") { var phTotal = Numbery.Denormalise(predicted[0], Util.MaxScore); var paTotal = Numbery.Denormalise(predicted[1], Util.MaxScore); var ahTotal = Numbery.Denormalise(actual[0], Util.MaxScore); var aaTotal = Numbery.Denormalise(actual[1], Util.MaxScore); if (print == "") { Console.WriteLine("[{0}, {1} Vs {2}, {3}]", phTotal, paTotal, ahTotal, aaTotal); } else if (!string.IsNullOrEmpty(print)) { Filey.Append(string.Format("[{0}, {1} Vs {2}, {3}]", phTotal, paTotal, ahTotal, aaTotal), print); } if (phTotal > paTotal && ahTotal > aaTotal) { return(true); } if (phTotal < paTotal && ahTotal < aaTotal) { return(true); } if (phTotal == paTotal && ahTotal == aaTotal) { return(true); } return(false); }
public static bool SuccessConditionGoalAndPoints(List <double> predicted, List <double> actual) { var phGoals = Numbery.Denormalise(predicted[0], Util.MaxGoals); var phPoints = Numbery.Denormalise(predicted[1], Util.MaxPoints); var paGoals = Numbery.Denormalise(predicted[2], Util.MaxGoals); var paPoints = Numbery.Denormalise(predicted[3], Util.MaxPoints); var phScore = phGoals * 6 + phPoints; var paScore = paGoals * 6 + paPoints; var ahGoals = Numbery.Denormalise(actual[0], Util.MaxGoals); var ahPoints = Numbery.Denormalise(actual[1], Util.MaxPoints); var aaGoals = Numbery.Denormalise(actual[2], Util.MaxGoals); var aaPoints = Numbery.Denormalise(actual[3], Util.MaxPoints); var ahScore = ahGoals * 6 + ahPoints; var aaScore = aaGoals * 6 + aaPoints; //Console.WriteLine("[{0}, {1} Vs {2}, {3}]", phScore, paScore, ahScore, aaScore); if (phScore > paScore && ahScore > aaScore) { return(true); } if (phScore < paScore && ahScore < aaScore) { return(true); } if (phScore == paScore && ahScore == aaScore) { return(true); } return(false); }
public double HomeWinningness() { const double MaxWickets = 10.0; const double MaxRuns = 75.0; var margin = 0.5; var marginAddition = 0.0; if (Result.MarginByWickets > 0) { marginAddition = Numbery.Normalise(Result.MarginByWickets, 0, MaxWickets, 0, 0.5); } else if (Result.MarginByRuns > 0) { marginAddition = Numbery.Normalise(Result.MarginByRuns, 0, MaxRuns, 0, 0.5); } if (Result.Victor == Victor.Home) { margin += marginAddition; } else if (Result.Victor == Victor.Away) { margin -= marginAddition; } return(margin); }
public override IEnumerable <double> BuildOutputs(Match m) { return(new List <double>() { Numbery.Normalise(m.HomeScore().Total(), Util.MaxScore) - Numbery.Normalise(m.AwayScore().Total(), Util.MaxScore) }); }
public void TestNormaliser_For_NormaliseDenormaliseAsymptotic() { var input = 10.0; var normalised = Numbery.Normalise(input, 5, 55, 25, 775, Numbery.NormalisationMethod.Asymptotic); var output = Numbery.Denormalise(normalised, 25, 775, 5, 55, Numbery.NormalisationMethod.Asymptotic); Assert.IsTrue(output < input + 0.000001); Assert.IsTrue(output > input - 0.000001); }
public override IEnumerable <double> BuildOutputs(Match m) { return(new List <double>() { Numbery.Normalise(m.HomeScore().Goals, Util.MaxGoals), Numbery.Normalise(m.HomeScore().Points, Util.MaxPoints), Numbery.Normalise(m.AwayScore().Goals, Util.MaxGoals), Numbery.Normalise(m.AwayScore().Points, Util.MaxPoints) }); }
public static List <double> Deconvert(List <double> input) { var hGoals = Numbery.Denormalise(input[0], Util.MaxGoals); var hPoints = Numbery.Denormalise(input[1], Util.MaxPoints); var aGoals = Numbery.Denormalise(input[2], Util.MaxGoals); var aPoints = Numbery.Denormalise(input[3], Util.MaxPoints); return(new List <double>() { hGoals, hPoints, aGoals, aPoints }); }
public List <Match> Predict(int year, int round, bool print) { Func <double, double> rule = (m => m > 27.0 ? 15.00 : 0.00); var results = new List <Match>(); var rounds = League.GetRounds(0, 0, year, round).Where(x => x.Matches.Count > 0).ToList(); foreach (var m in rounds.Where(r => (r.Year == year && r.Number == round)).SelectMany(r => r.Matches)) { var history = rounds.Where(r => !r.Matches.Any(rm => rm.Date >= m.Date)).SelectMany(r => r.Matches).ToList(); var test = BuildInputs(history, m); var result = Net.Run(test); results.Add(new Match( m.Home, new Score(0, 0), new Score(0, 0), new Score(0, 0), new Score( Numbery.Denormalise(result[0], Util.MaxGoals), //, Numbery.NormalisationMethod.Asymptotic), Numbery.Denormalise(result[1], Util.MaxPoints) //, Numbery.NormalisationMethod.Asymptotic) ), m.Away, new Score(0, 0), new Score(0, 0), new Score(0, 0), new Score( Numbery.Denormalise(result[2], Util.MaxGoals), //, Numbery.NormalisationMethod.Asymptotic), Numbery.Denormalise(result[3], Util.MaxPoints) //, Numbery.NormalisationMethod.Asymptotic) ), m.Ground, m.Date)); var margin = Math.Abs(results.Last().HomeScore().Total() - results.Last().AwayScore().Total()); var wager = rule(margin); if (print) { Console.WriteLine("{0,9} Vs {1, 9}: {2}, Bet: ${3:0.00}", m.Home.Mascot, m.Away.Mascot, Printlayer(new[] { results.Last().HomeScore().Goals, results.Last().HomeScore().Points, results.Last().HomeScore().Total(), results.Last().AwayScore().Goals, results.Last().AwayScore().Points, results.Last().AwayScore().Total() }), wager); } } return(results); }
public static double ExtractInputSpecific(List <Match> s, Func <Match, bool> wherePredicate, int skipLength, Func <Match, double> sumSelector, double max) { var value = s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Skip(skipLength) .Take(1) .Sum(sumSelector); return(Numbery.Normalise(value, max)); }
public static double ExtractInputFromScoreScoreDateTuple(int takeLength, Func <Tuple <Score, Score, DateTime>, double> sumSelector, List <Tuple <Score, Score, DateTime> > homeOppositionScores, Func <double, double> maxFunc) { var value = homeOppositionScores .OrderByDescending(x => x.Item3) .Take(takeLength) .Sum(sumSelector); var max = maxFunc( homeOppositionScores .OrderByDescending(x => x.Item3) .Take(takeLength) .Count()); return(Numbery.Normalise(value, max)); }
public static bool SuccessConditionLadderGoalsAndPointsPrint(List <double> predicted, List <double> actual, string print) { Func <double, double> rule = (m => m > 27.0 ? 15.00 : 0.00); var phLadder = Numbery.Denormalise(predicted[0], Util.MaxLadderPoints); var paLadder = Numbery.Denormalise(predicted[1], Util.MaxLadderPoints); var phGoals = Numbery.Denormalise(predicted[2], Util.MaxGoals); var phPoints = Numbery.Denormalise(predicted[3], Util.MaxPoints); var paGoals = Numbery.Denormalise(predicted[4], Util.MaxGoals); var paPoints = Numbery.Denormalise(predicted[5], Util.MaxPoints); var phScore = phGoals * 6 + phPoints; var paScore = paGoals * 6 + paPoints; var ahLadder = Numbery.Denormalise(actual[0], Util.MaxLadderPoints); var aaLadder = Numbery.Denormalise(actual[1], Util.MaxLadderPoints); var ahGoals = Numbery.Denormalise(actual[2], Util.MaxGoals); var ahPoints = Numbery.Denormalise(actual[3], Util.MaxPoints); var aaGoals = Numbery.Denormalise(actual[4], Util.MaxGoals); var aaPoints = Numbery.Denormalise(actual[5], Util.MaxPoints); var ahScore = ahGoals * 6 + ahPoints; var aaScore = aaGoals * 6 + aaPoints; var margin = Math.Abs(phScore - ahScore); var wager = rule(margin); if (print == "") { Console.WriteLine("[{0}: {1}, {2}: {3} Vs {4}: {5}, {6}: {7}] Suggested Bet: ${8:0.00}", phLadder, phScore, paLadder, paScore, ahLadder, ahScore, aaLadder, aaScore, wager); } else if (!string.IsNullOrEmpty(print)) { Filey.Save(string.Format("[{0}: {1}, {2}: {3} Vs {4}: {5}, {6}: {7}] Suggested Bet: ${8:0.00}", phLadder, phScore, paLadder, paScore, ahLadder, ahScore, aaLadder, aaScore, wager), print); } if (phScore > paScore && ahScore > aaScore) { return(true); } if (phScore < paScore && ahScore < aaScore) { return(true); } if (phScore == paScore && ahScore == aaScore) { return(true); } return(false); }
public static double ExtractInputAverage(List <Match> s, Func <Match, bool> wherePredicate, int takeLength, Func <Match, double> sumSelector, Func <double> maxFunc) { if (s.Where(wherePredicate).Count() == 0) { return(0.5); } var value = s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Take(takeLength) .Average(sumSelector); return(Numbery.Normalise(value, maxFunc())); }
public static double ExtractInput(List <Match> s, Func <Match, bool> wherePredicate, int takeLength, Func <Match, double> sumSelector, Func <double, double> maxFunc) { var value = s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Take(takeLength) .Sum(sumSelector); var max = maxFunc( s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Take(takeLength) .Count()); return(Numbery.Normalise(value, max)); }
public void EncodeDNA() { DNA.Add(Numbery.Normalise(NumHiddenLayers, NumHiddenLayersRange.Lower, NumHiddenLayersRange.Upper, 0, 1)); foreach (var num in NumInHidden) { DNA.Add(Numbery.Normalise(num, NumInHiddenRange.Lower, NumInHiddenRange.Upper, 0, 1)); } DNA.Add(Numbery.Normalise(RangeSize, RangeSizeRange.Lower, RangeSizeRange.Upper, 0, 1)); DNA.Add(Numbery.Normalise(Epochs, EpochsRange.Lower, EpochsRange.Upper, 0, 1)); foreach (var datapoint in Facade) { DNA.Add(Numbery.Normalise(datapoint ? 1 : 0, FacadeRange.Lower, FacadeRange.Upper, 0, 1)); } }
/* * public void Test(Data data) * { * var successes = 0; * var stopwatch = new Stopwatch(); * stopwatch.Start(); * * NetworkActor.Facade.SetData(data); * var subset = NetworkActor.Facade.GetData(); * * for(var i = 0; i < subset.Inputs().Count; i++) * { * var input = subset.DataPoints[i].Inputs; * var output = NetworkActor.Network.Run(input); * var wager = CalculateWager(output); * Money -= wager; * var success = subset.SuccessCondition(output, subset.DataPoints[i].Outputs, null); * if (success) * { * successes++; * var composite = (Tuple<DateTime, string>)subset.DataPoints[i].Reference; * //Attempting to convert from "DataPoint Match reference to tuple reference * //Realised this wasn't used and commented out for now * * var homescore = (Match.FindMatchByTuple(, ).HomeScore().Total(); * var awayscore = ((Match) subset.DataPoints[i].Reference).AwayScore().Total(); * var odds = 0.0; * if(homescore > awayscore) * odds = ((Match)subset.DataPoints[i].Reference).HomeOdds; * if (homescore < awayscore) * odds = ((Match)subset.DataPoints[i].Reference).AwayOdds; * Money += wager*odds; * } * } * //Console.WriteLine("successes = " + (double)successes / (double)subset.Inputs().Count); * stopwatch.Stop(); * TimeToTest = stopwatch.ElapsedMilliseconds; * }*/ private double CalculateWager(List <double> output) { var wager = 0.0; var phGoals = Numbery.Denormalise(output[0], Util.MaxGoals); var phPoints = Numbery.Denormalise(output[1], Util.MaxPoints); var paGoals = Numbery.Denormalise(output[2], Util.MaxGoals); var paPoints = Numbery.Denormalise(output[3], Util.MaxPoints); var phScore = phGoals * 6 + phPoints; var paScore = paGoals * 6 + paPoints; var margin = Math.Abs(phScore - paScore); var ordered = Rules.OrderByDescending(x => x.Priority).ToList(); foreach (var rule in ordered) { wager = rule.Scenario(margin); } return(wager); }
public List <PredictedMatch> PredictWinners(int year, int round, bool isFinal, DataInterpretation interpretation = null) { var predictions = new List <PredictedMatch>(); var rounds = League.GetRounds(0, 0, year, round).Where(x => x.Matches.Count > 0).ToList(); foreach (var m in rounds.Where(r => r.Year == year && r.Number == round && r.IsFinal == isFinal).SelectMany(r => r.Matches)) { //TODO: Are we ordering in the right direction? var history = rounds.Where(r => !r.Matches.Any(rm => rm.Date >= m.Date)).SelectMany(r => r.Matches).OrderBy(h => h.Date).ToList(); var test = BuildInputs(history, m, interpretation); var result = Net.Run(test); predictions.Add(new PredictedMatch(m.Home, m.Away, m.Ground, m.Date, Numbery.Denormalise(result[0], Util.MaxScore), Numbery.Denormalise(result[1], Util.MaxScore), round)); } return(predictions); }
public static double ExtractInput(List <Match> s, Func <Match, bool> wherePredicate, int takeLength, Func <Match, double> sumSelector, Func <double, double> maxFunc) { var value = s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Take(takeLength) .Sum(sumSelector); var max = maxFunc( s .Where(wherePredicate) .OrderByDescending(x => x.Date) .Take(takeLength) .Count()); //TODO: confirm or remove //Attempting to reduce the impact of missing data by massaging 0's into 0.5s //return max == 0 ? 0.5 : Numbery.Normalise(value, max); return(Numbery.Normalise(value, max)); }
public static BettingActor GenerateRandomActor(Random random) { var representative = BettingActor.GetBestGuessBettingActor(); var numRules = random.Next(MinNumRules, MaxNumRules); for (var i = 0; i < numRules; i++) { var wager = Numbery.Normalise(random.NextDouble(), 0, 1, MinWager, MaxWager); var threshold = Numbery.Normalise(random.NextDouble(), 0, 1, MinThreshold, MaxThreshold); var rule = new BettingRule() { Priority = i, Wager = wager, Threshold = threshold }; representative.Rules.Add(rule); } return(representative); }
public static bool SuccessConditionScore(List <double> predicted, List <double> actual) { var phScore = Numbery.Denormalise(predicted[0], Util.MaxScore); var paScore = Numbery.Denormalise(predicted[1], Util.MaxScore); var ahScore = Numbery.Denormalise(actual[0], Util.MaxScore); var aaScore = Numbery.Denormalise(actual[1], Util.MaxScore); if (phScore > paScore && ahScore > aaScore) { return(true); } if (phScore < paScore && ahScore < aaScore) { return(true); } if (phScore == paScore && ahScore == aaScore) { return(true); } return(false); }
public static bool SuccessConditionTotalAsymptotic(List <double> predicted, List <double> actual, string legacy) { var phTotal = Numbery.Denormalise(predicted[0], Util.MaxScore, Numbery.NormalisationMethod.Asymptotic); var paTotal = Numbery.Denormalise(predicted[1], Util.MaxScore, Numbery.NormalisationMethod.Asymptotic); var ahTotal = Numbery.Denormalise(actual[0], Util.MaxScore); var aaTotal = Numbery.Denormalise(actual[1], Util.MaxScore); if (phTotal > paTotal && ahTotal > aaTotal) { return(true); } if (phTotal < paTotal && ahTotal < aaTotal) { return(true); } if (phTotal == paTotal && ahTotal == aaTotal) { return(true); } return(false); }
public static bool SuccessConditionTotal(List <double> predicted, List <double> actual) { var phTotal = Numbery.Denormalise(predicted[0], Util.MaxScore); var paTotal = Numbery.Denormalise(predicted[1], Util.MaxScore); var ahTotal = Numbery.Denormalise(actual[0], Util.MaxScore); var aaTotal = Numbery.Denormalise(actual[1], Util.MaxScore); Filey.Append(string.Format("[{0}, {1} Vs {2}, {3}]", phTotal, paTotal, ahTotal, aaTotal), @"C:\Users\Jack\Desktop\ANN Optimizer results.txt"); if (phTotal > paTotal && ahTotal > aaTotal) { return(true); } if (phTotal < paTotal && ahTotal < aaTotal) { return(true); } if (phTotal == paTotal && ahTotal == aaTotal) { return(true); } return(false); }
public override double Encode() { //TODO: shouldn't really be using int min and max Encoded = Numbery.Normalise(Decoded, Int32.MinValue, Int32.MaxValue, 0, 1); return(Encoded); }