If anyone is REALLY interested in the timing of the sparse and dense versions,
you can try to work through this demonstration I put together...
Basically, (# % >./) is a good, really fast way to figure out how dense a list
is, and you want to start using the sparse form at about the point where it
crosses 1 (sparse for lower, dense for higher)
Marshall
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Henry Rich
Sent: Monday, September 06, 2010 11:35 AM
To: Programming forum
Subject: Re: [Jprogramming] Mask from list of indices with multiplicity
Allowing !. to change the universe is an interesting idea, but wouldn't !. be
needed in its usual role of tolerance, since there are implied comparisons in
the operation?
Also, your Ii works only on numeric operands, while
universe <:@(#/.~)@, y
works on all types (and shapes).
Since the key part, #/.~ , is already fast, I think that nothing more
is really needed. This is a matter of taste.
Henry Rich
Henry Rich
On 9/6/2010 10:06 AM, Marshall Lochbaum wrote:
> The only way I. I.^:_1 changes x is that it sorts it, and I.^:_1 I. only cuts
> out the trailing 0s:
> Ii=. ([:<:@(#/.~) i.@>:@(>./) , ])
> (; (;Ii)@I.) 1...@$2
> ┌───────────────────┬───────────┬─────────────────┐
> │1 1 1 0 0 1 1 0 1 0│0 1 2 5 6 8│1 1 1 0 0 1 1 0 1│
> └───────────────────┴───────────┴─────────────────┘
> (; (;I.)@Ii) 6...@$10
> ┌───────────┬─────────────────┬───────────┐
> │0 0 8 6 6 3│2 0 0 1 0 0 2 0 1│0 0 3 6 6 8│
> └───────────┴─────────────────┴───────────┘
>
> I think each of these cases is acceptable, especially if you allow !. to
> change the universe (this removes the I.^:_1 I. problem).
>
> Marshall
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Roger Hui
> Sent: Monday, September 06, 2010 2:26 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Mask from list of indices with
> multiplicity
>
> I.^:_1 seems too far from what<:#/.~universe,x does.
> Another way to say that is that I. I.^:_1 x can bear scant resemblance to x .
>
>
>
> ----- Original Message -----
> From: Zsbán Ambrus<[email protected]>
> Date: Sunday, September 5, 2010 14:21
> Subject: Re: [Jprogramming] Mask from list of indices with
> multiplicity
> To: Programming forum<[email protected]>
>
>> On Sun, Sep 5, 2010 at 10:57 PM, Roger Hui<[email protected]> wrote:
>>> <: #/.~ (i.7) ,x
>>
>> Nice solution.
>>
>>> ----- Original Message -----
>>> From: Zsbán Ambrus<[email protected]>
>>>> Would it make
>>>> sense if I.^:_1 did this?
>>
>> ^^^ What's your opinion on this?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
is=.#/.`(~...@])`(0 $~ >:@(>./)@])}~ NB. better for sparse lists
id=.[: <:@(#/.~) i.@>:@(>./) , ] NB. better for dense lists
]p=.([: /:~@(*/) 0 ?...@$~ ,&10)"0 i. 10 NB. probability that large numbers
are chosen often in a
1 1 1 1 1 1
1 1 1 1
0.278434 0.331206 0.663753 0.706277 0.773552 0.789781
0.875596 0.903315 0.965329 0.97229
0.0661658 0.134468 0.145077 0.20866 0.253118 0.279506
0.474124 0.584872 0.585165 0.634342
0.0205764 0.046323 0.0602206 0.0633379 0.0820097 0.126221
0.18072 0.193295 0.251766 0.305435
0.000676188 0.000953657 0.00142951 0.00625031 0.00694286 0.00722058
0.00916159 0.00921619 0.0733313 0.110358
0.000868989 0.00127869 0.00142348 0.00197492 0.00288268 0.00372089
0.00645907 0.0151088 0.0155373 0.0254523
5.56151e_7 0.000140783 0.000749229 0.000750442 0.00164517 0.00416057
0.0123433 0.0150865 0.0205059 0.0223685
3.89765e_8 0.000138143 0.000332681 0.000483219 0.000655637 0.000755605
0.00123158 0.0038672 0.00654349 0.00689194
4.62121e_6 7.77065e_5 0.000204845 0.000209031 0.000261824 0.000288918
0.000494159 0.00194955 0.0100389 0.0337553
1.0682e_7 2.34022e_6 1.19068e_5 1.45716e_5 2.18635e_5 5.76226e_5
0.000320198 0.00148068 0.00177353 0.00734558
$ a=.10-p&(I."1) 100...@$0 NB. long lists with skewed probability
distributions given by p
10 10000
ia =. <@I. a
]r=.(# % >./)@> ia NB. determines sparseness of the lists in ia
10.001 7.30653 3.43054 1.36214 0.240424 0.0826083 0.0839084 0.0236307 0.0528053
0.0132172
]r,t=.6!:2"1 ('is ',:'id ') ,"1/ '{::ia',"1~ ":"0 i.10 NB. (sparseness
factor) , (sparse time),:(dense time)
10.001 7.30653 3.43054 1.36214 0.240424 0.0826083
0.0839084 0.0236307 0.0528053 0.0132172
0.0027632 0.00285827 0.00162641 0.000792228 0.00033519 0.000142378
0.00013122 7.85533e_5 0.000119169 7.27511e_5
0.00217048 0.00174736 0.00117696 0.00067172 0.000609681 0.000358846
0.000355721 0.000345902 0.000351258 0.000347241
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm