Administrator
|
Normally in matrix one can do the following.
COMPUTE x={1:10:1}. resolves to {1,2,3,4,5,6,7,8,9,10} However : COMPUTE x={.1:.9,.1} One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. Well, instead: MATRIX. COMPUTE x={.1: .9 : .1}. PRINT x. END MATRIX. Run MATRIX procedure: >Error encountered in source line # 150 >Warning # 12575 >Non-integer range values were specified. Any non-integer range value will >be rounded to an integer. >Error encountered in source line # 150 >Error # 12557 >Increment value in the range operator is zero. >This command not executed. >Error encountered in source line # 151 >Error # 12492 >An attempt has been made to use previously undefined matrix (or scalar). >This command not executed. Matrix - 'X ' is undefined >Error encountered in source line # 151 >Error # 12332 >Undefined variable in PRINT. ------ END MATRIX ----- LOVELY eh? Doh!!! Ninja workaround. Also returns a column vector rather than a row vector (usually what I want in such cases). DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). + COMPUTE ParseErr=0. + COMPUTE #Z={!1}. + DO IF NCOL(#z) EQ 2. + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. + COMPUTE #Z={#Z,1}. + ELSE. + PRINT / TITLE "WARNING: Non integer argument pairs should have explicit increment.". + COMPUTE !2=T({!1}). + COMPUTE ParseERR=1. + END IF. + ELSE IF NCOL(#z) EQ 1. + COMPUTE #Z={#Z,#Z,1}. + END IF. + DO IF ParseErr=0. + COMPUTE #M=MOD(#Z,1). + COMPUTE #Pwr=1. + DO IF MSUM(ABS(#M )) GT .0000001. + LOOP. + COMPUTE #Pwr=#Pwr*10. + COMPUTE #Z=#Z*10. + COMPUTE #M=MOD(#Z,1). + END LOOP IF MSUM(ABS(#M)) LE .0000001. + END IF. + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). + END IF. !ENDDEFINE. MATRIX. ParsePar -.9,.9,.1 / ParOut . PRINT ParOut. END MATRIX. Run MATRIX procedure: PAROUT -.9000000000 -.8000000000 -.7000000000 -.6000000000 -.5000000000 -.4000000000 -.3000000000 -.2000000000 -.1000000000 .0000000000 .1000000000 .2000000000 .3000000000 .4000000000 .5000000000 .6000000000 .7000000000 .8000000000 .9000000000 ------ END MATRIX -----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
David, doesn't this do what you want?
MATRIX. COMPUTE x = t({-9:9:1} / 10). PRINT x. END MATRIX. OUTPUT: Run MATRIX procedure: X -.9000000000 -.8000000000 -.7000000000 -.6000000000 -.5000000000 -.4000000000 -.3000000000 -.2000000000 -.1000000000 .0000000000 .1000000000 .2000000000 .3000000000 .4000000000 .5000000000 .6000000000 .7000000000 .8000000000 .9000000000 ------ END MATRIX -----
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
It does, however I need users to be able to specify specific ranges without dealing with the internal logic.
ex .5,.75,.01 ie start ,stop, increment This is a small piece of a larger simulation application and I need the UI to be very transparent.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Note that the MATRIX documentation says
Incremented Ranges of Integers. Use a second colon followed by an integer to indicate the increment. The matrix {1,3,5,7;2,5,8,11} can be written as {1:7:2;2:11:3}, where 1:7:2 indicates the integers from 1 to 7 incrementing by 2, and 2:11:3 indicates the integers from 2 to 11 incrementing by 3. �� You must use integers when specifying a range in either of these ways. Numbers with fractional parts are truncated to integers. A little Python code would solve this easily, however. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email], Date: 04/20/2013 08:19 PM Subject: Re: [SPSSX-L] TIP: Resolving non integer range constructors in MATRIX. Sent by: "SPSSX(r) Discussion" <[hidden email]> It does, however I need users to be able to specify specific ranges without dealing with the internal logic. ex .5,.75,.01 ie start ,stop, increment This is a small piece of a larger simulation application and I need the UI to be very transparent. Bruce Weaver wrote > David, doesn't this do what you want? > > MATRIX. > COMPUTE x = t({-9:9:1} / 10). > PRINT x. > END MATRIX. > > OUTPUT: > Run MATRIX procedure: > > X > -.9000000000 > -.8000000000 > -.7000000000 > -.6000000000 > -.5000000000 > -.4000000000 > -.3000000000 > -.2000000000 > -.1000000000 > .0000000000 > .1000000000 > .2000000000 > .3000000000 > .4000000000 > .5000000000 > .6000000000 > .7000000000 > .8000000000 > .9000000000 > > ------ END MATRIX ----- > > David Marso wrote >> Normally in matrix one can do the following. >> COMPUTE x={1:10:1}. >> resolves to {1,2,3,4,5,6,7,8,9,10} >> However : >> COMPUTE x={.1:.9,.1} >> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. >> Well, instead: >> >> MATRIX. >> COMPUTE x={.1: .9 : .1}. >> PRINT x. >> END MATRIX. >> Run MATRIX procedure: >>>Error encountered in source line # 150 >> >>>Warning # 12575 >>>Non-integer range values were specified. Any non-integer range value will >>>be rounded to an integer. >> >>>Error encountered in source line # 150 >> >>>Error # 12557 >>>Increment value in the range operator is zero. >>>This command not executed. >> >>>Error encountered in source line # 151 >> >>>Error # 12492 >>>An attempt has been made to use previously undefined matrix (or scalar). >>>This command not executed. >> >> Matrix - 'X ' is undefined >>>Error encountered in source line # 151 >> >>>Error # 12332 >>>Undefined variable in PRINT. >> >> >> ------ END MATRIX ----- >> >> LOVELY eh? >> Doh!!! >> Ninja workaround. >> Also returns a column vector rather than a row vector (usually what I >> want in such cases). >> >> >> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). >> + COMPUTE ParseErr=0. >> + COMPUTE #Z={!1}. >> + DO IF NCOL(#z) EQ 2. >> + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. >> + COMPUTE #Z={#Z,1}. >> + ELSE. >> + PRINT / TITLE "WARNING: Non integer argument pairs should have >> explicit increment.". >> + COMPUTE !2=T({!1}). >> + COMPUTE ParseERR=1. >> + END IF. >> + ELSE IF NCOL(#z) EQ 1. >> + COMPUTE #Z={#Z,#Z,1}. >> + END IF. >> >> + DO IF ParseErr=0. >> + COMPUTE #M=MOD(#Z,1). >> + COMPUTE #Pwr=1. >> + DO IF MSUM(ABS(#M )) GT .0000001. >> + LOOP. >> + COMPUTE #Pwr=#Pwr*10. >> + COMPUTE #Z=#Z*10. >> + COMPUTE #M=MOD(#Z,1). >> + END LOOP IF MSUM(ABS(#M)) LE .0000001. >> + END IF. >> + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). >> + END IF. >> !ENDDEFINE. >> >> MATRIX. >> ParsePar -.9,.9,.1 / ParOut . >> PRINT ParOut. >> END MATRIX. >> >> Run MATRIX procedure: >> >> PAROUT >> -.9000000000 >> -.8000000000 >> -.7000000000 >> -.6000000000 >> -.5000000000 >> -.4000000000 >> -.3000000000 >> -.2000000000 >> -.1000000000 >> .0000000000 >> .1000000000 >> .2000000000 >> .3000000000 >> .4000000000 >> .5000000000 >> .6000000000 >> .7000000000 >> .8000000000 >> .9000000000 >> >> ------ END MATRIX ----- ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719606.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Thanks Jon,
You can probably imagine that I have read the MATRIX documentation in depth probably 20 times over the past few months. Python is not an option here. The solution will be widely distributed to many users with SPSS versions from 15? (maybe earlier) to 21 and I have NO intentions of supporting their python woes when they FUBAR their install or fail to realize the python dependency. I go native whenever possible and hate doing teksport for broken toys. Perhaps log this as another MATRIX enhancement request! Quick question: What is the earliest version of SPSS which supports Custom Dialogs. Can the earliest version support CDs written in Ver 21? David --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by David Marso
I remember this sort of intransigent problem from my earliest
days of learning Fortran -- There is unfortunate ambiguity when the units and increments cannot be expressed with exact precision in the underlying binary numbers. Thus, 0.5 and 0.75 are fine, but 0.01 is approximated to umpteen digits. The resulting loops have the risk of including an extra iteration. Or falling short by one. If there's a classical compiler solution that avoids all error, I don't remember it. The pragmatic solution that I know of is to eventually use some version of Bruce's answer. The mostly-safe way is to parse the user's entry so that you do not risk the roundoff error. Another way is to multiply what the user enters (by 100, by 1000?), add a tiny fraction and truncate; then use fixed code with a fixed division. -- Rich Ulrich > Date: Sat, 20 Apr 2013 19:19:16 -0700 > From: [hidden email] > Subject: Re: TIP: Resolving non integer range constructors in MATRIX. > To: [hidden email] > > It does, however I need users to be able to specify specific ranges without > dealing with the internal logic. > ex .5,.75,.01 > ie start ,stop, increment > This is a small piece of a larger simulation application and I need the UI > to be very transparent. > > Bruce Weaver wrote > > David, doesn't this do what you want? > > > > MATRIX. > > COMPUTE x = t({-9:9:1} / 10). > > PRINT x. > > END MATRIX. > > > > OUTPUT: > > Run MATRIX procedure: > > > > X > > -.9000000000 > > -.8000000000 > > -.7000000000 > > -.6000000000 > > -.5000000000 > > -.4000000000 > > -.3000000000 > > -.2000000000 > > -.1000000000 > > .0000000000 > > .1000000000 > > .2000000000 > > .3000000000 > > .4000000000 > > .5000000000 > > .6000000000 > > .7000000000 > > .8000000000 > > .9000000000 > > > > ------ END MATRIX ----- > > > > David Marso wrote > >> Normally in matrix one can do the following. > >> COMPUTE x={1:10:1}. > >> resolves to {1,2,3,4,5,6,7,8,9,10} > >> However : > >> COMPUTE x={.1:.9,.1} > >> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. > >> Well, instead: > >> > >> MATRIX. > >> COMPUTE x={.1: .9 : .1}. > >> PRINT x. > >> END MATRIX. > >> Run MATRIX procedure: > >>>Error encountered in source line # 150 > >> > >>>Warning # 12575 > >>>Non-integer range values were specified. Any non-integer range value > will > >>>be rounded to an integer. > >> > >>>Error encountered in source line # 150 > >> > >>>Error # 12557 > >>>Increment value in the range operator is zero. > >>>This command not executed. > >> > >>>Error encountered in source line # 151 > >> > >>>Error # 12492 > >>>An attempt has been made to use previously undefined matrix (or scalar). > >>>This command not executed. > >> > >> Matrix - 'X ' is undefined > >>>Error encountered in source line # 151 > >> > >>>Error # 12332 > >>>Undefined variable in PRINT. > >> > >> > >> ------ END MATRIX ----- > >> > >> LOVELY eh? > >> Doh!!! > >> Ninja workaround. > >> Also returns a column vector rather than a row vector (usually what I > >> want in such cases). > >> > >> > >> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). > >> + COMPUTE ParseErr=0. > >> + COMPUTE #Z={!1}. > >> + DO IF NCOL(#z) EQ 2. > >> + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. > >> + COMPUTE #Z={#Z,1}. > >> + ELSE. > >> + PRINT / TITLE "WARNING: Non integer argument pairs should have > >> explicit increment.". > >> + COMPUTE !2=T({!1}). > >> + COMPUTE ParseERR=1. > >> + END IF. > >> + ELSE IF NCOL(#z) EQ 1. > >> + COMPUTE #Z={#Z,#Z,1}. > >> + END IF. > >> > >> + DO IF ParseErr=0. > >> + COMPUTE #M=MOD(#Z,1). > >> + COMPUTE #Pwr=1. > >> + DO IF MSUM(ABS(#M )) GT .0000001. > >> + LOOP. > >> + COMPUTE #Pwr=#Pwr*10. > >> + COMPUTE #Z=#Z*10. > >> + COMPUTE #M=MOD(#Z,1). > >> + END LOOP IF MSUM(ABS(#M)) LE .0000001. > >> + END IF. > >> + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). > >> + END IF. > >> !ENDDEFINE. > >> > >> MATRIX. > >> ParsePar -.9,.9,.1 / ParOut . > >> PRINT ParOut. > >> END MATRIX. > >> > >> Run MATRIX procedure: > >> > >> PAROUT > >> -.9000000000 > >> -.8000000000 > >> -.7000000000 > >> -.6000000000 > >> -.5000000000 > >> -.4000000000 > >> -.3000000000 > >> -.2000000000 > >> -.1000000000 > >> .0000000000 > >> .1000000000 > >> .2000000000 > >> .3000000000 > >> .4000000000 > >> .5000000000 > >> .6000000000 > >> .7000000000 > >> .8000000000 > >> .9000000000 > >> > >> ------ END MATRIX ----- > |
Administrator
|
"The pragmatic solution that I know of is to eventually use some
version of Bruce's answer. The mostly-safe way is to parse the user's entry so that you do not risk the roundoff error. Another way is to multiply what the user enters (by 100, by 1000?), add a tiny fraction and truncate; then use fixed code with a fixed division." Rich, That is essentially what my TIP does. Mult by 10 until the result of Mod(x,1) is very small, then create the sequence then divide down. I figured post the solution for the other 2-3 people who might give a hoot.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by David Marso
Python programmability was introduced in
SPSS 14.1, but plugins prior to V18 are no longer available due to the
IBM acquisition (nor are those versions of SPSS, for that matter).
The CDB was introduced in V17 with enhancements in V18. Dialogs build in V21 will still work in V17 as long as they do not use the V18 enhancements. They will show text in the dialog warning that they might not work in V17, but there is a tricky way to get rid of that text if you know that they are okay. I expect that MATRIX, like the similar sequence constructs in R and Python, limits the sequence to integers due to the well known floating point issues with fractional values in a situation like this. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email], Date: 04/21/2013 10:12 AM Subject: Re: [SPSSX-L] TIP: Resolving non integer range constructors in MATRIX. Sent by: "SPSSX(r) Discussion" <[hidden email]> Thanks Jon, You can probably imagine that I have read the MATRIX documentation in depth probably 20 times over the past few months. Python is not an option here. The solution will be widely distributed to many users with SPSS versions from 15? (maybe earlier) to 21 and I have NO intentions of supporting their python woes when they FUBAR their install or fail to realize the python dependency. I go native whenever possible and hate doing teksport for broken toys. Perhaps log this as another MATRIX enhancement request! Quick question: What is the earliest version of SPSS which supports Custom Dialogs. Can the earliest version support CDs written in Ver 21? David -- Jon K Peck wrote > Note that the MATRIX documentation says > > Incremented Ranges of Integers. Use a second colon followed by an integer > to indicate the > increment. The matrix {1,3,5,7;2,5,8,11} can be written as {1:7:2;2:11:3}, > where > 1:7:2 indicates the integers from 1 to 7 incrementing by 2, and 2:11:3 > indicates the integers > from 2 to 11 incrementing by 3. > � You must use integers when specifying a range in either of these ways. > Numbers with > fractional parts are truncated to integers. > > A little Python code would solve this easily, however. > > Jon Peck (no "h") aka Kim > Senior Software Engineer, IBM > peck@.ibm > phone: 720-342-5621 > > > > > From: David Marso < > david.marso@ > > > To: > SPSSX-L@.uga > , > Date: 04/20/2013 08:19 PM > Subject: Re: [SPSSX-L] TIP: Resolving non integer range > constructors in MATRIX. > Sent by: "SPSSX(r) Discussion" < > SPSSX-L@.uga > > > > > > It does, however I need users to be able to specify specific ranges > without > dealing with the internal logic. > ex .5,.75,.01 > ie start ,stop, increment > This is a small piece of a larger simulation application and I need the UI > to be very transparent. > > Bruce Weaver wrote >> David, doesn't this do what you want? >> >> MATRIX. >> COMPUTE x = t({-9:9:1} / 10). >> PRINT x. >> END MATRIX. >> >> OUTPUT: >> Run MATRIX procedure: >> >> X >> -.9000000000 >> -.8000000000 >> -.7000000000 >> -.6000000000 >> -.5000000000 >> -.4000000000 >> -.3000000000 >> -.2000000000 >> -.1000000000 >> .0000000000 >> .1000000000 >> .2000000000 >> .3000000000 >> .4000000000 >> .5000000000 >> .6000000000 >> .7000000000 >> .8000000000 >> .9000000000 >> >> ------ END MATRIX ----- >> >> David Marso wrote >>> Normally in matrix one can do the following. >>> COMPUTE x={1:10:1}. >>> resolves to {1,2,3,4,5,6,7,8,9,10} >>> However : >>> COMPUTE x={.1:.9,.1} >>> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. >>> Well, instead: >>> >>> MATRIX. >>> COMPUTE x={.1: .9 : .1}. >>> PRINT x. >>> END MATRIX. >>> Run MATRIX procedure: >>>>Error encountered in source line # 150 >>> >>>>Warning # 12575 >>>>Non-integer range values were specified. Any non-integer range value > will >>>>be rounded to an integer. >>> >>>>Error encountered in source line # 150 >>> >>>>Error # 12557 >>>>Increment value in the range operator is zero. >>>>This command not executed. >>> >>>>Error encountered in source line # 151 >>> >>>>Error # 12492 >>>>An attempt has been made to use previously undefined matrix (or > scalar). >>>>This command not executed. >>> >>> Matrix - 'X ' is undefined >>>>Error encountered in source line # 151 >>> >>>>Error # 12332 >>>>Undefined variable in PRINT. >>> >>> >>> ------ END MATRIX ----- >>> >>> LOVELY eh? >>> Doh!!! >>> Ninja workaround. >>> Also returns a column vector rather than a row vector (usually what I >>> want in such cases). >>> >>> >>> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). >>> + COMPUTE ParseErr=0. >>> + COMPUTE #Z={!1}. >>> + DO IF NCOL(#z) EQ 2. >>> + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. >>> + COMPUTE #Z={#Z,1}. >>> + ELSE. >>> + PRINT / TITLE "WARNING: Non integer argument pairs should have >>> explicit increment.". >>> + COMPUTE !2=T({!1}). >>> + COMPUTE ParseERR=1. >>> + END IF. >>> + ELSE IF NCOL(#z) EQ 1. >>> + COMPUTE #Z={#Z,#Z,1}. >>> + END IF. >>> >>> + DO IF ParseErr=0. >>> + COMPUTE #M=MOD(#Z,1). >>> + COMPUTE #Pwr=1. >>> + DO IF MSUM(ABS(#M )) GT .0000001. >>> + LOOP. >>> + COMPUTE #Pwr=#Pwr*10. >>> + COMPUTE #Z=#Z*10. >>> + COMPUTE #M=MOD(#Z,1). >>> + END LOOP IF MSUM(ABS(#M)) LE .0000001. >>> + END IF. >>> + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). >>> + END IF. >>> !ENDDEFINE. >>> >>> MATRIX. >>> ParsePar -.9,.9,.1 / ParOut . >>> PRINT ParOut. >>> END MATRIX. >>> >>> Run MATRIX procedure: >>> >>> PAROUT >>> -.9000000000 >>> -.8000000000 >>> -.7000000000 >>> -.6000000000 >>> -.5000000000 >>> -.4000000000 >>> -.3000000000 >>> -.2000000000 >>> -.1000000000 >>> .0000000000 >>> .1000000000 >>> .2000000000 >>> .3000000000 >>> .4000000000 >>> .5000000000 >>> .6000000000 >>> .7000000000 >>> .8000000000 >>> .9000000000 >>> >>> ------ END MATRIX ----- > > > > > > ----- > Please reply to the list and not to my personal email. > Those desiring my consulting or training services please feel free to > email me. > --- > "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos > ne forte conculcent eas pedibus suis." > Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in > abyssum?" > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719606.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719609.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Thanks Jon, Any 411 on the specific nature of the v 18 enhancements? It would seem that the simple task of returning incremented sequences of non integers would be a non brainer? Maybe they overthink the issue! --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
I don't have V17 installed anymore - six
versions is enough, but the V18 What's New help says
The Custom Dialog Builder now has a list box control that supports single or multiple selection. Also, list items for combo box and list box controls can now be dynamically populated with values associated with the variables in a specified target list. In addition, radio buttons can now contain a set of nested controls Fractional increments would give behavior that would puzzle people. You would get the exact expected number of values for .5 but not for .6., for example, and I'm sure there would be differences of opinion on what the correct behavior should be. This, for example, popped up on a SAS list courtesy of Google. I am trying to use a %do loop in a macro, but it does not appear that I can increment by fractions. I am trying to increment by 0.25, but I get the following errors: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition ... Even if you wanted to introduce some rounding behavior, it gets tricky. The Python Decimal module, for example supports all these rounding methods.
ROUND_CEILING (towards Infinity),
Thanks Jon, Any 411 on the specific nature of the v 18 enhancements? It would seem that the simple task of returning incremented sequences of non integers would be a non brainer? Maybe they overthink the issue! -- Jon K Peck wrote > Python programmability was introduced in SPSS 14.1, but plugins prior to > V18 are no longer available due to the IBM acquisition (nor are those > versions of SPSS, for that matter). > > The CDB was introduced in V17 with enhancements in V18. Dialogs build in > V21 will still work in V17 as long as they do not use the V18 > enhancements. They will show text in the dialog warning that they might > not work in V17, but there is a tricky way to get rid of that text if you > know that they are okay. > > I expect that MATRIX, like the similar sequence constructs in R and > Python, limits the sequence to integers due to the well known floating > point issues with fractional values in a situation like this. > > > Jon Peck (no "h") aka Kim > Senior Software Engineer, IBM > peck@.ibm > phone: 720-342-5621 > > > > > From: David Marso < > david.marso@ > > > To: > SPSSX-L@.uga > , > Date: 04/21/2013 10:12 AM > Subject: Re: [SPSSX-L] TIP: Resolving non integer range > constructors in MATRIX. > Sent by: "SPSSX(r) Discussion" < > SPSSX-L@.uga > > > > > > Thanks Jon, > You can probably imagine that I have read the MATRIX documentation in > depth probably 20 times over the past few months. Python is not an option > here. The solution will be widely distributed to many users with SPSS > versions from 15? (maybe earlier) to 21 and I have NO intentions of > supporting their python woes when they FUBAR their install or fail to > realize the python dependency. I go native whenever possible and hate > doing > teksport for broken toys. > Perhaps log this as another MATRIX enhancement request! > Quick question: What is the earliest version of SPSS which supports > Custom > Dialogs. Can the earliest version support CDs written in Ver 21? > David > -- > > Jon K Peck wrote >> Note that the MATRIX documentation says >> >> Incremented Ranges of Integers. Use a second colon followed by an > integer >> to indicate the >> increment. The matrix {1,3,5,7;2,5,8,11} can be written as > {1:7:2;2:11:3}, >> where >> 1:7:2 indicates the integers from 1 to 7 incrementing by 2, and 2:11:3 >> indicates the integers >> from 2 to 11 incrementing by 3. >> � You must use integers when specifying a range in either of these > ways. >> Numbers with >> fractional parts are truncated to integers. >> >> A little Python code would solve this easily, however. >> >> Jon Peck (no "h") aka Kim >> Senior Software Engineer, IBM > >> peck@.ibm > >> phone: 720-342-5621 >> >> >> >> >> From: David Marso < > >> david.marso@ > >> > >> To: > >> SPSSX-L@.uga > >> , >> Date: 04/20/2013 08:19 PM >> Subject: Re: [SPSSX-L] TIP: Resolving non integer range >> constructors in MATRIX. >> Sent by: "SPSSX(r) Discussion" < > >> SPSSX-L@.uga > >> > >> >> >> >> It does, however I need users to be able to specify specific ranges >> without >> dealing with the internal logic. >> ex .5,.75,.01 >> ie start ,stop, increment >> This is a small piece of a larger simulation application and I need the > UI >> to be very transparent. >> >> Bruce Weaver wrote >>> David, doesn't this do what you want? >>> >>> MATRIX. >>> COMPUTE x = t({-9:9:1} / 10). >>> PRINT x. >>> END MATRIX. >>> >>> OUTPUT: >>> Run MATRIX procedure: >>> >>> X >>> -.9000000000 >>> -.8000000000 >>> -.7000000000 >>> -.6000000000 >>> -.5000000000 >>> -.4000000000 >>> -.3000000000 >>> -.2000000000 >>> -.1000000000 >>> .0000000000 >>> .1000000000 >>> .2000000000 >>> .3000000000 >>> .4000000000 >>> .5000000000 >>> .6000000000 >>> .7000000000 >>> .8000000000 >>> .9000000000 >>> >>> ------ END MATRIX ----- >>> >>> David Marso wrote >>>> Normally in matrix one can do the following. >>>> COMPUTE x={1:10:1}. >>>> resolves to {1,2,3,4,5,6,7,8,9,10} >>>> However : >>>> COMPUTE x={.1:.9,.1} >>>> One would expect/hope to receive {.1,.2,.3,.4,.5,.6,.7,.8,9}. >>>> Well, instead: >>>> >>>> MATRIX. >>>> COMPUTE x={.1: .9 : .1}. >>>> PRINT x. >>>> END MATRIX. >>>> Run MATRIX procedure: >>>>>Error encountered in source line # 150 >>>> >>>>>Warning # 12575 >>>>>Non-integer range values were specified. Any non-integer range value >> will >>>>>be rounded to an integer. >>>> >>>>>Error encountered in source line # 150 >>>> >>>>>Error # 12557 >>>>>Increment value in the range operator is zero. >>>>>This command not executed. >>>> >>>>>Error encountered in source line # 151 >>>> >>>>>Error # 12492 >>>>>An attempt has been made to use previously undefined matrix (or >> scalar). >>>>>This command not executed. >>>> >>>> Matrix - 'X ' is undefined >>>>>Error encountered in source line # 151 >>>> >>>>>Error # 12332 >>>>>Undefined variable in PRINT. >>>> >>>> >>>> ------ END MATRIX ----- >>>> >>>> LOVELY eh? >>>> Doh!!! >>>> Ninja workaround. >>>> Also returns a column vector rather than a row vector (usually what I >>>> want in such cases). >>>> >>>> >>>> DEFINE ParsePar ( !Pos !CHAREND ("/") /!POS !CMDEND). >>>> + COMPUTE ParseErr=0. >>>> + COMPUTE #Z={!1}. >>>> + DO IF NCOL(#z) EQ 2. >>>> + DO IF MSUM(ABS(MOD(#Z,1))) EQ 0. >>>> + COMPUTE #Z={#Z,1}. >>>> + ELSE. >>>> + PRINT / TITLE "WARNING: Non integer argument pairs should have >>>> explicit increment.". >>>> + COMPUTE !2=T({!1}). >>>> + COMPUTE ParseERR=1. >>>> + END IF. >>>> + ELSE IF NCOL(#z) EQ 1. >>>> + COMPUTE #Z={#Z,#Z,1}. >>>> + END IF. >>>> >>>> + DO IF ParseErr=0. >>>> + COMPUTE #M=MOD(#Z,1). >>>> + COMPUTE #Pwr=1. >>>> + DO IF MSUM(ABS(#M )) GT .0000001. >>>> + LOOP. >>>> + COMPUTE #Pwr=#Pwr*10. >>>> + COMPUTE #Z=#Z*10. >>>> + COMPUTE #M=MOD(#Z,1). >>>> + END LOOP IF MSUM(ABS(#M)) LE .0000001. >>>> + END IF. >>>> + COMPUTE !2=T({#Z(1):#Z(2):#Z(3)}/#Pwr). >>>> + END IF. >>>> !ENDDEFINE. >>>> >>>> MATRIX. >>>> ParsePar -.9,.9,.1 / ParOut . >>>> PRINT ParOut. >>>> END MATRIX. >>>> >>>> Run MATRIX procedure: >>>> >>>> PAROUT >>>> -.9000000000 >>>> -.8000000000 >>>> -.7000000000 >>>> -.6000000000 >>>> -.5000000000 >>>> -.4000000000 >>>> -.3000000000 >>>> -.2000000000 >>>> -.1000000000 >>>> .0000000000 >>>> .1000000000 >>>> .2000000000 >>>> .3000000000 >>>> .4000000000 >>>> .5000000000 >>>> .6000000000 >>>> .7000000000 >>>> .8000000000 >>>> .9000000000 >>>> >>>> ------ END MATRIX ----- >> >> >> >> >> >> ----- >> Please reply to the list and not to my personal email. >> Those desiring my consulting or training services please feel free to >> email me. >> --- >> "Nolite dare sanctum canibus neque mittatis margaritas vestras ante > porcos >> ne forte conculcent eas pedibus suis." >> Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff > in >> abyssum?" >> -- >> View this message in context: >> > http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719606.html > >> >> Sent from the SPSSX Discussion mailing list archive at Nabble.com. >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD > > > > > > ----- > Please reply to the list and not to my personal email. > Those desiring my consulting or training services please feel free to > email me. > --- > "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos > ne forte conculcent eas pedibus suis." > Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in > abyssum?" > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719609.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/TIP-Resolving-non-integer-range-constructors-in-MATRIX-tp5719604p5719613.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Jon,
Thanks for the CDB info. Re range sequence/constructors: I guess I must be doing something right. Using the code from first post. MATRIX. ParsePar -6,6,.6 / ParOut . PRINT ParOut / FORMAT "F20.16". END MATRIX. Run MATRIX procedure: PAROUT -6.0000000000000000 -5.4000000000000000 -4.8000000000000000 -4.2000000000000000 -3.6000000000000000 -3.0000000000000000 -2.4000000000000000 -1.8000000000000000 -1.2000000000000000 -.6000000000000000 .0000000000000000 .6000000000000000 1.2000000000000000 1.8000000000000000 2.4000000000000000 3.0000000000000000 3.6000000000000000 4.2000000000000000 4.8000000000000000 5.4000000000000000 6.0000000000000000 ------ END MATRIX -----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Hello, |
In reply to this post by David Marso
I can't speak to your particular application, but I like the way that R's "seq" works, in that you can either provide a "BY" statement or a desired length of the vector. Below is what I dreamed up in a few minutes (can't speak if it is better/inferior in any way - just throwing it out there).
Andy *********************************************************. *GIVEN BEGIN, END AND LENGTH. MATRIX. COMPUTE BEGINM = 12. COMPUTE ENDM = -36. COMPUTE LEN = 103. *SOLVE FOR ITER. COMPUTE ITER = (ENDM - BEGINM)/(LEN - 1). COMPUTE x = T(({1:LEN} - 1)*ITER + BEGINM). PRINT x. END MATRIX. *********************************************************. *********************************************************. *GIVEN BEGIN END AND ITER. MATRIX. COMPUTE BEGINM = 6. COMPUTE ENDM = -6. COMPUTE ITER = .7. *SOLVE FOR LENGTH. COMPUTE LEN = TRUNC(ABS((ENDM - BEGINM)/ITER) + 1). *IF NEGATIVE NEED TO NEGATE ITER. DO IF BEGINM > ENDM. COMPUTE ITER = -ITER. END IF. COMPUTE x = T(({1:LEN} - 1)*ITER + BEGINM). PRINT x. END MATRIX. *********************************************************. *The behavior of this is if the iter does not divide nicely. *it just stops the vector at the nearest iteration before the end. *appears to be behavior of David's macro and R's "seq" function. |
Administrator
|
To put a little flesh on the bones.
I am basically creating a macro to generate simulations (the exact nature of which I can't currently reveal). There are say 6 factors which can vary, 2 which can range between -1.0 ..1.0 the others are integer. I wanted to make it easy for users to specify such sequences without the burden of having them supply a multiplier. My very first version had that burden but my TIP is an easy way to make the limitations of MATRIX transparent to the user. In addition, for integers it permits specification of a pair (in which case the increment defaults to 1), or in either integer or float cases it permits a single value rather than a triplet. Sim par1 1,2 / par2 1,9,3 / par3 -.9,.9,.3 ....par6 ..... Would essentially generate all 56 combinations of values implied by these arguments (1,2) x (1,4,7,10) x (-.9, -.6, -.3, 0 .3, .6 .9) 1,1 -.9 1,1,-.6 1,1,-.3 1,1,0 ..... 1,1,.9 1,4,-.9 .... 2,9,.9
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |