in msticpy/analysis/anomalous_sequence/model.py [0:0]
def compute_setof_params_cond_cmd(self, use_geo_mean: bool): # noqa: MC0001
"""
Compute likelihood of combinations of params conditional on the cmd.
In particular, go through each command from each session and
compute the probability of that set of params (and values if provided)
appearing conditional on the command.
This can help us to identify unlikely combinations of params
(and values if provided) for each distinct command.
Note, this method is only available if each session is a list
of the Cmd datatype. It will result in an Exception if you
try and use it when each session is a list of strings.
Parameters
----------
use_geo_mean: bool
if True, then the probabilities will be raised to
the power of (1/K)
case1: we have only params:
Then K is the number of distinct params which appeared
for the given cmd across all the sessions.
case2: we have params and values:
Then K is the number of distinct params which appeared
for the given cmd across all the sessions + the number
of values which we included in the modelling for this cmd.
"""
if self.param_probs is None:
raise MsticpyException(
"please train the model first before using this method"
)
if self.session_type is None:
raise MsticpyException("session_type attribute should not be None")
if self.session_type == SessionType.cmds_only:
raise MsticpyException(
'this method is not available for your type of input data "sessions"'
)
if self.session_type == SessionType.cmds_params_only:
result = defaultdict(lambda: defaultdict(lambda: 0))
for ses in self.sessions:
for cmd in ses:
c_name = cmd.name
params = cmd.params
prob = cmds_params_only.compute_prob_setofparams_given_cmd(
cmd=c_name,
params=params,
param_cond_cmd_probs=self.param_cond_cmd_probs,
use_geo_mean=use_geo_mean,
)
result[c_name][tuple(params)] = prob
self.set_params_cond_cmd_probs = result
else:
result = defaultdict(lambda: defaultdict(lambda: 0))
for ses in self.sessions:
for cmd in ses:
c_name = cmd.name
params = cmd.params
pars = set(cmd.params.keys())
intersection_pars = pars.intersection(self.modellable_params)
key = set()
for par in pars:
if par in intersection_pars:
key.add(f"{par} --- {params[par]}")
else:
key.add(par)
prob = cmds_params_values.compute_prob_setofparams_given_cmd(
cmd=c_name,
params_with_vals=params,
param_cond_cmd_probs=self.param_cond_cmd_probs,
value_cond_param_probs=self.value_cond_param_probs,
modellable_params=self.modellable_params,
use_geo_mean=use_geo_mean,
)
result[c_name][tuple(key)] = prob
self.set_params_cond_cmd_probs = result