Last active
June 19, 2018 07:11
Revisions
-
supix revised this gist
Jun 19, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -107,4 +107,4 @@ Running the code we have: 0,35584 # Acknowledgement Thanks to [Julia](https://www.youtube.com/watch?v=BrK7X_XlGB8) for having inspired this riddle. -
supix revised this gist
Jun 19, 2018 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,20 +44,23 @@ namespace Bayes { internal class Program { private const double totalStudents = 1e6; private const double studentsToPick = 1e5; private static void Main(string[] args) { var rnd = new Random(); var people = new List<Student>(); for (int i = 0; i < totalStudents; i++) { people.Add(Student.Create()); } int selectedShys = 0; int mathStudents = 0; for (int i = 0; i < studentsToPick; i++) { var s = people[rnd.Next(people.Count)]; if (s.Shy) -
supix revised this gist
Jun 19, 2018 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,11 +75,14 @@ namespace Bayes public class Student { private const double probToBeMathStudent = .1d; private const double probToBeShyGivenMath = .75d; private const double probToBeShyGivenBA = .15d; private static Random rnd = new Random(); public bool Math { get; } public bool Shy { get; } public Student(bool math, bool shy) { this.Math = math; @@ -88,8 +91,8 @@ namespace Bayes public static Student Create() { var math = rnd.NextDouble() < probToBeMathStudent; var shy = math ? rnd.NextDouble() < probToBeShyGivenMath : rnd.NextDouble() < probToBeShyGivenBA; return new Student(math, shy); } -
supix revised this gist
Jun 19, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ Doing the math we have an overall probability of 0.3571428. # Solution through the [Frequentist Probability](https://en.wikipedia.org/wiki/Frequentist_probability) This piece of code, written in C#, prints the probability that picking a shy student he happens to be a math student. ```csharp using System; -
supix revised this gist
Jun 17, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Within math faculty, 75% students are shy. Within business administration, 15% s # Problem I see a student, and he is clearly shy. What's the probability that he is enrolled in math faculty? # Theoretical solution through Bayes Theorem -
supix revised this gist
Jun 17, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ Doing the math we have an overall probability of 0.3571428. # Solution through the [Frequentist Probability](https://en.wikipedia.org/wiki/Frequentist_probability) This piece of code, written in C#, prints the probability of picking a shy student he happens to be a math student. ```csharp using System; -
supix revised this gist
Jun 17, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ P(Math|Shy) = ----------------------- P(Shy) ``` From data it stems that: ``` P(Shy|Math) = 0.75 -
supix revised this gist
Jun 17, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -97,4 +97,8 @@ namespace Bayes } ``` Running the code we have: 0,35584 # Acknowledgement Thanks to [Julia](https://www.youtube.com/watch?v=BrK7X_XlGB8) for inspiring me this riddle. -
supix revised this gist
Jun 17, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Within math faculty, 75% students are shy. Within business administration, 15% s # Problem I see a student, and he is clearly shy. What's the probability that he is enrolled in math faculty. # Theoretical solution through Bayes Theorem -
supix revised this gist
Jun 17, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,13 +21,15 @@ P(Math|Shy) = ----------------------- From data stem that: ``` P(Shy|Math) = 0.75 P(Math) = 0.1 P(Shy) = P(Shy|Math) P(Math) + P(Shy|BA) P(BA) = 0.75 * 0.1 + 0.15 * 0.90 ``` Doing the math we have an overall probability of 0.3571428. # Solution through the [Frequentist Probability](https://en.wikipedia.org/wiki/Frequentist_probability) This piece of code, written in C#, prints the probability of picking a math student given that he is shy. -
supix created this gist
Jun 17, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,98 @@ # Context We are in a university campus. There are two faculties: math and business administration. 10% of student are enrolled in math (then, 90% of students are enrolled in business administration). Within math faculty, 75% students are shy. Within business administration, 15% students are shy. # Problem I see a student, and he is clearly shy. What's the probability that he applies to math faculty. # Theoretical solution through Bayes Theorem I have to compute P(Math|Shy). According to [Bayes theorem](https://en.wikipedia.org/wiki/Bayes%27_theorem), we have: ``` P(Shy|Math) P(Math) P(Math|Shy) = ----------------------- P(Shy) ``` From data stem that: P(Shy|Math) = 0.75 P(Math) = 0.1 P(Shy) = P(Shy|Math) P(Math) + P(Shy|BA) P(BA) = 0.75 * 0.1 + 0.15 * 0.90 Doing the math we have an overall probability of 0.3571428. # Solution through the [Frequantist Probability](https://en.wikipedia.org/wiki/Frequentist_probability) This piece of code, written in C#, prints the probability of picking a math student given that he is shy. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bayes { internal class Program { private static void Main(string[] args) { var rnd = new Random(); var people = new List<Student>(); for (int i = 0; i < 1e7; i++) { people.Add(Student.Create()); } int selectedShys = 0; int mathStudents = 0; for (int i = 0; i < 1e6; i++) { var s = people[rnd.Next(people.Count)]; if (s.Shy) { selectedShys++; if (s.Math) mathStudents++; } } Console.WriteLine(mathStudents / (double)selectedShys); Console.ReadLine(); } } public class Student { public bool Math { get; } public bool Shy { get; } private static Random rnd = new Random(); public Student(bool math, bool shy) { this.Math = math; this.Shy = shy; } public static Student Create() { var math = rnd.NextDouble() < .1d; var shy = math ? rnd.NextDouble() < .75d : rnd.NextDouble() < .15d; return new Student(math, shy); } } } ``` Running the code we have: 0,35584