Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread Ric Sherlock
Note that 1e6 ?@# 1e3 and 1e6 ?@$ 1e3 are both optimised compared to ? 1e6 # 1e3 10 timespacex '?100#1000' 0.0230934 1.67786e7 10 timespacex '100?@#1000' 0.0176543 8.39002e6 10 timespacex '100?@$1000' 0.0186202 8.39002e6 On Fri, Jul 28, 2017 at 10:36 AM, 'Mike Day' vi

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread 'Mike Day' via Programming
Just back from doing a BBC Prom! Very loud... Still some voice left. If I'm doing a simulation, I often do ? on a large sample, eg ?100#1000 or the like, and then "draw" from that sample in sequence. Usually for independent trials. For example, for this donation problem, it _might_ b

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread Raul Miller
The default result from 9!:42 is 2, which is the Mersenne Twister algorithm for roll, which is pretty fast. FYI, -- Raul On Thu, Jul 27, 2017 at 4:27 PM, Jimmy Gauvin wrote: > I was wondering if making rg tacit would boost performance. > Thanks to Raul for answering my unvoiced question. > >

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread Jimmy Gauvin
I was wondering if making rg tacit would boost performance. Thanks to Raul for answering my unvoiced question. I guess key, nub and amend are well optimized in the J interpreter. Jimmy PS Is roll also optimized for speed? If not should we look into ISAAC or other fast PRNGs? On Thu, Jul 27, 2

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread Raul Miller
Ah, i was testing it on too small of a data set. Thanks, -- Raul On Thu, Jul 27, 2017 at 4:33 AM, 'Mike Day' via Programming wrote: > Jimmy's original rg outperforms both tock and the best of > my various attempts at "new" for "larger" problems, eg > >10 ts 'rg^:1 #~400' > 0.633403 3

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-27 Thread 'Mike Day' via Programming
Jimmy's original rg outperforms both tock and the best of my various attempts at "new" for "larger" problems, eg 10 ts 'rg^:1 #~400' 0.633403 38272 10 ts 'tock^:1 #~400' 0.751826 34816 10 ts 'new^:1 #~400' 0.793394 39424 NB. less good on smaller ones 30 ts 'rg^:1 #~1

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-26 Thread Raul Miller
Oh, well, you could make it tacit. For example: rg=:(((#/.~@])`(~.@])`(0*[)} +/?@##)+-) * That does not speed it up, though. Anyways, good luck, -- Raul On Thu, Jul 27, 2017 at 12:29 AM, Jimmy Gauvin wrote: > I was hoping to get rid of some or all of the temporary vars so I guess > I'll

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-26 Thread Jimmy Gauvin
I was hoping to get rid of some or all of the temporary vars so I guess I'll try option 2 and see if I can come up with something. I like the *y instead of y>0 and the #/.~ the }~ was a bit harder to grasp until I realized that } is an adverb and then the equivalence of "what where} array" and "ar

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-26 Thread Raul Miller
When going for speed, there's two basic approaches: (1) try minor variations on the theme - rearrange to see if you can eliminate anything, or to incorporate any known special code, (2) rewrite from scratch and see if that's faster. Personally, I don't see any way to make that one any faster, th

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-26 Thread Jimmy Gauvin
​Hi, this function seems reasonably fast but I think it could be re-arranged to be a bit more compact, Would anyone have some tips as how to go about this? rg =: 3 : '(y-g) + (r #/. r) (~. r =. ? (+/ g =. y>0)$ $y) } 0 $~ $y' ts 'rg ^:1 ] 400$100' 0.209447 38272 ts 'rg ^:10 ]

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-21 Thread 'Mike Day' via Programming
fwiw, I had spotted a slip in my version. I wasn't going to bother the forum, but might as well mention it in view of your comparisons. " &. " should have been " &.: " - I put my carelessness down to the chaleur en France, unfamiliarity with the iPad and The correction improves "new"

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-20 Thread ol...@bluewin.ch
I like your new version very much Raul. Hard to top that. Hat's off for the i.@# #/.~@, part. Bravo! Louis Original Message From : rauldmil...@gmail.com Date : 20/07/2017 - 17:45 (EDT) To : programm...@jsoftware.com Subject : Re: [Jprogramming] Everyone giving dollars to random o

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-20 Thread Raul Miller
So... here's a collection of some of the definitions seen here, with some timing runs: NB. Xiao-Yong Jin's implementation as revised by Pascal Jasmin NB. http://jsoftware.com/pipermail/programming/2017-July/047881.html revised=: ''1 :(0 :0-.LF) /:~@( -&1`]@.(=&0)"0 (#/.~@] + ~.@]{[)

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-20 Thread Skip Cave
My explicit, looping version: NB. y is number of people and dollars NB. x is iteration count hist =: <: @ (#/.~) @ (i.@#@[ , I.) NB. Histogram iter =: 4 :0 nx =: y$y NB. initialize money while. x>0 do. sg =: +/nx>0 NB. How many still giving? nx =: nx-nx~:0NB. Th

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-20 Thread Raul Miller
7;stats' >>>>> stddev"1 tick^:(i.10) 45#45 >>>>> 0 0.977008 1.18705 1.73205 2.01133 2.15322 2.46798 2.86832 2.97719 3.1334 >>>>> tick^:1]20#20 >>>>> 3 20 1 15 10 38 6 8 23 24 11 90 33 67 5 13 7 20 1 5 >>>>> &

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-20 Thread 'Mike Day' via Programming
You win, Louis! Yes, it looks as if outer-product methods suffer, naturally enough, with larger problem size. Presumably they're ~ O(n^2) in time and space. NB. in J806 with avx, fairly pedestrian Lenovo ts'new ^:5000 #~200' NB. the one I posted eariler 0.758277 20992 ts'run ^:5000 #~2

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-19 Thread Louis de Forcrand
>> >>>> On Mon, Jul 10, 2017 at 7:50 PM, 'Pascal Jasmin' via Programming >>>> wrote: >>>>> >>>>> The number of $ available each round is the number of people with >&0. >>>> The number of potential recipients is

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-19 Thread Rob Hodgkinson
t;> >>>> The number of $ available each round is the number of people with >&0. >>> The number of potential recipients is the population. This simplification >>> though means its possible for someone to pay himself. >>>> >>>> A correction to your ve

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-19 Thread 'Mike Day' via Programming
doesn't seem to happen. As soon as some have 0, the rest have a "negative return" expectation each turn. From: Xiao-Yong Jin To: "programm...@jsoftware.com" Sent: Monday, July 10, 2017 3:43 PM Subject: [Jprogramming] Everyone givi

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-11 Thread Devon McCormick
that doesn't seem to happen. > > > > As soon as some have 0, the rest have a "negative return" expectation > each turn. > > > > > > > > > > > > From: Xiao-Yong Jin > > > > To: "programm...@

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Raul Miller
________ > > > From: Xiao-Yong Jin > > To: "programm...@jsoftware.com" > > Sent: Monday, July 10, 2017 3:43 PM > > Subject: [Jprogramming] Everyone giving dollars to random others > > > > > I thought this is a good lunch break exercise

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread 'Pascal Jasmin' via Programming
__ From: Xiao-Yong Jin To: "programm...@jsoftware.com" Sent: Monday, July 10, 2017 3:43 PM Subject: [Jprogramming] Everyone giving dollars to random others I thought this is a good lunch break exercise. http://www.decisionsciencenews.com/2017/06/

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Devon McCormick
His narration states Quote: “Imagine a room full of 100 people with 100 dollars each. With every tick of the clock, every person with money gives a dollar to one randomly chosen other person. After some time progresses, how will the money be distributed?” And I came up with this simulation. (45 p

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Raul Miller
Why do you think that? Or were you referring to Xiao-Yong Jin's narrative? Thanks, -- Raul On Mon, Jul 10, 2017 at 5:17 PM, Devon McCormick wrote: > So, you start with $10,000 (=100*$100) but end up with $2,025 (=45*$45), > how? > > On Mon, Jul 10, 2017 at 3:59 PM, Raul Miller wrote: > >> I

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Devon McCormick
So, you start with $10,000 (=100*$100) but end up with $2,025 (=45*$45), how? On Mon, Jul 10, 2017 at 3:59 PM, Raul Miller wrote: > I don't really understand what you mean by "mean expectations" - could > you describe the intent there? > > That said, here's how far I've gotten in implementing th

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Raul Miller
I don't really understand what you mean by "mean expectations" - could you describe the intent there? That said, here's how far I've gotten in implementing this concept: tick=: (0 >. <:) + i.@# +/@:(=/)~ +/@:* ?@# # (mean,stddev)"1 tick^:(i.10)]100#100 1000 100 0.932034 100 1.41421

[Jprogramming] Everyone giving dollars to random others

2017-07-10 Thread Xiao-Yong Jin
I thought this is a good lunch break exercise. http://www.decisionsciencenews.com/2017/06/19/counterintuitive-problem-everyone-room-keeps-giving-dollars-random-others-youll-never-guess-happens-next/ Quote: “Imagine a room full of 100 people with 100 dollars each. With every tick of the clock, ev