Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

TestDependencyCommand.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // TestDependencyCommand.cc 00004 // 00005 // Copyright (C) 2003 Pascal Vincent 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: TestDependencyCommand.cc,v 1.2 2004/07/21 16:30:49 chrish42 Exp $ 00037 ******************************************************* */ 00038 00040 #include "TestDependencyCommand.h" 00041 #include <plearn/db/getDataSet.h> 00042 #include <plearn/math/stats_utils.h> 00043 #include <plearn/vmat/VMat_maths.h> 00044 #include <plearn/sys/procinfo.h> 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00050 PLearnCommandRegistry TestDependencyCommand::reg_(new TestDependencyCommand); 00051 00053 void TestDependencyCommand::run(const vector<string>& args) 00054 { 00055 if(args.size()<3 || args.size()>3) 00056 PLERROR("test-dependencies expects 3 arguments, check the help"); 00057 00058 VMat data = getDataSet(args[0]); 00059 string x_spec = args[1]; 00060 string y_spec = args[2]; 00061 int x_col=0, y_col=0; 00062 if (x_spec[0]!='@') 00063 x_col = toint(x_spec); 00064 else { 00065 string x_name = x_spec.substr(1,x_spec.length()-1); 00066 x_col = data->fieldIndex(x_name); 00067 if (x_col<0) PLERROR("could not find field named %s in %s",x_name.c_str(),args[0].c_str()); 00068 } 00069 if (y_spec[0]!='@') 00070 y_col = toint(y_spec); 00071 else { 00072 string y_name = y_spec.substr(1,y_spec.length()-1); 00073 y_col = data->fieldIndex(y_name); 00074 if (y_col<0) PLERROR("could not find field named %s in %s",y_name.c_str(),args[0].c_str()); 00075 } 00076 00077 // extract the two columns 00078 TVec<int> columns(2); 00079 columns[0]=x_col; 00080 columns[1]=y_col; 00081 Mat xy_mat = data.columns(columns).toMat(); 00082 VMat x = VMat(xy_mat.column(0)); 00083 VMat y = VMat(xy_mat.column(1)); 00084 00085 Mat spearman_pvalue(1,1); 00086 Mat spearman_r(1,1); 00087 testSpearmanRankCorrelation(x,y,spearman_r,spearman_pvalue); 00088 Mat linear_pvalue(1,1); 00089 Mat linear_r(1,1); 00090 correlations(x,y,linear_r,linear_pvalue); 00091 00092 cout << "test-dependency between " << data->fieldName(x_col) << " (column " << x_col << ") and " 00093 << data->fieldName(y_col) << " (column " << y_col << "):" << endl; 00094 cout << "rank correlation = " << spearman_r(0,0) << " {p-value = " << spearman_pvalue(0,0) << "}" << endl; 00095 cout << "linear correlation = " << linear_r(0,0) << " {p-value = " << linear_pvalue(0,0) << "}" << endl; 00096 } 00097 00098 } // end of namespace PLearn 00099

Generated on Tue Aug 17 16:08:15 2004 for PLearn by doxygen 1.3.7