Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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 **
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-22-2004
"Rakesh Kumar" <> 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?


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      04-22-2004
On Wed, 21 Apr 2004 17:25:51 -0700 in comp.lang.c++, Rakesh Kumar
<> 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.

 
Reply With Quote
 
Dietmar Kuehl
Guest
Posts: n/a
 
      04-22-2004
"Victor Bazarov" <> 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.
--
<private.php?do=newpm&u=> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
 
Reply With Quote
 
puppet_sock@hotmail.com
Guest
Posts: n/a
 
      04-22-2004
(Dietmar Kuehl) wrote in message news:<. com>...
> "Victor Bazarov" <> 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
 
Reply With Quote
 
Siemel Naran
Guest
Posts: n/a
 
      04-22-2004
"David Harmon" <> 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?


 
Reply With Quote
 
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)
 
Reply With Quote
 
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 **
 
Reply With Quote
 
Siemel Naran
Guest
Posts: n/a
 
      04-23-2004
"Pete Becker" <> wrote in message
news:...
> 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.


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-23-2004
"Siemel Naran" <> wrote...
> "Pete Becker" <> wrote in message
> news:...
> > 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem storing tvmet vector objects in an stl vector container alexjcollins@gmail.com C++ 2 09-08-2008 09:18 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
Vector of STL maps versus Vector of objects amolpan@gmail.com C++ 2 07-26-2005 10:16 PM
Automatic Conversion of STL Containers: e.g. from vector<derived*> to vector<base*> CD C++ 2 10-05-2004 02:29 PM
STL algorithm problem vector<vector<double> > and find Dennis C++ 1 06-07-2004 10:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57