From 3d83bb3f8f37ab5f7a443c5b0ccd3adff5f852e2 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sun, 11 Mar 2018 22:02:38 +0100 Subject: [PATCH] umie sie uczyc --- data/sin.dat | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ data/wig20.dat | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ decider.h | 17 +- network.h | 11 +- trainer.h | 175 +++++++-- wtf.cpp | 50 ++- 6 files changed, 2209 insertions(+), 44 deletions(-) create mode 100644 data/sin.dat create mode 100644 data/wig20.dat diff --git a/data/sin.dat b/data/sin.dat new file mode 100644 index 0000000..ffb207f --- /dev/null +++ b/data/sin.dat @@ -0,0 +1,1000 @@ +51.249479231767 +52.4958354161707 +53.73595331184 +54.9667332698765 +56.1850989813631 +57.3880051665335 +58.5724451863863 +59.7354585577163 +60.8741383527808 +61.9856384651051 +63.0671807232665 +64.1160618348759 +65.129660143401 +66.1054421809423 +67.0409690005833 +67.9339022724881 +68.7820101285073 +69.5831727406871 +70.3353876197343 +71.0367746201974 +71.6855806398504 +72.2801840015359 +72.819098506513 +73.3009771491807 +73.7246154838897 +74.0889546354298 +74.3930839456665 +74.6362432497115 +74.8178247759397 +74.9373746651014 +74.9945941047339 +74.9893400760376 +74.921625711348 +74.7916202613117 +74.5996486718484 +74.3461907719549 +74.0318800743825 +73.6575021921854 +73.2239928750967 +72.732435670642 +72.1840592158344 +71.5802341662218 +70.9224697699624 +70.2124100954898 +69.451829922198 +68.642630304418 +67.7868338197711 +66.8865795137788 +65.9441175533626 +64.9618036025989 +63.9420929347854 +62.8875342955366 +61.8007635322471 +60.6844970058457 +59.5415248013083 +58.3747037538976 +57.1869503085636 +55.9812332303496 +54.7605661840257 +53.5280002014967 +52.2866160558109 +51.0395165608323 +49.7898188158213 +48.5406464143105 +47.2951216367473 +46.0563576464188 +44.827450708165 +43.6114724493292 +42.4114621822893 +41.2304193077595 +40.071295817851 +38.9369889176287 +37.8303337836075 +36.7540964772877 +35.7109670314414 +34.703552726432 +33.7343715733708 +32.8058460204007 +31.9202968978372 +31.0799376173018 +30.2868686393451 +29.5430722233897 +28.8504074731138 +28.2106056896603 +27.6252660442854 +27.0958515812636 +26.6236855610388 +26.2099481527621 +25.855673484484 +25.5617470583726 +25.3289035374191 +25.1577249091634 +25.048639031028 +25.0019185608975 +25.0176802756156 +25.095884779104 +25.2363366008322 +25.4386846843917 +25.7024232649545 +26.0268931334215 +26.4112832841023 +26.8546329418067 +27.3558339632824 +27.9136336069962 +28.5266376643352 +29.1933139444025 +29.9119961036961 +30.6808878111003 +31.4980672377776 +32.3614918607402 +33.2690035680935 +34.218334053192 +35.2071104842248 +36.2328614350591 +37.2930230625185 +38.3849455146561 +39.5058995540035 +40.6530833792441 +41.8236296282565 +43.0146125450268 +44.2230552925152 +45.4459373931976 +46.6802022786871 +47.9227649295626 +49.1705195863111 +50.4203475121087 +51.6691247880389 +52.9137301212623 +54.1510526466239 +55.3779997021954 +56.5915045593195 +57.7885340878344 +58.96609633732 +60.121248015415 +61.2511018445154 +62.3528337784652 +63.4236900612003 +64.460994109705 +65.4621532040756 +66.4246649679697 +67.3461236232441 +68.2242260031469 +69.0567773090353 +69.8416965962288 +70.5770219752876 +71.2609155157141 +71.891667839822 +72.4677023952907 +72.9875793957243 +73.4499994193685 +73.8538066569879 +74.1979918007872 +74.481694567155 +74.704205846925 +74.8649694777794 +74.9635836343651 +74.999801832648 +74.9735335459943 +74.8848444314405 +74.7339561655845 +74.52124589051 +74.2472452711272 +73.9126391662877 +73.5182639169943 +73.0651052559835 +72.5542958439073 +71.9871124382716 +71.364972702207 +70.6894316610496 +69.9621778155873 +69.1850289216872 +68.3599274468528 +67.4889357150667 +66.5742307520546 +65.6180988438548 +64.622929822294 +63.5912110916522 +62.5255214114471 +61.4285244508789 +60.3029621310439 +59.1516477715603 +57.9774590587338 +56.7833308528408 +55.5722478525062 +54.3472371345108 +53.1113605876765 +51.8677072597384 +50.6193856363339 +49.3695158714085 +48.1212219884548 +46.8776240720812 +45.6418304694255 +44.4169300209054 +43.2059843397264 +42.0120201594432 +40.8380217687018 +39.6869235520727 +38.561602655617 +37.4648717955201 +36.3994722277658 +35.3680668964241 +34.3732337776779 +33.4174594362251 +32.5031328101614 +31.6325392398801 +30.8078547559104 +30.031140639975 +29.3043382728587 +28.6292642819679 +28.0076060007083 +27.4409172510294 +26.9306144596798 +26.4779731178773 +26.0841245932453 +25.750053301983 +25.4765942483377 +25.2644309375287 +25.1140936673406 +25.0259582026546 +25.0002448362324 +25.0370178380989 +25.1361852949003 +25.29749933964 +25.5205567712171 +25.8048000622185 +26.1495187524478 +26.5538512247054 +27.0167868583831 +27.5371685554888 +28.1136956327893 +28.7449270728408 +29.4292851257823 +30.1650592528881 +30.9504104020242 +31.7833756043207 +32.6618728805719 +33.5837064450996 +34.5465721940742 +35.5480634645739 +36.5856770499891 +37.6568194567351 +38.758813386635 +39.8889044287715 +41.0442679440793 +42.2220161254718 +43.419205215855 +44.6328428659868 +45.8598956137923 +47.0972964664385 +48.34195256622 +49.5907529210915 +50.8405761805284 +52.0882984372777 +53.3308010354986 +54.5649783657784 +55.7877456275385 +56.9960465394294 +58.1868609784423 +59.3572125286439 +60.504175920666 +61.6248843433555 +62.7165366093093 +63.7764041563842 +64.8018378676806 +65.790274692956 +66.7392440549151 +67.6463740243666 +68.5093972488112 +69.3261566196415 +70.0946106637905 +70.812838646351 +71.4790453714124 +72.0915656691159 +72.6488685577116 +73.1495610702157 +73.5923917361026 +73.9762537093294 +74.3001875348744 +74.5633835468752 +74.7651838923718 +74.9050841755958 +74.9827347186979 +74.9979414357601 +74.950666317909 +74.8410275283191 +74.6692991068653 +74.4359102851671 +74.1414444137319 +73.7866375038837 +73.3723763881171 +72.8996965034785 +72.3697793035126 +71.7839493052438 +71.1436707785734 +70.4505440863674 +69.7063016843829 +68.9128037910311 +68.0720337377994 +67.1860930119565 +66.2571960039279 +65.2876644724735 +64.2799217414997 +63.2364866430116 +62.159967221345 +61.0530542144135 +59.9185143282653 +58.7591833217589 +57.5779589186426 +56.3777935647544 +55.1616870484449 +53.932679002669 +52.6938413074861 +51.4482704119599 +50.1990795946484 +48.949391182029 +47.702328744308 +46.4610092881222 +45.2285354656453 +44.0079878195736 +42.8024170833734 +41.614836556036 +40.4482145703998 +39.305467073864 +38.1894503400383 +37.1029538295473 +36.0486932178305 +35.0293036073691 +34.0473329413013 +33.1052356348918 +32.2053664407719 +31.3499745632841 +30.5411980366425 +29.7810583809613 +29.0714555495063 +28.4141631798024 +27.8108241604624 +27.2629465248219 +26.7718996816408 +26.3389109922948 +25.9650627030111 +25.6512892398165 +25.3983748729589 +25.2069517566403 +25.0774983489601 +25.0103382160196 +25.0056392231747 +25.0634131154605 +25.1835154882342 +25.365646148112 +25.6093498632961 +25.9140175014169 +26.2788875520469 +26.7030480300803 +27.1854387552204 +27.7248540018787 +28.3199455128605 +28.969225869306 +29.6710722084628 +30.4237302799975 +31.2253188307081 +32.073834306677 +32.9671558611125 +33.9030506553615 +34.8791794398429 +35.8931024009536 +36.9422852593317 +38.0241056042351 +39.1358594482026 +40.2747679856146 +41.4379845382597 +42.6226016705477 +43.8256584565845 +45.0441478809448 +46.275024354645 +47.5152113275288 +48.7616089780408 +50.0111019611662 +51.2605671951703 +52.5068816676773 +53.7469302415738 +54.97761344123 +56.195855199574 +57.398610546658 +58.5828732204974 +59.7456831811595 +60.8841340093223 +61.9953801708093 +63.0766441289424 +64.1252232869379 +65.13849674299 +66.1139318411614 +67.0490905017034 +67.9416353149857 +68.7893353838037 +69.5900718994589 +70.3418434376776 +71.0427709611295 +71.6911025160417 +72.2852176111717 +72.8236312681907 +73.3049977333566 +73.7281138411974 +74.0919220217979 +74.3955129441744 +74.638127789128 +74.8191601458977 +74.9381575278714 +74.9948225035667 +74.9890134400551 +74.92074485697 +74.7901873902155 +74.5976673654654 +74.3436659825192 +74.0288181125529 +73.6539107112718 +73.219880851931 +72.7278133831406 +72.1789382173088 +71.5746272565014 +70.9163909634014 +70.2058745859388 +69.4448540450273 +68.6352314956876 +67.7790305726496 +66.87839133232 +65.935564903756 +64.9529078620143 +63.9328763379415 +62.8780198791256 +61.7909750773549 +60.674458978512 +59.5312622913735 +58.3642424122921 +57.1763162831932 +55.9704531007396 +54.7496668948859 +53.5170089953738 +52.2755604049962 +51.028424098695 +49.7787172677399 +48.5295635283737 +47.284085114398 +46.0453950732153 +44.816589484831 +43.6007397232667 +42.4008847797238 +41.220023666689 +40.0611079219642 +38.9270342313595 +37.8206371884873 +36.7446822097543 +35.7018586222609 +34.6947729418838 +33.7259423583438 +32.7977884435426 +31.9126310988939 +31.0726827567783 +30.2800428506146 +29.5366925673691 +28.8444898956207 +28.2051649815566 +27.620315804508 +27.0914041828338 +26.6197521201365 +26.2065385009412 +25.8527961440982 +25.5594092212744 +25.3271110469838 +25.1564822456835 +25.0479493005151 +25.0017834873186 +25.0181001965843 +25.0968586450366 +25.2378619775711 +25.4407577592894 +25.7050388564034 +26.0300447038052 +26.4149629561361 +26.8588315182268 +27.3605409498344 +27.918837238665 +28.5323249347518 +29.1994706383525 +29.9186068326511 +30.6879360516807 +31.5055353730527 +32.369361224261 +33.2772544905494 +34.226945911574 +35.2160617533719 +36.2421297414602 +37.3025852402344 +38.3947776632223 +39.5159770981692 +40.6633811303971 +41.8341218473819 +43.0252730070412 +44.2338573518151 +45.4568540502606 +46.6912062475557 +47.9338287060454 +49.1816155167289 +50.431447862414 +51.6802018131369 +52.9247561343591 +54.162000088429 +55.3888412098055 +56.6022130346117 +57.7990827651976 +58.9764588505542 +60.1313984636339 +61.2610148568847 +62.3624845776165 +63.4330545251618 +64.4700488321938 +65.470875553001 +66.4330331420019 +67.3541167063061 +68.2318240166937 +69.0639612619901 +69.8484485324505 +70.583325018452 +71.2667539114958 +71.8970269952722 +72.4725689153117 +72.9919411165505 +73.4538454389694 +73.8571273623174 +74.2007788918114 +74.4839410775979 +74.7059061616804 +74.866119346946 +74.9641801838687 +74.9998435714255 +74.9730203697206 +74.883777622789 +74.7323383910212 +74.5190811936288 +74.2445390625429 +73.9093982101126 +73.5144963139308 +73.0608204230771 +72.5495044910089 +71.9818265412681 +71.3592054730881 +70.6831975148845 +69.9554923344947 +69.1779088158883 +68.3523905129039 +67.4810007913774 +66.5659176718018 +65.6094283854098 +64.6139236572875 +63.5818917308062 +62.5159121483104 +61.4186493036048 +60.2928457823579 +59.1413155070655 +57.9669367037106 +56.7726447076967 +55.5614246270388 +54.3363038811473 +53.1003446338564 +51.856636139609 +50.6082870219301 +49.358417503486 +48.1101516071535 +46.8666093475893 +45.6308989328176 +44.4061089953301 +43.1953008721121 +42.0015009528951 +40.8276931157581 +39.6768112689865 +38.5517320178297 +37.4552674744857 +36.390158229285 +35.3590665006426 +34.3645694808977 +33.4091528946758 +32.4952047858711 +31.6250095487806 +30.8007422183081 +30.0244630335097 +29.2981122880689 +28.6235054805732 +28.002328776713 +27.4361347947454 +26.926338724757 +26.4742147914262 +26.0808930691247 +25.7473566573204 +25.4744392233403 +25.2628229186366 +25.1130366737636 +25.0254548763263 +25.0002964352064 +25.0376242334046 +25.1373449708653 +25.2992093976785 +25.5228129370743 +25.8075966966549 +26.1528488653337 +26.557706492493 +27.0211576449106 +27.5420439360661 +28.1190634215041 +28.7507738530168 +29.4355962835139 +30.1718190135679 +30.9576018697708 +31.7909808042102 +32.669872803565 +33.5920810955552 +34.5553006397276 +35.5571238888567 +36.5950468065592 +37.6664751260805 +38.7687308346112 +39.8990588669234 +41.0546339915998 +42.2325678726407 +43.4299162887994 +44.6436864926028 +45.8708446906605 +47.1083236265691 +48.3530302474553 +49.6018534349975 +50.8516717816015 +52.0993613922937 +53.3418036928314 +54.5758932245147 +55.7985454062158 +57.0067042442255 +58.1973499706457 +59.3675065912365 +60.5142493238525 +61.6347119088739 +62.726093773364 +63.7856670310423 +64.8107833005794 +65.7988803251721 +66.7474883768496 +67.6542364295084 +68.5168580852419 +69.3331972391555 +70.1012134685059 +70.8189871326945 +71.4847241713704 +72.0967605886458 +72.65356661222 +73.1537505170132 +73.596062103754 +73.979395823827 +74.3027935425684 +74.5654469341035 +74.7666995017408 +74.9060482188716 +74.9831447862743 +74.9977965026817 +74.9499667464331 +74.8397750670099 +74.6674968862239 +74.4335628098065 +74.138557551118 +73.7832184696696 +73.3684337281076 +72.8952400722705 +72.3648202398631 +71.7785000042294 +71.1377448606087 +70.444156363161 +69.6994681219164 +68.9055414696516 +68.0643608095284 +67.1780286551186 +66.2487603752153 +65.2788786565649 +64.2708076983591 +63.2270671530006 +62.150265828283 +61.0430951667306 +59.9083225183943 +58.7487842239166 +57.5673785251579 +56.3670583211009 +55.1508237871408 +53.9217148762103 +52.6828037204786 +51.4371869526231 +50.1879779658586 +48.9382991320762 +47.6912739975407 +46.45001947565 +45.2176380562761 +43.9972100511556 +42.7917858947145 +41.6043785195715 +40.4379558257741 +39.2954332625962 +38.1796665414312 +37.0934444980018 +36.0394821217234 +35.0204137696434 +34.0387865819217 +33.0970541153059 +32.1975702105177 +31.3425831088771 +30.5342298328693 +29.7745308447023 +29.0653849962029 +28.4085647826761 +27.8057119125906 +27.2583332041618 +26.7677968190915 +26.335328842876 +25.9620102202307 +25.6487740532918 +25.3964032693464 +25.2055286639221 +25.076627324127 +25.0100214361799 +25.0058774801132 +25.0642058136588 +25.1848606463597 +25.3675404039699 +25.6117884822333 +25.916994388156 +26.2823952659215 +26.7070778036324 +27.1899805161148 +27.7298963980785 +28.3254759410011 +28.9752305061975 +29.6775360456399 +30.4306371612336 +31.2326514923972 +32.0815744209836 +32.9752840817819 +33.911546666075 +34.8880220049984 +35.9022694187434 +36.9517538169853 +38.0338520352896 +39.1458593916562 +40.2849964468164 +41.4484159513837 +42.6332099624936 +43.8364171121472 +45.0550300090884 +46.2860027557163 +47.5262585612428 +48.7726974320663 +50.0222039201429 +51.2716549099827 +52.5179274248125 +53.7579064323918 +54.9884926309697 +56.2066101959271 +57.4092144677346 +58.5932995620171 +59.7559058826987 +60.8941275194508 +62.0051195109565 +63.08610495583 +64.1343819534256 +65.1473303571816 +66.1224183236217 +67.057208640646 +67.9493648192911 +68.7966569337365 +69.5969671949573 +70.3482952440939 +71.0487631523076 +71.6966201146244 +72.290246826036 +72.8281595289187 +73.3090137216547 +73.7316075191863 +74.0948846571022 +74.3979371317487 +74.6400074697658 +74.8204906213764 +74.9389354726951 +74.9950459732786 +74.9886818760973 +74.9198590880796 +74.7887496303535 +74.5956812082827 +74.3411363923745 +74.025751412104 +73.6503145656727 +73.215764249673 +72.7231866135853 +72.1738128449706 +71.569016092142 +70.9103080320093 +70.1993350916746 +69.437874333221 +68.6278290119837 +67.7712238194023 +66.8701998223467 +65.9270091115656 +64.9440091726314 +63.9236569934553 +62.868502923096 +61.7811842972155 +60.6644188461143 +59.5209979018197 +58.3537794212105 +57.1656808426125 +55.9596717937223 +54.738766669085 +53.5060170956768 +52.264504305428 +51.0173314337466 +49.7676157632967 +48.5184809324153 +47.2730491276426 +46.0344332798823 +44.8057292836951 +43.5900082591746 +42.3903088757471 +41.2096297570796 +40.0509219860832 +38.917081728742 +37.8109429952065 +36.7352705562449 +35.692753032755 +34.6859961756133 +33.7175163526534 +32.7897342590582 +31.9049688668824 +31.0654316288292 +30.2732209507715 +29.5303169468289 +28.8385764901143 +28.1997285715182 +27.6153699781313 +27.0869613021092 +26.6158232899519 +26.2031335413259 +25.8499235656781 +25.5570762039995 +25.3253234221822 +25.1552444814864 +25.0472644906882 +25.0016533435299 +25.0185250441255 +25.0978374220102 +25.2393922375442 +25.4428356774091 +25.7076592389566 +26.0332010012002 +26.4186472792731 +26.8630346582167 +27.3652524010163 +27.9240452248645 +28.5380164387157 +29.205631434285 +29.9252215217709 +30.6949881007098 +31.5130071555411 +32.3772340646438 +33.2855087108257 +34.2355608804918 +35.2250159379956 +36.2514007609913 +37.3121499219526 +38.4046121004043 +39.5260567098437 +40.6736807227844 +41.8446156768649 +43.0359348445112 +44.2446605482311 +45.4677716032576 +46.7022108689372 +47.9448928899889 +49.1927116085367 +50.4425481276353 +51.6912785068895 +52.9357815706774 +54.1729467094639 +55.3996816547056 +56.6129202079102 +57.8096299045373 +58.9868195935798 +60.1415469138834 +61.270925648518 +62.3721329388157 +63.4424163400487 +64.4791007011068 +65.4795948509818 +66.4413980753467 +67.3621063670377 +68.2394184348213 +69.0711414554235 +69.8551965544455 +70.5896240024679 +71.272588113353 +71.9023818325044 +72.4774310036146 +72.9962983032354 +73.4576868333389 +73.8604433628861 +74.2035612103047 +74.4861827596687 +74.7076016042909 +74.8672643123726 +74.9647718102943 +74.999880380092 +74.9725022686255 +74.8827059069153 +74.7307157391004 +74.5169116614456 +74.241828072798 +73.9061525388684 +73.5107240736751 +73.0565310424461 +72.5447086912202 +71.9765363093236 +71.3534340318125 +70.6769592898754 +69.9488029180658 +69.1707849280968 +68.3448499597594 +67.4730624203356 +66.5576013246561 +65.6007548486969 +64.6049146103321 +63.5725696915341 +62.5063004169647 +61.4087719045084 +60.2827274038642 +59.1309814398514 +57.9564127775622 +56.7619572269486 +55.5506003048271 +54.32536977264 +53.0893280686306 +51.8455646533406 +50.5971882875685 +49.3473192620873 +48.0990815985412 +46.8555952410197 +45.6199682578213 +44.3952890729018 +43.1846187464232 +41.9909833236963 +40.8173662716452 +39.6667010216918 +38.5418636377059 +37.4456656273438 +36.3808469147422 +35.3500689921362 +34.3559082675132 +33.4008496249358 +32.4872802136258 +31.6174834813334 +30.7936334669083 +30.0177893663336 +29.2918903858089 +28.6177508947447 +27.9970558907835 +27.4313567881836 +26.9220675400911 +26.4704611043934 +26.0776662619878 +25.7446647954166 +25.4722890349226 +25.2612197780563 +25.1119845880371 +25.02495647512 +25.0003529642639 +25.0382355514326 +25.1385095498871 +25.300924326853 +25.5250739299718 +25.8103981019705 +26.1561836810132 +26.5615663832338 +27.0255329629962 +27.5469237454799 +28.1244355252638 +28.7566248236608 +29.4419114966627 +30.1785826844775 +30.9647970927865 +31.7985895950215 +32.6778761441576 +33.6004589817456 +34.5640321311635 +35.5661871613566 +36.6044192066621 +37.6761332276672 +38.7786504974574 +39.9092152970382 +41.0650018031972 +42.2431211515913 +43.4406286574018 diff --git a/data/wig20.dat b/data/wig20.dat new file mode 100644 index 0000000..cea3610 --- /dev/null +++ b/data/wig20.dat @@ -0,0 +1,1000 @@ +2456.54 +2459.32 +2420.29 +2411.29 +2389.9 +2378.18 +2307.82 +2348.91 +2393.01 +2385.24 +2351.44 +2389.97 +2377.01 +2367.52 +2413.2 +2425.24 +2435.44 +2447.54 +2459.7 +2472.4 +2473.72 +2448.68 +2448.8 +2456.24 +2472.83 +2472.48 +2447.1 +2449.44 +2435.88 +2421.68 +2403.29 +2431.46 +2459.6 +2454.01 +2439.38 +2431.39 +2448.98 +2453.3 +2435.2 +2430.16 +2415.04 +2382.41 +2406.54 +2412.44 +2389.34 +2422.76 +2416.1 +2413.33 +2398.46 +2396.05 +2403.22 +2407.53 +2435.27 +2469.05 +2478.36 +2468.19 +2463 +2445.8 +2462 +2438.21 +2446.33 +2440.32 +2467.06 +2490.9 +2505.2 +2488.66 +2503.01 +2480.45 +2475.56 +2435.63 +2448.85 +2469.79 +2466.57 +2464.25 +2474.52 +2447.18 +2434.19 +2399.46 +2411.65 +2408.97 +2402.34 +2384.41 +2370.25 +2365.95 +2386.36 +2364.92 +2347.42 +2343.53 +2382.61 +2382.63 +2390.84 +2387.31 +2386.99 +2398.1 +2391.59 +2408.51 +2407.35 +2408.27 +2408.05 +2404.23 +2384.11 +2346.75 +2325.31 +2356.94 +2367.11 +2357.93 +2365.66 +2312.18 +2333.64 +2343.37 +2355.74 +2380.32 +2415.31 +2447.78 +2441 +2452.81 +2451.55 +2448.91 +2448.8 +2469.4 +2459.68 +2418.86 +2426.98 +2453.14 +2456.29 +2508.12 +2534.14 +2545.58 +2540.34 +2536.46 +2536.01 +2508.92 +2470.5 +2487.26 +2509.74 +2510.28 +2508.65 +2525.55 +2520.76 +2489.81 +2484.22 +2465.15 +2489.39 +2493.7 +2490.44 +2451.13 +2447.55 +2458.67 +2445.08 +2422.13 +2433.19 +2404.85 +2393.2 +2397.92 +2412.23 +2392.44 +2386.72 +2409.26 +2382.3 +2436.35 +2421.51 +2434.43 +2443.39 +2440.36 +2460.9 +2443.09 +2462.75 +2462.13 +2452.62 +2464.12 +2442.9 +2430.38 +2419.73 +2407.27 +2407.25 +2394.32 +2413.56 +2421.05 +2432.9 +2410.47 +2400.95 +2423.67 +2411.95 +2412.28 +2421.24 +2430.43 +2404.3 +2425.24 +2447.12 +2448.42 +2427.19 +2443.38 +2420.69 +2400.29 +2373.7 +2379.51 +2359.66 +2317.17 +2269.56 +2315.66 +2332.84 +2312.72 +2317.66 +2329.12 +2312.26 +2323.3 +2304.64 +2273.35 +2317.92 +2357.49 +2336.38 +2327.62 +2349.17 +2349.68 +2254.33 +2256.97 +2265.71 +2249.92 +2292.99 +2322.49 +2305.3 +2313.16 +2318.69 +2321.4 +2345.43 +2344.22 +2333.87 +2337 +2337.47 +2344.11 +2347.74 +2342.25 +2345.33 +2329.33 +2344.81 +2350.22 +2360.91 +2369.74 +2351.85 +2349.94 +2359.47 +2364.12 +2366.87 +2350.47 +2361.45 +2371.78 +2354.2 +2323.71 +2346.01 +2358.87 +2341.26 +2343.04 +2317.97 +2334.7 +2329.03 +2306.79 +2315.57 +2333.12 +2352.78 +2387.65 +2410.35 +2405.98 +2408.49 +2383.55 +2379.49 +2383.57 +2394.45 +2390.61 +2394.37 +2407.5 +2422.16 +2423.81 +2443.83 +2441.37 +2441.59 +2432.55 +2476.35 +2500.19 +2468.91 +2513.88 +2510.36 +2529.38 +2524.02 +2520.88 +2547.24 +2549.16 +2518.69 +2519.97 +2523 +2503.35 +2522.86 +2525.11 +2546.05 +2537.79 +2537.11 +2535.55 +2515.54 +2521.14 +2525.73 +2524.07 +2518.85 +2522.37 +2501.45 +2459.98 +2451.44 +2462.81 +2442.55 +2441.39 +2437.04 +2411.41 +2387.28 +2365.68 +2356.16 +2339.7 +2387.95 +2384.63 +2353.17 +2356.77 +2357.51 +2315.57 +2328.66 +2312.13 +2355.85 +2340.37 +2345.61 +2352.13 +2285.5 +2288.77 +2320.06 +2298.5 +2295.87 +2263.47 +2272.83 +2219.58 +2219.76 +2244.68 +2275.22 +2269.4 +2262.78 +2264.61 +2300.1 +2282.98 +2249.27 +2247.23 +2175.41 +2195.82 +2190.8 +2192.86 +2200.4 +2216.29 +2193.59 +2221.27 +2228.64 +2228.26 +2241.44 +2196.01 +2203.61 +2221.86 +2217.08 +2203.68 +2224.61 +2200.35 +2171.63 +2179.98 +2189.96 +2181.55 +2139.45 +2053.54 +2054.43 +2091.04 +2126.23 +2142.45 +2149 +2119.03 +2115.73 +2150.62 +2154.74 +2137.37 +2153.54 +2140.69 +2185.48 +2175.24 +2182.07 +2187.9 +2179.71 +2199.43 +2166.54 +2178.38 +2128.39 +2110.49 +2093.29 +2092.84 +2031.63 +2052.89 +2074.84 +2053.15 +2046.23 +2089.63 +2106.04 +2104 +2129.49 +2147.86 +2129.58 +2115.39 +2125.36 +2146.31 +2124.66 +2108.15 +2119 +2101.44 +2108.45 +2093.76 +2108.5 +2108.61 +2098.37 +2059.5 +2061.56 +2079.14 +2063.18 +2058.67 +2040.32 +2023.65 +2012.57 +2029.2 +2006.62 +1972.9 +1973.98 +2004.13 +2033.94 +2011.7 +2018.63 +1983.03 +1947.12 +1945.77 +1962.26 +1934.54 +1930.2 +1921.82 +1884.46 +1858.4 +1870.57 +1862.91 +1816.59 +1775.94 +1811.51 +1759.14 +1757.73 +1775.68 +1808.52 +1832.7 +1854.45 +1866.89 +1880.5 +1874.62 +1879.39 +1891.75 +1832.4 +1811.27 +1763.59 +1750.93 +1721.38 +1712.16 +1758.21 +1760.5 +1766.35 +1712.35 +1694.97 +1680.19 +1682.42 +1696.79 +1730.44 +1714.31 +1710.66 +1726.3 +1763.09 +1781.67 +1776.26 +1734.44 +1748.87 +1789.26 +1790.32 +1766.02 +1772.4 +1759.51 +1758.1 +1780.23 +1788.14 +1786.14 +1847 +1848.09 +1849.6 +1847.9 +1844.44 +1826.34 +1845.08 +1836.93 +1826.93 +1830.28 +1828.14 +1877.6 +1874.03 +1887.19 +1875.09 +1876.34 +1892.86 +1917.09 +1909.88 +1909.6 +1907.65 +1944.75 +1951.9 +1948.94 +1959.07 +1933.12 +1939.41 +1962.38 +1982.94 +1985.37 +1970.39 +1976.23 +1939.74 +1928.52 +1911.93 +1919.03 +1915.38 +1918.51 +1941.15 +1952.47 +1932.52 +1946.09 +1963.66 +1966.84 +1949.6 +1940.55 +1925.44 +1913.09 +1885.19 +1899.32 +1898.93 +1890.87 +1865.17 +1838.83 +1859.84 +1845.54 +1823.5 +1817.25 +1812.82 +1829.37 +1859.85 +1845.98 +1844.07 +1800.76 +1805.88 +1817.47 +1837.25 +1849.78 +1840.91 +1844.22 +1809.97 +1759.87 +1760.19 +1797.23 +1799.46 +1833.06 +1842.55 +1815.5 +1770.85 +1777.15 +1766.96 +1758.15 +1739.54 +1764.76 +1775.08 +1801.47 +1820.28 +1676.13 +1759.88 +1753.04 +1756.86 +1751.77 +1756.47 +1728.89 +1722.62 +1716.3 +1697.51 +1714.84 +1719.81 +1747.85 +1747.31 +1740.03 +1746.76 +1764.85 +1787.4 +1797.25 +1800.15 +1800.87 +1798.64 +1812.16 +1800.65 +1791.55 +1792.92 +1760.37 +1777.79 +1806.56 +1791.12 +1822.66 +1828.23 +1836.65 +1845.78 +1850.84 +1863.79 +1856.22 +1847.28 +1824.61 +1824.95 +1799.87 +1793.48 +1787.89 +1788.99 +1783.26 +1772.66 +1776.41 +1797.35 +1796.61 +1760.27 +1770.85 +1792.02 +1792.71 +1811.76 +1792.55 +1746.6 +1736.54 +1730.91 +1736.24 +1745.2 +1740.57 +1748.71 +1755.52 +1762.09 +1774.4 +1756.5 +1741.68 +1734.12 +1730.66 +1723.24 +1713.16 +1728.57 +1755.28 +1762.95 +1762.35 +1757.71 +1767.37 +1753.78 +1751.92 +1732.81 +1717.26 +1720.14 +1722.43 +1751.16 +1751.18 +1753.46 +1782.68 +1785.14 +1780.78 +1795.14 +1816.88 +1804.87 +1764.66 +1765.48 +1773.16 +1767.24 +1761.64 +1800.19 +1794.23 +1757.25 +1757.61 +1761.95 +1736.82 +1731.39 +1765.41 +1772.69 +1798 +1810.46 +1794.64 +1777.84 +1783.45 +1802.89 +1787.79 +1788.93 +1846.82 +1877.73 +1898.82 +1916.66 +1904.31 +1886.78 +1917.77 +1931.36 +1913.05 +1915.46 +1929.47 +1941.74 +1927.7 +1942.49 +1933.1 +1935.38 +1934.69 +1948.89 +1947.54 +1961.73 +1991.97 +1994.72 +1999.15 +2007.4 +2024.89 +2029.68 +2023.01 +2013.32 +2026.4 +2018.57 +2005.6 +2015.31 +2004.04 +1994.53 +2015.01 +2086.78 +2078.43 +2082.83 +2052.23 +2065.94 +2078.01 +2065.59 +2078.45 +2089.06 +2087.15 +2092.88 +2144.56 +2161.17 +2181.34 +2180.23 +2185.44 +2214.85 +2193.39 +2192.53 +2252.57 +2249.81 +2252.39 +2212.87 +2214.22 +2195.25 +2256.56 +2244.31 +2232.66 +2212.81 +2196.62 +2215.88 +2195.42 +2200.2 +2242.95 +2244.71 +2246.85 +2285.74 +2294.85 +2280.19 +2230.81 +2216.35 +2235.16 +2215.3 +2209.06 +2235.73 +2218.61 +2203.46 +2188.57 +2215.65 +2238.79 +2243.86 +2250.06 +2250.93 +2241.61 +2223.29 +2216.92 +2237.96 +2243.91 +2273.77 +2287.86 +2283.16 +2300.42 +2354.17 +2378.56 +2384.53 +2381.68 +2395.19 +2367.91 +2389.8 +2378.66 +2409.88 +2381.66 +2367.93 +2378.39 +2375.63 +2330.87 +2299.09 +2297.16 +2336.02 +2339.18 +2305.98 +2339.54 +2353.12 +2326.69 +2315.74 +2292.96 +2283.62 +2292.38 +2301.67 +2270.87 +2308.36 +2310.69 +2339.71 +2329.9 +2297.3 +2301.42 +2293.17 +2312.63 +2327.84 +2295.92 +2313.6 +2305.7 +2313.84 +2334.82 +2343.41 +2334.5 +2324.71 +2305.25 +2317.64 +2298.75 +2309.29 +2299.26 +2305.52 +2303.48 +2297.08 +2335.49 +2349.47 +2353.46 +2367.99 +2364 +2375.73 +2356.9 +2344.63 +2337.8 +2344.28 +2361.54 +2344.85 +2357.45 +2377.03 +2387.69 +2365.65 +2365.84 +2380.96 +2387.51 +2420.38 +2403.19 +2373.71 +2375.77 +2378.88 +2378.87 +2346.8 +2358.89 +2380.47 +2387.52 +2395.3 +2464.81 +2474.13 +2525.41 +2507.29 +2520.23 +2512.46 +2513.38 +2521.04 +2512.11 +2511.82 +2488.67 +2489.43 +2518.15 +2507.73 +2502.15 +2507 +2503.74 +2495.79 +2505.52 +2501.16 +2464.57 +2479.08 +2452.04 +2447.67 +2430.81 +2430.17 +2459.84 +2471.22 +2470.39 +2444.16 +2466 +2483.61 +2506.81 +2520.81 +2557.48 +2538.56 +2528.44 +2534.17 +2518.16 +2490.24 +2473.82 +2466.64 +2468.98 +2449.02 +2452.47 +2462.46 +2490.8 +2514.24 +2524.52 +2503.49 +2497.52 +2521.05 +2545.38 +2513.25 +2477.93 +2458.9 +2464.53 +2460.26 +2428.52 +2412.64 +2438.15 +2469.21 +2490.63 +2482.04 +2502.59 +2477.97 +2494.79 +2491.96 +2436.48 +2411.13 +2392.69 +2403.25 +2400.9 +2396.49 +2400.6 +2410.81 +2385.06 +2411.34 +2405.42 +2430.72 +2420.28 +2465.96 +2455.5 +2460.57 +2462.69 +2445.51 +2475.48 +2479.48 +2463.26 +2473.23 +2530.77 +2534.53 +2552.5 +2531.05 +2517.35 +2536.81 +2535.37 +2541.61 +2587.72 +2604.79 +2592.75 +2600.44 +2629.53 +2629.4 +2614.92 +2592.23 +2599.2 +2581.75 +2565.29 +2558.83 +2526.55 +2492.39 +2445.53 +2426.89 +2440.29 +2396.78 +2402.18 +2417.65 +2439.12 +2461.15 +2445.4 +2409.93 +2404.56 +2409.27 +2389.87 +2412.41 +2418.02 +2417.07 +2410.71 +2361.73 +2327.98 diff --git a/decider.h b/decider.h index 6991e62..a43258c 100644 --- a/decider.h +++ b/decider.h @@ -6,6 +6,7 @@ #include #include + class decider { public: double start_money; @@ -37,6 +38,8 @@ template class neural_decider : public decider, macd_decider { public: using network_t = network; + using self_t = neural_decider; + network_t network; double start_money; @@ -61,13 +64,23 @@ public: return abs(buy - sell) <= .5 ? 0 : amount * start_stock / 10; } - virtual void reset() + virtual void reset() override { - this->reset(); + macd_decider::reset(); } virtual ~neural_decider() { } + self_t combine(self_t smth, typename network_t::combiner_t combiner = [](const double& a, const double& b) { return .35*a + .65*b; }) + { + self_t result; + + result.network = network.combine(smth.network, combiner); + result.start_money = start_money; + result.start_stock = start_stock; + + return result; + } private: typename network_t::input prepare(double money, unsigned stock) { diff --git a/network.h b/network.h index 51c7385..41e629f 100644 --- a/network.h +++ b/network.h @@ -101,7 +101,7 @@ public: } self combine(self& rhs, combiner_t weight_combiner, combiner_t bias_combiner) { - self result; + self result(normalizer); result.template get<0>() = get<0>().combine(rhs.template get<0>(), weight_combiner, bias_combiner); return result; @@ -159,13 +159,18 @@ public: } self combine(self& rhs, typename base::combiner_t weight_combiner, typename base::combiner_t bias_combiner) { - self result; + self result(normalizer); result.template get<0>() = get<0>().combine(rhs.template get<0>(), weight_combiner, bias_combiner); - result.subnetwork = subnetwork.combine(rhs.subnetwork); + result.subnetwork = subnetwork.combine(rhs.subnetwork, weight_combiner, bias_combiner); return result; } + + self combine(self& rhs, typename base::combiner_t combiner) + { + return combine(rhs, combiner, combiner); + } }; #endif diff --git a/trainer.h b/trainer.h index da46d23..bec8d8e 100644 --- a/trainer.h +++ b/trainer.h @@ -1,7 +1,10 @@ #include +#include +#include #include #include #include +#include template struct trained { @@ -10,23 +13,35 @@ struct trained { double monies; unsigned stock; + double wealth; + + void recalculate(double price) + { + wealth = monies + stock*price; + } - double result; + double score; }; template class trainer { - std::vector< trained* > trainees; + std::vector>> trainees; std::function factory; unsigned int id; + std::default_random_engine random_engine; + std::size_t n; + public: double money; unsigned stock; + std::function> x)> q; + trainer(double money, unsigned stock, std::size_t n, std::function factory) - : factory(factory), id(0), money(money), stock(stock) + : factory(factory), id(0), money(money), stock(stock), n(n), + q([](std::shared_ptr> x){ return x->wealth; }), random_engine(std::time(0)) { add(n); } @@ -34,12 +49,7 @@ public: void add(std::size_t n, std::function factory) { for(std::size_t i = 0; i < n; i++) { - trained *trainee = new trained(); - trainee->id = ++id; - trainee->result = 0.0; - trainee->decider = factory(); - - trainees.push_back(trainee); + add(factory()); } } @@ -48,6 +58,37 @@ public: add(n, factory); } + void add(const T& decider) + { + auto trainee = std::make_shared>(); + trainee->id = ++id; + trainee->decider = decider; + + trainees.push_back(trainee); + } + + int train(std::shared_ptr> trainee, double price) + { + auto decision = trainee->decider.decide(price, trainee->monies, trainee->stock); + auto current = price*trainee->stock + trainee->monies; + auto max_credit = std::max(current * 0.05, -1e4); + + /* std::cout << "D: " << decision << " C: " << current << " P: " << price << " MC: " << max_credit << std::endl; */ + if (decision > 0 && trainee->monies - decision*price < -max_credit) { + decision = floor((trainee->monies + max_credit) / price); + } + + if (decision < 0 && -decision > trainee->stock) { + decision = -trainee->stock; + } + + trainee->stock += decision; + trainee->monies -= price*decision; + trainee->recalculate(price); + + return decision; + } + void test(std::istream& input) { for (auto trainee : trainees) { @@ -56,6 +97,7 @@ public: trainee->decider.start_money = money; trainee->decider.start_stock = stock; + trainee->decider.reset(); } double price, start; @@ -64,21 +106,7 @@ public: do { for (auto trainee : trainees) { - auto decision = trainee->decider.decide(price, trainee->monies, trainee->stock); - auto current = price*trainee->stock + trainee->monies; - auto max_credit = std::max(current * 0.05, -1e4); - - /* std::cout << "D: " << decision << " C: " << current << " P: " << price << " MC: " << max_credit << std::endl; */ - if (decision > 0 && trainee->monies - decision*price < -max_credit) { - decision = floor((trainee->monies + max_credit) / price); - } - - if (decision < 0 && -decision > trainee->stock) { - decision = -trainee->stock; - } - - trainee->stock += decision; - trainee->monies -= price*decision; + train(trainee, price); } } while (input >> price); @@ -87,13 +115,102 @@ public: std::cout << "HODL: " << hodl << " START: " << start << std::endl; std::cout << "-----------------------" << std::endl; - std::sort(trainees.begin(), trainees.end(), [=](trained *a, trained *b){ - return (a->monies + a->stock * price) > (b->monies + b->stock * price); - }); + normalize(); for (auto trainee : trainees) { - auto earned = trainee->monies + trainee->stock * price; - std::cout << "#" << trainee->id << ": " << earned << " [" << earned - hodl << "] " << trainee->stock << " akcji, " << trainee->monies << " gelda w banku. " << std::endl; + std::cout + << "#" << trainee->id << ": " << trainee->wealth + << " [" << trainee->wealth - hodl << "] (" << trainee->score << ") " + << trainee->stock << " akcji, " + << trainee->monies << " gelda w banku. " << std::endl; + } + + filter(); + breed(); + } + + void normalize() + { + std::sort(trainees.begin(), trainees.end(), [=](std::shared_ptr> a, std::shared_ptr> b){ + return q(a) > q(b); + }); + + auto high = q(*trainees.begin()); + auto low = q(*(trainees.end() - 1)); + + // best = 1, worst = 0 + for (auto t : trainees) { + t->score = (q(t) - low) / (high - low); + }; + } + + void filter() + { + /* static std::exponential_distribution distribution(0.50); */ + + /* auto random = [=](){ return 1. - std::clamp(0., distribution(random_engine), 2.)/2.1; }; */ + /* auto iterator = std::remove_if(trainees.begin(), trainees.end(), [=](std::shared_ptr> t) { */ + /* return random() > t->score; */ + /* }); */ + + trainees.erase(trainees.begin() + 49, trainees.end()); + + std::cout << "Przy życiu pozostają: "; + for (auto trainee : trainees) { + std::cout << "#" << trainee->id << " "; + } + std::cout << std::endl; + } + + void breed() + { + std::size_t diff = n - trainees.size(); + std::cout << "---------------------------------------" << std::endl; + std::cout << "W populacji brakuje " << diff << " sieci, aktualnie " << trainees.size() << "." << std::endl; + + std::vector probability; + for (auto t : trainees) { + probability.push_back(t->score); + } + + std::discrete_distribution distribution(probability.begin(), probability.end()); + std::exponential_distribution exponential(1.5); + + auto combiner = [=](const double& a, const double& b){ + auto mutation = (rand() % 2 ? -1 : 1) * exponential(random_engine); + + if (exponential(random_engine) < 1) { + return .6 * a + .4 * b + mutation; + } + + return (rand() % 2 ? a : b) + mutation; + }; + + unsigned first, second; + for (int i = 0; i < diff; i++) { + first = distribution(random_engine); + do { second = distribution(random_engine); } while (first == second); + + auto combined = trainees[first]->decider.combine(trainees[second]->decider, combiner); + std::cout << "Łączenie #" << trainees[first]->id << " z #" << trainees[second]->id << " dało #" << (id+1) << std::endl; + add(combined); + } + } + + void see_best(std::istream& stream) + { + std::shared_ptr> trainee = this->trainees[0]; + + std::cout << "price,decision" << std::endl; + double price; + + trainee->monies = money; + trainee->stock = stock; + + trainee->decider.reset(); + while (stream >> price) { + int decision = train(trainee, price); + std::cout << price << "," << decision << std::endl; } } }; diff --git a/wtf.cpp b/wtf.cpp index c789b49..6651451 100644 --- a/wtf.cpp +++ b/wtf.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "argh.h" @@ -13,40 +14,69 @@ #include "decider.h" #include "trainer.h" +using current_decider = neural_decider<24, 12, 12, 32, 16>; + int main(int argc, char* argv[]) { argh::parser args; args.add_params({"-m", "--money"}); args.add_params({"-s", "--stock"}); args.add_params({"-p", "--population"}); + args.add_params({"-n", "--iterations"}); + args.parse(argc, argv); double money; - unsigned stock, population; + unsigned stock, population, iterations; + std::string input_file; args({ "m", "money" }, 1000.) >> money; args({ "s", "stock" }, 1000) >> stock; args({ "p", "population" }, 25) >> population; + args({ "n", "iterations" }, 4) >> iterations; + args(1) >> input_file; - std::uniform_real_distribution distribution(-1.0, 1.0); - std::default_random_engine random_engine; - random_engine.seed(std::time(0)); + std::uniform_real_distribution distribution(-2.0, 2.0); + std::uniform_real_distribution bias_distribution(-16.0, 16.0); - std::function randomizer = [&](const int& i, const int& j) -> double { + std::random_device rd; + + // + // Engines + // + std::mt19937 random_engine(rd()); + + std::function randomizer = [&](const int&, const int&) -> double { + return distribution(random_engine); + }; + + std::function bias_randomizer = [&](const int&, const int&) -> double { return distribution(random_engine); }; std::function normalizer = [](const double& result) -> double { return erf(result); }; - using current_decider = neural_decider<24, 12, 12, 32, 16>; - - std::function factory = [&]() -> current_decider { + std::function factory = [&]() -> current_decider { current_decider decider(normalizer); - decider.network.fill(randomizer); + decider.network.fill(randomizer, bias_randomizer); return decider; }; trainer train(money, stock, population, factory); - train.test(std::cin); + + std::fstream input; + input.open(input_file); + + for (int i = 0; i < iterations; i++) { + input.clear(); + input.seekg(0); + + train.test(input); + } + + input.clear(); + input.seekg(0); + + train.see_best(input); }