'Creates a new instance of ``cls`` that shares its underlying parameter
values with an existing model instance given by ``existing``.
This is used primarily by compound models to return a view of an
individual component of a compound model.  ``param_names`` should be
the names of the parameters in the *existing* model to use as the
parameters in this new model.  Its length should equal the number of
parameters this model takes, so that it can map parameters on the
existing model to parameters on this model one-to-one.'

@sharedmethod
def _from_existing(self, existing, param_names):

    if isinstance(self, type):
        needs_initialization = True
        dummy_args = ((0,) * len(param_names))
        self = self.__new__(self, *dummy_args)
    else:
        needs_initialization = False
        self = self.copy()
    aliases = dict(zip(self.param_names, param_names))
    constraints = {}
    for cons_type in self.parameter_constraints:
        orig = existing._constraints[cons_type]
        constraints[cons_type] = AliasDict(orig, aliases)
    self._constraints = constraints
    self._n_models = existing._n_models
    self._model_set_axis = existing._model_set_axis
    self._parameters = existing._parameters
    self._param_metrics = defaultdict(dict)
    for (param_a, param_b) in six.iteritems(aliases):
        self._param_metrics[param_a] = existing._param_metrics[param_b]
    if needs_initialization:
        self.__init__(*dummy_args)
    return self
