# How to create a constrained spline meta model in R?

Background

I have an outcome measure I'm trying to predict that is on a scale 0-1000. I've trained (say) M different models (model definition doesn't matter) on overlapping sub-ranges of the data (e.g. 0-200, 175-325, 275-525, ...), as well as one (much simpler) master model on the whole range of the training data. I want to create a meta-model that takes a weighted average of the M sub-range models' predictions and uses that as the overall/final predicted value. I'd like the model trained on the mth subrange to dominate predictions close to the centre of the mth subrange, but to use more of a mixture of the m-1th or m+1th model towards the boundaries of the mth subrange, as the subranges are arbitrarily chosen.

So, I want to create M weighting functions that:

1. Vary over the range 0-1000 (with respect to the master model's predictions)
2. Are smooth but not necessarily symmetrical over the range (loosely, in a spline-ish sort of way. Ideally I'd use some sort of constrained B/natural-spline)
3. Have at most one maximum point per weighting function (non-negative second derivative with respect to master model's predictions)
4. Sum to 1 (across the M weighting functions) for all points in the range 0-1000
5. Have parameters 'learned' so that they minimize the sum squared error of the meta model

I'm working in R.

How do I do this? If it weren't for requirements 2,3,4 I could do this an optimization problem...

Thanks!