test-check

nwjsmith 2018-04-14T17:52:19.000091Z

I think I've asked this before, but I'm writing some (non-shrinking) generators that rely on generating uniformly random numbers. Is there any way to get a uniformly random number generated?

nwjsmith 2018-04-14T17:52:54.000051Z

Are any of the provided generators uniformly random? (i.e. gen/bytes?)

nwjsmith 2018-04-14T17:53:11.000024Z

If so, I might be able to fmap my way into a random number

nwjsmith 2018-04-14T17:58:35.000107Z

Err, never mind. I might not want a uniform random number here

2018-04-14T18:01:11.000051Z

In any case, gen/choose is such a thing, for smaller ranges

2018-04-14T18:01:26.000102Z

I've thought about adding something more robust for integers and doubles

nwjsmith 2018-04-14T18:06:14.000001Z

FWIW I'm generating a probability between 0.0 and 1.0, a double.

2018-04-14T18:08:28.000056Z

But not uniform?

nwjsmith 2018-04-14T18:10:55.000122Z

I don't think it needs to be. It's a generator for a graph's adjacency matrix. It is the probability that one vertex is adjacent to another.

nwjsmith 2018-04-14T18:11:20.000091Z

So an argument could be made that the most simple graph is the fully disconnected one

nwjsmith 2018-04-14T18:11:32.000099Z

(i.e. the probabilities are all 0.0

2018-04-14T18:11:34.000033Z

Yeah that makes sense

2018-04-14T18:11:58.000074Z

I wonder what gen/double does in that range

2018-04-14T18:12:14.000088Z

It might bias toward 1 at first

2018-04-14T18:12:54.000048Z

If so you can fmap with #(- 1 %) to get the opposite

nwjsmith 2018-04-14T18:14:42.000111Z

Yeah, with a sample of 1000 I get 101 occurrences of 1.0 and 19 occurrences of 0.0.

2018-04-14T18:15:30.000054Z

That might be misleading

2018-04-14T18:15:57.000146Z

fmap to #(long (* 10 %)) and see what you get

2018-04-14T18:16:24.000070Z

It probably considers 0 and 1 simpler than everything in between

nwjsmith 2018-04-14T18:16:59.000092Z

{1 39, 0 698}

2018-04-14T18:17:49.000060Z

Nothing from 2 to 10?

nwjsmith 2018-04-14T18:18:14.000069Z

{0 700, 7 25, 1 39, 4 23, 6 14, 3 26, 2 31, 9 6, 5 36, 10 87, 8 13}

nwjsmith 2018-04-14T18:18:26.000114Z

Are the full frequencies

2018-04-14T18:19:33.000119Z

So mostly 0, because that's simpler, and next is 1.0, then 0.5, ...

nwjsmith 2018-04-14T18:20:41.000081Z

Looks like gen/double* will do just fine

2018-04-14T18:27:44.000136Z

Are you actually trying to generate probabilities, or trying to generate the graph itself?

nwjsmith 2018-04-14T19:48:10.000034Z

Generate the graph itself. I generate an adjacency matrix like this:

[[0.0 0.0 0.0 0.0]
 [P.1 0.0 0.0 0.0]
 [P.2 P.3 0.0 0.0]
 [P.4 P.5 P.6 0.0]]

nwjsmith 2018-04-14T19:49:18.000066Z

Where P1-`P6` are probabilities. This adjacency matrix ends up representing a random DAG.

nwjsmith 2018-04-14T19:50:30.000076Z

I map this probability matrix into a matrix where the values can be true/`false` based on whether or not the probability is above 0.5

nwjsmith 2018-04-14T19:53:19.000001Z

I have another generator that takes a DAG and generates a random topological ordering from it. It's also based on random number generation using gen/choose, but the range is small enough that it should be uniform.

nwjsmith 2018-04-14T19:57:42.000024Z

Both are looking good:

(let [g (gen/generate (gen-directed-acyclic-graph (seq "ABCD")))
       t (frequencies (gen/sample (gen-topological-ordering g) 1000))]
   (when (not-empty g)
     (println t)
     (<http://loom.io/view|loom.io/view> (loom.graph/digraph g))))
Produced: https://www.dropbox.com/s/q0rkqfy7z0vffs6/png223331814782198197.png?dl=0 and the topological orderings:
{[C B D A] 122,
 [D B A C] 117,
 [B D A C] 115,
 [D B C A] 127,
 [B D C A] 135,
 [C D B A] 132,
 [D C B A] 137,
 [B C D A] 115}

2018-04-14T19:59:53.000084Z

Cool