해인이의 과학이야기:  성염색체



'칸아카데미 > 생물' 카테고리의 다른 글

유사분열의 단계  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
세포  (0) 2015.10.03
생명의 탄생  (0) 2015.10.01
유전법칙1  (0) 2015.10.01


해인이의 과학이야기:  유사 분열의 단계

https://www.youtube.com/watch?v=tf0GtycfNxA

'칸아카데미 > 생물' 카테고리의 다른 글

성염색체  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
세포  (0) 2015.10.03
생명의 탄생  (0) 2015.10.01
유전법칙1  (0) 2015.10.01


해인이의 과학이야기 : 분자식의 이해(3)

https://www.youtube.com/watch?v=7ofEVT1L7oU

'칸아카데미 > 화학' 카테고리의 다른 글

분자식의 이해 (2)  (0) 2015.10.01
분자식의 이해(1)  (0) 2015.10.01

by jane kim(김해인) 2015.10.11에 작성: Vector개념을 배우고 이를 코드로 작성해 보았습니다..

코드 실행: https://www.khanacademy.org/computer-programming/pvector-instance/6479887750266880


/**

Try to catch the ball! It's harder when you move, but easy when you stay..... :)


Line 37: The reason why I used constrain() is because sometimes(or mostly) when you move your mouse in further directions, the ball can get off the canvas. Making the user a bit fustrated.

So, I just used constrain() to command the code where the ball can go without further ado.(it can only move inside the canvas!)

*/


background(97, 237, 255);


//I'm puting this in a function just in case somebody tweaks this code and gets an error. (Nobody wants that to happen!)

var ball = function(x, y) {

    translate(x, y);

    noStroke();

    fill(255, 0, 0);

    ellipse(0, 0, 30, 30);

    fill(255, 255, 255);

    arc(0, 0, 30, 30, 0, 180);

    fill(0, 0, 0);

    ellipse(0, 0, 5, 5);

};


mouseMoved = function() {

    background(97, 237, 255);

    

    //Creating two new PVectors, mouse and center.

    /* The mouse is a vector showing us where the mouse is, and the center is just the center of the canvas.(In vector scale!) */

    var mouse = new PVector(mouseX, mouseY);

    var center = new PVector(width/2, height/2);

    

    /* The mouse.sub(center) is in order to let the ball to fallow the mouse. Without it, it will go away twice from the position the mouse is currently on.

NOTE: mouse.mult(3) is to make distances from the mouse and the ball 3 times further.*/

    mouse.sub(center);

    mouse.mult(3);

    

    //Since translate() is not with either pushMatrix() or popMatrix(), we have to reset the code by using resetMatrix().

    resetMatrix();

    translate(width/2, height/2);

    ball(constrain(mouse.x, -185, 185), constrain(mouse.y, -185, 185));

};


/**

Note: This is just a practice program for my vector skills, not for khantober!

*/

by jane kim


<nature>

CRISPR, the disruptor

A powerful gene-editing technology is the biggest game changer to hit biology since PCR. But with its huge potential come pressing concerns.                    

https://www.nature.com/news/crispr-the-disruptor-1.17673


 제가 CRISPR!에 관심이 생겼답니다.  네이처지에서 읽은 기사를 설명하는 동영상입니다. 

https://www.youtube.com/watch?v=fLWgrSYJ9JA









<< 과학동아 기사입니다.>>

유전자 가위 크리스퍼

유전자 조작이 처음 시작된 것은 1970년대다. 1970년 DNA의 특정 서열을 인지해 자르는 '제한효소'가 발견된 것을 시작으로 DNA를 자르고 붙이고 삽입하는 유전자 조작 기술이 탄생했다. 그러나 제한효소를 활용한 유전자조작기술은 그 한계가 명확했다. 인식할 수 있는 서열의 길이가 너무 짧았다. 제한효소는 6~8개의 염기서열을 인식한다. DNA의 염기는 A,C,G,T 등 4가지기 때문에 만약 염기 여섯 개를 인지하는 제한효소를 쓰면 약 46(4096)개의 순서쌍밖에 구분하지 못한다. 

제한효소를 활용해 유방암 유전자 치료를 한다고 생각해보자. 유방암을 일으키는 유전자를 제거하려면 그 부분을 정밀하게 도려내야 한다. 고작 4096개 를 구분하는 효소로는 이런 정밀한 조작이 불가능하다. 인간의 DNA는 길이가 32억 개가 넘는데, 4096개마다 한 번씩 반복되는 서열을 잘랐다가는 산술적으로 7만 개가 넘는 다른 DNA까지 잘라버릴 수 있기 때문이다. 그래서 제한효소는 플라스미드 같이 염기서열이 수천 개 내외인 곳에서만 사용됐다.
제한효소를 대체하려는 시도가 없었던 것은 아니다. DNA에 결합하는 단백질인 징크 핑거(Zinc Finger)와 탈렌(TALEN)을 활용한 새로운 종류의 유전자 가위가 연구됐다. 하지만 이들 역시 인식서열이 10개 내외로 짧았고, 이렇게 짧은 서열을 자르기 위해서 수천 개가 넘는 유전자 가위 DNA를 새로 이식해야 했다. 배보다 배꼽이 더 큰 격이다. 이런 상황을 종식시킨 새롭고 강력한 유전자 가위가 2012년 개발된 'CRISPR(이하 크리스퍼)'다.
남궁석
고려대에서 생화학 전공으로 박사학위를 취득한 뒤 미국 예일대와 펜실베니아대에서 박사후 연구원으로 연구했다. 현재 충북대 동물바이오신약장기사업단에서 연구교수로 재직 중이다. 생화학에서 구조생물학, 발생학에 이르는 다양한 분야를 통합해 동물 발생의 첫단계의 원리를 찾는 것이 목표다. 연구가 생각대로 풀리지 않을 때는 블로그(madscientist.wordpress.com)에서 지구 정복을 위한 공상을 펼친다. suk.namgoong@gmail.com

어디에 쓰는 서열인고?

크리스퍼가 처음 발견된 것은 1987년이다. 일본 오사카대 소우 이시노 박사팀은 대장균의 단백질 유전자를 연구하던 중 특이한 서열을 발견했다. 이 서열은 일정한 간격을 두고 회문구조(palindrome)가 반복되고 있었다. 회문구조는 DNA에서 염기서열이 역순으로 배치되는 구조다. 예컨대 'GGTC'라는 DNA가 앞쪽에 나오면 이에 상보적으로 결합하는 'GACC'가 이어 나오는 것이다(DNA는 G와C, T와A가 짝을 이뤄 결합한다). 당시에는 단순히 단백질의 서열을 알아내는 걸로도 충분했기 때문에 이 서열은 한동안 잊혀졌다.
정체불명의 서열은 1990년대에 들어서 다시 한번 주목받았다. 1994년 최초의 세균 유전체지도가 나온 뒤, 여러 세균의 유전체 서열이 밝혀졌다. 이를 살펴보던 과학자들은 한 개의 공통적인 서열을 발견했다. 앞서 발견된 회문구조였다. 이 구조 사이에 21개 염기서열이 끼어있다는 것도 찾아냈다. 21개 서열은 세균의 다른 DNA에서 발견되지 않은 완전히 새로운 서 열이었다. 그때까지도 회문구조와 21개의 염기서열 이 어떤 의미를 가지는지는 정확히 알지 못했다. 단순 히 '주기적으로 간격을 띠고 분포하는 짧은 회문구조 반복서열(CRISPR, Clustered Regulary Interspaced Short Palindromic Repeats)'이라는 이름을 붙였을 뿐이다. 한 가지 중요한 점은 아무 의미가 없어 보이는 21개 서열 중에 어떤 것은 종의 구분 없이 여러 가지 세균에서 공통적으로 나타났다는 것이다.

요구르트 회사 직원들의 이상한 실험

21개 서열의 정체를 밝혀낸 것은 덴마크의 요구르트 회사인 '다니스코' 연구자들이다. 로돌프 바랭고 박사 와 필리피 호바스 박사는 세균에서 '적응면역'을 최초 로 발견해 2007년 '사이언스'에 발표했다. 요구르트 발효에 사용되는 대량의 유산균을 배양 할 때 세균 감염을 막는 것이 아주 중요하다. 특히 유 산균을 죽이는 박테리오파지가 나타나면 애써 키운 유산균이 떼죽음을 당할 수 있다. 다니스코의 연구자들은 이렇게 떼죽음 당한 유산균 사이에서 살아남 은 일부 유산균에 궁금증을 품었다. 이 유산균이 다 른 유산균을 몰살시킨 파지에 내성을 가진 게 아니냐 는 것이다. 연구결과 정말로 내성을 가지고 있었다. 마 치 사람이 바이러스에 감염되고 나면 항체가 생겨 이 후에 그 바이러스에 대해 내성을 갖는 것처럼, 비슷한 적응면역이 박테리아에서도 존재한 것이다.
다니스코 연구팀은 이어진 연구에서 정체를 알 수 없던 크리스퍼가 적응면역에 중요한 역할을 한다는 사실도 밝혀냈다. 회문구조 사이 21개 서열에서 파지 의 DNA가 발견된 것이다. 이 유전자를 지웠더니 내 성이 사라졌다. 이것을 토대로 연구팀은 ①파지가 침 투하면 파지의 DNA를 잘게 잘라 유산균의 유전자에 붙여 넣어서 '기억'하고 ②나중에 다시 침입하면 이 전에 DNA 형태로 기억해둔 정보를 활용해 면역작용 을 한다는 것을 알아냈다. 흥미로운 결과지만, 이때까 지도 단순히 고등동물에만 존재하던 적응면역이 세 균에도 존재한다는 것을 밝힌 데 불과했다.
크리스퍼가 유전자 가위로 활용되는 데 결정적인 역할을 한 것은 미국 버클리대 제니퍼 다우드나 교 수와 독일 하노버대 엠마뉴엘 카펜디어 교수가 이 끄는 공동연구팀이다. 이들은 크리스퍼 적응면역에 서 중요한 역할을 하는 'Cas9' 단백질을 세균에서 찾 아냈다고 '사이언스'에 2012년 발표했다. 연구팀은 세균에 기억된 파지 DNA(21개 염기)가 RNA로 전사되 고, 이 RNA와 Cas9이 결합해 외부에서 침투한 파지 의 DNA를 자른다는 것을 발견했다. 군대에 비유하 면 21개 염기는 다른 유전자를 찾아내는 정찰병이고, Cas9은 직접 적을 물리치는 전투병인 셈이다. 더구나 Cas9에 결합하는 RNA를 바꾸면, 파지의 유전자가 아닌 다른 유전자 서열도 자를 수 있다는 것을 찾아 냈다. 새로운 유전자 가위가 탄생하는 순간이었다.
크리스퍼를 활용한 유전자 가위는 기존 기술보다 훨 씬 간편하다. 징크 핑거나 탈렌 같은 인공 유전자 가위 는 단백질이 정찰병 역할을 했다. 두 가지 모두가 원래 는 DNA와 결합해 전사를 촉진하는 DNA 결합 단백질 로부터 나왔기 때문이다. 단백질은 덩치가 꽤 커서 연구자가 자신이 원하는 서열을 자르려면 수천 개의 새로운 인공 유전자로 적절한 단백질을 만들어야 했다. 반면에 크리스퍼는 단백질 보다 훨씬 작은 RNA가 그 역할을 한다. DNA 100개만 바꾸면 전혀 다른 서열 특이성을 가 지는 유전자 가위를 만들 수 있는 것이다.
모든 생물의 유전체를 수정할 수 있게 된 인간

크리스퍼의 발견은 유전자 수정 붐을 일으켰다. 가장 먼저 2013년 12월 동물 세포에서 유전자 수정이 가능하다는 사실 을 확인했다. 곧바로 실험 동물의 대표 격인 마우스의 수정란에 유전자를 삽입하는 데 성공했다는 연구 결 과도 나왔다.
기존에도 마우스에서는 유전자 발현을 막거나 새 로운 유전자를 집어넣을 수 있었기 때문에, 그때까지 만 해도 과학자들은 크리스퍼가 특별하다고 생각하 지 않았다. 그러나 기존 유전자 조작 마우스는 일단 배 아줄기세포 수준에서 유전자 조작을 하고, 조작된 배 아줄기세포를 배반포에 주입한 뒤 이식하고 또 검증 하는 매우 복잡한 과정을 거쳐야 했다. 반면 크리스퍼 를 이용하면 수정란에 Cas9과 RNA를 주입하는 방식 으로 간편하게 새로운 형질의 쥐를 만들 수 있다.
마우스의 성공 이후 1년도 안 되는 짧은 시간동안 제브라피시(어류), 래트(포유류), 초파리(곤충) 등의 대표적인 실험동물은 물론이고 소, 돼지, 밀, 쌀 등 동 식물의 유전자 수정도 성공했다. 모두 이전에는 줄기 세포가 없어 유전자 조작을 할 수 없던 생물들이다. 인간이 드디어 지구상에 존재하는 거의 모든 생물의 유전체 정보를 마음대로 수정할 수 있게 된 것이다. 물론 여기에는 사람도 포함된다.

