comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Negative Variance?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Negative Variance? [message #65767] Thu, 19 March 2009 20:11
Homeyer is currently offline  Homeyer
Messages: 9
Registered: March 2009
Junior Member
On Mar 19, 5:00 pm, "anniebry...@gmail.com" <anniebry...@gmail.com>
wrote:
> I am using the VARIANCE comand in IDL and am getting negative values.
> The description in the HELP menu for IDL doesn't provide much
> information, but from what I know, I thought variance was either an
> absolute value or a deviation from a squared number, neither of which
> could yield a negative value.
>
> I am looking at the variance for 2 different bands in an AVIRIS
> image.  I use the same .pro, just change the band I am looking at.
> The results for Band 1 (lets call it) make sense:  all positive
> values.  For Band 2, I get a lot of negatives.?!  How is this
> possible.
>
> These are the values for Band 1:
>
> integer  mean      std dev      minimum      maximum   n_elements
>        2633.3       2059.3       0.0000       9367.0   (160686) =
> 160686
>
> These are the values for Band2:
>
> integer  mean      std dev      minimum      maximum   n_elements
>        1167.5       18269.      -32768.       32767.   (160686) =
> 160686

I am not sure how you are doing your calculations.. but I think you
may have a conversion wrong in some process. If for some reason you
are converting a variance (should be a FLOAT or DOUBLE) to an INT,
which by the way maximizes at 32767 and minimizes at -32768, of course
you will have negative values. If you are converting to INTs, that is
your first problem. Variance should always be a FLOAT or DOUBLE.

Cheers,
Cameron Homeyer
Re: Negative Variance? [message #65768 is a reply to message #65767] Thu, 19 March 2009 19:43 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Mar 19, 6:00 pm, "anniebry...@gmail.com" <anniebry...@gmail.com>
wrote:
> I am using the VARIANCE comand in IDL and am getting negative values.

I would check that you not getting round-off problems by using double
precision or the /DOUBLE keyword to VARIANCE. As discussed in
http://en.wikipedia.org/wiki/Algorithms_for_calculating_vari ance
round-off error can accumulate in the two-pass variance calculation
(used by IDL) when most values are similar but some are wildly
different.

I had a similar headscratcher a few years back when I found that
SMOOTHing a non-negative array could yield negative numbers. This
was a roundoff problem that was fixed by using double precision.

--Wayne
Re: Negative Variance? [message #65769 is a reply to message #65768] Thu, 19 March 2009 18:47 Go to previous message
anniebryant@gmail.com is currently offline  anniebryant@gmail.com
Messages: 16
Registered: March 2009
Junior Member
On Mar 19, 4:35 pm, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> anniebry...@gmail.com wrote:
>> On Mar 19, 4:08 pm, Paolo <pgri...@gmail.com> wrote:
>>> anniebry...@gmail.com wrote:
>>>> I am using the VARIANCE comand in IDL and am getting negative values.
>>>> The description in the HELP menu for IDL doesn't provide much
>>>> information, but from what I know, I thought variance was either an
>>>> absolute value or a deviation from a squared number, neither of which
>>>> could yield a negative value.
>>>> I am looking at the variance for 2 different bands in an AVIRIS
>>>> image.  I use the same .pro, just change the band I am looking at.
>>>> The results for Band 1 (lets call it) make sense:  all positive
>>>> values.  For Band 2, I get a lot of negatives.?!  How is this
>>>> possible.
>>>> These are the values for Band 1:
>>>> integer  mean      std dev      minimum      maximum   n_elements
>>>>        2633.3       2059.3       0.0000       9367.0   (160686) =
>>>> 160686
>>>> These are the values for Band2:
>>>> integer  mean      std dev      minimum      maximum   n_elements
>>>>        1167.5       18269.      -32768.       32767.   (160686) =
>>>> 160686
>>> I don't see any variance here. The only negative number is the
>>> minimum.
>
>>> Ciao,
>>> Paolo
>
>> Those are the values of the vector AFTER the variance was computed, it
>> should read Variance_Band1 and Variance_Band2.
>
> How can you get multiple variances for a band?
> Jean

I created a moving kernel inside which to calculate the variance. So
the question is. What is the variance within a 17pixel x 17pixel
moving window. That is what I am calculating the variance for.
Re: Negative Variance? [message #65770 is a reply to message #65769] Thu, 19 March 2009 15:35 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
anniebryant@gmail.com wrote:
> On Mar 19, 4:08 pm, Paolo <pgri...@gmail.com> wrote:
>> anniebry...@gmail.com wrote:
>>> I am using the VARIANCE comand in IDL and am getting negative values.
>>> The description in the HELP menu for IDL doesn't provide much
>>> information, but from what I know, I thought variance was either an
>>> absolute value or a deviation from a squared number, neither of which
>>> could yield a negative value.
>>> I am looking at the variance for 2 different bands in an AVIRIS
>>> image. I use the same .pro, just change the band I am looking at.
>>> The results for Band 1 (lets call it) make sense: all positive
>>> values. For Band 2, I get a lot of negatives.?! How is this
>>> possible.
>>> These are the values for Band 1:
>>> integer mean std dev minimum maximum n_elements
>>> 2633.3 2059.3 0.0000 9367.0 (160686) =
>>> 160686
>>> These are the values for Band2:
>>> integer mean std dev minimum maximum n_elements
>>> 1167.5 18269. -32768. 32767. (160686) =
>>> 160686
>> I don't see any variance here. The only negative number is the
>> minimum.
>>
>> Ciao,
>> Paolo
>
> Those are the values of the vector AFTER the variance was computed, it
> should read Variance_Band1 and Variance_Band2.

How can you get multiple variances for a band?
Jean
Re: Negative Variance? [message #65771 is a reply to message #65770] Thu, 19 March 2009 15:10 Go to previous message
anniebryant@gmail.com is currently offline  anniebryant@gmail.com
Messages: 16
Registered: March 2009
Junior Member
On Mar 19, 4:08 pm, Paolo <pgri...@gmail.com> wrote:
> anniebry...@gmail.com wrote:
>> I am using the VARIANCE comand in IDL and am getting negative values.
>> The description in the HELP menu for IDL doesn't provide much
>> information, but from what I know, I thought variance was either an
>> absolute value or a deviation from a squared number, neither of which
>> could yield a negative value.
>
>> I am looking at the variance for 2 different bands in an AVIRIS
>> image.  I use the same .pro, just change the band I am looking at.
>> The results for Band 1 (lets call it) make sense:  all positive
>> values.  For Band 2, I get a lot of negatives.?!  How is this
>> possible.
>
>> These are the values for Band 1:
>
>> integer  mean      std dev      minimum      maximum   n_elements
>>        2633.3       2059.3       0.0000       9367.0   (160686) =
>> 160686
>
>> These are the values for Band2:
>
>> integer  mean      std dev      minimum      maximum   n_elements
>>        1167.5       18269.      -32768.       32767.   (160686) =
>> 160686
>
> I don't see any variance here. The only negative number is the
> minimum.
>
> Ciao,
> Paolo

Those are the values of the vector AFTER the variance was computed, it
should read Variance_Band1 and Variance_Band2.
Re: Negative Variance? [message #65773 is a reply to message #65771] Thu, 19 March 2009 15:08 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
anniebryant@gmail.com wrote:
> I am using the VARIANCE comand in IDL and am getting negative values.
> The description in the HELP menu for IDL doesn't provide much
> information, but from what I know, I thought variance was either an
> absolute value or a deviation from a squared number, neither of which
> could yield a negative value.
>
> I am looking at the variance for 2 different bands in an AVIRIS
> image. I use the same .pro, just change the band I am looking at.
> The results for Band 1 (lets call it) make sense: all positive
> values. For Band 2, I get a lot of negatives.?! How is this
> possible.
>
> These are the values for Band 1:
>
> integer mean std dev minimum maximum n_elements
> 2633.3 2059.3 0.0000 9367.0 (160686) =
> 160686
>
> These are the values for Band2:
>
> integer mean std dev minimum maximum n_elements
> 1167.5 18269. -32768. 32767. (160686) =
> 160686

I don't see any variance here. The only negative number is the
minimum.

Ciao,
Paolo
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Make easy and nice your IDL documentation
Next Topic: Span a graph across 2 spaces in a !P.MULTI environment?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:41:53 PDT 2025

Total time taken to generate the page: 0.00623 seconds