Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

multiclasscontinuousdistribution.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (c) 2003, Cornell University
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009    - Redistributions of source code must retain the above copyright notice,
00010        this list of conditions and the following disclaimer.
00011    - Redistributions in binary form must reproduce the above copyright
00012        notice, this list of conditions and the following disclaimer in the
00013        documentation and/or other materials provided with the distribution.
00014    - Neither the name of Cornell University nor the names of its
00015        contributors may be used to endorse or promote products derived from
00016        this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00028 THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 */
00031 
00032 // -*- C++ -*-
00033 
00034 #if !defined _CLUS_MULTICLASSCONTINUOUSDISTRIBUTION_H
00035 #define _CLUS_MULTICLASSCONTINUOUSDISTRIBUTION_H
00036 
00037 #include "distribution.h"
00038 #include "multiclassdistribution.h"
00039 #include "statfct.h"
00040 
00041 using namespace TNT;
00042 
00043 namespace CLUS
00044 {
00045 
00046 /** The class is a repository of continuous sistributions that each predict
00047     one of the class labels of a discrete variable.
00048 */
00049 template< class T_Distribution >
00050 class MulticlassContinuousDistribution : public MulticlassDistribution
00051 {
00052 protected:
00053     Vector<T_Distribution> distributions;
00054 
00055 public:
00056     /** Constructor.
00057 
00058         @param NoClasses  number of classes
00059         @param D          a distribution that contains all the parameters
00060                           the distributions inside the class have.
00061     */
00062     MulticlassContinuousDistribution(int NoClasses, T_Distribution& D):
00063             MulticlassDistribution(NoClasses), distributions(NoClasses,D)
00064     { }
00065 
00066     /** Infer will use data to produce noClasses normalized probabilities
00067     into result. 
00068     */
00069     virtual void Infer(const double* cdata, const int* ddata, double* result)
00070     {
00071         double Coef=0.0;
00072         for (int i=0; i<noClasses; i++)
00073         {
00074             Coef+=distributions[i].Probability(cdata);
00075         }
00076 
00077         for (int i=0; i<noClasses; i++)
00078             result[i]=distributions[i].NormalizeProbability(Coef);
00079 
00080     }
00081 
00082     /** MultiplicativeInfer uses data to produce probabilities and
00083     multiplies these probabilities with the ones in result.
00084     */
00085     virtual void MultiplicativeInfer(const double* cdata, const int* ddata, double* result)
00086     {
00087         for (int i=0; i<noClasses; i++)
00088             result[i]*=distributions[i].Probability(cdata);
00089     }
00090 
00091     /** Prepares the distributions for learning. */
00092     virtual void StartLearning(void)
00093     {
00094         for (int i=0; i<noClasses; i++)
00095             distributions[i].InitializeStatistics();
00096     }
00097 
00098     virtual void LearnSample(const double* cdata, const int* ddata, int classLabel, double weightSample=1.0)
00099     {
00100         distributions[classLabel].UpdateStatistics(cdata, weightSample);
00101     }
00102 
00103     virtual void LearnSample(const double* cdata, const int* ddata,
00104                              double* classProbabilities, double weightSample=1.0)
00105     {
00106         for (int i=0; i<noClasses; i++)
00107             distributions[i].UpdateStatistics(cdata, weightSample*classProbabilities[i]);
00108     }
00109 
00110 
00111     virtual void StopLearning(void)
00112     {
00113         for (int i=0; i<noClasses; i++)
00114             distributions[i].UpdateParameters();
00115     }
00116 
00117     virtual double PValueStatisticalTest(void);
00118 
00119 #ifdef CLUS_USE_XML
00120 
00121     virtual void PrintToXmlStream(ostream& output)
00122     {
00123         output << "<MulticlassContinuousDistribution";
00124         PrintAttribute(output, "typeDistribution", T_Distribution::TypeName());
00125         output << ">" << endl;
00126 
00127         PrintVectorOfElements(output, distributions);
00128 
00129         output << "</MulticlassContinuousDistribution>" << endl;
00130     }
00131 #endif
00132 
00133     virtual bool IsClassLabelAbsent(int index)
00134     {
00135         return distributions[index].HasZeroWeight();
00136     }
00137 };
00138 
00139 }
00140 
00141 #endif // _CLUS_MULTICLASSCONTINUOUSDISTRIBUTION_H

Generated on Mon Jul 21 16:57:24 2003 for SECRET by doxygen 1.3.2