이제 인간은 거의 모든 생명체의 유전자를 고칠 수 있는 전지전능한 힘을 가지게 됐다
인간이 크리스퍼를 감당할 수 있을까

지난 4월 1일 중국 중산대 황쥔주 박사팀이 크리스퍼를 활용한 인간 수정란 유전체 편집 결과를 발표했 다. 효율이 낮아 유의미한 성과는 아니었지만 크리스 퍼를 인간에 적용한 첫 번째 결과라는 점에서 크게 주목받았다. 인간이 드디어 자신의 유전정보를 스스 로 편집할 수 있는 전지전능한 힘을 가지게 된 것일까. 과연 인간은 이 힘을 감당할 수 있을까.
결론부터 말하자면 당장은 SF영화에 나오는 괴물 을 실험실에서 만들어낼 수는 없다. 아직까지는 인간 을 비롯한 고등생물 유전체를 수정할 능력이 없다. 생 명체를 자동차와 같은 복잡한 기계에 비유하면 지금 은 자동차를 구성하는 복잡한 부품 일부의 기능을 알고, 고장이 났을 때 교체하는 방법을 고민하는 것 도 망설이는 수준이다. 헐크 같은 괴물을 만드는 것은 자동차를 개조해 트랜스포머를 만드는 수준에 비유 할 수 있다. 아직은 갈 길이 멀다.
현실적으로 크리스퍼로 당장 할 수 있는 것은 기능 을 아는 유전체 내의 유전자 몇 개의 기능을 없애고 잘못된 부분을 수선하는 정도다. 이마저도 넘어야 할 산이 많다. 가령 유전자의 기능을 없애는 것에 비해서 새로운 유전자를 집어넣는 것은 아직까지 걸음마 단 계다. 또 세포 밖에서 만들어진 크리스퍼를 세포 안으 로 전달하는 것도 큰 난관이다. 크기가 꽤 큰 Cas9 단 백질을 최소화하는 게 관건이다.
 




 

 

유전자와 유전자 편집의 역사

http://www.sciencecenter.go.kr/scipia/downloadRequest?filePath=BOARD%2F19037%2F2015%EB%85%84+%EC%97%90%EC%84%B8%EC%9D%B4+%EC%88%98%EC%83%81%EC%9E%91_2.pdf

 

 

'칸아카데미 > 생물' 카테고리의 다른 글

성염색체  (0) 2018.04.01
유사분열의 단계  (0) 2018.04.01
세포  (0) 2015.10.03
생명의 탄생  (0) 2015.10.01
유전법칙1  (0) 2015.10.01

해인이의 과학이야기 : 세포 

https://www.youtube.com/watch?v=xglGMaflw3Q


'칸아카데미 > 생물' 카테고리의 다른 글

유사분열의 단계  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
생명의 탄생  (0) 2015.10.01
유전법칙1  (0) 2015.10.01
감수분열  (0) 2015.10.01

Let's say we want to make that program that generates a world of monkeys. Your program could generate a thousand Monkey objects, each with a height value between 200 and 300 (as this is a world of monkeys that have heights between 200 and 300 pixels).

var randomHeight = random(200, 300);

Does this accurately depict the heights of real-world beings? Think of a crowded sidewalk in New York City. Pick any person off the street and it may appear that their height is random. Nevertheless, it’s not the kind of random that random() produces. People’s heights are not uniformly distributed; there are a great deal more people of average height than there are very tall or very short ones. To simulate nature, we may want it to be more likely that our monkeys are of average height (250 pixels), yet still allow them to be, on occasion, very short or very tall.

       표준편차의 이해: http://bcho.tistory.com/972

     

