Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 00020 #include "Kurtosis.h" 00021 #include "../common_source.h" 00022 00023 using std::ostringstream; 00024 using namespace Marsyas; 00025 00026 00027 Kurtosis::Kurtosis(mrs_string name):MarSystem("Kurtosis",name) 00028 { 00029 z_ = 0.0; 00030 b_ = 0.0; 00031 q_ = 0.0; 00032 } 00033 00034 00035 Kurtosis::~Kurtosis() 00036 { 00037 } 00038 00039 00040 MarSystem* 00041 Kurtosis::clone() const 00042 { 00043 return new Kurtosis(*this); 00044 } 00045 00046 void 00047 Kurtosis::myUpdate(MarControlPtr sender) 00048 { 00049 (void) sender; //suppress warning of unused parameter(s) 00050 MRSDIAG("Kurtosis.cpp - Kurtosis:myUpdate"); 00051 00052 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")); 00053 setctrl("mrs_natural/onObservations", (mrs_natural)1); 00054 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00055 setctrl("mrs_string/onObsNames", "Kurtosis,"); 00056 00057 //defaultUpdate(); [!] 00058 inObservations_ = getctrl("mrs_natural/inObservations")->to<mrs_natural>(); 00059 00060 obsrow_.create(inObservations_); 00061 } 00062 00063 00064 void 00065 Kurtosis::myProcess(realvec& in, realvec& out) 00066 { 00067 mrs_natural o,t; 00068 //checkFlow(in,out); 00069 00070 // old code for Kurtosis calculation 00071 00072 /* for (t = 0; t < inSamples_; t++) 00073 { 00074 00075 for (o=0; o < inObservations_; o++) 00076 { 00077 obsrow_(o) = in(o,t); 00078 } 00079 z_ = 0.0; 00080 mrs_real mean = obsrow_.mean(); 00081 for (o=0; o < inObservations_; o++) 00082 { 00083 b_ = obsrow_(o) - mean ; 00084 00085 // take x - u to the fourth power into the sum 00086 z_ += (b_ * b_ * b_ * b_); 00087 } 00088 00089 // standard deviation to the fourth power 00090 q_ = obsrow_.var() * obsrow_.var(); 00091 00092 00093 if ((z_ < 1.0e-45)||(q_ < 1.0e-45)) 00094 out(0,t) = 0.5; 00095 else 00096 { 00097 // out(0,t) = (mrs_real)((z_ / q_ * inObservations_) - 3.0); 00098 out(0,t) = (mrs_real)((z_ / q_ ) - 3.0); 00099 } 00100 } 00101 00102 00103 cout << "k1 = " << out(0,0) << endl; 00104 */ 00105 00106 00107 for (t = 0; t < inSamples_; t++) 00108 { 00109 00110 for (o=0; o < inObservations_; o++) 00111 { 00112 obsrow_(o) = in(o,t); 00113 } 00114 z_ = 0.0; 00115 mrs_real mean = obsrow_.mean(); 00116 for (o=0; o < inObservations_; o++) 00117 { 00118 obsrow_(o) = obsrow_(o) - mean ; 00119 b_ = obsrow_(o); 00120 00121 z_ += (b_ * b_ * b_ * b_); 00122 q_ += (b_ * b_); 00123 } 00124 q_ = q_ * q_; 00125 q_ = q_ / inObservations_; 00126 00127 if ((z_ < 1.0e-45)||(q_ < 1.0e-45)) 00128 out(0,t) = 0.5; 00129 else 00130 { 00131 out(0,t) = (mrs_real)((z_ / q_ ) - 3.0); 00132 } 00133 } 00134 00135 00136 // cout << "k2 = " << out(0,0) << endl; 00137 }