Change mean of a set of values I'm trying to solve this problem, but I'm not even sure how to formulate it in a coherent mathematical manner, or even what branch of mathematics this might fall in to.
Basically I have a set of weights, where each weight individually must remain in the range $[0,1]$.  I want to change the mean of the weights to some new mean, also in the $[0,1]$ range, by modifying all the weights slightly (that is, I can't add or remove weights; only modify their values).
Also, ideally, after changing the mean to a new value, if I do the algorithm again, and try to return to the original mean, I'll get the same original weights.  That is, the mapping function can work as its own inverse.  Which I think implies certain things about the distribution of the values of the weights before and after the mapping, but I'm not sure how to describe it in mathematical terms.
Last, the amount of movement of individual weights should be minimized, probably in a least squares sort of way.  That is, I'd prefer to move all the values a slight amount over moving a single value from 0 to 1, for instance.
Does anyone know how I might go about this sort of remapping?  Basically I have four requirements:


*

*After modifying the original weights, the new values stay within $[0,1]$.

*The new mean of the modified weights must be the mean I wanted

*The mapping can be applied again to get back to the original weights.

*The change in weights is minimized in a least squares-esque manner.

 A: I'd use an exponential transform, eg raise each value to the same real power.  I'm not sure it's possible to get a closed form for the power at which to raise to achieve a specific target mean, though.  Iterative approximation should work for this, though, if performance is not too much of a concern.
see https://math.stackexchange.com/questions/498235/is-there-a-closed-form-for-sum-i-1n-a-ix-nk
A: First, put aside all the 0s and 1s, which will stay the same. (If you only have 0s and 1s you'll need to use a different strategy, and you won't be able to do #3.) Put the remaining weights through the logit function. Then find a constant which you can add to all the logit-scale weights such that, after putting them back through the logistic function, you get the desired mean. (I don't have a closed form for this offhand, but Newton-Raphson should work fine.) This should accomplish the first three requirements. It obeys the fourth in that it mostly modifies weights which are around 0.5, while applying less of a change to weights that are nearly 0 or nearly 1.
A: What you describe is a minimization problem under constraints. I will provide a mathematical formalization, and work the problem up to a point.
We have $n$ weights $w_1,...,w_n$, with $w_i \in [0,1], \; i=1,...n$. We want to arrive at new weights $w_i^* = w_i+d_i$, with $ |d_i|\le 1-w_i$. This is a constraint that guarantees that the new weights will range also in $[0,1]$. We want to achieve a specific mean value for the new set of weights, $\frac 1n \sum_{i=1}^nw_i^* = \bar w^* \Rightarrow \sum_{i=1}^n(w_i+d_i) = n\bar w^*$. And we want to determine the new weights under a least-squares criterion. Then we have the minimization problem
$$ \min_{d_1,...,d_n}\sum_{i=1}^nd_i^2 \\
s.t. \qquad \sum_{i=1}^n(w_i+d_i) = n\bar w^* \\
\qquad d_i^2\le (1-w_i)^2 \qquad i=1,...,n
$$
The Lagrangean of the problem is 
$$L =\sum_{i=1}^nd_i^2 - q\left(\sum_{i=1}^n(w_i+d_i) - n\bar w^*\right) -\sum_{i=1}^{n}\mu_i\left(d_i^2- (1-w_i)^2\right) \qquad q\neq 0\;,\; \mu_i\ge 0$$
First-order necessary conditions are
$$\frac {\partial L}{\partial d_i} = 0 \Rightarrow 2d_i - q - 2\mu_id_i  =0 \qquad i=1,...,n$$
$$\Rightarrow 2(1-\mu_i) d_i = q \qquad i=1,...,n$$
From this relation we conclude that all weights must change, because $q\neq 0 \Rightarrow d_i\neq 0\qquad i=1,...,n$.
Moreover we obtain the following relation, since the multiplier $q$ is common in all equations:
$$\frac {d_i}{d_j} = \frac {1-\mu_j}{1-\mu_i}$$
We can draw some conclusions from this relation.  
If the optimal solution dictates that no new weight will be equal to zero or unity, then all $\mu_i$ multipliers will be zero (non-binding) and we will have
$$\frac {d_i}{d_j} = 1 \Rightarrow d_1=...=d_n =d$$
Then, using the constraint we obtain 
$$\sum_{i=1}^n(w_i+d_i) = n\bar w^* \Rightarrow \sum_{i=1}^nw_i+nd = n\bar w^* \Rightarrow d=\bar w^* - \bar w$$
But such a solution will be feasible if either $\bar w^* > \bar w$ and $\forall\; w_i,\; w_i< 1-(\bar w^* - \bar w)$,
or if $\bar w^* < \bar w$ and $\forall\; w_i,\; w_i> \bar w-\bar w^* $.
Only in these two cases the specific solution will lead to all new weights being in $[0,1]$.
If neither of these two cases holds (because, say, some initial weights are either zero or unity, or because you want to make a large change in the value of the average weight), then the solution will necessarily dictate that some new weights will be equal to zero or unity.
By writing and working the problem starting from the new weights, you can derive what conditions should hold so that you can return back to the original set of weights.