A distribution of values that cluster around an average (referred to as the “mean”) is known as a “normal” distribution. It is also called the Gaussian distribution (named for mathematician Carl Friedrich Gauss) or, if you are French, the Laplacian distribution (named for Pierre-Simon Laplace). Both mathematicians were working concurrently in the early nineteenth century on defining such a distribution.

When you graph the distribution, you get something that looks like the following, informally known as a bell curve:

Graph of a standard bell curveA standard bell curve

The curve is generated by a mathematical function that defines the probability of any given value occurring as a function of the mean (often written as μ, the Greek letter mu) and standard deviation (σ, the Greek letter sigma).

The mean is pretty easy to understand. In the case of our height values between 200 and 300, you probably have an intuitive sense of the mean (i.e. average) as 250. However, what if I were to say that the standard deviation is 3 or 15? What does this mean for the numbers? Looking at graphs can give us a hint. The graph above shows us the distribution with a very low standard deviation, where the majority of the values cluster closely around the mean. The graph below shows us a higher standard deviation, where the values are more evenly spread out from the average:

Graph of a bell curve with a higher standard deviationA bell curve with a higher standard deviation

Not familiar with the concept of "standard deviation"? Don't worry! You can studyVariance and standard deviation separately on Khan Academy before continuing.

The numbers work out as follows: Given a population, 68% of the members of that population will have values in the range of one standard deviation from the mean, 98% within two standard deviations, and 99.7% within three standard deviations. Given a standard deviation of 5 pixels, only 0.3% of the monkey heights will be less than 235 pixels (three standard deviations below the mean of 250) or greater than 265 pixels (three standard deviations above the mean of 250).


Calculating Mean and Standard Deviation

Consider a class of ten students who receive the following scores (out of 100) on a test:

85, 82, 88, 86, 85, 93, 98, 40, 73, 83

The mean is the average: 81.3

The standard deviation is calculated as the square root of the average of the squares of deviations around the mean. In other words, take the difference from the mean for each person and square it (variance). Calculate the average of all these values and take the square root as the standard deviation.

ScoreDifference from MeanVariance
8585 - 81.3 = 3.7(3.7)^2 = 13.69
8282 - 81.3 = 0.7(0.7)^2 = 0.49
8888 - 81.3 = 6.7(6.7)^2 = 44.89
etc.... ... 
 Average Variance:228.81

The standard deviation is the square root of the average variance: 15.13

Want to understand standard deviation better? You can study Variance and standard deviation in more depth here on Khan Academy.


Luckily for us, to use a normal distribution of random numbers in a program here, we don't have to do any of these calculations ourselves. Instead, we can make use of the Randomobject provided by ProcessingJS.

To use Random, we must first instantiate a new Random object, passing in 1 as the parameter. We call that variable "generator" because what we've created can be basically thought of as a random number generator.

var generator = new Random(1);

If we want to produce a random number with a normal (or Gaussian) distribution each time we run through draw(), it’s as easy as calling the function nextGaussian().

var num = generator.nextGaussian();
println(num);

So, now, what are we supposed to do with this value? What if we wanted to use it, for example, to assign the x-position of a shape we draw on screen?

The nextGaussian() function returns a normal distribution of random numbers with the following parameters: a mean of zero and a standard deviation of one. Let’s say we want a mean of 200 (the center horizontal pixel in a window of width 400) and a standard deviation of 60 pixels. We can adjust the value to our parameters by multiplying it by the standard deviation and adding the mean.

var standardDeviation = 60;
var mean = 200;
var x = standardDeviation * num + mean;

Now, we can create our program that draws semi-transparent circles according to a normal distribution. The darkest spot will be near the center, where most of the values cluster, but every so often circles are drawn farther to the right or left of the center.


// Adapted from Dan Shiffman, natureofcode.com


var generator = new Random(1);


<코드>

var draw = function() {

    // The nextGaussian() function returns a normal distribution of random numbers with the following parameters: a mean of zero and a standard deviation of one

    var num = generator.nextGaussian();

    var standardDeviation = 60;

    var mean = 200;

    

    // Multiply by the standard deviation and add the mean.

    var x = standardDeviation * num + mean;

    

    noStroke();

    fill(214, 159, 214, 10);

    ellipse(x, 200, 16, 16);

};


    <출력>



<코드>

var generator = new Random(1);

var standardDeviation = 2;

var mean = 0;


var Walker = function() {

    this.x = width/2;

    this.y = height/2;

};


Walker.prototype.display = function() {

    strokeWeight(3);

    stroke(0, 0, 0);

    point(this.x, this.y);

};

// Randomly move up, down, left, right, or stay in one place

Walker.prototype.walk = function() {

    var xStepSize = standardDeviation * generator.nextGaussian() + mean;

    var yStepSize = standardDeviation * generator.nextGaussian() + mean;

    this.x += xStepSize;

    this.y += yStepSize;

};


var w = new Walker();


var draw = function() {

    w.walk();

    w.display();

};

<출력>



      

2# 잘못된 코드

var generator = new Random(1);

var standardDeviation = 2;

var mean = 0;

var num = generator.nextGaussian();


var Walker = function() {

    this.x = width/2;

    this.y = height/2;

};


Walker.prototype.display = function() {

    strokeWeight(3);

    stroke(0, 0, 0);

    point(this.x, this.y);

};


// Randomly move up, down, left, right, or stay in one place

Walker.prototype.walk = function() {


    var xStepSize = standardDeviation*num + mean;

    var yStepSize = standardDeviation*num + mean;

  

    this.x += xStepSize;

    this.y += yStepSize;

};


var w = new Walker();


var draw = function() {

    w.walk();

    w.display();

};

<출력>


3#절충형

var generator = new Random(1);

var standardDeviation = 2;

var mean = 0;



var Walker = function() {

    this.x = width/2;

    this.y = height/2;

};


Walker.prototype.display = function() {

    strokeWeight(3);

    stroke(0, 0, 0);

    point(this.x, this.y);

};


// Randomly move up, down, left, right, or stay in one place

Walker.prototype.walk = function() {

    var num = generator.nextGaussian();

    var xStepSize = standardDeviation * num + mean;

    var yStepSize = standardDeviation * generator.nextGaussian() + mean;

  

    this.x += xStepSize;

    this.y += yStepSize;

};


var w = new Walker();


var draw = function() {

    w.walk();

    w.display();

};


<출력>


<^^>





<< 칸아카데미의 Advenced JS를 학습한 내용입니다. 칸선생님 감사합니다. by 해인>>


     probability & non-uniform distributions


Remember when you first started programming here? Perhaps you wanted to draw a lot of circles on the screen. So you said to yourself: “Oh, I know. I’ll draw all these circles at random locations, with random sizes and random colors.” In a computer graphics system, it’s often easiest to seed a system with randomness. In these lessons, however, we’re looking to build systems modeled on what we see in nature. Defaulting to randomness is not a particularly thoughtful solution to a design problem—particularly the kind of problem that involves creating an organic or natural-looking simulation.

With a few tricks, we can change the way we use random() to produce “non-uniform” distributions of random numbers. This will come in handy throughout this course as we look at a number of different scenarios. When we examine genetic algorithms, for example, we’ll need a methodology for performing “selection”—which members of our population should be selected to pass their DNA to the next generation? Remember the concept of survival of the fittest? Let’s say we have a population of monkeys evolving. Not every monkey will have an equal chance of reproducing. To simulate Darwinian evolution, we can’t simply pick two random monkeys to be parents. We need the more “fit” ones to be more likely to be chosen. We need to define the “probability of the fittest.” For example, a particularly fast and strong monkey might have a 90% chance of procreating, while a weaker one has only a 10% chance.

Let’s pause here and take a look at probability’s basic principles. First we’ll examine single event probability, i.e. the likelihood that a given event will occur.

If you have a system with a certain number of possible outcomes, the probability of the occurrence of a given event equals the number of outcomes that qualify as that event divided by the total number of all possible outcomes. A coin toss is a simple example—it has only two possible outcomes, heads or tails. There is only one way to flip heads. The probability that the coin will turn up heads, therefore, is one divided by two: 1/2 or 50%.

Take a deck of fifty-two cards. The probability of drawing an ace from that deck is:

number of aces / number of cards = 4 / 52 = 0.077 = ~ 8%

The probability of drawing a diamond is:

number of diamonds / number of cards = 13 / 52 = 0.25 = 25%

We can also calculate the probability of multiple events occurring in sequence. To do this, we simply multiply the individual probabilities of each event.

