MCPcopy Create free account
hub / github.com/Derive-Risk/pyfair / FairMetaModel

Class FairMetaModel

pyfair/model/meta_model.py:14–263  ·  view source on GitHub ↗

A class for aggregating FAIR models. An instance of this class is created by taking multiple FAIR models and rolling the total risk into a collection, or MetaModel. A user creates a metamodel from inputs, calls calculate_all() to perform the requisite calculations, and then uses the

Source from the content-addressed store, hash-verified

12
13
14class FairMetaModel(object):
15 """A class for aggregating FAIR models.
16
17 An instance of this class is created by taking multiple FAIR models and
18 rolling the total risk into a collection, or MetaModel. A user creates
19 a metamodel from inputs, calls calculate_all() to perform the requisite
20 calculations, and then uses the metamodel for reporting.
21
22 Parameters
23 ----------
24 name : str
25 A human-readable designation for identification
26 models : list of FairModels
27 The sub-models that roll up into the aggregate MetaModel risk
28 calculation.
29 model_uuid : str, optional
30 uuid.uuid4 string (default is None, meaning one will be assigned)
31 creation_date : str, optional
32 Creation date (default is None, meaning one will be assigned)
33
34 Examples
35 --------
36 >>> m1 = pyfair.model.FairModel.from_json('model_1.json')
37 >>> m2 = pyfair.model.FairModel.from_json('model_2.json')
38 >>> meta1 = pyfair.model.FairMetaModel('Name', [m1, m2])
39 >>> meta1.calculate_all()
40 >>> meta1.export_results()
41
42 .. warning:: Do not supply your own UUID/creation date unless you
43 want to break things.
44
45 """
46 def __init__(self, name, models, model_uuid=None, creation_date=None):
47 self._name = name
48 self._params = {}
49 self._risk_table = pd.DataFrame()
50 # For every model, flatten and save params.
51 for model in models:
52 # If model, load
53 if type(model) == FairModel:
54 self._load_model(model)
55 # If metamodel, load components.
56 elif type(model) == type(self):
57 self._load_meta_model(model)
58 else:
59 err = f'Input {model} is not a FairModel or FairMetaModel.'
60 raise FairException(err)
61 # Assign UUID
62 if model_uuid and creation_date:
63 self._model_uuid = model_uuid
64 self._creation_date = creation_date
65 else:
66 self._model_uuid = str(uuid.uuid1())
67 self._creation_date = str(datetime.datetime.now())
68
69 def get_name(self):
70 """Returns the model name.
71

Callers 9

test_creationMethod · 0.90
test_calculationMethod · 0.90
test_good_inputsMethod · 0.90
setUpMethod · 0.90
test_input_checkMethod · 0.90
test_generate_imageMethod · 0.90
read_jsonMethod · 0.85

Calls

no outgoing calls

Tested by 8

test_creationMethod · 0.72
test_calculationMethod · 0.72
test_good_inputsMethod · 0.72
setUpMethod · 0.72
test_input_checkMethod · 0.72
test_generate_imageMethod · 0.72