in msticpy/analysis/anomalous_sequence/model.py [0:0]
def _laplace_smooth_counts(self):
"""
Laplace smooth all the counts for the model.
We do this by adding 1 to all the counts. This is so we shift
some of the probability mass from the very probable
commands/params/values to the unseen and very unlikely
commands/params/values. The `unk_token` means we can handle
unseen commands, params, values, sequences of commands.
"""
if self._seq1_counts is None:
raise MsticpyException("Please run the _compute_counts method first.")
if self.session_type == SessionType.cmds_only:
seq1_counts_ls, seq2_counts_ls = cmds_only.laplace_smooth_counts(
seq1_counts=self._seq1_counts,
seq2_counts=self._seq2_counts,
start_token=self.start_token,
end_token=self.end_token,
unk_token=self.unk_token,
)
self.seq1_counts = seq1_counts_ls
self.seq2_counts = seq2_counts_ls
elif self.session_type == SessionType.cmds_params_only:
(
seq1_counts_ls,
seq2_counts_ls,
param_counts_ls,
cmd_param_counts_ls,
) = cmds_params_only.laplace_smooth_counts(
seq1_counts=self._seq1_counts,
seq2_counts=self._seq2_counts,
param_counts=self._param_counts,
cmd_param_counts=self._cmd_param_counts,
start_token=self.start_token,
end_token=self.end_token,
unk_token=self.unk_token,
)
self.seq1_counts = seq1_counts_ls
self.seq2_counts = seq2_counts_ls
self.param_counts = param_counts_ls
self.cmd_param_counts = cmd_param_counts_ls
elif self.session_type == SessionType.cmds_params_values:
(
seq1_counts_ls,
seq2_counts_ls,
param_counts_ls,
cmd_param_counts_ls,
value_counts_ls,
param_value_counts_ls,
) = cmds_params_values.laplace_smooth_counts(
seq1_counts=self._seq1_counts,
seq2_counts=self._seq2_counts,
param_counts=self._param_counts,
cmd_param_counts=self._cmd_param_counts,
value_counts=self._value_counts,
param_value_counts=self._param_value_counts,
start_token=self.start_token,
end_token=self.end_token,
unk_token=self.unk_token,
)
self.seq1_counts = seq1_counts_ls
self.seq2_counts = seq2_counts_ls
self.param_counts = param_counts_ls
self.cmd_param_counts = cmd_param_counts_ls
self.value_counts = value_counts_ls
self.param_value_counts = param_value_counts_ls