Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 44 additions & 48 deletions docs/calculation_details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Multiply the Loss Event Frequency vector by the Loss Magnitude vector
Example
~~~~~~~
For a given year, if we have the number of times a particular event
occurs (Loss Event Frequency/LEF) and the dollar losses associated with
each of those events (Loss Magnitude/LM), we can multiply these
occurs (Loss Event Frequency/LEF) and the dollar losses associated with
each of those events (Loss Magnitude/LM), we can multiply these
together to derive the ultimate dollar value amount lost (Risk/R).

+------------+-----+--------+--------------+
Expand All @@ -64,7 +64,7 @@ together to derive the ultimate dollar value amount lost (Risk/R).

Description
~~~~~~~~~~~
A vector of elements which represent the number of times a particular
A vector of elements which represent the number of times a particular
loss occurs during a given time frame (generally one year)

Restrictions
Expand Down Expand Up @@ -119,7 +119,7 @@ multiply these together to derive the number of losses that will occur

.. note::

Though intended to represent a discrete number of events, TEF and
Though intended to represent a discrete number of events, TEF and
LEF are not rounded to the nearest integer. This allows for
the modeling of events that happen infrequently. For instance, if
we are running a simulation for a single year, one might model a
Expand All @@ -130,7 +130,7 @@ multiply these together to derive the number of losses that will occur

Description
~~~~~~~~~~~
A vector of elements representing the number of times a particular
A vector of elements representing the number of times a particular
threat occurs, whether or not it results in a loss

Restrictions
Expand All @@ -139,7 +139,7 @@ All elements must be positive

Derivation
~~~~~~~~~~
Supplied directly, or multiply the Contact Frequency vector and the
Supplied directly, or multiply the Contact Frequency vector and the
Probability of Action vector

.. math::
Expand Down Expand Up @@ -312,8 +312,8 @@ a control (Vulnerability/V).

Description
~~~~~~~~~~~
A vector with elements representing the number of threat
actor contacts that could potentially yield a threat within a given
A vector with elements representing the number of threat
actor contacts that could potentially yield a threat within a given
timeframe

Restrictions
Expand All @@ -332,7 +332,7 @@ attack, and in turn can potentially yield a loss (Contact Frequency/C).
+------------+-----------+
| Simulation | C |
+============+===========+
| 1 | 5,000,000 |
| 1 | 5,000,000 |
+------------+-----------+
| 2 | 3,000,000 |
+------------+-----------+
Expand All @@ -345,7 +345,7 @@ attack, and in turn can potentially yield a loss (Contact Frequency/C).
Description
~~~~~~~~~~~
A vector with elements representing the probability that a threat actor
will proceed after coming into contact with an organization
will proceed after coming into contact with an organization

Restrictions
------------
Expand All @@ -363,7 +363,7 @@ resource (Probability of Action/P)
+------------+------+
| Simulation | P |
+============+======+
| 1 | 0.95 |
| 1 | 0.95 |
+------------+------+
| 2 | 0.90 |
+------------+------+
Expand All @@ -375,7 +375,7 @@ resource (Probability of Action/P)

Description
~~~~~~~~~~~
A vector of unitless elements that describe the relative
A vector of unitless elements that describe the relative
level of expertise and resources of a threat actor (relative to a
Control Strength)

Expand All @@ -395,7 +395,7 @@ relates to the relative strength of the controls (Control Strength/CS)
+------------+------+
| Simulation | TC |
+============+======+
| 1 | 0.75 |
| 1 | 0.75 |
+------------+------+
| 2 | 0.60 |
+------------+------+
Expand All @@ -407,7 +407,7 @@ relates to the relative strength of the controls (Control Strength/CS)

Description
~~~~~~~~~~~
A vector of unitless elements that describe the relative strength of a
A vector of unitless elements that describe the relative strength of a
given control (relative to the Threat Capability of a given actor)

Restrictions
Expand All @@ -427,7 +427,7 @@ Capability/TC)
+------------+------+
| Simulation | TC |
+============+======+
| 1 | 0.15 |
| 1 | 0.15 |
+------------+------+
| 2 | 0.10 |
+------------+------+
Expand Down Expand Up @@ -514,7 +514,7 @@ Loss/PL)
+------------+------------+
| Simulation | PL |
+============+============+
| 1 | $5,000,000 |
| 1 | $5,000,000 |
+------------+------------+
| 2 | $3,500,000 |
+------------+------------+
Expand All @@ -540,43 +540,39 @@ multiplied together on an elementwise basis.

.. math::

\begin{bmatrix}
\text{SL}_{1} \\
\text{SL}_{1} \\
\vdots \\
\text{SL}_{1} \\
\end{bmatrix}
\quad
=
\quad
\sum\limits^n_{j=1}
\quad
\left(
\quad
\begin{bmatrix}
\text{SLEF}_{1,1} & \text{SLEF}_{1,2} & \dots & \text{SLEF}_{1,n} \\
\text{SLEF}_{2,1} & \text{SLEF}_{2,2} & \dots & \text{SLEF}_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
\text{SLEF}_{m,1} & \text{SLEF}_{m,2} & \dots & \text{SLEF}_{m,n} \\
\end{bmatrix}
\quad
\circ
\quad
\begin{bmatrix}
\text{SLEM}_{1,1} & \text{SLEM}_{1,2} & \dots & \text{SLEM}_{1,n} \\
\text{SLEM}_{2,1} & \text{SLEM}_{2,2} & \dots & \text{SLEM}_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
\text{SLEM}_{m,1} & \text{SLEM}_{m,2} & \dots & \text{SLEM}_{m,n} \\
\end{bmatrix}
\quad
\right)
\\begin{split}
\\mathbf{SL} &=
\\sum_{j=1}^{n} \\left( \\mathbf{SLEF} \\circ \\mathbf{SLEM} \\right)_{rowwise} \\\\
\\text{where:} \\\\
\\mathbf{SLEF} &=
\\begin{bmatrix}
\\text{SLEF}_{1,1} & \\text{SLEF}_{1,2} & \\dots & \\text{SLEF}_{1,n} \\\\
\\text{SLEF}_{2,1} & \\text{SLEF}_{2,2} & \\dots & \\text{SLEF}_{2,n} \\\\
\\vdots & \\vdots & \\ddots & \\vdots \\\\
\\text{SLEF}_{m,1} & \\text{SLEF}_{m,2} & \\dots & \\text{SLEF}_{m,n}
\\end{bmatrix} \\\\
\\mathbf{SLEM} &=
\\begin{bmatrix}
\\text{SLEM}_{1,1} & \\text{SLEM}_{1,2} & \\dots & \\text{SLEM}_{1,n} \\\\
\\text{SLEM}_{2,1} & \\text{SLEM}_{2,2} & \\dots & \\text{SLEM}_{2,n} \\\\
\\vdots & \\vdots & \\ddots & \\vdots \\\\
\\text{SLEM}_{m,1} & \\text{SLEM}_{m,2} & \\dots & \\text{SLEM}_{m,n}
\\end{bmatrix} \\\\
\\mathbf{SL} &=
\\begin{bmatrix}
\\text{SL}_{1} \\\\
\\text{SL}_{2} \\\\
\\vdots \\\\
\\text{SL}_{m}
\\end{bmatrix}
\\end{split}

Example
~~~~~~~
For a given model, we can have a matrix of secondary loss
probabilities. Each row can represent a simulation and each column can
represent a loss type. In this example below we have three different
probability columns for different types of probability loss. E.g. the
represent a loss type. In this example below we have three different
probability columns for different types of probability loss. E.g. the
probabilities of loss for simulation 1 are 0.95, 0.05, and 1.00.

+------------+-------------+--------------+--------------+
Expand Down
2 changes: 1 addition & 1 deletion pyfair/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""PyFair is an open source implementation of the FAIR methodology."""

VERSION = '0.1-alpha.12'
from ._version import __version__


from . import model
Expand Down
1 change: 1 addition & 0 deletions pyfair/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1-alpha.12"
34 changes: 12 additions & 22 deletions pyfair/model/model_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ class FairCalculations(object):
3) a multiplication function.

"""

def __init__(self):
# Lookup table for functions (no leaf nodes required)
self._function_dict = {
'Risk' : self._calculate_multiplication,
'Loss Event Frequency' : self._calculate_multiplication,
'Threat Event Frequency': self._calculate_multiplication,
'Vulnerability' : self._calculate_step_average,
'Loss Magnitude' : self._calculate_addition,
'Primary Loss' : self._calculate_multiplication,
'Secondary Loss' : self._calculate_multiplication,
"Risk": self._calculate_multiplication,
"Loss Event Frequency": self._calculate_multiplication,
"Threat Event Frequency": self._calculate_multiplication,
"Vulnerability": self._calculate_step_average,
"Loss Magnitude": self._calculate_addition,
"Primary Loss": self._calculate_multiplication,
"Secondary Loss": self._calculate_multiplication,
}

def calculate(self, parent_name, child_1_data, child_2_data):
Expand Down Expand Up @@ -58,22 +59,11 @@ def calculate(self, parent_name, child_1_data, child_2_data):
return calculated_result

def _calculate_step_average(self, child_1_data, child_2_data):
"""Get bool series based on step function, then average for vuln"""
"""Return per-simulation boolean (as float) for Vulnerability: 1.0 if TC > CS, else 0.0"""
# Get Trues (1) where child_2 (TCap) is greater than child_1 (CS)
# Otherwise False (0)
bool_series = child_1_data < child_2_data
# Treat those bools as 1 and 0 and get mean
bool_scalar_average = bool_series.mean()
# Create a long array of that mean
vuln_data = np.full(
len(bool_series),
bool_scalar_average
)
# And put it in a series
vuln = pd.Series(
data=vuln_data,
index=bool_series.index
)
bool_series = (child_1_data < child_2_data).astype(float)
# Return the per-simulation result as a Series
vuln = pd.Series(data=bool_series.values, index=bool_series.index)
return vuln

def _calculate_addition(self, child_1_data, child_2_data):
Expand Down
Loading