home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.ai.fuzzy      Fuzzy logic... all warm and fuzzy-like      1,275 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 680 of 1,275   
   Dmitry A. Kazakov to All   
   Re: Fuzzy Union in C++ (1/2)   
   03 Feb 07 19:29:11   
   
   From: mailbox@dmitry-kazakov.de   
      
   On Sat, 03 Feb 2007 17:39:28 +0100, Seweryn Habdank-Wojewódzki wrote:   
      
   > Hi!   
   >   
   > Dmitry A. Kazakov wrote:   
   >   
   >> And what was the problem? To make Bar working for numeric types? You don't   
   >> need generics for that:   
   >>   
   >> procedure Bar (X : Numeric'Class); -- Done   
   >   
   > The difference is much bigger than you can see. Again:   
   >   
   > template < typename T >   
   > void function ( T x );   
   >   
   > vs.   
   >   
   > void function ( double x );   
   > void function ( int x );   
      
   But I didn't propose overloading. Bar as declared above has exactly one   
   body.   
      
   >>>>>>>>    * : T x T -> T   
   >>>>>>>>   
   >>>>>>>> But what is needed is   
   >>>>>>>>   
   >>>>>>>>    * : T1 x T1 -> T2   
   > [...]   
   >> Yes, this is how it works. Because type_C is replaced by a class of types.   
   >> So the signature of * is:   
   >>   
   >> * : T'Class x T'Class -> T'Class   
   >>   
   >> where T'Class = {T, T1, T2, T3, ...}   
   >>   
   >> This is a sufficiently more powerful type system than generics.   
   >   
   > Show me the implementation that T * T - > T and T1 * T1 -> T2   
   > but T2 * T2 -> T3, and T3 * T3 -> T3. Because just from this 2 line this is   
   > not clear that such a sequence works.   
      
   This is quite straightforward. Ti is a member of class T. So any argument   
   of Ti is automatically converted to T'Class where the latter is expected.   
   Therefore * has only one body it is defined for the whole class T. The   
   implementation of the body is similar to a generic body, it is defined in   
   the operations of the class. To have this * must be decomposable into   
   operations of T and T'Class. That is the basics of generic programming.   
      
   >> Yes, generics can be made contracted. In Java and Ada the language of   
   >> generics is typed. In C++ it is weakly/untyped. There is no language I   
   >> knew where generics would have ADTs, though that should be doable. But all   
   >> that does not solve the fundamental weakness of generics, as they are a   
   >> meta language. Please observe, it is not C++ vs. Ada, it is generic vs.   
   >> not.   
   >   
   > Yes, but the question is which design leads to making less mistakes. And to   
   > clearer code, which is easier to maintaining and developing by many coders.   
      
   Which is the goal of design by contract methodology.   
      
   > Yes. All. Again look what you can say when you want ask the class in compile   
   > time. Again Boost::trains. Again example of the is_special_kind template.   
   > so this is very easy to maintain big code.   
      
   Well, if you honestly believe that templated code is maintainable then I   
   cannot imagine how we could come to an agreement.   
      
   >> I don't see how it solves the problem:   
   >>   
   >> Given:   
   >>   
   >> 1. Set representation described by OP   
   >> 2. The set A = { (1.0, 1.0) }   
   >>   
   >> Required:   
   >>   
   >> Compute the set B = ~A, where ~ is defined as forall x ~A(x)=1-A(x).   
   >>   
   >> You didn't explain how to represent an infinite set by a finite map   
   >> without changing the representation from a set of singletons to anything   
   >> else.   
   >   
   > Again. Function fuzzy_negation_complement ( Fuzzy_set const & set ) is a   
   > pure set B. Try to compile the code and at the beginning look in to the   
   > main() function. Just this. When you understand that you can try to change   
   > values in the main function.   
   >   
   > // definition of raw A set - just data   
   >     std::map data;   
   >     data[0.0] = 1.0;   
   >     data[0.1] = 0.5;   
   >   
   > // construction of the fuzzy set   
   > // first double type represents all possible data   
   > // you can change it to the other types like int, long double or std::string   
   > // of course changes here should be similar to the changes in raw A set   
   > // this can be implemented better, but this is just my simplification.   
   > // the second type represents type of the membership function results.   
   > // presently I am working on to add m_type which is a subset of double [0,1]   
   > // and have proper operators, and inform me if the value excide   
   > // the [0,1] interval.   
   >     fuzzy_set_type A(data);   
   >   
   > // you can take a value of the membership, just by calculating A(x);   
   > // values are calculated properly to the set which was used in the   
   > // construction.   
   > // look carefully you can ask about value even if the value was not in   
   > // raw set A e.g. -0.1 and 0.2. This is very important because   
   > // you can just work nad construct the values on the set support   
   >     std::cout << "mi_A ( " << -0.1 << " ) = "   
   >         << A(-0.1) << std::endl; // 0.0   
   >     std::cout << "mi_A ( " << 0.0 << " ) = "   
   >         << A(0.0) << std::endl; // 1.0   
   >     std::cout << "mi_A ( " << 0.1 << " ) = "   
   >         << A(0.1) << std::endl; // 0.5   
   >     std::cout << "mi_A ( " << 0.2 << " ) = "   
   >         << A(0.2) << std::endl; // 0.0   
   >   
   > // negation of the set ~A == fuzzy_negation_complement(A).   
   > // to calculate the value of the membership I am using   
   > // fuzzy_negation_complement(A)(x)   
   >     std::cout << "mi_{~A} ( " << -0.1 << " ) = "   
   >         << fuzzy_negation_complement(A)(-0.1)   
   >         << std::endl; // 1.0   
   >     std::cout << "mi_{~A} ( " << 0.0 << " ) = "   
   >         << fuzzy_negation_complement(A)(0.0)   
   >         << std::endl; // 0.0   
   >     std::cout << "mi_{~A} ( " << 0.1 << " ) = "   
   >         << fuzzy_negation_complement(A)(0.1)   
   >         << std::endl; // 0.5   
   >     std::cout << "mi_{~A} ( " << 0.2 << " ) = "   
   >         << fuzzy_negation_complement(A)(0.2)   
   >         << std::endl; // 1.0   
   >   
   > Just fuzzy_negation_complement(A) function is a negation. I do not need to   
   > define abything more. Because if you want to calculate ANY membership value   
   > you just use this function with extra argument - the value.   
      
   This is not what I want. The requirement is to compile:   
      
      fuzzy_set_type A = ... // a singleton set;   
      fuzzy_set_type B = ~A;   
      
   Observe difference.   
      
   Lazy expressions might be OK, but it is a different representation of the   
   set. That was the whole point I was making.   
      
   --   
   Regards,   
   Dmitry A. Kazakov   
   http://www.dmitry-kazakov.de   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca