Re: Fuzzy Union in C++



On Sun, 21 Jan 2007 20:03:40 +0100, Seweryn Habdank-Wojewódzki wrote:

Dmitry A. Kazakov wrote:

But you can multiply them in dimensional algebra. In fact this is a
perfect example where templates fail. Try to design a unit-aware
calculator with dimensioned values like value<unit>.

The algebra of fuzzy sets is similar in that respect.
fuzzy_set<domain_set> were unusable.

Just look very carefully on the website:
http://www.boost.org/libs/mpl/doc/tutorial/dimensional-analysis.html
especially concentrate on:
http://www.boost.org/libs/mpl/doc/tutorial/representing-quantities.html

This is what I meant. It cannot work for the challenge I posed: to write a
unit-aware console calculator. The authors are well aware of that. They
stress that all checks are strictly compile-time. They explicitly talk
about different types. I.e. unit expressions cannot be evaluated at
run-time, which is required by the challenge.

For an alternative see:

http://www.dmitry-kazakov.de/ada/units.htm

I have also implemented a C++ library based on similar approach though a
somewhat weaker, because C++ does not support subtyping constraints. But it
is a commercial product, so I cannot show the sources.

My
target is to say that it is possible to make a good design and
implementation for fuzzy sets, especially with respect to the performance.

Yes, there is no doubt about it. Though comparing fuzzy vs. crisp (both
dealing crisp data) the loss will be substantial.

Where you need
dynamical polymorphism I never tell you use statical one, but I always
prefer to start of thinking how much dynamical polymorphism I REALLY need.

No. Basically it is a language weakness if it forces you to take such
decision. Especially if it does this early in design. The language should
support polymorphism. Static resolution of dispatch targets is mere a
matter of optimization, not of software design. Templates miss here badly.

being under impression that to dispatch were slow.

Slower than, no dispatch, but not slow. C++ is not a Python.

But it could be as fast as no dispatch. That's the point.

A decomposition into OR is incomputable. BTW, the initial OP's example is
such. He asked exactly for a design which would circumvent such
decomposition into per-point max over uncountable R. The heuristic used
was based on an assumption about the membership function behavior, which
does not hold in general case.

Yes. I understand, but I can address you a lecture of boost::binders. You
can design all fuzzy operators, similarly to the functional language. You
can define most of them. And until there is no need to have an result, you
just keep them statically constructed. If they derived form a single class,
you can switch then in runtime. If you want to know what are some
interesting implementation read at the very beggining of the page:
http://www.oonumerics.org/blitz/docs/blitz_3.html

look, that:

Array<int,1> A, B, C, D; // ...
A = B + C + D;

Above is equivalent to:

for (int i=A.lbound(firstDim); i <= A.ubound(firstDim); ++i)
A[i] = B[i] + C[i] + D[i];

Not to:

for (int i=A.lbound(firstDim); i <= A.ubound(firstDim); ++i)
A[i] = B[i] + C[i];
for (int i=A.lbound(firstDim); i <= A.ubound(firstDim); ++i)
A[i] = A[i] + D[i];

Until yo will compose all operations no calculation is done.

1. Many (most of) mathematical operations do not take closures of this
kind. Examples: matrix multiplication, or for that matter, Zadeh extension
principle. For instance fuzzy numbers: A + B:

(A+B)(w) =def=
= Sup min {A(x), B(y)}
x,y|w=x+y

2. The problem we are discussing is not in "+". The problem is in "int".
Instead of one type int (the fuzzy set domain) you have an unknown in
advance number of:

Array<string> A;
Array<int> B
Array<Read_From_Soruce_File> C
Array<Ask_The_Operator> D

A = f(B, C, D);

3. The question of OP concerned the case where the parameter type (the
domain set) was whole R. For R fuzzy union is incomputable in the form you
have described:

for (r=-oo; r<=+oo, r+=0)
{
C(r) = max(A(r),B(r));
}

OP decomposed f:R->[0,1] into a *finite* set of functions of special kind
(singletons). This is an assumption that does not hold for all fuzzy sets.
For this reason it cannot be taken as a universal form of. Other
representations might have functions of different classes, which cannot be
represented in the form chosen. The rules of decomposition of AND, OR etc
heavily depend on the class of function considered. You cannot take for
granted that a plain enumeration of points would work in all cases for
everything possible. It just don't.

I believe
that you need functional like structures, but I really do not understand,
why you want to implies that in C++ I can not made a good design and
implementation of a fuzzy sets.

Of course you can, but it will not be based on templates alone. For
simplicity consider design of a tree node. A note test a feature. A feature
value is a fuzzy set.

template<class Domain> class Node {...

Domain is the template parameter of the fuzzy set the feature tested by
Node will have as a value. Now the function Get_Child cannot be expressed
as a template, because you don't have the template parameter of the child:

Node<class ?>& Get_Child (unsigned Child_No) const;

It can be any.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.