Dec 1, 2021 14:04
Yeah it's a classic divide-and-conquer style algorithm isn't it
Dec 1, 2021 14:02
(any within the range of course)
Dec 1, 2021 14:01
yeah, ideally I'd like basically any interval size to be possible. Oh well...
Dec 1, 2021 13:53
It looks like the rejection sampling version also has the probability gap go to 0 but far more slowly
Dec 1, 2021 13:27
Really the one big downside to this is how it's locked into powers of 2. The input image has to be power-of-2-dimensioned, and all the intervals it comes up with are also power-of-2-dimensioned. If those two things were relaxed, I think this would be just about perfect
Dec 1, 2021 13:26
ah nice sim code, I'll try it out, thanks
Dec 1, 2021 13:25
I noticed that setting a larger b, rather than rejection-sampling the too small examples away, leads to almost always giving the smallest possible image size. This seems to have improved slightly with tweaking the k==b case, but still, it feels like the scales are not very diverse.
That said, I'm guessing this might be the nature of the scale free property?
I'm wondering whether rejectionsampling that part instead might also work
Dec 1, 2021 13:20
off by one errors amirite
Dec 1, 2021 13:18
ok so originally it also should have been k == 0 then?
Dec 1, 2021 12:28
yeah what a pain to debug haha
Dec 1, 2021 12:27
thanks!
Dec 1, 2021 12:27
literally had the same issue with alpha before, duh
Dec 1, 2021 12:27
OH dangit, right that makes sense
Dec 1, 2021 12:21
nah, local python script. Rerunning from scratch everytime
Dec 1, 2021 12:21
changed to b and instantly got 0 again
Dec 1, 2021 12:19
might still be the problem currently, testing
Dec 1, 2021 12:18
ah sorry, yes I did, but I changed it back
Dec 1, 2021 12:18
sorry about the indentations, it just flattens itself everytime :-/
Dec 1, 2021 12:16
def sample_interval(k, alpha=0.1228, b=1):
# minimum scale is 2**b
if k == 1:
return (0, 2**(b-1) - 1)

# with prob alpha return the whole interval
if rnd.random() < alpha:
return (0, 2**k - 1)

l0, r0 = sample_interval(k-1, alpha)
# half the times, do not add 2**(k-1)
if rnd.random() < 0.5:
return (l0, r0)

# half the times, do add 2**(k-1)
return (l0 + 2**(k-1), r0 + 2**(k-1))

def sample_rectangle(n, m, alphan=0.1228, alpham=0.1228,device="cuda"):


x1, x2 = sample_interval(n, alphan, 4)
y1, y2 = sample_interval(m, alpham, 4)
Dec 1, 2021 12:10
Ok I must have done something very wrong. Currently I seem to get a random interval of size 1 almost always. (The minimum should be 16)
Guess I'll have to bug hunt
Dec 1, 2021 12:04
(with your previous version I didn't though)
Dec 1, 2021 12:04
hmm, seems to not work. I somehow still get zero sized intervals. I'll have to figure out why that happens
Dec 1, 2021 12:01
How do you get code indentation in chat? The usual stuff seems not to work
Dec 1, 2021 12:01
that makes more sense, thanks
Dec 1, 2021 11:57
I think the way you set up b is a bit off:

if k == b:
return (0, 2**b - 1)

doesn't reduce to

if k = 1
return (0, 0)

when b = 1
Dec 1, 2021 11:51
Yeah might give that a try as well, thanks
Dec 1, 2021 11:46
OK, then I think I'll introduce b for a minimum scale, but I'll stick to rejecting very skewed rectangles for now. If you have any more insight after more analysis, I'll gladly reconsider though :)
Dec 1, 2021 11:46
yeah absolutely not an issue
Dec 1, 2021 11:43
Not entirely sure I like that better than simply rejecting samples though - at least in terms of acceptance rate, it's perfectly fine. No notable impact on time at all
Dec 1, 2021 11:42
it'd certainly be easy enough to at least restore symmetry by randomly picking which one goes first
Dec 1, 2021 11:40
that would also further restrict the minimum size of the sample rectangle, right?
Dec 1, 2021 11:39
The aspect ratio part is different though, as it will rely on two separate samples
Dec 1, 2021 11:38
ok that makes sense. Easy fix
Dec 1, 2021 11:35
So that'd amount to simply setting the first line to k==2 and probably changing what it returns then
Dec 1, 2021 11:35
(plus indentations)
Dec 1, 2021 11:35
So currently it's:

def sample_interval(k, alpha=0.1228):
if k == 1:
return (0, 0)

# with prob alpha return the whole interval
if rnd.random() < alpha:
return (0, 2**k - 1)

l0, r0 = sample_interval(k-1, alpha)
# half the times, do not add 2**(k-1)
if rnd.random() < 0.5:
return (l0, r0)

# half the times, do add 2**(k-1)
return (l0 + 2**(k-1), r0 + 2**(k-1))
Dec 1, 2021 11:31
yeah, in principle that'd be fine, but another function I relied on later down the line ended up generating a singular matrix in such cases and trying to invert it
Dec 1, 2021 11:30
(I'd later change it so the aspect ratio isn't hard-coded in. This was just for testing)
Dec 1, 2021 11:28
Currently I simply do this:
```python
while x1 == x2 or y1 == y2 or 4 * (x2 - x1) < 3 * (y2 - y1) or 4 * (y2 - y1) < 3 * (x2 - x1):
x1, x2 = sample_interval(n)
y1, y2 = sample_interval(m)
```

I also had a problem with zero-size intervals
Dec 1, 2021 11:26
I know I actually asked for this, but it turns out very extreme aspect ratios, as this method tends to give, are, well, too extreme. I have changed the algorithm to simply reject interval pairs if the aspect ratio is too extreme, and try again. Is that a reasonable thing to do or do you think that will distort the other properties? (I still don't want squares, just not as extreme rectangles)
Dec 1, 2021 11:26
Ok, I really like, that there is no overscan at all here. I guess if the AI can see an area $h w$ and my image has area $H W$ I'd likely want $a_s$ to be $\frac{h w}{H W}$ giving me $\alpha = \frac{1}{2 \sqrt{\frac{H W}{hw}} - 1}$ as a solid starting point. I can make do with powers of 2 for $H$ and $W$ for now, so I'll accept this answer. If somebody found a way to generalize this to arbitrary (rational) aspect ratios, I'd probably switch to that answer instead. For now this will work though. thank you!
Dec 1, 2021 11:26
Yeah that $\alpha$ was meant as an initial guess. Hyperparameter search would definitely be a more rigorous way to figure out a good value for it. Thanks :)
Dec 1, 2021 11:26
If I see that right, you are assuming that the minimum coordinate is (1, 1) and the maximum one is (W = 2^w, H = 2^h)? Very minor thing that's gonna vary between languages and such, but most of the time (python included), you'd want to start with (0, 0) and end with (W-1, H-1) - thanks, this looks very promising. I would prefer if the power-of-2 requirement were dropped for a less stringent rational aspect ratio (which is always possible with integer-dimensioned images) Technically I want this to work for floats, but that might be more trouble than it's worth, so your assumption is fine there
 
Aug 25, 2017 15:14
cu later then. Thanks!
Aug 25, 2017 15:14
I'll be there
Aug 25, 2017 15:14
That's fine
Aug 25, 2017 15:09
which certainly is unusual
Aug 25, 2017 15:09
hmm, it's like having a space with a variable number of dimensions
Aug 25, 2017 15:08
Can you write a proper answer or something?
Aug 25, 2017 15:08
Not sure what to do with my question though