SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > General > General Topics
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 10-27-14, 02:49 PM   #16
Aktungbby
Gefallen Engel U-666
 
Aktungbby's Avatar
 
Join Date: Jul 2013
Location: On a tilted, overheated, overpopulated spinning mudball on Collision course with Andromeda Galaxy
Posts: 30,006
Downloads: 24
Uploads: 0


Default That's not mean deviation-that's CRUEL deviation!

^ I see it so clearly now; Jeff! You've got it in a nutshell!I didn't know air guns were so complicated.
__________________

"Only two things are infinite; The Universe and human squirrelyness?!!
Aktungbby is offline   Reply With Quote
Old 10-27-14, 03:16 PM   #17
ikalugin
Ocean Warrior
 
Join Date: Aug 2014
Location: Moscow, Russia
Posts: 3,212
Downloads: 8
Uploads: 0


Default

Err you don't really need to create an object (class) for this, a simple function should do just fine.
ikalugin is offline   Reply With Quote
Old 10-28-14, 09:38 AM   #18
Jeff-Groves
GLOBAL MODDING TERRORIST
 
Jeff-Groves's Avatar
 
Join Date: Sep 2014
Posts: 5,650
Downloads: 137
Uploads: 0


Default

Yep. A new function is plenty good enuff. I don't like adding some monster package I'll never use.
Jeff-Groves is offline   Reply With Quote
Old 10-28-14, 09:47 AM   #19
Eichhörnchen
Starte das Auto
 
Eichhörnchen's Avatar
 
Join Date: Aug 2014
Location: The Fens
Posts: 17,388
Downloads: 5
Uploads: 0


Default

Nothing worse than having a monster package and never using it.
Eichhörnchen is online   Reply With Quote
Old 10-28-14, 10:52 AM   #20
Pisces
Silent Hunter
 
Join Date: Dec 2004
Location: AN9771
Posts: 4,904
Downloads: 304
Uploads: 0
Default

I have never understood why it has to divide by N-1. Can anyone explain why it is less 1?

I mean, simple averages are simply the sum divided by N. That makes sense to spread the (sum of) differences accross all samples.
Pisces is offline   Reply With Quote
Old 10-28-14, 01:34 PM   #21
Tango589
Still crazy as ever!
 
Tango589's Avatar
 
Join Date: Jan 2008
Location: A little south of sanity
Posts: 3,375
Downloads: 180
Uploads: 1
Default

Quote:
Originally Posted by Eichhornchen View Post
Nothing worse than having a monster package and never using it.
Fnaar, fnaar.

__________________


Hanging on in quiet desperation is the English way...
Tango589 is offline   Reply With Quote
Old 10-28-14, 04:58 PM   #22
vienna
Navy Seal
 
Join Date: Jun 2005
Location: Anywhere but the here & now...
Posts: 7,711
Downloads: 85
Uploads: 0


Default

You know, when I saw the title of this thread, I was a bit confused. I live in Hollywood, California; here, a standard deviation is anything that does not require above normal medical attention, a lengthy session in a confessional, or an excessive bail...


<O>
__________________
__________________________________________________ __
vienna is offline   Reply With Quote
Old 10-28-14, 05:28 PM   #23
Chad
ACE
 
Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
Default

I am a bit rusty on my C++, but maybe we can get you going in the right direction with some psuedo-code!

We know we will have a list of items with numeric values, for simplicity sake, let's assume these are doubles.

So, let's pass that to stubbed method:

Code:
public void CalculateStandardDev(double listOfDoubles)
{

}
Now, we know the length of our array using the following:

Code:
listOfDoubles.size();
This will be our 'n' variable

Code:
public void CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
}
Now we can find the mean by adding an additional local parameter called temporarySum and adding to it while in scope. This may be where my C++ rusty-ness shows

Code:
public void CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
     double temporarySum = 0;

     for(int i=0; i<sizeOfList; i++)
     {
         temporarySum += listOfDoubles[i];
     }
}
__________________
Chad is offline   Reply With Quote
Old 10-28-14, 05:39 PM   #24
Chad
ACE
 
Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
Default

Sorry, was scared I was going to lose progress.. Anyways, now we have the sum of all of our items and our 'n' variable. But we still don't have the mean, or the average. So.. to find the average we divide the sum of all of our numbers by 'n', our size of our list:

Code:
public void CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
     double temporarySum = 0;

     for(int i=0; i<sizeOfList; i++)
     {
         temporarySum += listOfDoubles[i];
     }

     double averageOfList = temporarySum / sizeOfList;
}

Done with Step 1!

