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

VMField.h

Go to the documentation of this file.
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,v 1.4 2004/07/21 16:30:55 chrish42 Exp $ 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 // void print(ostream& out) const; 00077 // void write(ostream& out) const; 00078 // void read(istream& in); 00079 }; 00080 00081 // inline ostream& operator<<(ostream& out, const VMField& f) { f.print(out); return out; } 00082 00083 // inline void write(ostream& out, const VMField& f) { f.write(out); } 00084 // inline void read(istream& in, VMField& f) { f.read(in); } 00085 00086 // inline PStream &operator<<(PStream &out, const VMField &f) 00087 // { f.write(out.rawout()); return out; }; 00088 00089 // inline PStream &operator>>(PStream &in, VMField &f) 00090 // { f.read(in.rawin()); return in; }; 00091 00093 class VMFieldStat 00094 { 00095 protected: 00096 int nmissing_; 00097 int nnonmissing_; 00098 int npositive_; 00099 int nnegative_; 00100 double sum_; 00101 double sumsquare_; 00102 real min_; 00103 real max_; 00104 00106 int maxndiscrete; 00107 00108 public: 00109 00112 map<real,int> counts; 00113 00114 VMFieldStat(int the_maxndiscrete=255); 00115 00116 int count() const { return nmissing_ + nnonmissing_; } 00117 int nmissing() const { return nmissing_; } 00118 int nnonmissing() const { return nnonmissing_; } 00119 int npositive() const { return npositive_; } 00120 int nnegative() const { return nnegative_; } 00121 int nzero() const { return nnonmissing_ - (npositive_+nnegative_); } 00122 real sum() const { return real(sum_); } 00123 real sumsquare() const { return real(sumsquare_); } 00124 real min() const { return min_; } 00125 real max() const { return max_; } 00126 real mean() const { return real(sum_/nnonmissing_); } 00127 real variance() const { return real((sumsquare_ - square(sum_)/nnonmissing_)/(nnonmissing_-1)); } 00128 real stddev() const { return sqrt(variance()); } 00129 00130 real prob(real value) { return counts[value]/real(nnonmissing()); } 00131 00132 void update(real val); 00133 00134 void write(ostream& out) const; 00135 void read(istream& in); 00136 }; 00137 00138 } // end of namespace PLearn 00139 00140 #endif 00141

Generated on Tue Aug 17 16:10:48 2004 for PLearn by doxygen 1.3.7