cancel
Showing results for 
Search instead for 
Did you mean: 

Convergence using binary?

JP
New Contributor III

Hi,

Hope this will be clear enough; I am trying to pass 2 parameters (x;y) to a function, for convergence:

  • "x" being an initial table, which the convergence function will gradually modify until no change, using...
  • "y", a list, which current value allows defining current conditions within the convergence function.

The first "y" value sets the 1st convergence function applied to table "x". The resulting converged table, together with the second "y" value, then feed the next convergence... etc, up until the last item in the "y" list. Basically, the parameter "y" allows the condition(s), within the function to converge, to change as "y" is iterated and feeding the next loop.

The following pseudo code is what I am looking for:

Step 1

f:{[x;y]

  cond based on 1st item of y;

  x: <delete from x where cond>, until x is stable;

  }/[initial table]/[first in list]

Step 2 & following: using table output from previous convergence, together with next element in list:

f:{[x;y]

  cond based on n'th item of y;

  x: <delete from x where cond>, until x is stable

  }/[output table from previous step]/[next in list]

... obviously with the bizarre "/[table]/[list]" interpreted as <converge table> over <list>. I think it is possible to achieve this through encapsulation and/or .z.s, but my attempts have failed. Any help would be appreciated.

Thx

JP

1 ACCEPTED SOLUTION

JP
New Contributor III

Precisely (removing the <count>), many thanks:-)

Funny, I dug into it this am and came up with {f/[x;1 2]}/[t], but didn't think (still not super fluent in q) about using the projection in the lambda.   

Again, thank you for your time and input.

JP

View solution in original post

7 REPLIES 7

Rolf
New Contributor III
q)t:([]til 10)

q)t{y x}/(5_;-2_)
x
-
5
6
7

/ the intermediate steps
q)t{y x}\(5_;-2_;2#)
+(,`x)!,5 6 7 8 9
+(,`x)!,5 6 7
+(,`x)!,5 6

JP
New Contributor III

Rolf,

I don't see any convergence in t{y x}/(5_;-2_), but 2 composed operations on t , using atoms.  Am I missing something?  

JP

JP
New Contributor III

To illustrate what I am looking for:

/An example
t:([] a:100?10;b:100?1.)    	 

/What I am looking for, (case of 2=count list)
{[x;it] 
	c1:		(-1_(>':) (it+1)>x`a),0b;  				/Cond1: ID first of each group of 1b's (source of convergence in this ex, til stable)			
	c2: 	0.5>abs log ratios next x`b; 			/Cond2: Some value
	cond: 	$[1=it; c1; c1&c2];						/Set condition according to current param in [1 2]
	t:		delete from x where cond|prev cond 		/Delete a duo of entries, where cond
	}/[t] ... with each of [1 2] using the previously converged [t]

/with its equivalent sequence of processing:
{[x]
	it:		2;
	c1:		(-1_(>':) (it+1)>x`a),0b;  										
	c2: 	0.5>abs log ratios next x`b;
	cond: 	$[1=it; c1; c1&c2];	
	t:		delete from x where cond|prev cond
	}/ [{
		it:		1;
		c1:		(-1_(>':) (it+1)>x`a),0b;  									
		c2: 	0.5>abs log ratios next x`b;
		cond: 	$[1=it; c1; c1&c2];	
		t:		delete from x where cond|prev cond
		}/[t]]

Rolf
New Contributor III
/ our diadic function takes two arguments
/ x will be the table
/ y will be the elements in the list incrementally

/ converge form of over shows final result
q)t{y _ x}/2 -3 4
x
-
6

/ using scan you can see the intermediate changes
q)t{y _ x}\2 -3 4
+(,`x)!,2 3 4 5 6 7 8 9
+(,`x)!,2 3 4 5 6
+(,`x)!,,6

??

JP
New Contributor III

I perfectly understand your example, but there is no convergence per se.  It is a standard iterative <over> a list applied to t, as in {y _ x}/[t;2 -3 4].   I realize that the title of my post was not a work of art:-)

I posted an example of what I am looking for just prior to your last reply; it uses a very short list of n=2 that needs to be fed into the convergence function (convergence in the sens of successive modifications to <t>, based on the current atom in the list, up until no further changes in <t>).  Please look into it.  Thx 

jfealy
New Contributor

Is this the behavior you're looking for?

 

 

q)t:([] a:100?10;b:100?1.)
q)f:{[x;it]c1:(-1_(>':) (it+1)>x`a),0b;c2: 0.5>abs log ratios next x`b;cond: $[1=it; c1; c1&c2];delete from x where cond|prev cond}
q)count {f[;y]/[x]}/[t;1 2]
56

 

 

 

JP
New Contributor III

Precisely (removing the <count>), many thanks:-)

Funny, I dug into it this am and came up with {f/[x;1 2]}/[t], but didn't think (still not super fluent in q) about using the projection in the lambda.   

Again, thank you for your time and input.

JP