00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00044 protected:
00045 double sigma2;
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
00093 for(int j=i; j<inDim+1; j++)
00094 S(i+1,j+1)+=aux*dataCache[j];
00095 }
00096 return distanceClus*E;
00097 }
00098
00099
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
00126 for(int i=0; i<inDim; i++)
00127 out << L[i] << " ";
00128 out << " ] ( ";
00129
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