C++ (Qt)#include <iostream>#include <vector>#include <cmath>#include <iomanip> #include "maxnet.h" static constexpr unsigned int period = 10; // число предыдущих шагов для определения вероятности следующего шага static constexpr size_t SIZE = 550; // Полный размер данных static constexpr size_t TRAINING_SIZE = 500; // Часть данных, для обучения сети template <class V, class F>void apply(V & data, F f){ for (size_t i = 0; i < data.size(); ++i) { data[i] = f(i); }} int main(){ std::vector<bool> data(SIZE); apply(data, [](size_t i)->bool { return (sin(i) + cos(4*i) >= 0); }); // периодическая функция vanda::maxnet<period, 0> maxnet; // Наша сеть) // Разделяем данные на две части: // для обучения и тестирования auto end = data.begin()+TRAINING_SIZE; maxnet.training(data.begin(), end); // обучаем сеть auto beg = end; end += period; // Тестируем её на оставшейся части данных while (end != data.end()) { auto p = maxnet.prediction_for(beg++, end); std::cout << "observed value = " << *end++ << "\t p(1) = " << p.probability_for_1 << "\t p(0) = " << p.probability_for_0 << std::endl; } std::cout << std::endl << "number of groups = " << maxnet.num_groups() << std::endl; return 0;}
C++ (Qt)observed value = 1 p(1) = 0.894737 p(0) = 0.105263observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 0.941176 p(0) = 0.0588235observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 0.47619 p(0) = 0.52381observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0.454545 p(0) = 0.545455observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0.5 p(0) = 0.5observed value = 1 p(1) = 0.5 p(0) = 0.5observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0.894737 p(0) = 0.105263observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0.47619 p(0) = 0.52381observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 0.3 p(0) = 0.7observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0.5 p(0) = 0.5observed value = 0 p(1) = 0 p(0) = 1observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 1 p(0) = 0observed value = 0 p(1) = 0 p(0) = 1 number of groups = 59
C++ (Qt)observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 1 p(1) = 0.921875 p(0) = 0.078125observed value = 0 p(1) = 0.921875 p(0) = 0.078125observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0 p(0) = 1observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 0 p(1) = 0.0448878 p(0) = 0.955112observed value = 1 p(1) = 0.0448878 p(0) = 0.955112observed value = 1 p(1) = 0.944444 p(0) = 0.0555556observed value = 1 p(1) = 0.941176 p(0) = 0.0588235observed value = 1 p(1) = 1 p(0) = 0observed value = 1 p(1) = 0.921875 p(0) = 0.078125
Generate source...Prepare datas...Training...epoch = 100/1000epoch = 200/1000epoch = 300/1000epoch = 400/1000epoch = 500/1000epoch = 600/1000epoch = 700/1000epoch = 800/1000epoch = 900/1000epoch = 1000/1000Checking...i = 500 observed = 0 predicted0 = 0.982339 predicted1 = 0.0130699i = 501 observed = 0 predicted0 = 0.463006 predicted1 = 0.54449i = 502 observed = 0 predicted0 = 0.964694 predicted1 = 0.0568292i = 503 observed = 1 predicted0 = -0.0217657 predicted1 = 1.01777i = 504 observed = 1 predicted0 = -0.0199576 predicted1 = 1.02494i = 505 observed = 0 predicted0 = 1.00691 predicted1 = -0.0121645i = 506 observed = 1 predicted0 = -0.0239787 predicted1 = 1.02294i = 507 observed = 0 predicted0 = 0.962106 predicted1 = 0.0530213i = 508 observed = 0 predicted0 = 0.972935 predicted1 = 0.0304997i = 509 observed = 1 predicted0 = -0.020028 predicted1 = 1.04145i = 510 observed = 1 predicted0 = 0.104954 predicted1 = 0.902725i = 511 observed = 1 predicted0 = -0.0344391 predicted1 = 1.03813i = 512 observed = 1 predicted0 = -0.0232968 predicted1 = 1.02557i = 513 observed = 0 predicted0 = 0.977863 predicted1 = 0.0280755i = 514 observed = 0 predicted0 = 0.965899 predicted1 = 0.0414848i = 515 observed = 1 predicted0 = 0.0409188 predicted1 = 0.977059i = 516 observed = 0 predicted0 = 0.987053 predicted1 = 0.0240999i = 517 observed = 1 predicted0 = -0.0230293 predicted1 = 1.02866i = 518 observed = 1 predicted0 = -0.0182573 predicted1 = 1.02402i = 519 observed = 0 predicted0 = 0.988447 predicted1 = 0.0201739i = 520 observed = 0 predicted0 = 0.979333 predicted1 = 0.0346248i = 521 observed = 0 predicted0 = 0.982198 predicted1 = 0.0327407i = 522 observed = 1 predicted0 = 0.488875 predicted1 = 0.523117i = 523 observed = 1 predicted0 = -0.0182998 predicted1 = 1.02597i = 524 observed = 0 predicted0 = 0.996294 predicted1 = 0.00668677i = 525 observed = 0 predicted0 = 0.524088 predicted1 = 0.479666i = 526 observed = 0 predicted0 = 0.976493 predicted1 = 0.029696i = 527 observed = 0 predicted0 = 0.981843 predicted1 = 0.0314973i = 528 observed = 1 predicted0 = -0.0170248 predicted1 = 1.02021i = 529 observed = 1 predicted0 = 0.000147805 predicted1 = 0.991886i = 530 observed = 0 predicted0 = 0.495998 predicted1 = 0.501123i = 531 observed = 1 predicted0 = 0.463006 predicted1 = 0.54449i = 532 observed = 0 predicted0 = 0.965241 predicted1 = 0.0396554i = 533 observed = 0 predicted0 = 0.974981 predicted1 = 0.0321968i = 534 observed = 1 predicted0 = -0.0154935 predicted1 = 1.01879i = 535 observed = 0 predicted0 = 0.104954 predicted1 = 0.902725i = 536 observed = 1 predicted0 = -0.0244336 predicted1 = 1.04083i = 537 observed = 1 predicted0 = -0.0257705 predicted1 = 1.03416i = 538 observed = 0 predicted0 = 0.989959 predicted1 = 0.00164001i = 539 observed = 0 predicted0 = 0.948124 predicted1 = 0.0420177i = 540 observed = 0 predicted0 = 0.97792 predicted1 = 0.0555568i = 541 observed = 0 predicted0 = 0.488875 predicted1 = 0.523117i = 542 observed = 1 predicted0 = -0.0205053 predicted1 = 1.02438i = 543 observed = 1 predicted0 = 0.645398 predicted1 = 0.362072i = 544 observed = 0 predicted0 = 0.982339 predicted1 = 0.0130699i = 545 observed = 0 predicted0 = 0.463006 predicted1 = 0.54449i = 546 observed = 0 predicted0 = 0.964694 predicted1 = 0.0568292i = 547 observed = 1 predicted0 = -0.0217657 predicted1 = 1.01777i = 548 observed = 1 predicted0 = -0.0199576 predicted1 = 1.02494i = 549 observed = 0 predicted0 = 1.00691 predicted1 = -0.0121645