class AutoCreatedDMRICompositeModel(method_binding_meta(template, DMRICompositeModel)): def __init__(self, *args): super(AutoCreatedDMRICompositeModel, self).__init__( deepcopy(template.name), CompartmentModelTree(parse(template.model_expression)), deepcopy(template.evaluation_model), signal_noise_model=deepcopy(template.signal_noise_model), add_default_weights_dependency=template.add_default_weights_dependency) self.add_parameter_dependencies(_resolve_dependencies(deepcopy(template.dependencies))) self.add_post_optimization_modifiers(deepcopy(template.post_optimization_modifiers)) for full_param_name, value in template.inits.items(): self.init(full_param_name, deepcopy(value)) for full_param_name, value in template.fixes.items(): self.fix(full_param_name, deepcopy(value)) for full_param_name, value in template.lower_bounds.items(): self.set_lower_bound(full_param_name, deepcopy(value)) for full_param_name, value in template.upper_bounds.items(): self.set_upper_bound(full_param_name, deepcopy(value)) for full_param_name, value in template.parameter_transforms.items(): if hasattr(value, '__call__'): self.set_parameter_transform(full_param_name, value(self)) else: self.set_parameter_transform(full_param_name, deepcopy(value)) def _get_suitable_volume_indices(self, problem_data): volume_selection = template.volume_selection if not volume_selection: return super(AutoCreatedDMRICompositeModel, self)._get_suitable_volume_indices(problem_data) use_unweighted = volume_selection.get('use_unweighted', True) use_weighted = volume_selection.get('use_weighted', True) unweighted_threshold = volume_selection.get('unweighted_threshold', 25e6) protocol = problem_data.protocol if protocol.has_column('g') and protocol.has_column('b'): if use_weighted: if 'min_bval' in volume_selection and 'max_bval' in volume_selection: protocol_indices = protocol.get_indices_bval_in_range(start=volume_selection['min_bval'], end=volume_selection['max_bval']) else: protocol_indices = protocol.get_weighted_indices(unweighted_threshold) else: protocol_indices = [] if use_unweighted: protocol_indices = list(protocol_indices) + \ list(protocol.get_unweighted_indices(unweighted_threshold)) else: return list(range(protocol.length)) return np.unique(protocol_indices)
class AutoFreeParameter( method_binding_meta(template, FreeParameter)): def __init__(self): super(AutoFreeParameter, self).__init__( data_type, template.name, template.fixed, template.init_value, template.lower_bound, template.upper_bound, parameter_transform=template.parameter_transform, sampling_proposal=template.sampling_proposal, sampling_prior=template.sampling_prior, sampling_statistics=template.sampling_statistics)
class AutoCreatedDMRICompartmentModel( method_binding_meta(template, CompartmentBuildingBase)): def __init__(self, *args): new_args = [ template.name, template.cl_function_name, _get_parameters_list(template.parameter_list), template.cl_header, template.cl_code, _resolve_dependencies(template.dependency_list) ] for ind, already_set_arg in enumerate(args): new_args[ind] = already_set_arg super(AutoCreatedDMRICompartmentModel, self).__init__(*new_args) if hasattr(template, 'init'): template.init(self)
class AutoCreatedCascadeModel( method_binding_meta(template, SimpleCascadeModel)): def __init__(self, *args): new_args = [ deepcopy(template.name), list(map(mdt.get_model, template.models)) ] for ind, arg in args: new_args[ind] = arg super(AutoCreatedCascadeModel, self).__init__(*new_args) def _prepare_model(self, model, output_previous, output_all_previous): super(AutoCreatedCascadeModel, self)._prepare_model(model, output_previous, output_all_previous) def parse_value(v): if isinstance(v, six.string_types): return output_previous[v] elif hasattr(v, '__call__'): return v(output_previous, output_all_previous) return v for item in template.inits.get(model.name, {}): model.init(item[0], parse_value(item[1])) for item in template.fixes.get(model.name, {}): model.fix(item[0], parse_value(item[1])) for item in template.lower_bounds.get(model.name, {}): model.set_lower_bound(item[0], parse_value(item[1])) for item in template.upper_bounds.get(model.name, {}): model.set_upper_bound(item[0], parse_value(item[1])) self._prepare_model_cb(model, output_previous, output_all_previous)
class AutoStaticMapParameter( method_binding_meta(template, StaticMapParameter)): def __init__(self): super(AutoStaticMapParameter, self).__init__(data_type, template.name, template.value)
class AutoModelDataParameter( method_binding_meta(template, ModelDataParameter)): def __init__(self): super(AutoModelDataParameter, self).__init__(data_type, template.name, template.value)
class AutoProtocolParameter( method_binding_meta(template, ProtocolParameter)): def __init__(self): super(AutoProtocolParameter, self).__init__(data_type, template.name)