1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Tool Library //
9 // table_calculus //
10 // //
11 //-------------------------------------------------------//
12 // //
13 // table_mRMR.cpp //
14 // //
15 // Copyright (C) 2014 by //
16 // Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. SAGA is free software; you //
22 // can redistribute it and/or modify it under the terms //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the //
25 // License, or (at your option) any later version. //
26 // //
27 // SAGA is distributed in the hope that it will be //
28 // useful, but WITHOUT ANY WARRANTY; without even the //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
30 // PARTICULAR PURPOSE. See the GNU General Public //
31 // License for more details. //
32 // //
33 // You should have received a copy of the GNU General //
34 // Public License along with this program; if not, see //
35 // <http://www.gnu.org/licenses/>. //
36 // //
37 //-------------------------------------------------------//
38 // //
39 // e-mail: oconrad@saga-gis.org //
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Hamburg //
44 // Germany //
45 // //
46 ///////////////////////////////////////////////////////////
47
48 //---------------------------------------------------------
49 #ifdef WITH_MRMR
50
51
52 ///////////////////////////////////////////////////////////
53 // //
54 // //
55 // //
56 ///////////////////////////////////////////////////////////
57
58 //---------------------------------------------------------
59 #include "table_mRMR.h"
60
61
62 ///////////////////////////////////////////////////////////
63 // //
64 // //
65 // //
66 ///////////////////////////////////////////////////////////
67
68 //---------------------------------------------------------
CTable_mRMR(void)69 CTable_mRMR::CTable_mRMR(void)
70 {
71 Set_Name (_TL("Minimum Redundancy Feature Selection"));
72
73 Set_Author ("O.Conrad (c) 2014");
74
75 Set_Description (_TW(
76 "Identify the most relevant features for subsequent classification of tabular data.\n"
77 "\n"
78 ) + CSG_mRMR::Get_Description());
79
80 //-----------------------------------------------------
81 Parameters.Add_Table("",
82 "DATA" , _TL("Data"),
83 _TL(""),
84 PARAMETER_INPUT
85 );
86
87 Parameters.Add_Table_Field("DATA",
88 "CLASS" , _TL("Class Identifier"),
89 _TL("")
90 );
91
92 Parameters.Add_Table("",
93 "SELECTION" , _TL("Feature Selection"),
94 _TL(""),
95 PARAMETER_OUTPUT
96 );
97
98 Parameters.Add_Bool("",
99 "VERBOSE" , _TL("Verbose Output"),
100 _TL("output of intermediate results to execution message window"),
101 true
102 );
103
104 CSG_mRMR::Parameters_Add(&Parameters);
105 }
106
107
108 ///////////////////////////////////////////////////////////
109 // //
110 ///////////////////////////////////////////////////////////
111
112 //---------------------------------------------------------
On_Parameters_Enable(CSG_Parameters * pParameters,CSG_Parameter * pParameter)113 int CTable_mRMR::On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
114 {
115 CSG_mRMR::Parameters_Enable(pParameters, pParameter);
116
117 return( CSG_Tool::On_Parameters_Enable(pParameters, pParameter) );
118 }
119
120
121 ///////////////////////////////////////////////////////////
122 // //
123 ///////////////////////////////////////////////////////////
124
125 //---------------------------------------------------------
On_Execute(void)126 bool CTable_mRMR::On_Execute(void)
127 {
128 CSG_mRMR mRMR;
129
130 mRMR.Set_Verbose(Parameters("VERBOSE")->asBool());
131
132 CSG_Table *pData = Parameters("DATA")->asTable();
133
134 if( !mRMR.Set_Data(*pData, Parameters("CLASS")->asInt(), &Parameters) )
135 {
136 return( false );
137 }
138
139 if( !mRMR.Get_Selection(&Parameters) )
140 {
141 return( false );
142 }
143
144 //-----------------------------------------------------
145 CSG_Table *pSelection = Parameters("SELECTION")->asTable();
146
147 pSelection->Destroy();
148 pSelection->Fmt_Name("%s (%s)", _TL("Feature Selection"), pData->Get_Name());
149
150 pSelection->Add_Field("RANK" , SG_DATATYPE_Int);
151 pSelection->Add_Field("INDEX", SG_DATATYPE_Int);
152 pSelection->Add_Field("NAME" , SG_DATATYPE_String);
153 pSelection->Add_Field("SCORE", SG_DATATYPE_Double);
154
155 for(int i=0; i<mRMR.Get_Count(); i++)
156 {
157 CSG_Table_Record *pFeature = pSelection->Add_Record();
158
159 pFeature->Set_Value(0, i + 1);
160 pFeature->Set_Value(1, mRMR.Get_Index(i));
161 pFeature->Set_Value(2, mRMR.Get_Name (i));
162 pFeature->Set_Value(3, mRMR.Get_Score(i));
163 }
164
165 //-----------------------------------------------------
166 return( true );
167 }
168
169
170 ///////////////////////////////////////////////////////////
171 // //
172 // //
173 // //
174 ///////////////////////////////////////////////////////////
175
176 //---------------------------------------------------------
177 #endif // WITH_MRMR
178