The probability of a coin turning up heads three times in a row is:

(1/2) * (1/2) * (1/2) = 1/8 (or 0.125)

…meaning that a coin will turn up heads three times in a row one out of eight times (each “time” being three tosses).

Want to review probability before continuing? Study compound events and dependent probability.

There are a couple of ways in which we can use the random() function with probability in code. One technique is to fill an array with a selection of numbers—some of which are repeated—then choose random numbers from that array and generate events based on those choices.


<코드>

var stuff = [];


// We store 1 and 3 in the array twice, making them more likely to be picked.

stuff[0] = 1;

stuff[1] = 1;

stuff[2] = 2;

stuff[3] = 3;

stuff[4] = 3;


// Picking a random element from an array

var index = floor(random(stuff.length));

println(stuff[index]);


//출력 3


2#

Running this code will produce a 40% chance of printing the value 1, a 20% chance of printing 2, and a 40% chance of printing 3.

We can also ask for a random number (let’s make it simple and just consider random decimal values between 0 and 1) and allow an event to occur only if our random number is within a certain range. Check out the example below, and keep clicking restart until the randomly picked number is finally less than the threshold:


<코드>
// Adapted from Dan Shiffman, natureofcode.com

var prob = 0.10;
var r = random(1);
 
// If our random number is less than 0.1, do something
if (r < prob) {
    println("Doing something!");
} else {
    println("Waiting...");
}         

// 출력 Waiting...


3#

This method can also be applied to multiple outcomes. Let’s say that Outcome A has a 60% chance of happening, Outcome B, a 10% chance, and Outcome C, a 30% chance. We implement this in code by picking a random number and seeing into what range it falls.

  • between 0.00 and 0.60 (60%) –> Outcome A

  • between 0.60 and 0.70 (10%) –> Outcome B

  • between 0.70 and 1.00 (30%) –> Outcome C

Click the restart button to see how often you get different outcomes:


<코드>

// Adapted from Dan Shiffman, natureofcode.com


var num = random(1);

 

// If random number is less than 0.6

if (num < 0.6) {

  println("Outcome A");

// Between 0.6 and 0.7

} else if (num < 0.7) {

  println("Outcome B");

// Greater than 0.7

} else {

  println("Outcome C");

}


4#

We could use the above methodology to create a random walker that tends to move to the right. Here is an example of a Walker with the following probabilities:

  • chance of moving up: 20%

  • chance of moving down: 20%

  • chance of moving left: 20%

  • chance of moving right: 40%

<코드>

// Adapted from Dan Shiffman, natureofcode.com


var num = random(1);

 

// If random number is less than 0.6

if (num < 0.6) {

  println("Outcome A");

// Between 0.6 and 0.7

} else if (num < 0.7) {

  println("Outcome B");

// Greater than 0.7

} else {

  println("Outcome C");

}



Challenge: Make it walk up



Currently, our walker tends to walk to the right. Change the logic so that it has a 10% chance of walking right, 10% chance of walking left, 60% chance of walking up, and 20% chance of walking down.


var Walker = function() {

    this.x = width/2;

    this.y = height/2;

};


Walker.prototype.display = function() {

    stroke(0, 0, 0);

    point(this.x, this.y);

};


// Randomly move up, down, left, right, or stay in one place

Walker.prototype.walk = function() {

    var r = random(1);

     

    if (r < 0.1) {

      this.x++;

    } else if (r < 0.2) {

      this.x--;

    } else if (r < 0.4) {

      this.y++;

    } else {

      this.y--;

    }

};



var w = new Walker();


var draw = function() {

    w.walk();

    w.display();

};


<출력>

<< 칸아카데미의 Advenced JS를 학습한 내용입니다. 칸선생님 감사합니다. by 해인>>

The Random Walker Object

Let's review a bit of object-oriented programming (OOP) first by building a Walker object. This will be only a cursory review. If you have never worked with OOP before, you should go through the section on Object-Oriented JavaScript.

An object in JavaScript is a data type that has both properties and functionality attached to it, via its prototype. We are looking to design a Walker object that both keeps track of its data (where it exists on the screen) and has the capability to perform certain actions (such as draw itself or take a step).

In order to create instances of Walkers, we need to define a Walker object. We'll use that object as the cookie cutter, and each new Walker instance are the cookies.

