Last active
May 1, 2016 06:29
-
-
Save tkaczenko/55f0c0c4a057d98ad85d to your computer and use it in GitHub Desktop.
Вычисление асимметрии и эксцесса C++ (Qt) / Calculating asymmetry and kurtosis written in C++ (Qt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QVector> | |
#include <iostream> | |
#include "qmath.h" | |
using namespace std; | |
// Abs data of vector | |
void absVector (QVector <qint16> v, quint32 n) | |
{ | |
qint16* data = v.data(); | |
for (quint32 i = 0; i < n; i++) | |
data[i] = qAbs(data[i]); | |
} | |
// Sum of vector elements | |
qint32 sumVector (QVector <qint16> v, quint32 n) | |
{ | |
qint16* data = v.data(); | |
qint32 s = 0; | |
for (quint32 i = 0; i < n; i++) | |
s += data[i]; | |
return s; | |
} | |
// Arithemit mean of vector elements | |
double arithmeticMean (qint32 s, quint32 n) | |
{ | |
double res = s / n; | |
return res; | |
} | |
// Central moment random variables | |
QVector <qint16> centralMoment (QVector <qint16> v, quint32 n, double mx) | |
{ | |
QVector <qint16> temp(n); | |
qint16* data = v.data(); | |
for (quint32 i = 0; i < n; i++) | |
temp[i] = data[i] - mx; | |
return temp; | |
} | |
// Exponentiation of vector elements | |
QVector <qint16> exponentiation (QVector <qint16> v, quint32 n, quint32 y) | |
{ | |
QVector <qint16> temp(n); | |
qint16* data = v.data(); | |
for (quint32 i = 0; i < n; i++) | |
temp[i] = qPow(data[i], y); | |
return temp; | |
} | |
// Standart deviation | |
double deviation (qint32 s, quint32 n) | |
{ | |
double res = qSqrt( (double) s / (n - 1)); | |
return res; | |
} | |
// Asymmetry of vector elements | |
double asymmetry (qint32 s, quint32 n, double sig) | |
{ | |
double res = s / (n * qPow(sig,3)); | |
return res; | |
} | |
// Kurtosis of vector elements | |
double kurtosis(qint32 s, quint32 n, double sig) | |
{ | |
double res = s / (n * qPow(sig,4)) - 3; | |
return res; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QVector <qint16> v1(0); | |
cout << "Write number of vector elements: " << endl; | |
quint32 size; | |
cin >> size; | |
for (int i = 0; i < size; i++) { | |
qint16 x; | |
cin >> x; | |
v1.append(x); | |
} | |
absVector(v1, size); | |
for (int i = 0; i < 5; i++) { | |
std::cout << v1[i] << " "; | |
} | |
qint32 s1 = sumVector(v1, size); | |
double Mx = arithmeticMean(s1, size); | |
cout << "Mx = " << Mx << endl; | |
QVector <qint16> v2 = centralMoment(v1, size, Mx); | |
cout << endl; | |
QVector <qint16> v3 = exponentiation(v2, size, 2); | |
cout << endl; | |
qint32 s2 = sumVector(v3, size); | |
double sigma = deviation(s2, size); | |
cout << "Standart deviation = " << sigma << endl; | |
cout << endl; | |
v3 = exponentiation(v2, size, 3); | |
cout << endl; | |
qint32 s3 = sumVector(v3, size); | |
cout << endl; | |
double asymmetry1 = asymmetry(s3, size, sig); | |
cout << "Asymmetry = " << asymmetry1 << endl; | |
v3 = exponentiation(v2, size, 4); | |
qint32 s4 = sumVector(v3, size); | |
double kurtosis1 = kurtosis(s4, size, sig); | |
cout << s4 << endl; | |
cout << "Ex = " << kurtosis1 << endl; | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment