Пример #1
0
/* Main function with command line parameters - Validates parameters & calls
   necessary functions to support the parameters*/
int main(int argc, char *argv[])
{
    int func_num;

    if (argc >= 2) {
        if (streq(argv[1], "rootap_addr")) {
            get_set_addr(1);
        } else if (streq(argv[1], "rpt_addr")) {
            get_set_addr(2); 
        } else if (streq(argv[1], "sta_addr")) {
            get_set_addr(3);
        } else if(streq(argv[1], "rec_msg")) {
            if (argc != 4) {
                printf("Missing argument : msg \n");
                usage();
                exit(0); 
            }
            if (atoi(argv[2]) == 3)
                func_num = 1;  
            else if (atoi(argv[2]) == 6)
                func_num = 2;
            else if (atoi(argv[2]) == 7) 
                func_num = 3;
            else {       
                printf("Invalid func: msg \n");
                exit(0);             
            } 
            rpttoolListen(func_num, 0, atoi(argv[3])); 
        } else if (streq(argv[1], "rec_gput")) {
            if (argc != 4) {
                printf("Missing argument : mode \n");
                usage();
                exit(0); 
            }
            rpttoolListen(0,atoi(argv[2]), atoi(argv[3])); 
        } else if (streq(argv[1], "node_blk")) {
            if (argc != 3) {
                printf("Missing argument : mode \n");
                usage();
                exit(0); 
            }
            block_nodes(atoi(argv[2]));
        } else if (streq(argv[1], "master")) {
            master = atoi(argv[2]);
            if (master < 0 || master > 4 ) {
                printf("Invalid mode. Exiting...\n");
                usage();
            }
            mode = master >> 1;
            interface = atoi(argv[3]); 
            init_training(); 
            if (master%2 == 1) {
                master_sm();
            } else {
                slave_sm();
            } 
        } else if (streq(argv[1],"-h")) {
Пример #2
0
    typename rbm_t::weight train(RBM& rbm, IIterator ifirst, IIterator ilast, EIterator efirst, EIterator elast, std::size_t max_epochs) {
        dll::auto_timer timer("rbm_trainer:train");

        //In case of shuffle, we don't want to shuffle the input, therefore create a copy and shuffle it

        std::vector<typename std::iterator_traits<IIterator>::value_type> input_copy;
        std::vector<typename std::iterator_traits<EIterator>::value_type> expected_copy;

        auto iterators = prepare_it(ifirst, ilast, efirst, elast, input_copy, expected_copy);

        decltype(auto) input_first = std::get<0>(iterators);
        decltype(auto) input_last = std::get<1>(iterators);

        decltype(auto) expected_first = std::get<2>(iterators);
        decltype(auto) expected_last = std::get<3>(iterators);

        //Initialize RBM and trainign parameters
        init_training(rbm, input_first, input_last);

        //Some RBM may init weights based on the training data
        //Note: This can't be done in init_training, since it will
        //sometimes be called with the wrong input values
        init_weights(rbm, input_first, input_last);

        //Allocate the trainer
        auto trainer = get_trainer(rbm);

        //Train for max_epochs epoch
        for (std::size_t epoch = 0; epoch < max_epochs; ++epoch) {
            //Shuffle if necessary
            shuffle(input_first, input_last, expected_first, expected_last);

            //Create a new context for this epoch
            rbm_training_context context;

            //Start a new epoch
            init_epoch();

            //Train on all the data
            train_sub(input_first, input_last, expected_first, trainer, context, rbm);

            //Finalize the current epoch
            finalize_epoch(epoch, context, rbm);
        }

        return finalize_training(rbm);
    }