PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: VMField.h 9227 2008-07-10 18:53:55Z saintmlx $ 00041 * This file is part of the PLearn library. 00042 ******************************************************* */ 00043 00044 00047 #ifndef VMField_INC 00048 #define VMField_INC 00049 00050 #include <plearn/base/general.h> 00051 #include <plearn/io/PStream.h> 00052 00053 namespace PLearn { 00054 using namespace std; 00055 00057 class VMField 00058 { 00059 public: 00060 00061 enum FieldType 00062 { 00063 UnknownType = 0, 00064 Continuous, 00065 DiscrGeneral, 00066 DiscrMonotonic, 00067 DiscrFloat, 00068 Date 00069 }; 00070 00071 string name; 00072 FieldType fieldtype; 00073 00074 VMField(const string& the_name="", FieldType the_fieldtype=UnknownType); 00075 00076 bool operator==(const VMField& other) const; 00077 bool operator!=(const VMField& other) const; 00078 00079 }; 00080 00081 PStream& operator>>(PStream& in, VMField::FieldType& x); // dummy placeholder; do not call 00082 00083 PStream& operator>>(PStream& in, VMField& x); 00084 PStream& operator<<(PStream& out, const VMField& x); 00085 00087 class VMFieldStat 00088 { 00089 protected: 00090 int nmissing_; 00091 int nnonmissing_; 00092 int npositive_; 00093 int nnegative_; 00094 double sum_; 00095 double sumsquare_; 00096 real min_; 00097 real max_; 00098 00100 int maxndiscrete; 00101 00102 public: 00103 00106 map<real,int> counts; 00107 00108 VMFieldStat(int the_maxndiscrete=255); 00109 00110 int count() const { return nmissing_ + nnonmissing_; } 00111 int nmissing() const { return nmissing_; } 00112 int nnonmissing() const { return nnonmissing_; } 00113 int npositive() const { return npositive_; } 00114 int nnegative() const { return nnegative_; } 00115 int nzero() const { return nnonmissing_ - (npositive_+nnegative_); } 00116 real sum() const { return real(sum_); } 00117 real sumsquare() const { return real(sumsquare_); } 00118 real min() const { return min_; } 00119 real max() const { return max_; } 00120 real mean() const { return real(sum_/nnonmissing_); } 00121 real variance() const { return real((sumsquare_ - square(sum_)/nnonmissing_)/(nnonmissing_-1)); } 00122 real stddev() const { return sqrt(variance()); } 00123 00124 real prob(real value) { return counts[value]/real(nnonmissing()); } 00125 00126 void update(real val); 00127 00128 void write(PStream& out) const; 00129 void read(PStream& in); 00130 }; 00131 00132 } // end of namespace PLearn 00133 00134 #endif 00135 00136 00137 /* 00138 Local Variables: 00139 mode:c++ 00140 c-basic-offset:4 00141 c-file-style:"stroustrup" 00142 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00143 indent-tabs-mode:nil 00144 fill-column:79 00145 End: 00146 */ 00147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :