Sample Entropy Calculation
Model was written in NetLogo 6.4.0
•
Viewed 130 times
•
Downloaded 0 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [ m ;; length of substrings that can be derived from the input-string substrings ;; list of the substrings derived from the input-string substr-copy ;; a copy of the previous list similar ;; couple of similar substrings in the previous list sampen ;; the sample entropy of the input-string index ;; an index/pointer ] ;; --------- CALCULATING SAMPLE ENTROPY FOR THE INPUT-STRING SEQUENCE -------------------------------- ;; --------------------------------------------------------------------------------------------------- to compute-sample-entropy ca ifelse input-string = "" [output-print "No string to operate on" stop] [start-message] set input-string word input-string "_" ;; Creating patterns with m = 2 set m 2 set similar 0 set substrings [] built-substrings let substrings2 substrings output-print word "Set of patterns with m = 2 --> " substrings2 ;; evaluate each pair of patterns ;; to determine if they are similar within a tolerance of 𝑟 = 0. set substr-copy substrings2 calculate-distancies let S2 similar output-print word "Similar patterns of length = 2 --> " S2 output-print "" if S2 = 0 [stop-message stop] ;; Creating patterns with m = 3 set m m + 1 set index 0 set similar 0 set substrings [] built-substrings set input-string but-last input-string let substrings3 substrings output-print word "Set of patterns with m + 1 = 3 --> " substrings3 set substr-copy substrings3 calculate-distancies let S3 similar output-print word "Similar patterns of length = 3 --> " S3 output-print "" if S3 = 0 [stop-message stop] ;; sample entropy computation set sampen precision (- ln (S3 / S2)) 5 output-type word "*** SAMPLE ENTROPY = - ln " S3 output-type word " / " S2 output-type word " = " sampen output-print " ***" end to built-substrings set substrings lput (substring input-string index (index + m)) substrings set index index + 1 if index < (length input-string - m) [built-substrings] end to calculate-distancies set index 0 let short.copy but-first substr-copy repeat length short.copy [ if item 0 substr-copy = item index short.copy [set similar similar + 1] set index index + 1 ] if length short.copy > 1 [ set substr-copy but-first substr-copy calculate-distancies ] set index 0 end to start-message output-print "" output-print "Let's compute the sample entropy for the given sequence (with r=0 and m=2)." output-print "" end to stop-message output-print "It is not possible to compute the sample entropy for this string" output-type "because the similar patterns of length " output-type m output-type " is null." if m = 2 [set input-string but-last input-string] end ;; Public Domain: to the extent possible under law, the author has waived ;; all copyright and related or neighboring rights to this model.
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Sample Entropy Calculation.png | preview | Preview for 'Sample Entropy Calculation' | 4 months ago, by Cosimo Leuci | Download |
This model does not have any ancestors.
This model does not have any descendants.