import argparse
import os
from runner.MVAE_runner import MAE_runner, MGVAE_runner, MLVAE_runner, MGMVAE_runner, MLMVAE_runner


def arg_parser():
    parser = argparse.ArgumentParser(description=globals()['__doc__'])

    parser.add_argument('--run', type=str, default='./results/', help='The runner to execute')
    parser.add_argument('--model_name', type=str, default='MAE', help='Select model to run')
    parser.add_argument('--M', type=int, default=4, help='The number of RF nodes')
    parser.add_argument('--P', type=int, default=6, help='Each node has P measurement positions')
    parser.add_argument('--N', type=int, default=6, help='The number of links: M*(M-1)')
    parser.add_argument('--K0', type=int, default=40, help='SLF image dimension K[0]')
    parser.add_argument('--K1', type=int, default=40, help='SLF image dimension K[1]')
    parser.add_argument('--lambda0', type=float, default=1, help='loss weight for kl-divergence')
    parser.add_argument('--lambda1', type=float, default=100, help='loss weight for RSS reconstruction')
    parser.add_argument('--lambda2', type=float, default=200, help='loss weight for SLF estimation')
    parser.add_argument('--lambda3', type=float, default=1, help='loss weight for ab parameters estimation')
    parser.add_argument('--lambda4', type=float, default=1, help='loss weight for noise level prediction')
    parser.add_argument('--optimizer', type=str, default='Adam')
    parser.add_argument('--seed', type=int, default=1, help='Random seed')
    parser.add_argument('--no-cuda', action='store_true', default=False, help='enables CUDA training')
    parser.add_argument('--batch_size', type=int, default=128)
    parser.add_argument('--n_epochs', type=int, default=60)
    parser.add_argument('--log_interval', type=int, default=10, metavar='N',
                        help='how many batches to wait before logging training status')
    parser.add_argument('--save_freq', type=int, default=100,
                        help='how many epochs to save model before logging training status')
    parser.add_argument('--lr', type=float, default=1e-3)
    parser.add_argument('--weight_decay', type=float, default=0.00)
    parser.add_argument('--pretrain', type=bool, default=True, metavar='P',
                        help='whether exists pretrained model (default: True)')
    args = parser.parse_args()
    args.N = int(args.M*(args.M-1))
    return args


def main():
    args = arg_parser()
    print(args.model_name)
    if not os.path.exists(args.run):
        os.makedirs(args.run)
    if args.model_name == 'MAE':
        runner = MAE_runner(args)
    elif args.model_name == 'MGVAE':
        runner = MGVAE_runner(args)
    elif args.model_name == 'MLVAE':
        runner = MLVAE_runner(args)
    elif args.model_name == 'MGMVAE':
        runner = MGMVAE_runner(args)
    elif args.model_name == 'MLMVAE':
        runner = MLMVAE_runner(args)
    else:
        raise NotImplementedError('Model {} not understood.'.format(args.model_name))
    if not args.pretrain:
        runner.train_save()
    else:
        # runner.test_model()
        # runner.test_model('low')
        # runner.test_model('mid')
        # runner.test_model('high')
        runner.test_model_ROC()
        runner.test_model_ROC('low')
        runner.test_model_ROC('mid')
        runner.test_model_ROC('high')


if __name__ == '__main__':
    main()
import argparse
import os
from runner.MVAE_runner import MAE_runner, MGVAE_runner, MLVAE_runner, MGMVAE_runner, MLMVAE_runner


def arg_parser():
    parser = argparse.ArgumentParser(description=globals()['__doc__'])

    parser.add_argument('--run', type=str, default='./results/', help='The runner to execute')
    parser.add_argument('--model_name', type=str, default='MAE', help='Select model to run')
    parser.add_argument('--M', type=int, default=4, help='The number of RF nodes')
    parser.add_argument('--P', type=int, default=6, help='Each node has P measurement positions')
    parser.add_argument('--N', type=int, default=6, help='The number of links: M*(M-1)')
    parser.add_argument('--K0', type=int, default=40, help='SLF image dimension K[0]')
    parser.add_argument('--K1', type=int, default=40, help='SLF image dimension K[1]')
    parser.add_argument('--lambda0', type=float, default=1, help='loss weight for kl-divergence')
    parser.add_argument('--lambda1', type=float, default=100, help='loss weight for RSS reconstruction')
    parser.add_argument('--lambda2', type=float, default=200, help='loss weight for SLF estimation')
    parser.add_argument('--lambda3', type=float, default=1, help='loss weight for ab parameters estimation')
    parser.add_argument('--lambda4', type=float, default=1, help='loss weight for noise level prediction')
    parser.add_argument('--optimizer', type=str, default='Adam')
    parser.add_argument('--seed', type=int, default=1, help='Random seed')
    parser.add_argument('--no-cuda', action='store_true', default=False, help='enables CUDA training')
    parser.add_argument('--batch_size', type=int, default=128)
    parser.add_argument('--n_epochs', type=int, default=60)
    parser.add_argument('--log_interval', type=int, default=10, metavar='N',
                        help='how many batches to wait before logging training status')
    parser.add_argument('--save_freq', type=int, default=100,
                        help='how many epochs to save model before logging training status')
    parser.add_argument('--lr', type=float, default=1e-3)
    parser.add_argument('--weight_decay', type=float, default=0.00)
    parser.add_argument('--pretrain', type=bool, default=True, metavar='P',
                        help='whether exists pretrained model (default: True)')
    args = parser.parse_args()
    args.N = int(args.M*(args.M-1))
    return args


def main():
    args = arg_parser()
    print(args.model_name)
    if not os.path.exists(args.run):
        os.makedirs(args.run)
    if args.model_name == 'MAE':
        runner = MAE_runner(args)
    elif args.model_name == 'MGVAE':
        runner = MGVAE_runner(args)
    elif args.model_name == 'MLVAE':
        runner = MLVAE_runner(args)
    elif args.model_name == 'MGMVAE':
        runner = MGMVAE_runner(args)
    elif args.model_name == 'MLMVAE':
        runner = MLMVAE_runner(args)
    else:
        raise NotImplementedError('Model {} not understood.'.format(args.model_name))
    if not args.pretrain:
        runner.train_save()
    else:
        # runner.test_model()
        # runner.test_model('low')
        # runner.test_model('mid')
        # runner.test_model('high')
        runner.test_model_ROC()
        runner.test_model_ROC('low')
        runner.test_model_ROC('mid')
        runner.test_model_ROC('high')


if __name__ == '__main__':
    main()
# runner.test_model() # runner.test_model('low') # runner.test_model('mid') # runner.test_model('high')