def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--distribution', choices=['normal', 't'], default='t')
    parser.add_argument('-x', '--dimension-x', type=int, default=DIMENSION_X_DEFAULT)
    parser.add_argument('-y', '--dimension-y', type=int, default=DIMENSION_Y_DEFAULT)
    parser.add_argument('-N', '--num-samples', type=int, default=NUM_SAMPLES_DEFAULT, nargs='+')
    parser.add_argument('-M', '--average-iterations', type=int, default=AVERAGE_ITERATIONS_DEFAULT)
    parser.add_argument('-s', '--seed', type=int, default=1)
    args = parser.parse_args()

    dx = args.dimension_x
    dy = args.dimension_y
    Ns = args.num_samples
    M = args.average_iterations
    T = 200
    dist = args.distribution

    dataset = SyntheticDataset(dx=dx, dy=dy, Ns=Ns, M=M, dist=dist, seed=args.seed)
    metric = plots.ConditionalRegressionNMSEErrorMetric(T=T, dataset=dataset, output_path='results-camsap-synthetic.pickle')

    estimator_objects = [
        regressors.common.HuberRegressor(name='ROMER-Huber'),
        regressors.conditional.ConditionalRegressor(estimators.conditional.gauss_loss.NewtonConditionalEstimator(newton_tol=1e-6), name='GCRF'),
        #regressors.conditional.ConditionalRegressor(estimators.conditional.general_loss.MMNewtonConditionalEstimator(
        #    loss=losses.tyler(dy), tolerance=1e-6, max_iters=25, newton_tol=1e-6), name='ROMER-Tyler'),
        regressors.conditional.ConditionalRegressor(estimators.conditional.general_loss.MMNewtonConditionalEstimator(
            loss=losses.generalized_gaussian(0.5, 1), tolerance=1e-6, max_iters=25, newton_tol=1e-6), name='ROMER-GG beta=0.5'),
        regressors.conditional.ConditionalRegressor(estimators.conditional.general_loss.MMNewtonConditionalEstimator(
            loss=losses.multivariate_t(dy, T_DIST_NU), tolerance=1e-6, max_iters=25, newton_tol=1e-6), name='ROMER-T-distribution')
    ]

    plots.plot_variables_vs_N(estimator_objects, Ns, M, metric)
コード例 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        '--dimension',
                        type=int,
                        default=DIMENSION_DEFAULT)
    parser.add_argument('-N',
                        '--num-samples',
                        type=int,
                        default=[60, 70, 80, 100, 150, 250, 500, 850],
                        nargs='+')
    parser.add_argument('-M',
                        '--average-iterations',
                        type=int,
                        default=AVERAGE_ITERATIONS_DEFAULT)
    parser.add_argument('-b',
                        '--beta',
                        type=float,
                        default=[1.0, 0.5, 0.2],
                        nargs='+')
    args = parser.parse_args()

    p = args.dimension
    Ns = args.num_samples
    M = args.average_iterations
    T = 200

    TYLER_MAX_ITERS = 1000
    TYLER_NEWTON_STEPS = 750
    GAUSSIAN_NEWTON_STEPS = 750

    for beta in args.beta:
        dataset = SyntheticDataset(p=p, Ns=Ns, M=M, beta=beta)
        metric = JointEstimationDistanceErrorMetric(T=T, dataset=dataset)

        estimator_objects = [
            #estimators.joint.general_loss.MMNewtonJointEstimator(
            #   loss=losses.tyler(dataset.get_dimension()), tolerance=1e-6, max_iters=TYLER_MAX_ITERS, newton_num_steps=TYLER_NEWTON_STEPS,
            #   newton_tol=1e-6, name='Tyler'),
            # estimators.joint.gauss_loss.NewtonJointEstimator(
            #     newton_num_steps=GAUSSIAN_NEWTON_STEPS, newton_tol=1e-6, name='GMRF Newton'),
            # estimators.joint.general_loss.MMJointEstimator(
            #     estimators.joint.gauss_loss.InvestJointEstimator(), loss=losses.tyler(dataset.get_dimension()),
            #     tolerance=1e-6, max_iters=TYLER_MAX_ITERS, name='Tyler'),
            #estimators.joint.gauss_loss.InvestJointEstimator(name='GMRF'),
            estimators.joint.general_loss.MMNewtonJointEstimator(
                loss=losses.generalized_gaussian(beta, 1),
                tolerance=1e-6,
                max_iters=TYLER_MAX_ITERS,
                newton_num_steps=TYLER_NEWTON_STEPS,
                newton_tol=1e-6,
                name='GG'),
            estimators.joint.gauss_loss.SampleCovarianceJointEstimator(
                name='Sample covariance')
        ]

        plots.plot_variables_vs_N(estimator_objects, Ns, M, metric, show=False)

    plots.show()
コード例 #3
0
def main():
    #M = 5
    T = 50

    parser = argparse.ArgumentParser()
    parser.add_argument('-N',
                        '--num-samples',
                        type=int,
                        nargs='+',
                        default=NUM_SAMPLES_DEFAULT)
    parser.add_argument('-M',
                        '--average-iterations',
                        type=int,
                        default=AVERAGE_ITERATIONS_DEFAULT)
    args = parser.parse_args()

    M = args.average_iterations
    Ns = args.num_samples
    #Ns = list(range(30, 401, 10))
    #Ns = list(range(30, 401, 20))

    dataset = FloodsDataset(Ns=Ns,
                            M=M,
                            test_size=200,
                            mode=FloodsDataset.Mode.DP_TO_D)
    dataset_full = dataset.structured_full()
    dataset_time = dataset.structured_time()
    dataset_timespace = dataset.structured_timespace()

    loss = losses.tyler(dataset.get_dimension())

    TYLER_MAX_ITERS = 12
    TYLER_NEWTON_STEPS = 25
    GAUSSIAN_NEWTON_STEPS = 200

    dx = dataset.get_dimension_x()
    dy = dataset.get_dimension_y()

    plots.plot_variables_vs_N(
        [
            # regressors.joint.JointRegressor(dx, dy, estimators.joint.general_loss.MMNewtonJointEstimator(
            #     loss=loss, tolerance=1e-6, max_iters=TYLER_MAX_ITERS, newton_num_steps=TYLER_NEWTON_STEPS,
            #     newton_tol=1e-6
            # ), name='Tyler time', dataset=dataset_time, initial_N=30),
            # regressors.joint.JointRegressor(dx, dy, estimators.joint.gauss_loss.NewtonJointEstimator(
            #     newton_num_steps=GAUSSIAN_NEWTON_STEPS, newton_tol=1e-6
            # ), name='GMRF time', dataset=dataset_time, initial_N=30),
            #
            # regressors.joint.JointRegressor(dx, dy, estimators.joint.general_loss.MMNewtonJointEstimator(
            #     loss=loss, tolerance=1e-6, max_iters=TYLER_MAX_ITERS, newton_num_steps=TYLER_NEWTON_STEPS,
            #     newton_tol=1e-6
            # ), name='Tyler time-space', dataset=dataset_timespace, initial_N=60),
            # regressors.joint.JointRegressor(dx, dy, estimators.joint.gauss_loss.NewtonJointEstimator(
            #     newton_num_steps=GAUSSIAN_NEWTON_STEPS, newton_tol=1e-6
            # ), name='GMRF time-space', dataset=dataset_timespace, initial_N=50),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.log_loss.TylerJointEstimator(),
                name='Tyler',
                dataset=dataset_full,
                initial_N=180),
            regressors.common.LinearRegressor(
                dx=dx, dy=dy, name='GMRF', dataset=dataset_full,
                initial_N=240),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.general_loss.MMNewtonJointEstimator(
                    losses.generalized_gaussian(0.5, 1)),
                name='GG 0.5',
                dataset=dataset_full,
                initial_N=180),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.general_loss.MMNewtonJointEstimator(
                    losses.generalized_gaussian(0.2, 1)),
                name='GG 0.2',
                dataset=dataset_full,
                initial_N=180),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.general_loss.MMNewtonJointEstimator(
                    losses.multivariate_t(dx + dy, 4)),
                name='T 2.5',
                dataset=dataset_full,
                initial_N=180),
        ],
        dataset.get_Ns(),
        dataset.get_averaging(),
        plots.metrics.JointRegressionNMSEErrorMetric(T),
        independent_variable='Training set size')
コード例 #4
0
def main():
    #M = 5
    T = 20  #50

    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--divisions', type=int, default=5)  #default=75)
    parser.add_argument('-s', '--shuffling', type=int,
                        default=2)  #default=100)
    parser.add_argument('-N',
                        '--num-samples',
                        type=int,
                        default=list(range(200, 801, 50)) + [900],
                        nargs='+')
    args = parser.parse_args()

    #Ns = list(range(200, 801, 50)) + [900]
    #Ns = [200, 300, 400, 600, 700, 900]
    Ns = [200, 500, 800]
    #Ns = args.num_samples

    #dataset = StocksDataset(Ns=Ns, divisions=args.divisions, shuffling=args.shuffling, num_observed=30, num_hidden=7)
    dataset = StocksDataset(Ns=Ns,
                            divisions=args.divisions,
                            shuffling=args.shuffling,
                            num_observed=105,
                            num_hidden=15)
    #dataset = StocksDataset(Ns=Ns, divisions=args.divisions, shuffling=args.shuffling, num_observed=60, num_hidden=15)
    #dataset = StocksDataset(Ns=Ns, divisions=args.divisions, shuffling=args.shuffling)

    #TYLER_MAX_ITERS = 12
    #TYLER_NEWTON_STEPS = 25
    TYLER_MAX_ITERS = 100
    TYLER_NEWTON_STEPS = 750
    GAUSSIAN_NEWTON_STEPS = 750

    dx = dataset.get_dimension_x()
    dy = dataset.get_dimension_y()

    plots.plot_variables_vs_N(
        [
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.general_loss.MMNewtonJointEstimator(
                    loss=losses.tyler(dataset.get_dimension()),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='Tyler'),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.gauss_loss.NewtonJointEstimator(
                    newton_num_steps=GAUSSIAN_NEWTON_STEPS, newton_tol=1e-6),
                name='GMRF'),
            regressors.joint.JointRegressor(
                dx,
                dy,
                estimators.joint.general_loss.MMNewtonJointEstimator(
                    loss=losses.generalized_gaussian_d(0.5, 1, dx + dy),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=GAUSSIAN_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='Laplace'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.general_loss.
                MMNewtonConditionalEstimator(
                    loss=losses.tyler(dataset.get_dimension()),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='Tyler conditional'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.gauss_loss.NewtonConditionalEstimator(
                    newton_num_steps=GAUSSIAN_NEWTON_STEPS, newton_tol=1e-6),
                name='GCRF'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.general_loss.
                MMNewtonConditionalEstimator(
                    loss=losses.generalized_gaussian_d(0.5, 1, dx + dy),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='Laplace conditional'),

            # regressors.joint.JointRegressor(dx, dy, estimators.joint.log_loss.TylerJointEstimator(),
            #                                 name='Unstructured Tyler'),

            # regressors.joint.JointRegressor(dx, dy, estimators.joint.general_loss.MMNewtonJointEstimator(
            #     loss=losses.generalized_gaussian(0.2, 1), tolerance=1e-6, max_iters=15,
            #     newton_num_steps=400, newton_tol=1e-6
            # ), name='GG m=1 b=0.2'),
            #regressors.joint.JointRegressor(dx, dy, estimators.joint.gauss_loss.InvestJointEstimator(), name='GMRF invest')
        ],
        dataset.get_Ns(),
        dataset.get_averaging(),
        StocksMSEErrorMetric(T, divisions=args.divisions, dataset=dataset),
        independent_variable='Training samples')
コード例 #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-N',
                        '--num-samples',
                        type=int,
                        nargs='+',
                        default=NUM_SAMPLES_DEFAULT)
    parser.add_argument('-M',
                        '--average-iterations',
                        type=int,
                        default=AVERAGE_ITERATIONS_DEFAULT)
    args = parser.parse_args()

    T = 20
    M = args.average_iterations
    Ns = args.num_samples

    dataset = FloodsDataset(Ns=Ns,
                            M=10,
                            test_size=200,
                            mode=FloodsDataset.Mode.DP_TO_D)
    dataset = dataset.structured_full()

    plots.plot_variables_vs_N(
        [
            regressors.common.LinearRegressor(name='Linear Regression'),
            # regressors.conditional.ConditionalRegressor(estimators.conditional.general_loss.MMNewtonConditionalEstimator(
            #     loss=losses.tyler(dataset.get_dimension_y()),
            #     tolerance=1e-6, max_iters=TYLER_MAX_ITERS, newton_num_steps=TYLER_NEWTON_STEPS, newton_tol=1e-6
            # ), name='ROMER-Tyler'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.general_loss.
                MMNewtonConditionalEstimator(
                    loss=losses.generalized_gaussian(0.8, 1),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='ROMER-GG m=1 beta=0.8'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.general_loss.
                MMNewtonConditionalEstimator(
                    loss=losses.generalized_gaussian(0.5, 1),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='ROMER-GG m=1 beta=0.5'),
            regressors.conditional.ConditionalRegressor(
                estimators.conditional.general_loss.
                MMNewtonConditionalEstimator(
                    loss=losses.multivariate_t(dataset.get_dimension(), 4),
                    tolerance=1e-6,
                    max_iters=TYLER_MAX_ITERS,
                    newton_num_steps=TYLER_NEWTON_STEPS,
                    newton_tol=1e-6),
                name='ROMER-T-distribution')
        ],
        dataset.get_Ns(),
        dataset.get_averaging(),
        plots.metrics.ConditionalRegressionNMSEErrorMetric(
            T,
            dataset=dataset,
            output_path='results-camsap-floods-dense.pickle'),
        independent_variable='Training set size')