Re: Classifying by Inequalities???
- To: mathgroup at smc.vnet.net
- Subject: [mg29258] Re: Classifying by Inequalities???
- From: "Orestis Vantzos" <atelesforos at hotmail.com>
- Date: Fri, 8 Jun 2001 04:15:42 -0400 (EDT)
- Organization: National Technical University of Athens, Greece
- References: <9fk3i8$t4j$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
A slightly more elegant solution: labelF[{A_,B_}]/;(A<0&&B<0&&A!=B) := k; labelF[{A_,B_}]/;(A<0&&B=0) := l; ... labelF[{A_,B_}]/;(A>0&&B>0&&A!=B) := p; ... Notice that using an explicit inequality in the definitions of k and p, solves the "shadowing" problem. Then you just Map labelF to your list: labelF /@ myList Orestis Vantzos <BobHanlon at aol.com> wrote in message news:9fk3i8$t4j$1 at smc.vnet.net... > > In a message dated 2001/6/4 5:52:09 AM, Moranresearch at aol.com writes: > > >I have a series of integers l1={{a1,b1},{a2,b2},...{ai,bi}} > >I want to label each pair in the series according to the inequality rules > > > >defined below > >such that I get a series of labels l2={n,k,p....} > > > >k = A<0 B<0 > >l = A<0 B=0 > >m = A<0 B<0 A=B > >n = A<0 B>0 > >p = A>0 B>0 > >q = A=0 B>0 > >r = A>0 B>0 A=B > > > > You cannot test with your rules in the order given. For example, any pair > meeting the condition for m, that is, A<0 && B<0 && A==B (which is > more simply A<0 && A==B) would always first meet the condition for k. > Likewise, the condition for r would always be met first by the condition > for p. > > Generate random data restricted to meet one of your conditions (that is, > there are pairs which do not meet any of your conditions such as > {0, 0}, {0, -1}, {1, 0}, {1, -1}) > > l1 = Select[ > Table[{Random[Integer, {-2, 2}], > Random[Integer, {-2, 2}]}, {50}], #[[1]]< > 0&&#[[2]]==#[[1]]|| > #[[1]]<0&&#[[2]]< > 0|| > #[[1]]<0&&#[[2]]\[Equal]0|| > #[[1]]< > 0&&#[[2]]>0|| > #[[1]]==0&&#[[2]]>0|| > #[[1]]> > 0&&#[[2]]==#[[1]]|| > #[[1]]>0&&#[[2]]>0&]; > > You can use a Which statement > > ans = (Which[ > #[[1]]<0 && #[[2]]==#[[1]],m, > #[[1]]<0 && #[[2]]<0,k, > #[[1]]<0 && #[[2]]==0,l, > #[[1]]<0 && #[[2]]>0,n, > #[[1]]==0 && #[[2]]>0,q, > #[[1]]>0 && #[[2]]==#[[1]],r, > #[[1]]>0 && #[[2]]>0,p]&/@l1) > > {n, n, k, n, n, k, l, k, n, q, n, p, r, > k, l, n, m, n, r, n, n, r, k, n, m, > n, n, k, l, n, q, m, r, p, l} > > or you can nest several If statements > > ans = (If[#[[1]]<0, > If[#[[2]]==#[[1]],m, > If[#[[2]]<0,k, > If[#[[2]]==0,l,n]]], > If[#[[1]]==0&&#[[2]]>0,q, > If[#[[1]]>0, > If[#[[2]]==#[[1]],r, > If[#[[2]]>0,p]]]]]&/@l1) > > True > > > Bob Hanlon > Chantilly, VA USA >