Editing Talk:2435: Geothmetic Meandian

Jump to: navigation, search
Ambox notice.png Please sign your posts with ~~~~

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 163: Line 163:
  
  
I'd like to add my own implementation:
+
I'd like to add my own implemetation:
 
+
from math import *
from math import *
+
def getMeans(n=list):
def getMeans(n=list):
+
    n.sort()
    n.sort()
+
    mean=sum(n)/len(n)
    mean=sum(n)/len(n)
+
    if len(n)%2==1:
    if len(n)%2==1:
+
        median=n[len(n)//2]
        median=n[len(n)//2]
+
    else:
    else:
+
        median=(n[1+floor(len(n)/2)]-n[floor(len(n)/2)])/2
        median=(n[1+floor(len(n)/2)]-n[floor(len(n)/2)])/2
+
    prod=1
    prod=1
+
    for i in n:
    for i in n:
+
        prod*=i
        prod*=i
+
    gmean=prod**(1/len(n))
    gmean=prod**(1/len(n))
+
    return [mean,median,gmean]
    return [mean,median,gmean]
+
def gmdn(tol,n=list):
def gmdn(tol,n=list):
+
    mList=n
    mList=n
+
    mList=getMeans(mList)
    mList=getMeans(mList)
+
    while not (isclose(mList[0],mList[1],rel_tol=tol) and isclose(mList[1],mList[2],rel_tol=tol) and isclose(mList[0],mList[2],rel_tol=tol) ) :
    while not (isclose(mList[0],mList[1],rel_tol=tol) and isclose(mList[1],mList[2],rel_tol=tol) and  
+
        mList = getMeans(mList)
isclose(mList[0],mList[2],rel_tol=tol) ) :
+
    return (mList[0]+mList[1]+mList[2])/3
        mList = getMeans(mList)
+
print(gmdn(1e-15,[1,1,2,3,5]))
    return (mList[0]+mList[1]+mList[2])/3
 
print(gmdn(1e-15,[1,1,2,3,5]))
 
 
   
 
   
 
which gives me 2.089057949736859
 
which gives me 2.089057949736859
Line 284: Line 282:
  
 
My python program:
 
My python program:
from math import *
+
from math import *
def getMeans(n=list):
+
def getMeans(n=list):
    n.sort()
+
    n.sort()
    mean=sum(n)/len(n)
+
    mean=sum(n)/len(n)
    if len(n)%2==1:
+
    if len(n)%2==1:
        median=n[len(n)//2]
+
        median=n[len(n)//2]
    else:
+
    else:
        median=(n[1+floor(len(n)/2)]-n[floor(len(n)/2)])/2
+
        median=(n[1+floor(len(n)/2)]-n[floor(len(n)/2)])/2
    prod=1
+
    prod=1
    for i in n:
+
    for i in n:
        prod*=i
+
        prod*=i
    gmean=prod**(1/len(n))
+
    gmean=prod**(1/len(n))
    return [mean,median,gmean]
+
    return [mean,median,gmean]
def gmdn(tol,n=list):
+
def gmdn(tol,n=list):
    mList=n
+
    mList=n
    mList=getMeans(mList)
+
    mList=getMeans(mList)
    while not (isclose(mList[0],mList[1],rel_tol=tol) and isclose(mList[1],mList[2],rel_tol=tol) and  
+
    while not (isclose(mList[0],mList[1],rel_tol=tol) and isclose(mList[1],mList[2],rel_tol=tol) and isclose(mList[0],mList[2],rel_tol=tol) ) :
isclose(mList[0],mList[2],rel_tol=tol) ) :
+
        mList = getMeans(mList)
        mList = getMeans(mList)
+
    return mList[0]
    return mList[0]
+
print(gmdn(1e-15,[1,1,2,3,5]))
print(gmdn(1e-15,[1,1,2,3,5]))
 
  
 
It gave me 2.0890579497368584
 
It gave me 2.0890579497368584
Line 365: Line 362:
 
:Yes, here's a bit more on that.. I agree with [[User:Elektrizikekswerk|Elektrizikekswerk]] the joke is explained. The stat tip: "If you aren't sure whether to use the mean, median or geometric mean, just calculate all three, then repeat until it converges." is funny because there are many situations in the physical sciences where the arthmean, geometric mean and median for some data are different values. It is perhaps common that scientists not well versed in statistics are unsure which to use. The funny bit is imagining this less-statistically-versed-scientist throwing up their hands and just accepting the fixed constant given by iterating GMDN as the 'answer' irrelevant of any physical meaning. Also the name "geothmetic meandian" is funny because the word meandian is similar to both median, which it uses, and to ''meander'' which is indicated by the alternate assignment of the median on each iteration -- informally, this function meanders. [[User:Ramakarl|Ramakarl]]
 
:Yes, here's a bit more on that.. I agree with [[User:Elektrizikekswerk|Elektrizikekswerk]] the joke is explained. The stat tip: "If you aren't sure whether to use the mean, median or geometric mean, just calculate all three, then repeat until it converges." is funny because there are many situations in the physical sciences where the arthmean, geometric mean and median for some data are different values. It is perhaps common that scientists not well versed in statistics are unsure which to use. The funny bit is imagining this less-statistically-versed-scientist throwing up their hands and just accepting the fixed constant given by iterating GMDN as the 'answer' irrelevant of any physical meaning. Also the name "geothmetic meandian" is funny because the word meandian is similar to both median, which it uses, and to ''meander'' which is indicated by the alternate assignment of the median on each iteration -- informally, this function meanders. [[User:Ramakarl|Ramakarl]]
 
:Thanks to all who shared the absurdity so I could also enjoy the joke, and the joke is on me for needing to have a joke "explained". Now where is the button for me to give credit to the best answer? I want to be sure you get points toward your next-level badge. ;-) [[User:Rtanenbaum|Rtanenbaum]] ([[User talk:Rtanenbaum|talk]]) 16:23, 13 March 2021 (UTC)
 
:Thanks to all who shared the absurdity so I could also enjoy the joke, and the joke is on me for needing to have a joke "explained". Now where is the button for me to give credit to the best answer? I want to be sure you get points toward your next-level badge. ;-) [[User:Rtanenbaum|Rtanenbaum]] ([[User talk:Rtanenbaum|talk]]) 16:23, 13 March 2021 (UTC)
:This is actually one of my favorite xkcd comics. Even before seeing this comic, one thing I would always do was take the AM(AM,GM) instead of using either average on it's own. [[User:nullcline|nullcline]] ([[User talk:nullcline|talk]]) 17:33, 20 July 2021 (UTC)
+
 
  
 
== PyPi-package ==
 
== PyPi-package ==
Line 400: Line 397:
  
 
Since it uses F(F(F...)) someone should write a Hascal version that actually uses the fixedpoint function. [[Special:Contributions/172.69.35.175|172.69.35.175]] 22:56, 30 March 2021 (UTC)
 
Since it uses F(F(F...)) someone should write a Hascal version that actually uses the fixedpoint function. [[Special:Contributions/172.69.35.175|172.69.35.175]] 22:56, 30 March 2021 (UTC)
 
Short proof that the thing converges. Basically there are three cases, one is that the median is larger than both one is that it is smaller than both and one is that it is in between. If it is in between, both he max must decrease and the min must increase. If it is greater, then the minimum must increase. If it is less, the maximum must decrease. In all three cases max(F(n+1))-min(F(n+1))<max(F(n))-min(F(n)) so by monotonic convergence theorem it must converge.
 
[[Special:Contributions/172.70.206.163|172.70.206.163]] 02:40, 1 April 2022 (UTC)
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)

Template used on this page: