A main class to act as an API for FAIR Model construction. A single instance of this class is created for each FAIR model. It contains a dependency resolution tree (self._tree), a calculation member (self._calculation), and an input parser (self._input). Calculations are strucutre
| 13 | |
| 14 | |
| 15 | class FairModel(object): |
| 16 | """A main class to act as an API for FAIR Model construction. |
| 17 | |
| 18 | A single instance of this class is created for each FAIR model. It |
| 19 | contains a dependency resolution tree (self._tree), a calculation |
| 20 | member (self._calculation), and an input parser (self._input). |
| 21 | |
| 22 | Calculations are strucutred as a series of connected nodes, with |
| 23 | one node for each of the potential FAIR inputs. A user interacts |
| 24 | with this class by loading data via JSON or by inputting data |
| 25 | for the individual nodes. The user then triggers the |
| 26 | calculate_all() method to run all the subcalculations necessary |
| 27 | to complete the FAIR model. |
| 28 | |
| 29 | Parameters |
| 30 | ---------- |
| 31 | name : str |
| 32 | A human-readable designation for identification |
| 33 | n_simulations : int, optional |
| 34 | Number of simulations created (default is 10,000) |
| 35 | random_seed : int, optional |
| 36 | Random seed for number generation (default is 42) |
| 37 | model_uuid : str, optional |
| 38 | uuid.uuid4 string (default is None, meaning one will be assigned) |
| 39 | creation_date : str, optional |
| 40 | Creation date (default is None, meaning one will be assigned) |
| 41 | |
| 42 | Examples |
| 43 | -------- |
| 44 | >>> model = pyfair.model.FairModel(name='Data Loss') |
| 45 | >>> model.input_data('Loss Magnitude', mean=20, stdev=10) |
| 46 | >>> model.input_data('Loss Event Frequency', constant=5) |
| 47 | >>> model.calculate_all() |
| 48 | >>> model.export_results() |
| 49 | |
| 50 | .. warning:: Do not supply your own UUID/creation date unless |
| 51 | you want to break things. |
| 52 | |
| 53 | """ |
| 54 | |
| 55 | ########################################################################## |
| 56 | # Creation Methods |
| 57 | ########################################################################## |
| 58 | |
| 59 | def __init__(self, |
| 60 | name, |
| 61 | n_simulations=10_000, |
| 62 | random_seed=42, |
| 63 | model_uuid=None, |
| 64 | creation_date=None): |
| 65 | # Set n_simulations and random seed for reproducablility |
| 66 | self._name = name |
| 67 | self._n_simulations = n_simulations |
| 68 | # Do not change the random_seed unless you have a good reason. |
| 69 | self._random_seed = random_seed |
| 70 | np.random.seed(random_seed) |
| 71 | # Instantiate components |
| 72 | self._model_table = pd.DataFrame(columns=[ |
no outgoing calls