wordhit

버전 1.1.0.0 (11.3 KB) 작성자: Ben Petschel
determines probabilities and expected times to produce words in a random character stream
다운로드 수: 200
업데이트 날짜: 2011/7/22

라이선스 보기

Consider the following problems:

- is HH or TH more likely to appear first in a series of coin flips?
- how long does it take on average for a monkey to type out the phrase "to be or not to be"?

WORDHIT solves the general problem for any list of reasonably-sized words. For example,

wordhit('HH','TH') % returns [1/4,3/4]
[P,T]=wordhit('HH','TH') % T = [0.5,2.5]
T./P % conditional hitting times [2,10/3]
sum(T) % total hitting time [3]

% optional symbolic probability values (requires Symbolic Toolbox)
[~,t]=wordhit(repmat('H',1,5),'',sym('p')) % (1+p+p^2+p^3+p^4)/p^5

The algorithm works by determining the transition matrix of the Markov chain where each state represents a given combination of matches to the first few elements of each word, with the absorbing states being where a full word is matched. This allows the hitting probabilities and hitting times to be expressed as limits of matrix powers.

The values can be challenging to compute even for some relatively small examples, so several methods have been implemented.

For some examples the results are accurate to values close to REALMIN, e.g.

log2(wordhit(repmat('H',1,1000),'TH')) % get [-1000,0]

For other examples, a modified Kramer's method is more accurate due to poor conditioning of the transition matrix:

[~,t]=wordhit(repmat('H',1,500)) % accuracy warning
[~,t]=wordhit(repmat('H',1,500),'','kramer') % get 2^501 as expected
[~,t]=wordhit('to be or not to be','','kramer') % 5.815e25
% adjust for unequal key probabilites:
[~,t]=wordhit('to be or not to be','',[32*ones(1,26),190]/2800,'kramer') % 1.225e31

See the help file for more examples and extensive documentation of the options, theory and methods.

Let me know if you find any bugs or interesting examples.

인용 양식

Ben Petschel (2024). wordhit (https://www.mathworks.com/matlabcentral/fileexchange/31748-wordhit), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2010a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

(previously htseqprob.m) - added calculation of hitting times; support for alphabets of size > 2; symbolic inputs; additional methods

1.0.0.0