확률과 관련된 문제로 간단해 보이지만, 의외로 복잡하다.
문제1: 길이가 1인 막대를 임의로(즉, uniform probability로) 2 조각으로 나눌 때,
왼쪽 부분의 길이의 평균은 얼마일까?
문제2: 문제 1과 같은 조건에서, 2 조각중 길이가 가장 짧은 조각의 평균 길이와 길이가 가장 긴 조각의 평균 길이는 각각 얼마일까?
문제3: 길이가 1인 막대를 임의로(즉, uniform probability로) 3 조각으로 나눌 때,
가장 긴 조각의 평균 길이는 얼마일까? 가장 짧은 조각의 평균 길이는?
여기서 막대를 조각으로 나누는 것은 하나, 또는 두개의 임의의 점을 찍는 것과 같다고 생각할 수 있다.
Q1: There is a stick with length 1. If you randomly divide the stick into two pieces,
what is the average length of the left part ?
Q2: There is a stick with length 1. If you randomly divide the stick into two pieces,
what is the average length of the longest part ?
Q3: There is a stick with length 1. If you randomly divide the stick into three pieces,
what is the average length of the longest part ?
2016년 9월 1일 목요일
Brain Teaser: boy or girl?
Q: I met a man with two children and I know one of them is a boy.
What is the probability that the other children is also a boy?
If I know one boy's birthday is Tuesday,
what is the probability that the other children is also a boy?
아이가 둘인 사람을 만났는데, 그 중 적어도 한명은 남자라는 것을 안다고 하자.
이 때, 다른 아이도 남자아이일 확률은?
만약, 남자애가 화요일에 태어났다는 것을 안다면, 다른 아이가 남자아이일 확률은?
What is the probability that the other children is also a boy?
If I know one boy's birthday is Tuesday,
what is the probability that the other children is also a boy?
아이가 둘인 사람을 만났는데, 그 중 적어도 한명은 남자라는 것을 안다고 하자.
이 때, 다른 아이도 남자아이일 확률은?
만약, 남자애가 화요일에 태어났다는 것을 안다면, 다른 아이가 남자아이일 확률은?
2016년 7월 24일 일요일
dos file to linux/unix file
Removing ^M from file:
There are several ways to do it
(1) Using Vi editor
(1-1) To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:
:set fileformat=unix
(1-2) Or, type this script in ViM, in the command mode and type :w to save the changes:
^V^M gives ^M character in the screen
:1,$s/^V^M//g
(2) Use sed:
$ sed 's/^M//g' filename > newfilename
(3) Use Dos2Unix
$ dos2unix filename newfilename
(4) Use col:
$ cat filename | col -b > newfilename
(5) Use 'tr' :
$tr -d '\r' < inputfile > outputfile
2016년 6월 10일 금요일
ipython install for OSX El Capitan
컴퓨터를 Mac 으로 바꾸고 ipython 을 설치하려니 문제가 생겼다.
먼저 pip install ipython 을 시도했지만, pip 가 설치되어 있지 않음.
그래서 일단 pip 를 설치.( sudo easy_install pip )
다시 pip 로 ipython 을 설치하려 했지만, 실패.
아마도 Apple의 정책상 시스템과 관련된 디렛토리에 쓰는 것이 금지 된 듯.
이번에는 sudo easy_install ipython 을 시도했으나 역시 에러 발생. (six 라는
프로그램의 버전이 문제인 듯.)
결국 다음과 같은 방법으로 설치 성공. (설치하는 김에 python3도 설치했다.)
sudo pip install haxor-news --upgrade --ignore-installed six
2016년 1월 5일 화요일
vmware에서 guest resize problem
vmware에서 어느 순간부터 guest os 의 windows size를 바꾸지 못하는 문제가 발생했다.
다양하게 시도해 본 결과 linux에서 open-vm-tools 가 제대로 설치되지 않은 것이 문제 인것으로 보인다.
Ubuntu에서
open-vm-tools
open-vm-tools-desktop
을 재설치 하는 것으로 해결되었다.
다양하게 시도해 본 결과 linux에서 open-vm-tools 가 제대로 설치되지 않은 것이 문제 인것으로 보인다.
Ubuntu에서
open-vm-tools
open-vm-tools-desktop
을 재설치 하는 것으로 해결되었다.
2015년 12월 24일 목요일
Keyword arguments passing, Unpacking arguments
Python의 scipy 와 같은 library를 사용하다보면,
라이브러리의 함수에 자신이 만든 함수를 지정하고,
args=() 로 Extra arguments to pass to function. 넘겨주어야 할 때가 있다.
아마도, scipy에서 함수를 정의할 때
*args와 **kwargs를 이용해서 unlimited number of argument를
넘겨 받도록 함수를 정의하였을 것이다.
그러나 만약 extra argument가 keyword argument라면?
위 함수를 libary에서 사용할때 다음과 같이 extra argument y,a,b를
positional parameter로 넘겨준다.
libfunc( myfunc, x, args=(y,a,b))
(2) 다음과 같이 wrapper를 만들어서 넘겨주는 방법이 있다.
(또는 global variable로 정의해서 넘겨주거나.)
(3) 그러나 이 경우에는 언제나 wrapper를 한번 불러 주어야 한다는 불편함이 있다.
keyword argument를 한번에 args=() 로 넘겨주는 방법은 없을까?....?
==> Scipy 함수의 argument는 positional argument에만 적용되고 keyword argument로는
쓸 수 없다. 따라서 (1)번이나 (2)번 방법만 가능하다.
라이브러리의 함수에 자신이 만든 함수를 지정하고,
args=() 로 Extra arguments to pass to function. 넘겨주어야 할 때가 있다.
아마도, scipy에서 함수를 정의할 때
*args와 **kwargs를 이용해서 unlimited number of argument를
넘겨 받도록 함수를 정의하였을 것이다.
그러나 만약 extra argument가 keyword argument라면?
def myfunc(x,y,a=1,b=2): # y,a,b are optional arguments
if y > 1.0:
c = (1.0+b)**a
else:
c = (1.0+a)**b
return c*x
(1) 모든 argument를 positional argument로 넘기기.위 함수를 libary에서 사용할때 다음과 같이 extra argument y,a,b를
positional parameter로 넘겨준다.
libfunc( myfunc, x, args=(y,a,b))
(2) 다음과 같이 wrapper를 만들어서 넘겨주는 방법이 있다.
(또는 global variable로 정의해서 넘겨주거나.)
def mywrapper(*args, **kwargs): # args for y, kwargs for a, b
def func(x):
return myfunc(x, *args, **kwargs)
return func
myfunc_with_args = mywrapper(2.5, a=4.0, b=5.0)
integral = integrate.romberg(myfunc_with_args, 1, 10)
(3) 그러나 이 경우에는 언제나 wrapper를 한번 불러 주어야 한다는 불편함이 있다.
keyword argument를 한번에 args=() 로 넘겨주는 방법은 없을까?....?
==> Scipy 함수의 argument는 positional argument에만 적용되고 keyword argument로는
쓸 수 없다. 따라서 (1)번이나 (2)번 방법만 가능하다.
2015년 12월 13일 일요일
[퍼옴] Hollow Mask 착시 효과
리차드 도킨스의 책에 언급된, 착시 효과를 인터넷에서 찾아보았다.
마스크의 움푹 들어간 뒤편에 색칠을 한 것을 보면, 음각임에도 불구하고,
양각으로 느껴진다. 이것을 도킨스는 인간의 뇌가 어느 곳에서나
얼굴의 패턴을 인식하려고 하는 경향 때문이라고 설명하고, 인간의 인식이
있는 자연을 그대로가 아니라 뇌의 시뮬레이션을 거쳐서 이루어지는 증거라고
한다.
마스크의 움푹 들어간 뒤편에 색칠을 한 것을 보면, 음각임에도 불구하고,
양각으로 느껴진다. 이것을 도킨스는 인간의 뇌가 어느 곳에서나
얼굴의 패턴을 인식하려고 하는 경향 때문이라고 설명하고, 인간의 인식이
있는 자연을 그대로가 아니라 뇌의 시뮬레이션을 거쳐서 이루어지는 증거라고
한다.
피드 구독하기:
글 (Atom)