Ejemplo n.º 1
0
 def find_sub_dictionaries(self, super_id):
     """ Finds a subdictionary by superid inside of the database. """
     # Should use the find within function for every subkey
     mega_dict = ADict()
     for key, sub in self.subs.items():
         key_dict = ADict()
         try:
             res = sub.client.search(f'"{super_id}"')
             if res.total == 0:
                 continue
             dd = [dictify(doc, False) for doc in res.docs]
             key_dict[key] = dd[0]
         except ResponseError:
             pass
         mega_dict.update(key_dict)
     return mega_dict
Ejemplo n.º 2
0
    def pick(self, _id: str):
        """ 
            Given an id find the element with the top level id. We aren't searching lower level_ids. 
            
            After we pull all of the 
        """
        self.set_entity()
        self.keystore.reset()
        doc = self.client.load_document(_id)
        dd = doc.__dict__
        doc = ADict(**dd)
        _id = doc.pop("id", None)
        doc.pop("payload", None)
        doc_z = len(doc) > 0
        if len(self.subs) == 0:
            if not doc_z:
                return None
            doc.update({"id": _id})
            return doc

        if doc_z:
            sub_dicts = self.find_sub_dictionaries(_id)
            # if len(sub_dicts) > 0:
            doc.update(sub_dicts)
            doc.update({"id": _id})
            return doc

        return None
Ejemplo n.º 3
0
class ModelProcedureAbstract(ProcedureAbstract):
    # _dict = None
    def __init__(self):
        self._mod = None
        self._opt = None
        self._crit = None

        self._model_dict = ADict()
        self._model_dict.model = None
        self._model_dict.optimizer = None
        self._model_dict.criteria = None

        self._model_typing = ADict()
        self._model_typing.model = None
        self._model_typing.optimizer = None
        self._model_typing.criteria = None

        self._model_requirements = ADict()
        self._model_requirements.model = True
        self._model_requirements.optimizer = False
        self._model_requirements.criteria = False

        self.changed = False
        self.named_metric_set = NamedModelMetricSet()

    @property
    def dictionary(self):
        """ A dictionary with all of the model information contained inside. """
        return self._model_dict

    @dictionary.setter
    def dictionary(self, _md: ADict):
        """ Load in raw model dict information """
        self._model_dict.update(_md)
        # self.verify()

    @property
    def requirements(self) -> ADict:
        """ Return a dictionary of requirements for the ... checking requirements"""
        return self._model_requirements

    @requirements.setter
    def requirements(self, _md: ADict):
        """ Load in raw model dict information """
        self._model_requirements.update(_md)

    @property
    def types(self) -> ADict:
        return self._model_typing

    @types.setter
    def types(self, _mt: ADict):
        self._model_typing.update(_mt)

    """
        Verification
    """

    def verify_model_typing(self):
        """Check that none of the model types are none """
        for k, v in self.requirements.items():
            if not isinstance(v, bool):
                raise ValueError(
                    f"Model Requirement \'{k}\' must be a boolean value")
            if v == True:
                if self.types[k] is None:
                    raise ValueError(
                        f"\'{k}\' Cannot be None in typing delarations")
                if self.dictionary[k] is None:
                    raise ValueError(
                        f"\'{k}\' Cannot be None inside of the main model dictionary"
                    )

    def verify_model_dict(self):
        """ Verify that """
        for name, _type in self.types.items():
            if name is None or _type is None:
                continue
            current_item = self.dictionary[name]
            if not isinstance(current_item, _type) and not issubclass(
                    current_item, _type):
                raise TypeError(f"{name} is not an instance of {_type}")

    def verify(self):
        self.verify_model_typing()
        self.verify_model_dict()

    def is_valid_data(self, _data) -> bool:
        """ Determines if the data we're about to use is valid"""
        raise NotImplementedError("Data validation not implemented yet")

    def split(self, X, y, **params):
        raise NotImplementedError

    def fit(self, X, y, **params):
        raise NotImplementedError

    def partial_fit(self, X, y, **params):
        raise NotImplementedError

    def predict(self, X, **params):
        raise NotImplementedError

    def predict_proba(self, X, **params):
        raise NotImplementedError

    def score(self, X, y, **params):
        raise NotImplementedError

    def get_params(self, **params):
        raise NotImplementedError

    def set_params(self, **params):
        raise NotImplementedError

    def extract(self):
        """ Get a dictionary to save the model. Should be called in close """
        return self.dictionary

    @property
    def metrics(self):
        """ Given the information we have, return a set of metrics"""
        metric_set = self.named_metric_set.metrics(0, 0)
        return metric_set