Beispiel #1
0
def mog_cross_validate(x):
    import rpy2.robjects as robjects
    from rpy2.robjects import r as R
    from rpy2.robjects.packages import importr
    R.library('mclust')
    log_predictions = []
    for training, validation in k_fold_cross_validation(x, options.x_validate_groups):
        r_x = robjects.FloatVector(inv_sigmoid(training))
        clustering = R.Mclust(r_x)
        predictions = R.dens(
            modelName = clustering.rx2('modelName'),
            data = robjects.FloatVector(validation),
            parameters = clustering.rx2('parameters')
        )
        log_predictions.extend(np.log(predictions))
    return log_predictions
Beispiel #2
0
def kde_cross_validate(x, adjust=0.05):
    import rpy2.robjects as robjects
    from rpy2.robjects import r as R
    from rpy2.robjects.packages import importr
    log_predictions = []
    for training, validation in k_fold_cross_validation(x, options.x_validate_groups):
        r_x = robjects.FloatVector(training)
        density_args = {
            'from' : 0,
            'to' : 1,
            'adjust' : adjust,
        }
        kde = R['density'](r_x, **density_args)
        predictions = R['approx'](kde, xout=robjects.FloatVector(validation))
        log_predictions.extend(np.log(predictions[1]))
    return log_predictions
Beispiel #3
0
def start_cross_validation(task_ids, T):
    for fold, (training, validation) in enumerate(k_fold_cross_validation(T, options.x_validate_groups)):
        train_mixtures(task_ids, fold, training, validation)