Changeset 9107:5147237d35fa in orange


Ignore:
Timestamp:
10/14/11 11:06:41 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
d01fb1bb0ee749429088d6cc69802f4a78dac236
Message:

Added Lp distance measure.

Location:
source/orange
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/orange/distance.cpp

    r8735 r9107  
    340340{} 
    341341 
     342TExamplesDistanceConstructor_Lp::TExamplesDistanceConstructor_Lp(): p(1.0) 
     343{} 
    342344 
    343345PExamplesDistance TExamplesDistanceConstructor_Maximal::operator()(PExampleGenerator egen, const int &weightID, PDomainDistributions ddist, PDomainBasicAttrStat bstat) const 
     
    352354{ return mlnew TExamplesDistance_Euclidean(ignoreClass, normalize, ignoreUnknowns, egen, weightID, ddist, bstat); } 
    353355 
    354  
     356PExamplesDistance TExamplesDistanceConstructor_Lp::operator()(PExampleGenerator egen, const int &weightID, PDomainDistributions ddist, PDomainBasicAttrStat bstat) const 
     357{ return mlnew TExamplesDistance_Lp(ignoreClass, normalize, ignoreUnknowns, egen, weightID, ddist, bstat, p); } 
    355358 
    356359TExamplesDistance_Maximal::TExamplesDistance_Maximal() 
     
    403406} 
    404407 
    405  
     408TExamplesDistance_Lp::TExamplesDistance_Lp() 
     409{ 
     410    this->p = 1.0; 
     411} 
     412TExamplesDistance_Lp::TExamplesDistance_Lp(float p) 
     413{ 
     414    this->p = p; 
     415} 
     416 
     417TExamplesDistance_Lp::TExamplesDistance_Lp(const bool &ignoreClass, const bool &normalize, const bool &ignoreUnknowns, PExampleGenerator egen, const int &weightID, PDomainDistributions ddist, PDomainBasicAttrStat dstat, float _p) 
     418: TExamplesDistance_Normalized(ignoreClass, normalize, ignoreUnknowns, egen, weightID, ddist, dstat), p(_p) 
     419{} 
    406420 
    407421float TExamplesDistance_Maximal::operator ()(const TExample &e1, const TExample &e2) const  
     
    480494 
    481495 
     496float TExamplesDistance_Lp::operator ()(const TExample &e1, const TExample &e2) const 
     497{ 
     498  vector<float> difs; 
     499  getDifs(e1, e2, difs); 
     500  float dist = 0.0; 
     501  const_ITERATE(vector<float>, di, difs) 
     502    dist += pow(fabs(*di), p); 
     503  return pow(dist, 1.0f / p); 
     504} 
    482505 
    483506 
  • source/orange/distance.hpp

    r6531 r9107  
    193193}; 
    194194 
     195/* Lp distance: 
     196     p root of sum of distances raised to the power of p between corresponding attribute values. 
     197     A generalization of Euclidean (p=2), Manhattan (p=1) and Maximal (p=inf) 
     198*/ 
     199 
     200class ORANGE_API TExamplesDistance_Lp : public TExamplesDistance_Normalized { 
     201public: 
     202  __REGISTER_CLASS 
     203 
     204  float p; //PR p 
     205  TExamplesDistance_Lp(); 
     206  TExamplesDistance_Lp(float p); 
     207  TExamplesDistance_Lp(const bool &ignoreClass, const bool &normalize, const bool &ignoreUnknowns, PExampleGenerator, const int & = 0, PDomainDistributions = PDomainDistributions(), PDomainBasicAttrStat = PDomainBasicAttrStat(), float p = 1.0); 
     208  virtual float operator()(const TExample &, const TExample &) const; 
     209}; 
     210 
     211 
     212class ORANGE_API TExamplesDistanceConstructor_Lp : public TExamplesDistanceConstructor_Normalized { 
     213public: 
     214  __REGISTER_CLASS 
     215 
     216  float p; //P p 
     217  TExamplesDistanceConstructor_Lp(); 
     218  virtual PExamplesDistance operator()(PExampleGenerator, const int & = 0, PDomainDistributions = PDomainDistributions(), PDomainBasicAttrStat = PDomainBasicAttrStat()) const; 
     219}; 
     220 
    195221 
    196222/* Relief distance */ 
  • source/orange/lib_components.cpp

    r8070 r9107  
    13641364C_NAMED(ExamplesDistance_Manhattan - Orange.distances.Manhattan, ExamplesDistance_Normalized, "()") 
    13651365C_NAMED(ExamplesDistance_Euclidean - Orange.distances.Euclidean, ExamplesDistance_Normalized, "()") 
     1366C_NAMED(ExamplesDistance_Lp - Orange.distances.Lp, ExamplesDistance_Normalized, "()") 
    13661367C_NAMED(ExamplesDistance_Relief - Orange.distances.Relief, ExamplesDistance, "()") 
    13671368C_NAMED(ExamplesDistance_DTW - Orange.distances.DTW, ExamplesDistance_Normalized, "()") 
     
    13711372C_CALL(ExamplesDistanceConstructor_Manhattan - Orange.distances.ManhattanConstructor, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Manhattan") 
    13721373C_CALL(ExamplesDistanceConstructor_Euclidean - Orange.distances.EuclideanConstructor, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Euclidean") 
     1374C_CALL(ExamplesDistanceConstructor_Lp - Orange.distances.LpConstructor, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Lp") 
    13731375C_CALL(ExamplesDistanceConstructor_Relief - Orange.distances.ReliefConstructor, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Relief") 
    13741376C_CALL(ExamplesDistanceConstructor_DTW - Orange.distances.DTWConstructor, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_DTW") 
Note: See TracChangeset for help on using the changeset viewer.