From 5388502f42cc19c7b7118c804632fbccd403ca39 Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Mon, 19 Feb 2024 20:19:20 +0100 Subject: [PATCH] updated model output definitions --- src/model_experiential/__init__.py | 25 ++++- src/model_experiential/classes.py | 61 ++++++++++++ src/model_experiential/output.py | 3 +- src/model_interpersonal/__init__.py | 10 +- src/model_interpersonal/classes.py | 149 ++++++++++++++++++++++++++++ src/model_interpersonal/output.py | 4 +- src/model_textual/__init__.py | 6 +- src/model_textual/classes.py | 75 ++++++++++++++ 8 files changed, 326 insertions(+), 7 deletions(-) create mode 100644 src/model_experiential/classes.py create mode 100644 src/model_interpersonal/classes.py create mode 100644 src/model_textual/classes.py diff --git a/src/model_experiential/__init__.py b/src/model_experiential/__init__.py index b0d4f72..9a2791c 100644 --- a/src/model_experiential/__init__.py +++ b/src/model_experiential/__init__.py @@ -1 +1,24 @@ -from .output import model_labels \ No newline at end of file +from .classes import ExperientialModelOutput + + + +# CLASS_NAME_LIST = Literal[ +# "non transactional action", +# "non transactional reaction", +# "unidirectional transactional action", +# "unidirectional transactional reaction", +# "bidirectional transactional action", +# "bidirectional transactional reaction", +# "conversion", +# "speech process", +# "classification overt taxonomy", +# "analytical exhaustive", +# "analytical disarranged", +# "analytical temporal", +# "analytical distributed", +# "anaytical topological", +# "analytical exploded", +# "analytical inclusive", +# "symbolic suggestive", +# "symbolic attributive" +# ] \ No newline at end of file diff --git a/src/model_experiential/classes.py b/src/model_experiential/classes.py new file mode 100644 index 0000000..9d9bdcd --- /dev/null +++ b/src/model_experiential/classes.py @@ -0,0 +1,61 @@ +from __future__ import annotations +from pydantic import BaseModel +from typing import List +import random + + +class ExperientialModelOutput(BaseModel): + non_transactional_action: float + non_transactional_reaction: float + unidirectional_transactional_action: float + unidirectional_transactional_reaction: float + bidirectional_transactional_action: float + bidirectional_transactional_reaction: float + conversion: float + speech_process: float + classification_overt_taxonomy: float + analytical_exhaustive: float + analytical_disarranged: float + analytical_temporal: float + analytical_distributed: float + analytical_topological: float + analytical_exploded: float + analytical_inclusive: float + symbolic_suggestive: float + symbolic_attributive: float + + @classmethod + def list_fields(cls) -> List[str]: + """List options that are stored as attributes.""" + return list(cls.model_fields.keys()) + + @classmethod + def from_random(cls) -> ExperientialModelOutput: + """Instantiate with random numbers.""" + kwargs = {field: random.random() for field in cls.list_fields()} + return ExperientialModelOutput(**kwargs) + + def __repr__(self) -> str: + model_dict = self.model_dump() + model_repr_str = "ExperientialModelOutput(" + model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) + model_repr_str += ")" + return model_repr_str + + def highest_score_field(self) -> str: + """Return name of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict, key=lambda k: model_dict[k]) + + def highest_score_value(self) -> float: + """Return value of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict.values()) + + +if __name__ == '__main__': + m = ExperientialModelOutput.from_random() + print(m) + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) diff --git a/src/model_experiential/output.py b/src/model_experiential/output.py index bddaf06..188234f 100644 --- a/src/model_experiential/output.py +++ b/src/model_experiential/output.py @@ -1,5 +1,4 @@ - -model_labels = [ +CLASS_NAMES = [ "non transactional action", "non transactional reaction", "unidirectional transactional action", diff --git a/src/model_interpersonal/__init__.py b/src/model_interpersonal/__init__.py index b0d4f72..74211a9 100644 --- a/src/model_interpersonal/__init__.py +++ b/src/model_interpersonal/__init__.py @@ -1 +1,9 @@ -from .output import model_labels \ No newline at end of file +from .classes import ( + ContactModelOutput, + AngleModelOutput, + PointOfViewModelOutput, + DistanceModelOutput, + ModalityLightingModelOutput, + ModalityColorModelOutput, + ModalityDepthModelOutput +) \ No newline at end of file diff --git a/src/model_interpersonal/classes.py b/src/model_interpersonal/classes.py new file mode 100644 index 0000000..60c16ad --- /dev/null +++ b/src/model_interpersonal/classes.py @@ -0,0 +1,149 @@ +from pydantic import BaseModel +from typing import List, Dict +import random + + +class ModelOutput(BaseModel): + + @classmethod + def classname(cls) -> str: + """Return classname.""" + return cls.__name__ + + @classmethod + def list_fields(cls) -> List[str]: + """List options that are stored as attributes.""" + return list(cls.model_fields.keys()) + + @classmethod + def from_random(cls): + """Instantiate with random numbers.""" + kwargs = {field: random.random() for field in cls.list_fields()} + return cls(**kwargs) + + def __repr__(self) -> str: + model_dict = self.model_dump() + model_repr_str = f"{self.classname()}(" + model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) + model_repr_str += ")" + return model_repr_str + + def highest_score_field(self) -> str: + """Return name of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict, key=lambda k: model_dict[k]) + + def highest_score_value(self) -> float: + """Return value of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict.values()) + + +class ContactModelOutput(ModelOutput): + offer: float + demand: float + + +class AngleModelOutput(ModelOutput): + high: float + eye_level: float + low: float + + +class PointOfViewModelOutput(ModelOutput): + frontal: float + oblique: float + + +class DistanceModelOutput(ModelOutput): + long: float + medium: float + close: float + + +class ModalityLightingModelOutput(ModelOutput): + high: float + medium: float + low: float + + +class ModalityColorModelOutput(ModelOutput): + high: float + medium: float + low: float + + +class ModalityDepthModelOutput(ModelOutput): + high: float + medium: float + low: float + + +# class InterpersonalModelOutput(BaseModel): +# contact: ContactModelOutput +# angle: AngleModelOutput +# point_of_view: PointOfViewModelOutput +# distance: DistanceModelOutput +# modality_lighting: ModalityLightingModelOutput +# modality_color: ModalityColorModelOutput +# modality_depth: ModalityDepthModelOutput + +# @classmethod +# def list_fields(cls) -> List[str]: +# """List options that are stored as attributes.""" +# return list(cls.model_fields.keys()) + +# @classmethod +# def from_random(cls) -> InterpersonalModelOutput: +# """Instantiate with random numbers.""" +# print(cls.model_fields) +# kwargs = {field: info.annotation.from_random() for field, info in cls.model_fields.items()} +# return InterpersonalModelOutput(**kwargs) + +# def __repr__(self) -> str: +# model_dict = self.model_dump() +# model_repr_str = "ExperientialModelOutput(" +# model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) +# model_repr_str += ")" +# return model_repr_str + +# def highest_score_field(self) -> str: +# """Return name of field with highest score.""" +# model_dict = self.model_dump() +# return max(model_dict, key=lambda k: model_dict[k]) + +# def highest_score_value(self) -> float: +# """Return value of field with highest score.""" +# model_dict = self.model_dump() +# return max(model_dict.values()) + + +if __name__ == '__main__': + m = ContactModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = AngleModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = PointOfViewModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = DistanceModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = ModalityLightingModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = ModalityColorModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = ModalityDepthModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) diff --git a/src/model_interpersonal/output.py b/src/model_interpersonal/output.py index a95e916..14c84a9 100644 --- a/src/model_interpersonal/output.py +++ b/src/model_interpersonal/output.py @@ -1,8 +1,8 @@ model_labels = { "contact": [ - "contact offer", - "contact demand" + "offer", + "demand" ], "angle": [ "high", diff --git a/src/model_textual/__init__.py b/src/model_textual/__init__.py index b0d4f72..9e7b87c 100644 --- a/src/model_textual/__init__.py +++ b/src/model_textual/__init__.py @@ -1 +1,5 @@ -from .output import model_labels \ No newline at end of file +from .classes import ( + InformationValueModelOutput, + FramingModelOutput, + SalienceModelOutput +) \ No newline at end of file diff --git a/src/model_textual/classes.py b/src/model_textual/classes.py new file mode 100644 index 0000000..8b135f5 --- /dev/null +++ b/src/model_textual/classes.py @@ -0,0 +1,75 @@ +from pydantic import BaseModel +from typing import List, Dict +import random + + +class ModelOutput(BaseModel): + + @classmethod + def classname(cls) -> str: + """Return classname.""" + return cls.__name__ + + @classmethod + def list_fields(cls) -> List[str]: + """List options that are stored as attributes.""" + return list(cls.model_fields.keys()) + + @classmethod + def from_random(cls): + """Instantiate with random numbers.""" + kwargs = {field: random.random() for field in cls.list_fields()} + return cls(**kwargs) + + def __repr__(self) -> str: + model_dict = self.model_dump() + model_repr_str = f"{self.classname()}(" + model_repr_str += ", ".join([f"{field}={value:.3f}" for field, value in model_dict.items()]) + model_repr_str += ")" + return model_repr_str + + def highest_score_field(self) -> str: + """Return name of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict, key=lambda k: model_dict[k]) + + def highest_score_value(self) -> float: + """Return value of field with highest score.""" + model_dict = self.model_dump() + return max(model_dict.values()) + + +class InformationValueModelOutput(ModelOutput): + given_new: float + ideal_real: float + central_marginal: float + + +class FramingModelOutput(ModelOutput): + frame_lines: float + empty_space: float + colour_contrast: float + form_contrast: float + + +class SalienceModelOutput(ModelOutput): + size: float + colour: float + tone: float + form: float + positioning: float + + +if __name__ == '__main__': + m = InformationValueModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = FramingModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) + m = SalienceModelOutput.from_random() + print(repr(m)) + print(m.highest_score_field()) + print(m.highest_score_value()) \ No newline at end of file