I'm trying to find an algorithm that uniformly samples elements in the following variety:
$A_p=\{(\lambda_1,...,\lambda_n) \in [0,1]^n / \sum \lambda_i = 1, \, \sum \lambda_i^2 = p\}$
I think it can be formalized as finding the Haar measure over $A_p$ (seen as an algebraic group), but I'm not sure exactly how to proceed to come up with the algorithm.
Any idea?
Let $$ B_{n,p}=\{\lambda\mid \textstyle\sum_i \lambda_i=1, \sum_i \lambda_i^2=p\} $$ You can show that $B_{n,p}$ is an $(n-2)$ dimensional sphere with center $(1/n,1/n,\dots,1/n)$ and radius $\sqrt{p-\tfrac1n}$ in the hyperplane defined by $\sum_i \lambda_i=1$. Therefore, to sample uniformly from $B_{n,p}$, it suffices to use this method to sample a point on the unit hypersphere of dimension $(n-2)$, then apply an appropriate affine transformation.
However, you instead want to sample from $$ A_{n,p}=B_{n,p}\cap [0,1]^n $$ You could do this using rejection sampling; sample randomly from $B_{n,p}$, repeating until the point is in $[0,1]^n$. The unfortunate aspect of this is that as $p$ gets closer to its maximum value for which $A_{n,p}$ is nonempty, the probability of a sample lying in the box will go to zero, so the expected number of re-samples will approach infinity. However, this will work well for moderate values of $p$.