skcriteria.io.dmsy module
DMSY (Decision Matrix Simple YAML) format support.
This module provides functions to read and write DecisionMatrix objects in DMSY format, a simple YAML-based format designed for easy human readability and editing of multi-criteria decision analysis data.
The DMSY format generates YAML files optimized for human readability through intelligent use of flow and block styles. One-dimensional arrays are represented in compact flow style (e.g., [1, 2, 3]), while multi-dimensional structures use block style for the outer dimension with flow style for inner dimensions (e.g., - [1, 2, 3] on separate lines). This combination allows complex decision matrices to maintain a clear and navigable structure, facilitating both manual inspection and direct file editing, without sacrificing compactness when appropriate.
- skcriteria.io.dmsy.DEFAULT_DM_TYPE = 'discrete-dm'
Default decision matrix type for DMSY format. Currently only supports discrete multi-criteria decision matrices.
- skcriteria.io.dmsy.DEFAULT_DMSY_VERSION = 1
Default DMSY format version number. Version 1 is the current stable format specification.
- class skcriteria.io.dmsy.CustomYAMLDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]
Bases:
SafeDumperCustom YAML Dumper that handles numpy arrays and uses flow style for lists.
This dumper automatically converts numpy arrays to Python lists and formats all lists using flow style (e.g., [1, 2, 3] instead of block style).
- yaml_multi_representers = {<class 'numpy.generic'>: <function _numpy_scalar_representer>}
- yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'frozenset'>: <function _iterable_not_ndarray_representer>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function _iterable_not_ndarray_representer>, <class 'numpy.ndarray'>: <function _numpy_array_representer>, <class 'set'>: <function _iterable_not_ndarray_representer>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'tuple'>: <function _iterable_not_ndarray_representer>, None: <function SafeRepresenter.represent_undefined>}
- class skcriteria.io.dmsy.DMSYDiscreteHandlerV1[source]
Bases:
objectHandler for discrete decision matrices in DMSY format version 1.
- Parameters:
- dm_type = 'discrete-dm'
- version = 1
- to_dm(dm_data)[source]
Convert DMSY data to DecisionMatrix object.
- Parameters:
dm_data (dict) – Dictionary containing the decision matrix data from DMSY format.
- Returns:
The constructed DecisionMatrix object.
- Return type:
- to_yml(dm)[source]
Convert DecisionMatrix object to DMSY-compatible data.
- Parameters:
dm (DecisionMatrix) – The DecisionMatrix object to convert.
- Returns:
Dictionary containing the data in DMSY format.
- Return type:
- skcriteria.io.dmsy.read_dmsy(filepath_or_buffer)[source]
Load a DecisionMatrix from a DMSY format file or buffer.
- Parameters:
filepath_or_buffer (str or file-like object) – Path to the DMSY file or a file-like object containing DMSY data.
- Returns:
The loaded DecisionMatrix object.
- Return type:
Examples
>>> import skcriteria as skc >>> dm = skc.io.read_dmsy("dataset.dmsy")
- skcriteria.io.dmsy.to_dmsy(dm, filepath_or_buffer)[source]
Save a DecisionMatrix to a DMSY format file or buffer.
- Parameters:
dm (DecisionMatrix) – The DecisionMatrix object to save.
filepath_or_buffer (str or file-like object) – Path where to save the DMSY file or a file-like object to write to.
Examples
>>> import skcriteria as skc >>> dm = skc.mkdm([[1, 2], [3, 4]], [max, min]) >>> skc.io.to_dmsy(dm, "output.dmsy")