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

distribution.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_DISTRIBUTION_H_
00035 #define _CLUS_DISTRIBUTION_H_
00036 
00037 #include <string>
00038 #include <iostream>
00039 #include <math.h>
00040 
00041 // The maximum dimentionality of the space
00042 #define MAX_IN_DIM 1000
00043 
00044 class Regressor;
00045 
00046 namespace CLUS
00047 {
00048 
00049 /** Base class for all the continuous distributions that have sufficient statistics.
00050 */
00051 class Distribution
00052 {
00053 protected:
00054     /// The dimentionality of the input space.
00055     int inDim;
00056     
00057     /// Used for optimization purpses. Is the last parameter passed to Infer or Learn
00058     
00059     const double* dataCache;
00060     
00061     /// Cached values for the last probabilities of belonging to the cluster
00062     double probabilityInfer, probabilityLearn;
00063     
00064     /// The weight in the sum of distributions
00065     double weight;
00066 
00067 public:
00068     Distribution(int InDim=0):
00069             inDim(InDim), dataCache(NULL), probabilityInfer(0.0),
00070             probabilityLearn(0.0), weight(1.0)
00071     {}
00072 
00073     /// Creates a class that can do the regression for this distribution if given the input
00074     Regressor* CreateRegressor(void)
00075     {
00076         return 0;
00077     }
00078 
00079     /// Returns true if weitht=0. In this case the distribution should not be used
00080     bool HasZeroWeight(void)
00081     {
00082         return (weight==0.0);
00083     }
00084 
00085     /// Initializes the parameters of the distribution randomly
00086     void RandomCluster(void)
00087     {}
00088 
00089     /// Perform distribution dependent transformations on the data
00090     void NormalizeData(const double* DataCache, double* X)
00091     {
00092         // Just copy the content of DataCache into X
00093         for (int i=0; i<inDim; i++)
00094             X[i]=DataCache[i];
00095     }
00096 
00097     /// Reverse the normalization transformation in original space
00098     void DenormalizeParameters(Distribution* pD)
00099     {/* do nothing */
00100     }
00101     
00102     /// Probability that a point belongs to this distribution at inference, unnormalized
00103     double InferProbability(const double* DataCache)
00104     {
00105         return 0.0;
00106     }
00107     
00108     /// Probability that a point belongs to this distribution at learning, unnormalized
00109     double LearnProbability(const double* DataCache)
00110     {
00111         return 0.0;
00112     }
00113     
00114     /// Probability that a point belongs to this distribution (unnormalized). Same as learn probability
00115     double Probability(const double* DataCache)
00116     {
00117         return LearnProbability(DataCache);
00118     }
00119     
00120     /// Returns the last Inference probability
00121     double LastInferProbability(void)
00122     {
00123         return probabilityInfer;
00124     }
00125     
00126     /// Returns the last Learning probability
00127     double LastLearnProbability(void)
00128     {
00129         return probabilityLearn;
00130     }
00131 
00132     double LastProbability(void)
00133     {
00134         return probabilityLearn;
00135     }
00136     
00137     /// Normalizes the probability of belonging to this cluster, normalizing over the mixture
00138     /// Coef is sum alpha*P(x|distribution)
00139     double NormalizeInferProbability(double Coef, int nrClus=1)
00140     {
00141         if (Coef==0.0)
00142             return 1.0/nrClus;
00143         probabilityInfer/=Coef;
00144         return probabilityInfer;
00145     }
00146     
00147     /// Normalizes the probability of belonging to this cluster, normalizing over the mixture
00148     /// Coef is sum alpha*P(x|distribution)
00149     double NormalizeLearnProbability(double Coef, int nrClus=1)
00150     {
00151         if (Coef==0.0)
00152             return probabilityLearn = 1.0/nrClus; // this is used when the point is far from any of the clusters
00153         if (isinf(Coef))
00154             return probabilityLearn = 0.0;
00155         probabilityLearn/=Coef;
00156         return probabilityLearn;
00157     }
00158     
00159     /// Makes the simple normalization of the probability not more sophisticated version that can be later added
00160     double NormalizeProbability(double Coef, int nrClus=1)
00161     {
00162         return NormalizeLearnProbability(Coef,nrClus);
00163     }
00164 
00165     /// Prepares the distribution for learning
00166     void InitializeStatistics(void)
00167     { }
00168     
00169     /// Updates the sufficient statistics
00170     void UpdateStatistics(double prob)
00171     { }
00172 
00173     /// Computes the values of the new parameters from sufficient statistics
00174     double UpdateParameters(void)
00175     {
00176         return 0.0;
00177     }
00178     
00179     static string TypeName(void)
00180     {
00181         return string("Distribution");
00182     }
00183     
00184     bool SetOptionDbl(char* optName,double value)
00185     {
00186         if ( strcmp(optName,"weight") )
00187         {
00188             weight=value;
00189             return true;
00190         }
00191         return false;
00192     }
00193     
00194     /// Computes the output value for the distribution*probab
00195     void AdjustYwithYoverD(double& y)
00196     {}
00197     
00198     /// Random initialization of a distribution
00199     void RandomDistribution(int NrClusters)
00200     {}
00201     
00202     /// Saves the state of the Distribution in a stream
00203     void SaveToStream(ostream& out)
00204     {}
00205     
00206     /// Loads the state of the Distribution in a stream
00207     void LoadFromStream(istream& in)
00208     {}    
00209 
00210 #ifdef CLUS_USE_XML
00211     /// Prints the distribution in XML in a stream
00212     void PrintToXmlStream(ostream& output)
00213     {
00214         output << "<Distribution";
00215         PrintAttribute(output, "weight", weight);
00216         output << "/>" << endl;
00217     }
00218 #endif
00219 
00220 };
00221 }
00222 
00223 
00224 
00225 #endif // _CLUS_DISTRIBUTION_H

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