00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ZeroRClassifier.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 ZeroRClassifier::ZeroRClassifier(mrs_string name):MarSystem("ZeroRClassifier",name)
00025 {
00026 addControls();
00027 }
00028
00029 ZeroRClassifier::~ZeroRClassifier()
00030 {
00031 }
00032
00033 MarSystem*
00034 ZeroRClassifier::clone() const
00035 {
00036 return new ZeroRClassifier(*this);
00037 }
00038
00039 void
00040 ZeroRClassifier::addControls()
00041 {
00042 addctrl("mrs_string/mode", "train");
00043 addctrl("mrs_natural/nClasses", 1);
00044 setctrlState("mrs_natural/nClasses", true);
00045 addctrl("mrs_bool/done", false);
00046 addctrl("mrs_natural/prediction", 0);
00047 }
00048
00049 void
00050 ZeroRClassifier::myUpdate(MarControlPtr sender)
00051 {
00052 (void) sender;
00053 MRSDIAG("ZeroRClassifier.cpp - ZeroRClassifier:myUpdate");
00054
00055 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00056 setctrl("mrs_natural/onObservations", (mrs_natural)2);
00057 setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00058
00059 mrs_natural nlabels = getctrl("mrs_natural/nClasses")->to<mrs_natural>();
00060
00061 if ((mrs_natural)labelSizes_.getSize() != nlabels)
00062 labelSizes_.create(nlabels);
00063 mrs_string mode = getctrl("mrs_string/mode")->to<mrs_string>();
00064 if (mode == "predict")
00065 {
00066
00067 }
00068 }
00069
00070 void
00071 ZeroRClassifier::myProcess(realvec& in, realvec& out)
00072 {
00073 mrs_string mode = getctrl("mrs_string/mode")->to<mrs_string>();
00074 mrs_natural nlabels = getctrl("mrs_natural/nClasses")->to<mrs_natural>();
00075 mrs_natural l, t;
00076 mrs_natural prediction = 0;
00077
00078 mrs_real label;
00079
00080 if ((prev_mode_ == "predict") && (mode == "train"))
00081 {
00082 labelSizes_.setval(0.0);
00083 }
00084
00085 if (mode == "train")
00086 {
00087 for (t=0; t < inSamples_; t++)
00088 {
00089 label = in(inObservations_-1, t);
00090 if(label >= 0)
00091 {
00092 labelSizes_((int)label) = labelSizes_((int)label) + 1;
00093 }
00094 out(0,t) = label;
00095 out(1,t) = label;
00096 }
00097 }
00098
00099 if ((prev_mode_ == "train") && (mode == "predict"))
00100 {
00101 int max = -1;
00102 for (l=0; l < nlabels; l++)
00103 {
00104 if (labelSizes_(l) > max)
00105 {
00106 prediction = l;
00107 max = (int)labelSizes_(l);
00108 }
00109 }
00110 updControl("mrs_natural/prediction", prediction);
00111 }
00112
00113 if (mode == "predict")
00114 {
00115 for (t=0; t < inSamples_; t++)
00116 {
00117 label = in(inObservations_-1, t);
00118 prediction = getctrl("mrs_natural/prediction")->to<mrs_natural>();
00119 out(0,t) = (mrs_real)prediction;
00120 out(1,t) = label;
00121 }
00122 }
00123 prev_mode_ = mode;
00124 }