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 #include "Skewness.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 Skewness::Skewness(mrs_string name):MarSystem("Skewness",name) 00026 { 00027 //type_ = "Skewness"; 00028 //name_ = name; 00029 } 00030 00031 00032 Skewness::~Skewness() 00033 { 00034 } 00035 00036 00037 MarSystem* 00038 Skewness::clone() const 00039 { 00040 return new Skewness(*this); 00041 } 00042 00043 00044 void 00045 Skewness::myUpdate(MarControlPtr sender) 00046 { 00047 (void) sender; //suppress warning of unused parameter(s) 00048 MRSDIAG("Skewness.cpp - Skewness:myUpdate"); 00049 00050 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")); 00051 setctrl("mrs_natural/onObservations", (mrs_natural)1); 00052 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00053 setctrl("mrs_string/onObsNames", "Skewness,"); 00054 00055 //defaultUpdate();[!] 00056 inObservations_ = getctrl("mrs_natural/inObservations")->to<mrs_natural>(); 00057 00058 obsrow_.create(inObservations_); 00059 } 00060 00061 00062 void 00063 Skewness::myProcess(realvec& in, realvec& out) 00064 { 00065 mrs_natural t,o; 00066 00067 for (t = 0; t < inSamples_; t++) 00068 { 00069 00070 for (o=0; o < inObservations_; o++) 00071 { 00072 obsrow_(o) = in(o,t); 00073 } 00074 z_ = 0.0; 00075 for (o=0; o < inObservations_; o++) 00076 { 00077 b_ = obsrow_(o) - obsrow_.mean() ; 00078 00079 // take x - mean to the third power into the sum 00080 z_ += (b_ * b_ * b_); 00081 } 00082 if (z_ > 1.0e-45) 00083 z_ /= inObservations_; 00084 else 00085 z_ = 0.0; 00086 00087 00088 // standard deviation to the fourth power 00089 q_ = pow(obsrow_.var(), (mrs_real)1.5); 00090 00091 if ((q_ < 1.0e-45)||(z_== 1.0e-45)) 00092 out(0,t) = 0.5; 00093 else 00094 out(0,t) = (z_ / q_) / inObservations_; 00095 } 00096 00097 }