⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lingfuncapprx.cpp

📁 模糊聚類分析源碼。包含教學文件
💻 CPP
字号:
/*    Context       : Fuzzy Clustering Algorithms  Author        : Frank Hoeppner, see also AUTHORS file   Description   : implementation of class module LingFuncApprx                    History       :      Comment       :     This file was generated automatically. DO NOT EDIT.  Copyright     : Copyright (C) 1999-2000 Frank Hoeppner    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*  The University of Applied Sciences Oldenburg/Ostfriesland/Wilhelmshaven  hereby disclaims all copyright interests in the program package `fc'   (tool package for fuzzy cluster analysis) written by Frank Hoeppner.    Prof. Haass, President of Vice, 2000-Mar-10*/#ifndef LingFuncApprx_SOURCE#define LingFuncApprx_SOURCE/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include "LingFuncApprx.hpp"// data// implementationtemplate < class ANALYSIS >LingFuncApprx< ANALYSIS >::LingFuncApprx  (  Algorithm<ANALYSIS> *ap_alg  )  : mp_succ_alg(ap_alg)      {    }template < class ANALYSIS >LingFuncApprx< ANALYSIS >::~LingFuncApprx  (  )  {  FUNCLOG("~LingFuncApprx");    delete mp_succ_alg;  }template < class ANALYSIS >voidLingFuncApprx< ANALYSIS >::operator()  (  ANALYSIS& a_analysis  )  {  FUNCLOG("LingFuncApprx");    invariant(a_analysis.option().data_dimension()==1,"assume SISO function");  const int c(a_analysis.option().number_prototypes());  int polynom_degree((*a_analysis.prototypes().begin()).coefficient().rows()-1);  invariant((1<=polynom_degree)&&(polynom_degree<=2),"linear or quadratic",SOURCELOC);  trace("polynom degree",polynom_degree);  Histogram<real_type,real_type> HX[c],HY[c],HDY[c];  typename ANALYSIS::link_iter i_link(a_analysis.links().begin());  real_type xmin(POS_IMPOSSIBLE_RANGE),xmax(NEG_IMPOSSIBLE_RANGE),    ymin(POS_IMPOSSIBLE_RANGE),ymax(NEG_IMPOSSIBLE_RANGE);  for (      typename ANALYSIS::data_iter i_data(a_analysis.data().begin());      i_data != a_analysis.data().end();      ++i_data      )    {    real_type x((*i_data).datum()[0]);    real_type y((*i_data).result()[0]);    xmin=min(xmin,x); xmax=max(xmax,x);    ymin=min(ymin,y); ymax=max(ymax,y);    int p(0);    for (        typename ANALYSIS::prot_iter i_prot(a_analysis.prototypes().begin());        i_prot != a_analysis.prototypes().end();        ++i_prot        )      {      real_type b((*i_prot).coefficient()[1]);      real_type c((polynom_degree==2)?(*i_prot).coefficient()[2]:0);      real_type u((*i_link).membership());      HX[p].insert(x,u);      HY[p].insert(y,u);      HDY[p].insert(b+2.0*c*x,u);      ++i_link; ++p;      }    }  // L dictionary, 10 values;  int i;  list<real_type> LX,LY;  for (i=0;i<=10;++i)    {    LX.push_back( xmin+(xmax-xmin)/10.0*i );    LY.push_back( ymin+(ymax-ymin)/10.0*i );    }  trace("LX=",LX);  trace("LY=",LY);  list<real_type> DL;  DL.push_back(-20);  DL.push_back(-10);  DL.push_back(-DERIVATIVE_BIG);  DL.push_back(-DERIVATIVE_MEDIUM);  DL.push_back(-DERIVATIVE_SMALL);  DL.push_back( DERIVATIVE_ZERO);  DL.push_back( DERIVATIVE_SMALL);  DL.push_back( DERIVATIVE_MEDIUM);  DL.push_back( DERIVATIVE_BIG);  DL.push_back(10);  DL.push_back(20);  i=0;  for (      typename ANALYSIS::prot_iter i_prot(a_analysis.prototypes().begin());      i_prot != a_analysis.prototypes().end();      ++i_prot      )    {    HX[i].convex(); HY[i].convex(); HDY[i].convex();    FuzzySet<real_type> FDY(HDY[i]),FX(HX[i]),FY(HY[i]);    #define buflen 1000    char buffer[buflen];    #define HEDGE(h,N,V,Q) ((h==HEDGE_NONE)?(N):((h==HEDGE_VERY)?(V):(Q)))    #define DEFAULTHEDGE(h) HEDGE(h,"about","close to","more or less")    ostrstream rule(buffer,buflen,ios::trunc);    hedge_enum hx,hy,hdy;    real_type vx1,vx2,vy1,vy2,vdy1,vdy2;    rule << "(rule \"if x is ";    trace("FX=",FX);    linguistic_approximation(FX,LX,CRISPNESS,LX.size(),hx,vx1,vx2);    if (vx1==vx2)      rule << DEFAULTHEDGE(hx) << " " << vx1;    else      rule << DEFAULTHEDGE(hx) << " [" << vx1 << "," << vx2 << "]";    rule << " then f(x) ";    trace("FY=",FY);    linguistic_approximation(FY,LY,CRISPNESS,3,hy,vy1,vy2);    trace("f=",make_pair(vy1,vy2));    trace("FDY=",FDY);    linguistic_approximation(FDY,DL,CRISPNESS,DL.size(),hdy,vdy1,vdy2);    trace("f'=",make_pair(vdy1,vdy2));    trace("h'=",hdy);    int descriptor(0);    real_type value;    if ((vdy1==0) && (vdy2==0)) // derivative zero      {      SET_TAG(descriptor,SHAPE_CONSTANT);      switch (hdy)        {        case HEDGE_NONE : break;        case HEDGE_VERY : SET_TAG(descriptor,MODIFIER_ABSOLUTELY); break;        case HEDGE_QUITE: SET_TAG(descriptor,MODIFIER_MORE_OR_LESS); break;        }      value = vy1;      }    else      {      real_type vd(max(fabs(vdy1),fabs(vdy2)));      if (vd>=DERIVATIVE_BIG)        SET_TAG(descriptor,SLOPE_STEEPLY); else      if (vd>=DERIVATIVE_MEDIUM)        SET_TAG(descriptor,SLOPE_MODERATELY);      else        SET_TAG(descriptor,SLOPE_GENTLY);      if ((vdy1==vdy2) || (polynom_degree==1))         {        if (vdy1<0)          { SET_TAG(descriptor,SHAPE_DECREASING); value=vy1; }        else          { SET_TAG(descriptor,SHAPE_INCREASING); value=vy2; }        }      else        {        real_type ddf((*i_prot).coefficient()[2]);        // we have (vdy1!=vdy2), thus df really changes        if (ddf>0)          SET_TAG(descriptor,CURVATURE_CONCAVE);        else          SET_TAG(descriptor,CURVATURE_CONVEX);        if (signum(vdy1)!=signum(vdy2)) // local max/min (special case 0)!!          if (ddf<0) // max            { SET_TAG(descriptor,SHAPE_LOCAL_MAX); value=vy2; }          else            { SET_TAG(descriptor,SHAPE_LOCAL_MIN); value=vy1; }        else          if ((vdy1>0) && (vdy2>0))            { SET_TAG(descriptor,SHAPE_INCREASING); value=vy2; }          else            { SET_TAG(descriptor,SHAPE_DECREASING); value=vy1; }        }      }    write_description(rule,descriptor,value);    rule << "\")" << '\0';    trace("rule=",rule.str());    (*i_prot).unrecognized() += rule.str();    ++i;    }  (*mp_succ_alg)(a_analysis);    }voidwrite_description  (  ostream& os,  int a_descriptor,  real_type a_value  )  {  if (IS_MASKED(a_descriptor,SHAPE_MASK,SHAPE_LOCAL_MIN) ||      IS_MASKED(a_descriptor,SHAPE_MASK,SHAPE_LOCAL_MAX))    {    os << "has a ";    switch (a_descriptor&SLOPE_MASK) {      case SLOPE_STEEPLY : os << "steep "; break;      case SLOPE_MODERATELY : os << "moderate "; break;      case SLOPE_GENTLY : os << "gentle "; break; }    os << "local ";    switch (a_descriptor&SHAPE_MASK) {      case SHAPE_LOCAL_MIN : os << "minimum at "; break;      case SHAPE_LOCAL_MAX : os << "maximum at "; break; }    }  else    {    os << "is ";    switch (a_descriptor&MODIFIER_MASK) {      case MODIFIER_ABSOLUTELY : os << "absolutely "; break;      case MODIFIER_MORE_OR_LESS : os << "more or less "; break; }    switch (a_descriptor&SLOPE_MASK) {      case SLOPE_STEEPLY : os << "steeply "; break;      case SLOPE_MODERATELY : os << "moderately "; break;      case SLOPE_GENTLY : os << "gently "; break; }    switch (a_descriptor&CURVATURE_MASK) {      case CURVATURE_CONVEX : os << "convex "; break;      case CURVATURE_CONCAVE : os << "concave "; break; }    switch (a_descriptor&SHAPE_MASK) {      case SHAPE_CONSTANT : os << "constant at "; break;      case SHAPE_INCREASING : os << "increasing to "; break;      case SHAPE_DECREASING : os << "decreasing to "; break; }     }  os << a_value;  }// template instantiation#endif // LingFuncApprx_SOURCE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -