Пример #1
0
def classify_rf(
    classify_rf_params,
    train_rf_result,
    sigproc_result,
    sim_params,
    progress=None,
):
    if sigproc_result.n_channels != sim_params.n_channels:
        raise ValueError(
            f"Sigproc n_channels ({sigproc_result.n_channels}) does not match "
            f"classifier n_channels ({sim_params.n_channels})")

    if sigproc_result.n_cycles != sim_params.n_cycles:
        raise ValueError(
            f"Sigproc n_cycles ({sigproc_result.n_cycles}) does not match "
            f"classifier n_cycles ({sim_params.n_cycles})")

    pred_pep_iz, scores, all_class_scores = train_rf_result.classifier.classify(
        utils.mat_flatter(sigproc_result.signal_radmat()), progress)

    return ClassifyRFResult(
        params=classify_rf_params,
        pred_pep_iz=pred_pep_iz,
        scores=scores,
        all_class_scores=all_class_scores,
        peps_pr=peps_pr,
    )
Пример #2
0
def _sig_in_range(sigproc_v2):
    """
    Returns a mask indicating which signals are in range.  "In range" means
    able to be represented as np.float32 for the moment.  The radmat is float64,
    but some downstream ops (e.g. classify_rf) want to represent as float32.

    Or we could just truncate these signals?  But these signals really are
    probably bad.
    """
    finfo = np.finfo(np.float32)
    max_allowed = finfo.max
    min_allowed = finfo.min

    radmat = utils.mat_flatter(sigproc_v2.sig())
    peak_max = np.max(radmat, axis=1)
    peak_min = np.min(radmat, axis=1)
    in_range_mask = (peak_min > min_allowed) & (peak_max < max_allowed)
    return in_range_mask
Пример #3
0
def _create_flann(dt_mat):
    pyflann.set_distance_type("euclidean")
    flann = pyflann.FLANN()
    flann.build_index(utils.mat_flatter(dt_mat), algorithm="kdtree_simple")
    return flann
Пример #4
0
 def flat_test_radmat(self):
     assert self.test_radmat.ndim == 3
     return utils.mat_flatter(self.test_radmat)
Пример #5
0
 def flat_if_requested(self, mat, flat_chcy=False):
     if flat_chcy:
         return utils.mat_flatter(mat)
     return mat