Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Fastest way to check inequality

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91380] Re: [mg91361] Fastest way to check inequality
  • From: DrMajorBob <drmajorbob at att.net>
  • Date: Tue, 19 Aug 2008 07:15:01 -0400 (EDT)
  • References: <4130912.1219083186830.JavaMail.root@m08>
  • Reply-to: drmajorbob at longhorns.com

> (And @@ NonPositive[constrMat . # ]) & /@ x;

That's a very fast way to do nothing, since "constrMat" is undefined.

A.x also makes no sense, since A and x don't have compatible dimensions.

There are a couple of ways to "make" them compatible, namely

a = RandomReal[{0, 1}, {3500, 3}];
x = RandomReal[{0, 1}, {2000, 3}];

a.Transpose[x] // Dimensions

{3500, 2000}

x.Transpose[a] // Dimensions

{2000, 3500}

(I shrank the dimensions so that I didn't get old waiting for results.)

Now the question is whether you intend 35000 inequalities, 20000, or  
35000*20000.

I'm guessing the latter. That is, ALL entries must be non-positive in  
EITHER of the dot products above.

If that guess is correct, we can speed things up by stopping when we reach  
a failure.

Since Dot is a special case of Inner, we can do it this way:

Catch[Inner[Times, a,
   Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True]

Here are a couple of examples with obvious answers:

a = RandomReal[{-1, 0}, {35, 3}];
x = RandomReal[{0, 1}, {20, 3}];
Catch[Inner[Times, a,
   Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True]

True

a = RandomReal[{0, 1}, {35, 3}];
x = RandomReal[{0, 1}, {20, 3}];
Catch[Inner[Times, a,
   Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True]

False

Bobby

On Mon, 18 Aug 2008 02:36:52 -0500, Ravi Balasubramanian  
<bravi at cs.washington.edu> wrote:

> Hello Math-groupers,
>
> I need to test the inequality
>
> A . x <= 0, where
>
> x is a three-D vector.
> A is a 35000x3 matrix.
>
> I need to test this for 20000 points.
>
> So I set this up as follows:
>
> A = RandomReal[{0,1},{35000,3}];
>
> x = RandomReal[{0,1},{20000,3}];
>
> (And @@ NonPositive[constrMat . # ]) & /@ x;
>
> Is this the fastest way?
>
> Ravi
> The University of Washington
> Seattle, WA
>
>
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: NDSolve
  • Next by Date: Re: Player Pro Usage
  • Previous by thread: Re: Fastest way to check inequality
  • Next by thread: Legend text font