Wow, this is really great! I'll use yours! I started ffrom because I have an 'expensive' forward model with 8 parameters, which is then going to be inverted using iterative least squares.
So I will apply ffrom2 very many times. Ben -----Original Message----- From: [email protected] on behalf of Marshall Lochbaum Sent: Sun 1/23/2011 9:33 PM To: 'Programming forum' Subject: Re: [Jprogramming] Floating from One correction to ffrom2: ffrom2=:4 :0 "0 _ x=.,>x range=. { (<.,>.)&.> x mult=. *// (,.~-.) (-<.) x mult +/^:(#x)@:* range{y ) Now it replicates all of your results. This version outperforms yours in speed and space: 6!:2 '(<?20$0) ffrom i.20#2' 5.51853 6!:2 '(<?20$0) ffrom2 i.20#2' 1.44303 7!:2 '(<?20$0) ffrom i.20#2' 1535325568 7!:2 '(<?20$0) ffrom2 i.20#2' 666901632 However, I would like to see a version that only uses the one value if an integer is given (mine uses two copies of the same value and gives weight 1 to one of them and 0 to the other). Marshall -----Original Message----- From: Marshall Lochbaum [mailto:[email protected]] Sent: Sunday, January 23, 2011 3:21 PM To: 'Programming forum' Subject: RE: [Jprogramming] Floating from This is a version that works only for lists. Given an exact index, it does not interpolate; given a value outside of the range, it halts with an index error. ffromlist=:4 :0"0 1 range=. (<.,>.) x mult=.(,~-.) (-<.) x mult +/@:* range{y ) A similar, but less thoroughly tested, model for arbitrary rank is given below. ffrom2=:4 :0 "0 _ range=. { (<.,>.)&.> >x mult=. *// (,.~-.) (-<.) ,>x mult +/@,@:* range{y ) Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Ben Gorte - LR Sent: Sunday, January 23, 2011 11:38 AM To: [email protected] Subject: [Jprogramming] Floating from Hi, I believe I made a nice verb, called ffrom. It acts like { (from) : 1 3 ffrom i.10 1 3 (<1 3) ffrom i.3 5 8 (<1 3) ffrom i.3 5 6 48 49 50 51 52 53 but it also does: 1.4 3.2 ffrom i.10 1.4 3.2 (<1.4 3.2) ffrom i.3 5 10.2 (<1.4 3.2) ffrom i.3 5 6 61.2 62.2 63.2 64.2 65.2 66.2 It does that by multi-linear interpolation in any-dimensional grids: (<0.5 0.5) ffrom 2 2$0 0 0 10 2.5 (<1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8) ffrom i. 3 3 3 3 3 3 3 3 3771.6 Here it is: ffrom 4 : 0"0 _ vect =. _1e_7 + >x n =. 2^#vect bin =. #:i.n pos =. <.vect frac =. vect-pos +/(*/(,./bin){"0 1 (1-frac),.frac) * (;/"2 pos +"1 1 bin) { y ) I have no doubts that members in this forum can make it nicer. What i particularly do not like is the _e_7 at the beginning. Its only purpose is to allow for (n-1) ffrom i.n=.4 3 which otherwise would interpolate between the 3rd and 4th element causing an index error. If I want to solve that in another way it gets messy. By the way, _1 _1.5 _2 ffrom i.4 3 2.5 1 looks okay to me, and _0.3 ffrom i.4 0.9 interpolates between the last and the first value, which also seems reasonable. Finally, (<?20$0) ffrom i.20#2 281616 interpolates between the 1,048,576 vertices of a 20-dimensional hypercube :-) Of course improvements and other suggestions will be greatly appreciated. Perhaps it can end up in the wiki? Greetings, Ben ---------------------------------------------------------------------- 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