So now we go into Step 2, which has this equation:



We look at each value and subtract the mean and square the result. Sounds easy enough:


Code:
public void CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
     double temporarySum = 0;

     for(int i=0; i<sizeOfList; i++)
     {
         temporarySum += listOfDoubles[i];
     }

     double averageOfList = temporarySum / sizeOfList;

     for(int j=0; j<sizeOfList; j++)
     {
         listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
     }
}
What I am doing is replacing the original value from the list with the calculated result of that value minus the average, and using the pow method to square the result. Square being to the second power.

Code:
pow(number, exponentValue)
Now we will loop through our list again and add the new listOfDoubles to eachother, or from 1 to N, N being our variable sizeOfList. We then need to divide by our size of list to give us, VARIANCE!

Code:
public void CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
     double temporarySum = 0;

     for(int i=0; i<sizeOfList; i++)
     {
         temporarySum += listOfDoubles[i];
     }

     double averageOfList = temporarySum / sizeOfList;

     for(int j=0; j<sizeOfList; j++)
     {
         listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
     }

    double squaredDifference = 0;
    double variance = 0;

    for(int k=0; k<sizeOfList; k++)
   {
         squaredDifference += listOfDoubles[k];
   }

   variance = squaredDifference / sizeOfList;
}
__________________
Chad is offline   Reply With Quote
Old 10-28-14, 05:43 PM   #25
Chad
ACE
 
Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
Default

Now that we have our variance, the last step is extremely easy. We simply take the square root of variance to give us the Standard Deviation value!!!

Code:
public double CalculateStandardDev(double listOfDoubles)
{
     int sizeOfList = listOfDoubles.size();
     double temporarySum = 0;

     for(int i=0; i<sizeOfList; i++)
     {
         temporarySum += listOfDoubles[i];
     }

     double averageOfList = temporarySum / sizeOfList;

     for(int j=0; j<sizeOfList; j++)
     {
         listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2);
     }

    double squaredDifference = 0;
    double variance = 0;

    for(int k=0; k<sizeOfList; k++)
   {
         squaredDifference += listOfDoubles[k];
   }

   variance = squaredDifference / sizeOfList;

   double standardDeviationValue = sqrt (variance );
   return standardDeviationValue;
}
__________________
Chad is offline   Reply With Quote
Old 10-28-14, 05:52 PM   #26
Skybird
Soaring
 
Skybird's Avatar
 
Join Date: Sep 2001
Location: the mental asylum named Germany
Posts: 42,622
Downloads: 10
Uploads: 0


Default

Brrr, take it away, it hurts our eyes! Last time I did stuff like that, was in GFA 3.0 on an Amiga, 25 years ago.
__________________
If you feel nuts, consult an expert.
Skybird is online   Reply With Quote
Old 10-29-14, 12:04 PM   #27
Jeff-Groves
GLOBAL MODDING TERRORIST
 
Jeff-Groves's Avatar
 
Join Date: Sep 2014
Posts: 5,650
Downloads: 137
Uploads: 0


Default

I'm gonna go with C++ Mathematical Expression Toolkit Library (ExprTk).
It's a neat header file I can use then throw away along with those old Dewalt side cuts.
Jeff-Groves is offline   Reply With Quote
Old 10-29-14, 04:07 PM   #28
Chad
ACE
 
Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
Default

Quote:
Originally Posted by Jeff-Groves View Post
I'm gonna go with C++ Mathematical Expression Toolkit Library (ExprTk).
It's a neat header file I can use then throw away along with those old Dewalt side cuts.
Well it was fun going back and writing that method
__________________
Chad is offline   Reply With Quote
Old 10-29-14, 05:16 PM   #29
Armistead
Rear Admiral
 
Join Date: Dec 2008
Location: on the Dan
Posts: 10,880
Downloads: 364
Uploads: 0


Default

I had a deviated septum once.
__________________

You see my dog don't like people laughing. He gets the crazy idea you're laughing at him. Now if you apologize like I know you're going to, I might convince him that you really didn't mean it.
Armistead is offline   Reply With Quote
Old 10-29-14, 09:02 PM   #30
Red October1984
Airplane Nerd
 
Red October1984's Avatar
 
Join Date: Aug 2011
Location: Texas
Posts: 6,243
Downloads: 115
Uploads: 0


Default

Quote:
Originally Posted by Skybird View Post
Started statistics courses?
I've got this stuff in Psychology right now. It's in a chapter about mental retardation and how common and how severe it is.
__________________
Red October1984 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:49 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 1995- 2025 Subsim®
"Subsim" is a registered trademark, all rights reserved.