<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save_to_mat_file(self, parameter_space, result_parsing_function, filename, runs):
 """ Return the results relative to the desired parameter space in the form of a .mat file. Args: parameter_space (dict):
 dictionary containing parameter/list-of-values pairs. result_parsing_function (function):
 user-defined function, taking a result dictionary as argument, that can be used to parse the result files and return a list of values. filename (path):
 name of output .mat file. runs (int):
 number of runs to gather for each parameter combination. """


        # Make sure all values are lists
        for key in parameter_space:
            if not isinstance(parameter_space[key], list):
                parameter_space[key] = [parameter_space[key]]

        # Add a dimension label for each non-singular dimension
        dimension_labels = [{key: str(parameter_space[key])} for key in
                            parameter_space.keys() if len(parameter_space[key])
                            > 1] + [{'runs': range(runs)}]

        # Create a list of the parameter names

        return savemat(
            filename,
            {'results':
             self.get_results_as_numpy_array(parameter_space,
                                             result_parsing_function,
                                             runs=runs),
             'dimension_labels': dimension_labels})