[Numpy-discussion] determinant of a scalar not handled

Robert Kern robert.kern at gmail.com
Tue Jul 27 12:47:39 EDT 2010


On Tue, Jul 27, 2010 at 11:36, Skipper Seabold <jsseabold at gmail.com> wrote:
> On Tue, Jul 27, 2010 at 12:00 PM, Robert Kern <robert.kern at gmail.com> wrote:
>> On Tue, Jul 27, 2010 at 07:51, Skipper Seabold <jsseabold at gmail.com> wrote:
>>> On Mon, Jul 26, 2010 at 10:05 PM, Alan G Isaac <aisaac at american.edu> wrote:
>>>> But I am still confused about the use case.
>>>> What is the scalar- (or 1d-array-) returning procedure
>>>> invokedbefore taking the determinant?
>>>
>>> Recently I ran into this trying to make the log-likelihood of a
>>> multivariate and univariate autoregressive process use the same
>>> function.  One has log(sigma_scalar) and one calls for
>>> logdet(Sigma_matrix).  I also ran in to again yesterday working on the
>>> Kalman filter, depending on the process being modeled and how the user
>>> writes a function if the needed coefficient arrays depend on
>>> parameters.  To be more general, I have to put in atleast_2d, even
>>> though these checks are really in slogdet.
>>
>> Not necessarily. In this context, you are treating a scalar as a 1x1
>> matrix. Or rather, in full generality, you have a 1x1 matrix and
>> 1-element vectors and only doing operations on them that map fairly
>> neatly onto a subset of scalar properties. Consequently, you can use
>> scalars in their place without much problem (to add confusion, the
>> scalar case was formulated first, then generalized to the multivariate
>> case, but that doesn't change the mathematics unless if you believe
>> certain ethnomathematicians).
>>
>> However, there are other contexts in which scalars are used where the
>> determinant would come into play. For example, scalar-vector
>> multiplication is defined. If you have an n-vector, then scalar-vector
>> multiplication behaves like matrix-vector multiplication provided that
>> the matrix is a diagonal matrix with the diagonal entries each being
>> the scalar value. In this context, the determinant is not just the
>> scalar value itself, but rather value**n.
>>
>
> Ok, but I'm not sure I see why this would make automatic handling of
> scalars as 2d 1x1 arrays a bad idea.

Because scalars might not be representing 1x1 matrices but rather NxN
diagonal matrices.

>> Many of the references you found stating that the "determinant of a
>> scalar value is" the scalar itself were actually referring to 1x1
>> matrices, not true scalars. 1x1 matrices behave like scalars, but not
>> all scalars behave like 1x1 matrices. linalg.det() does not know the
>> context in which you are treating the scalar, so it rightly complains.
>>
>> That said, I expect you will be running into this 1x1<->scalar special
>> case reasonably frequently in statsmodels. Writing a dwim_logdet()
>> utility function there that does what you want is a perfectly
>> reasonable thing to do.
>>
>
> Fair enough.
>
> Can someone mark the ticket invalid or won't fix then?  It doesn't
> look like I can do it.
>
> http://projects.scipy.org/numpy/ticket/1556

Done.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list