![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
![]() |
#16 |
Gefallen Engel U-666
|
![]()
^
![]() ![]() ![]() ![]() ![]()
__________________
"Only two things are infinite; The Universe and human squirrelyness?!! |
![]() |
![]() |
![]() |
#17 |
Ocean Warrior
![]() |
![]()
Err you don't really need to create an object (class) for this, a simple function should do just fine.
|
![]() |
![]() |
![]() |
#18 |
GLOBAL MODDING TERRORIST
|
![]()
Yep. A new function is plenty good enuff. I don't like adding some monster package I'll never use.
|
![]() |
![]() |
![]() |
#19 |
Starte das Auto
|
![]()
Nothing worse than having a monster package and never using it.
|
![]() |
![]() |
![]() |
#20 |
Silent Hunter
![]() Join Date: Dec 2004
Location: AN9771
Posts: 4,904
Downloads: 304
Uploads: 0
|
![]()
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. |
![]() |
![]() |
![]() |
#21 | |
Still crazy as ever!
Join Date: Jan 2008
Location: A little south of sanity
Posts: 3,375
Downloads: 180
Uploads: 1
|
![]() Quote:
![]()
__________________
Hanging on in quiet desperation is the English way... |
|
![]() |
![]() |
![]() |
#22 |
Navy Seal
![]() |
![]()
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>
__________________
__________________________________________________ __ |
![]() |
![]() |
![]() |
#23 |
ACE
![]() Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
|
![]()
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) { } Code:
listOfDoubles.size(); Code:
public void CalculateStandardDev(double listOfDoubles) { int sizeOfList = listOfDoubles.size(); } ![]() Code:
public void CalculateStandardDev(double listOfDoubles) { int sizeOfList = listOfDoubles.size(); double temporarySum = 0; for(int i=0; i<sizeOfList; i++) { temporarySum += listOfDoubles[i]; } } |
![]() |
![]() |
![]() |
#24 |
ACE
![]() Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
|
![]()
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; } ![]() 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); } } Code:
pow(number, exponentValue) 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; } |
![]() |
![]() |
![]() |
#25 |
ACE
![]() Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
|
![]()
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; } |
![]() |
![]() |
![]() |
#26 |
Soaring
|
![]()
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. |
![]() |
![]() |
![]() |
#27 |
GLOBAL MODDING TERRORIST
|
![]()
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. ![]() |
![]() |
![]() |
![]() |
#28 | |
ACE
![]() Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
|
![]() Quote:
![]() |
|
![]() |
![]() |
![]() |
#29 |
Rear Admiral
![]() |
![]()
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. |
![]() |
![]() |
![]() |
#30 |
Airplane Nerd
|
![]()
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.
__________________
|
![]() |
![]() |
![]() |
|
|