Let's begin by defining the Walker object type. The Walker only needs two pieces of data—a number for its x-location and one for its y-location. We'll set those in its constructor function, setting them to the center of the canvas.

var Walker = function() {
    this.x = width/2;
    this.y = height/2;
};

In addition to keeping track of its x and y, our Walker object will also have methods that we can call on it. The first will be a method that allows the object to display itself as a black dot. Remember that we add methods to an object in JavaScript by attaching them to the object's prototype.

Walker.prototype.display = function() {
    stroke(0, 0, 0);
    point(this.x, this.y);
};

The second method directs the Walker object to take a step. Now, this is where things get a bit more interesting. Remember that floor on which we were taking random steps? Well, now we can use our canvas in that same capacity. There are four possible steps. A step to the right can be simulated by incrementing x (x++); to the left by decrementing x (x--); forward by going down a pixel (y++); and backward by going up a pixel (y--). How do we pick from these four choices? Earlier we stated that we could flip two coins. In ProcessingJS, however, when we want to randomly choose from a list of options, we can pick a random number using random().

Walker.prototype.walk = function() {
    var choice = floor(random(4));
};

The above line of code picks a random floating point number between 0 and 4 and converts it to a whole number by using floor(), with a result of 0, 1, 2, or 3. Technically speaking, the highest number will never be 4.0, but rather 3.999999999 (with as many 9s as there are decimal places); since floor() returns the closest whole number that is lesser or equal, the highest result we can get is 3. Next, we take the appropriate step (left, right, up, or down) depending on which random number was picked.

Walker.prototype.walk = function() {
    var choice = floor(random(4));
    if (choice === 0) {
        this.x++;
    } else if (choice === 1) {
        this.x--;
    } else if (choice === 2) {
        this.y++;
    } else {
        this.y--;
    } 
};

Now that we've written the class, it's time to make an actual Walker object in our program. Assuming we are looking to model a single random walk, we declare and initialize one global variable of type Walker, by calling the constructor function with the new operator.

var w = new Walker();

Now, to make the walker actually do something, we define the draw() function, and tell the walker to take a step and draw itself each time that's called:


var draw = function() {
    w.walk();
    w.display();
};

Since we don't call background() in the draw function, we can see the trail of the random walk on our canvas:


<코드>

var Walker = function() {

    this.x = width / 2;

    this.y = height / 2;

};

Walker.prototype.display = function() {

    stroke(0, 34, 255);

    point(this.x, this.y);

};

Walker.prototype.walk = function() {

    var num = floor(random(4));

    if (num === 0) {

        this.x++;

    } else if (num === 1) {

        this.x--;

    } else if (num === 2) {

        this.y++;

    } else {

        this.y--;

    }

};

var guy = new Walker();

draw = function() {

    guy.display();

    guy.walk();

};




해인이의 과학이야기 : 분자식의 이해(2)

https://www.youtube.com/watch?v=tg9QoyP3isw

'칸아카데미 > 화학' 카테고리의 다른 글

분자식의 이해(3)  (0) 2018.04.01
분자식의 이해(1)  (0) 2015.10.01

해인이의 과학이야기: 분자식의 이해(1)

https://www.youtube.com/watch?v=8GiYzm6mTzE

'칸아카데미 > 화학' 카테고리의 다른 글

분자식의 이해(3)  (0) 2018.04.01
분자식의 이해 (2)  (0) 2015.10.01

해인이의 과학이야기:  생명의탄생



'칸아카데미 > 생물' 카테고리의 다른 글

유사분열의 단계  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
세포  (0) 2015.10.03
유전법칙1  (0) 2015.10.01
감수분열  (0) 2015.10.01

해인이의 과학이야기:  유전법칙1



'칸아카데미 > 생물' 카테고리의 다른 글

유사분열의 단계  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
세포  (0) 2015.10.03
생명의 탄생  (0) 2015.10.01
감수분열  (0) 2015.10.01

해인이의 과학이야기:  감수 분열의 단계



'칸아카데미 > 생물' 카테고리의 다른 글

유사분열의 단계  (0) 2018.04.01
생명과학>>크리스퍼  (0) 2015.10.04
세포  (0) 2015.10.03
생명의 탄생  (0) 2015.10.01
유전법칙1  (0) 2015.10.01

+ Recent posts