Velocity Reviews > C++ > STL - Vector - Normalization ?

# STL - Vector - Normalization ?

Rakesh Kumar
Guest
Posts: n/a

 04-22-2004
Hi,
Is there a function that can help me to normalize the given vector
(belonging to C++ STL) of 'double's in the range 0.0 - 1.0

i.e . given a set of 'double's, each element 'ele' would be replaced by
elenew = (ele - min) / (max - min) , where max and min are the
maximum and minimum of the given vector.

Or, aliter - is there a way , I can specify a function (here, in
this case, I could specify my normalize function) to be applied to each
and every element of a vector and get a new vector consisting of the
value returned by the function.

--
Rakesh Kumar
** Remove nospamplz from my email address for my real email **

Victor Bazarov
Guest
Posts: n/a

 04-22-2004
"Rakesh Kumar" <(E-Mail Removed)> wrote...
> Hi,
> Is there a function that can help me to normalize the given vector
> (belonging to C++ STL) of 'double's in the range 0.0 - 1.0
>
> i.e . given a set of 'double's, each element 'ele' would be replaced by
> elenew = (ele - min) / (max - min) , where max and min are the
> maximum and minimum of the given vector.
>
> Or, aliter - is there a way , I can specify a function (here, in
> this case, I could specify my normalize function) to be applied to each
> and every element of a vector and get a new vector consisting of the
> value returned by the function.

Aw, come on... What happened to the programmer's pride? Couldn't
you write one if you just needed it?

David Harmon
Guest
Posts: n/a

 04-22-2004
On Wed, 21 Apr 2004 17:25:51 -0700 in comp.lang.c++, Rakesh Kumar
<(E-Mail Removed)> wrote,

>i.e . given a set of 'double's, each element 'ele' would be replaced by
> elenew = (ele - min) / (max - min) , where max and min are the
>maximum and minimum of the given vector.

See std::min_element<>, std::max_element<>, and std::transform<>.
Stroustrup section 18.9, 18.6.2.

Dietmar Kuehl
Guest
Posts: n/a

 04-22-2004
"Victor Bazarov" <(E-Mail Removed)> wrote:
> Aw, come on... What happened to the programmer's pride? Couldn't
> you write one if you just needed it?

Actually, I think it would make sense to have a quite extensive algorithms
library which would cover, amoung other things, also many of the typical
numerical algorithms.
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

puppet_sock@hotmail.com
Guest
Posts: n/a

 04-22-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Dietmar Kuehl) wrote in message news:<(E-Mail Removed). com>...
> "Victor Bazarov" <(E-Mail Removed)> wrote:
> > Aw, come on... What happened to the programmer's pride? Couldn't
> > you write one if you just needed it?

>
> Actually, I think it would make sense to have a quite extensive algorithms
> library which would cover, amoung other things, also many of the typical
> numerical algorithms.

Indeed it would. But I'm not sure it would make sense for it to
be part of the standard language. The language is already pretty
large. I think it makes more sense to have math packages available.
As well, it makes sense for such things to be tweaked for special
purposes, tweaked for specific hardware, etc.

Hey, guess what? That's the situation now. So I can be lazy.
Socks

Siemel Naran
Guest
Posts: n/a

 04-22-2004
"David Harmon" <(E-Mail Removed)> wrote in message
> On Wed, 21 Apr 2004 17:25:51 -0700 in comp.lang.c++, Rakesh Kumar

> >i.e . given a set of 'double's, each element 'ele' would be replaced by
> > elenew = (ele - min) / (max - min) , where max and min are the
> >maximum and minimum of the given vector.

>
> See std::min_element<>, std::max_element<>, and std::transform<>.
> Stroustrup section 18.9, 18.6.2.

This would be an 2*O(N) algorithm to find the min element and then the max
element. Is there a standard algorithm to find the max and min in one pass?

Pete Becker
Guest
Posts: n/a

 04-22-2004
Siemel Naran wrote:
>
> This would be an 2*O(N) algorithm to find the min element and then the max
> element.

2*O(N) == O(N).

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

Rakesh Kumar
Guest
Posts: n/a

 04-23-2004
Thanks David for the pointers.

David Harmon wrote:
> See std::min_element<>, std::max_element<>, and std::transform<>.
> Stroustrup section 18.9, 18.6.2.
>

--
Rakesh Kumar
** Remove nospamplz from my email address for my real email **

Siemel Naran
Guest
Posts: n/a

 04-23-2004
"Pete Becker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Siemel Naran wrote:

> > This would be an 2*O(N) algorithm to find the min element and then the

max
> > element.

>
> 2*O(N) == O(N).

Sure, mathematically speaking. But what I'm trying to say is the original
algorithm performs 2 passes through the array, whereas we could get by with
just 1.

Victor Bazarov
Guest
Posts: n/a

 04-23-2004
"Siemel Naran" <(E-Mail Removed)> wrote...
> "Pete Becker" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Siemel Naran wrote:

>
> > > This would be an 2*O(N) algorithm to find the min element and then the

> max
> > > element.

> >
> > 2*O(N) == O(N).

>
> Sure, mathematically speaking. But what I'm trying to say is the original
> algorithm performs 2 passes through the array, whereas we could get by

with
> just 1.

But the whole point of complexity being the same is that while doing
your single path, you will have to do more on every iteration, which
basically negates the difference between one and two passes.

Victor