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

Method input_raw_data

pyfair/model/model.py:363–417  ·  view source on GitHub ↗

Supply a raw array to the model This function allows for arbitrary data to be placed within the model by passing an array. Parameters ---------- target : str The node to which to send the data array : np.array, list, or pd.Series

(self, target, array)

Source from the content-addressed store, hash-verified

361 return self
362
363 def input_raw_data(self, target, array):
364 """Supply a raw array to the model
365
366 This function allows for arbitrary data to be placed within the
367 model by passing an array.
368
369 Parameters
370 ----------
371 target : str
372 The node to which to send the data
373 array : np.array, list, or pd.Series
374 Raw input data for the model
375
376 Returns
377 -------
378 pyfair.model.FairModel
379 A reference to this object of type FairModel
380
381 Raises
382 ------
383 FairException
384 If an inappropriate number of items are supplied
385
386 Examples
387 --------
388 >>> array = np.array([1,2,3])
389 >>> model = pyfair.FairModel(name="Insider Threat")
390 >>> model.input_raw_data('Loss Magnitude', array)
391
392 .. warning:: raw inputs can drastically increase the size of your
393 stored models. Because this raw data must be recorded
394 and cannot be simulated, it is stored in its entirity
395 within the model's JSON.
396
397 """
398 # Standardize inputs to account for abbreviations
399 target = self._standardize_target(target)
400 # Check types
401 acceptable_types = [list, np.array, pd.Series]
402 if type(array) not in acceptable_types:
403 raise FairException('Inappropriate input type.')
404 # Check length
405 if len(array) != self._n_simulations:
406 message = "Input legnth {}, but simulations count is is {}".format(
407 len(array),
408 self._n_simulations
409 )
410 raise FairException(message)
411 # Generate data via data captive class
412 data = self._data_input.supply_raw(target, array)
413 # Update dependency tracker captive class
414 self._tree.update_status(target, 'Supplied')
415 # Update the model table with the generated data
416 self._model_table[target] = data
417 return self
418
419 def _standardize_target(self, target):
420 """A function to change target abbreviations into full names"""

Callers 2

test_inputsMethod · 0.95
read_jsonMethod · 0.95

Calls 4

_standardize_targetMethod · 0.95
FairExceptionClass · 0.85
supply_rawMethod · 0.80
update_statusMethod · 0.80

Tested by 1

test_inputsMethod · 0.76