Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to count correctly number of matching pairs in two vector
    primarykey
    data
    text
    <p>please let us consider this code</p> <pre><code>function averageentropy=calculate(f,y) count1=0; count0=0; n=length(f); n1=0; n0=0; entrop1=0; entrop2=0; bigp=sum(f)/n; indf1 = f == 1; indf0 = ~indf1 ; indy1 = y == 1; indy0 = ~indy1 ; count1 = sum(indf1 &amp; indy1) ; count0 = sum(indf0 &amp; indy0) ; n1 = sum(indf1); n0 = sum(indf0); smallpplus=count1/n1; smallpminus=count0/n0; if smallpplus==0 || (1-smallpplus==0) entrop1=0; else entrop1=-smallpplus*log2(smallpplus)-(1- smallpplus)*log2(1- smallpplus); end if smallpminus==0 || (1-smallpminus==0) entrop2=0; else entrop2=-smallpminus*log2(smallpminus)-(1- smallpminus)*log2(1- smallpminus); end averageentropy=bigp*entrop1+(1-bigp)*entrop2; end </code></pre> <p>and i want following thing,first of all consider following data for f2 and y</p> <pre><code>f2 0 0 0 1 1 1 0 1 </code></pre> <p>and </p> <pre><code>y 1 1 1 0 0 0 0 0 </code></pre> <p>and i want to calculate following steps </p> <p>1.calculate bigp which is equal number of 1 in f2 divided by length of f2,this code does well this part</p> <ol> <li>i want to count number of 1 in y where f2=1</li> </ol> <p>2.1 i defined small p plus as this number divided by number of 1 in f2</p> <p>3.i want to count number of 1 in y where f2=0</p> <p>3.1 i defined small p minus as this number divided total number of f2=0</p> <p>and finaly i want to calculate average entropy,formula is indicated in code</p> <p>what is should get is 0.47,but i am getting 0.4,pl;ease help me to fix this</p> <p>UPDATED i think this line should be error</p> <pre><code>count1 = sum(indf1 &amp; indy1) ; count0 = sum(indf0 &amp; indy1) ; </code></pre> <p>more precisely</p> <pre><code>count0 = sum(indf0 &amp; indy1) count0 = 3 </code></pre> <p>there is error,there must be 3/8=0.375</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload