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

emhipclus.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 #if !defined(_EMHIPCLUS_H)
00033 #define _EMHIPCLUS_H
00034 
00035 #include "hipclus.h"
00036 
00037 #define MULT 0.5
00038 
00039 namespace CLUS
00040 {
00041 class EMHiperPlan:public HiperPlanCluster
00042 {
00043     // Crafted after HiperPlan
00044 protected:
00045     double sigma2; // the 2*sigma^2 value in the clusters
00046 public:
00047     EMHiperPlan():HiperPlanCluster()
00048     {
00049         sigma2=2.0*pow2(MULT);
00050     }
00051     
00052     EMHiperPlan(int InDim, int OutDim):HiperPlanCluster(InDim,OutDim)
00053     {
00054         sigma2=2.0*pow2(MULT);
00055     }
00056     
00057     EMHiperPlan(int InDim, int OutDim, int):HiperPlanCluster(InDim,OutDim,0)
00058     {
00059         sigma2=2.0*pow2(MULT);
00060     }
00061     
00062     inline double InferDistance(const double* DataCache)
00063     {
00064         double dist2=HiperPlanCluster::InferDistance(DataCache);
00065         return distanceInfer=exp( dist2/sigma2 );
00066     }
00067     
00068     inline double ClusDistance(const double* DataCache)
00069     {
00070         double dist2=HiperPlanCluster::ClusDistance(DataCache);
00071         return distanceClus=exp( dist2/sigma2 );
00072     }
00073     
00074     double CorrectApartGrade(double Coef)
00075     {
00076         double E;
00077         if (!finite(Coef))
00078             E=1.0;
00079         else
00080             E=1.0/(distanceClus*Coef);
00081 
00082         if (!finite(E))
00083             E=1.0;
00084 
00085         assert(finite(E));
00086 
00087         s_Ai+=E;
00088         for(int i=0; i<inDim+1; i++)
00089         {
00090             double aux=E*dataCache[i];
00091             s_Ai_Xj[i]+=aux;
00092             // fill only the upper part of S
00093             for(int j=i; j<inDim+1; j++)
00094                 S(i+1,j+1)+=aux*dataCache[j];
00095         }
00096         return distanceClus*E; // to be modified
00097     }
00098     
00099     // AdjustPrototypes is OK so far
00100     static string TypeName(void)
00101     {
00102         return string("EMHiperPlan");
00103     }
00104     
00105     void SetSigma(double sigma)
00106     {
00107         sigma2=2*pow2(sigma);
00108     }
00109     
00110     bool SetOptionDbl(char* optName,double value)
00111     {
00112         if ( strcmp(optName,"sigma")==0 )
00113         {
00114             sigma2=2*pow2(value);
00115             return true;
00116         }
00117         return HiperPlanCluster::SetOptionDbl(optName,value);
00118     }
00119     
00120     void SaveToStream(ostream& out)
00121     {
00122         ComputeCCoef();
00123 
00124         out << "[ ";
00125         // the centre of the pattern
00126         for(int i=0; i<inDim; i++)
00127             out << L[i] << " ";
00128         out << " ] ( ";
00129         // the C coefs
00130         for(int i=0; i<inDim+1; i++)
00131             out << C[i] << " ";
00132         out << " ) { " << Elipsoidality << " " << error
00133         << " " << sqrt(sigma2/2) << " } " << endl;
00134     }
00135     
00136     void LoadFromStream(istream& in)
00137     {
00138         string s;
00139 
00140         in >> s;
00141         if (s!="[")
00142             throw ErrMsg("[ missing in emhypercluster");
00143         for(int i=0; i<inDim; i++)
00144             in >> L[i];
00145         in >> s;
00146         if (s!="]")
00147             throw ErrMsg("] missing in emhypercluster");
00148         in >> s;
00149         if (s!="(")
00150             throw ErrMsg("( missing in emhypercluster");
00151         for(int i=0; i<inDim+1; i++)
00152             in >> C[i];
00153         in >> s;
00154         if (s!=")")
00155             throw ErrMsg(") missing emhypercluster");
00156         in >> s;
00157         if (s!="{")
00158             throw ErrMsg("{ missing in emhypercluster");
00159         in >> Elipsoidality;
00160         in >> error;
00161         in >> sigma2;
00162         sigma2=2*pow2(sigma2);
00163         in >> s;
00164         if (s!="}")
00165             throw ErrMsg("} missing in emhypercluster");
00166         ComputeU();
00167     }
00168 };
00169 }
00170 
00171 #endif // _EMHIPCLUS_H

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