Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@valtih1978
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valtih1978/3daffbdd86963ca4725c to your computer and use it in GitHub Desktop.
Save valtih1978/3daffbdd86963ca4725c to your computer and use it in GitHub Desktop.
4% degradation with every generation
// This talk https://www.youtube.com/watch?v=MGfr_col5PI claims that if 4% of healty people degenerate with every
// and if 50% recover from defective genetics then we reach 8% failed genetics. Here is the simulation that confirms this.
def sim1(healthy: Double, generation: Int = 1): Unit = if (generation < 100) {
val degenerates = 1 - healthy; println((degenerates * 100) + "% down" )
sim1(healthy * 0.96 + degenerates * 0.5, generation + 1)
} //> sim1: (healthy: Double, generation: Int)Unit
sim1(1) //> 0.0% down
//| 4.0000000000000036% down
//| 5.840000000000001% down
//| 6.6864000000000035% down
//| 7.075744000000006% down
//| 7.2548422400000145% down
//| 7.337227430400006% down
//| 7.375124617983997% down
//| 7.392557324272642% down
//| 7.400576369165424% down
//| 7.4042651298161015% down
//| Output exceeds cutoff limit.
sim1(0) //> 100.0% down
//| 50.0% down
//| 27.0% down
//| 16.42% down
//| 11.553199999999997% down
//| 9.314472000000007% down
//| 8.284657120000016% down
//| 7.810942275200006% down
//| 7.593033446592001% down
//| Output exceeds cutoff limit.
// However, the simple simulation violates the law of entropy non-recovery. The law of Darwin says that
// piece of shit cannot born a superman, you cannot recover the disgenied allele. You can do that in 50%
// of cases only if you couple a broken gene with a healty parent in sexual reproduction. This means that
// you need to couple healty parents with genetic garbage to get 50% genetically broken children instead
// of normal rate of 4%. Do you want that? BTW, you should get 52% failed children in this case because
// assuming that healthy allele was selected, it still has 4% additional failures due to additional mutation.
//
// In this biologically plausible model we see that healthy population is washed down to 0.
var rec = List[String]() //> rec : List[String] = List()
def sexual(healthy: Double, mixedDefectRate: Double = 0.5, gen: Int = 1) {
val down = (1-healthy); rec ::= "%.1f".format(down * 100).replace(",", ".")
//There are h healthy parents and b bad parents (h/2 + b/2) mothrs and (h/2 + b/2) fathers.
//Each of h/2 mohtres is randomly paired with (h/2 + b/2) * h/2 fathers.
//THe remaining b/2 mohtres is randomly paired with (h/2 + b/2) * b/2 fathers.
// In result, we have got h^2/4 healthy families, b^2/4 disgenic families and (b*h) / 2 one parent disgenic.
// Totally healthy degrade 4%, half healthy have 50% degenerate and downs never produce healthy genes.
val hh = healthy * healthy; val bb = down * down ; val mixed = 1 - hh - bb;
val newHealth = hh * 0.96 + mixed * mixedDefectRate
if (Math.abs(newHealth - healthy) > 0.00001) sexual(newHealth, mixedDefectRate, gen + 1) else {
println(s"sexual $mixedDefectRate:" + (healthy * 100) + "% healthy after " + gen + " generations")
println(rec.reverse mkString " ") ; rec = List()
}
} //> sexual: (healthy: Double, mixedDefectRate: Double, gen: Int)Unit
sexual(1, 0.5) //> sexual 0.5:1.5811103764988879% healthy after 1553 generations
//| 0.0 4.0 7.7 11.1 14.3 17.2 19.9 22.5 24.9 27.2 29.3 31.3 33.2 35.0 36.7 38.
//| 3 39.8 41.2 42.6 43.9 45.2 46.4 47.5 48.6 49.7 50.7 51.7 52.6 53.5 54.4 55.
//| 2 56.0 56.8 57.5 58.3 59.0 59.6 60.3 60.9 61.5 62.1 62.7 63.2 63.8 64.3 64.
//| 8 65.3 65.8 66.3 66.7 67.2 67.6 68.0 68.4 68.8 69.2 69.6 70.0 70.3 70.7 71.
//| 0 71.4 71.7 72.0 72.3 72.6 72.9 73.2 73.5 73.8 74.1 74.3 74.6 74.8 75.1 75.
//| 3 75.6 75.8 76.1 76.3 76.5 76.7 77.0 77.2 77.4 77.6 77.8 78.0 78.2 78.4 78.
//| 6 78.7 78.9 79.1 79.3 79.4 79.6 79.8 79.9 80.1 80.3 80.4 80.6 80.7 80.9 81.
//| 0 81.2 81.3 81.4 81.6 81.7 81.8 82.0 82.1 82.2 82.4 82.5 82.6 82.7 82.9 83.
//| 0 83.1 83.2 83.3 83.4 83.5 83.6 83.7 83.9 84.0 84.1 84.2 84.3 84.4 84.5 84.
//| 6 84.7 84.7 84.8 84.9 85.0 85.1 85.2 85.3 85.4 85.5 85.5 85.6 85.7 85.8 85.
//| 9 86.0 86.0 86.1 86.2 86.3 86.3 86.4 86.5 86.6 86.6 86.7 86.8 86.8 86.9 87.
//| 0 87.1 87.1 87.2 87.2 87.3 87.4 87.4
//| Output exceeds cutoff limit.
sexual(1, 0.48) //> sexual 0.48:0.02417305499396611% healthy after 205 generations
//| 0.0 4.0 7.8 11.5 15.1 18.5 21.7 24.9 27.9 30.7 33.5 36.2 38.7 41.2 43.5 45.
//| 8 48.0 50.0 52.0 54.0 55.8 57.6 59.3 60.9 62.5 64.0 65.4 66.8 68.1 69.4 70.
//| 6 71.8 72.9 74.0 75.0 76.0 77.0 77.9 78.8 79.6 80.5 81.2 82.0 82.7 83.4 84.
//| 1 84.7 85.3 85.9 86.5 87.0 87.5 88.0 88.5 89.0 89.4 89.8 90.2 90.6 91.0 91.
//| 4 91.7 92.0 92.4 92.7 93.0 93.2 93.5 93.8 94.0 94.3 94.5 94.7 94.9 95.1 95.
//| 3 95.5 95.7 95.9 96.0 96.2 96.3 96.5 96.6 96.8 96.9 97.0 97.1 97.2 97.4 97.
//| 5 97.6 97.7 97.8 97.8 97.9 98.0 98.1 98.2 98.2 98.3 98.4 98.4 98.5 98.6 98.
//| 6 98.7 98.7 98.8 98.8 98.9 98.9 99.0 99.0 99.0 99.1 99.1 99.2 99.2 99.2 99.
//| 3 99.3 99.3 99.3 99.4 99.4 99.4 99.4 99.5 99.5 99.5 99.5 99.5 99.6 99.6 99.
//| 6 99.6 99.6 99.6 99.7 99.7 99.7 99.7 99.7 99.7 99.7 99.7 99.8 99.8 99.8 99.
//| 8 99.8 99.8 99.8 99.8 99.8 99.8 99.8 99.8 99.8 99.9 99.9 99.9 99.9 99.9 99.
//| 9 99.9 99.9 99.9 99.9 99.9 99.9 99.
//| Output exceeds cutoff limit.
sexual (0) //> sexual 0.5:0.0% healthy after 1 generations
//| 100.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment