Browse Source

first commit

master
Gustavo Adolfo Mesa Roldán 3 years ago
commit
a9410fd6e3
11 changed files with 697 additions and 0 deletions
  1. +4
    -0
      .formatter.exs
  2. +24
    -0
      .gitignore
  3. +21
    -0
      README.md
  4. +525
    -0
      lib/dataset.ex
  5. +70
    -0
      lib/p1.ex
  6. +29
    -0
      mix.exs
  7. +5
    -0
      mix.lock
  8. +10
    -0
      nan.csv
  9. BIN
      rand.mtx
  10. +8
    -0
      test/p1_test.exs
  11. +1
    -0
      test/test_helper.exs

+ 4
- 0
.formatter.exs View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

+ 24
- 0
.gitignore View File

@ -0,0 +1,24 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
p1-*.tar

+ 21
- 0
README.md View File

@ -0,0 +1,21 @@
# P1
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `p1` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:p1, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/p1](https://hexdocs.pm/p1).

+ 525
- 0
lib/dataset.ex View File

@ -0,0 +1,525 @@
defmodule Dataset do
def points do
[
[-0.5325013, -0.10546442],
[-1.03089824, 0.10421003],
[-0.31511768, -0.3580566 ],
[-0.12135353, -0.49380539],
[-0.09259915, -0.45908907],
[ 0.82847608, 0.30073466],
[-0.78180988, -0.78455065],
[ 0.43385777, 0.19805848],
[ 0.67322282, 0.66979336],
[-0.42003401, 0.1956628 ],
[-0.94844143, 0.09915151],
[-0.37666332, 0.97927911],
[-0.54166487, 0.01426488],
[-0.60412545, 0.70198777],
[-0.34710817, 0.3261212 ],
[-0.45912719, 0.09624041],
[-0.11578411, 1.02938317],
[-0.97705327, -0.40605477],
[-0.97606444, 0.07079185],
[ 0.23944661, -0.38289626],
[-0.26269025, 0.37961123],
[ 0.42694003, 0.11355085],
[ 0.48752156, 0.10595635],
[ 0.27625208, -0.40485168],
[-0.23859905, -0.46991893],
[ 0.01209145, 0.5998427 ],
[ 0.26996142, -0.96223409],
[-0.15091093, 0.48555064],
[ 0.36093376, -0.36683441],
[-0.52479429, -0.06742592],
[-0.79530255, 0.55092893],
[-0.85227656, 0.35729785],
[ 0.86787065, -0.57148325],
[-0.49284681, -0.87737318],
[-0.96799764, 0.39468453],
[-0.86879119, -0.40415205],
[ 0.3717826, 0.97139771],
[-0.51188624, 0.0425301 ],
[-0.37844806, -0.24383501],
[-0.39532345, 0.99878417],
[-0.83669448, 0.62752948],
[-0.29677967, -0.36734735],
[-0.09769515, -0.45139157],
[-0.574123, -0.80784837],
[-0.43040205, 0.2397863 ],
[-0.98741561, 0.04231927],
[-0.7610116, 0.64201039],
[ 0.81790536, 0.31318188],
[ 0.75883798, 0.72636825],
[ 0.1445411, -0.44627203],
[ 0.71539507, 0.6531527 ],
[-0.83810442, -0.552195, ],
[ 0.2421904, 1.00934198],
[ 0.10252954, 0.37594465],
[ 0.47269277, -0.14787488],
[ 0.97673244, 0.36481626],
[ 0.0079426, -1.03138314],
[-0.3945097, -0.36361197],
[ 0.63140021, 0.78392715],
[ 0.15340651, 0.40069593],
[-0.53124424, 0.05685945],
[ 0.16819624, -0.49486955],
[-0.93523393, -0.00883696],
[ 0.0495638, 0.536739, ],
[-0.37316092, 0.2846943 ],
[ 0.22576117, -0.46826589],
[-0.11518363, 0.45745642],
[-0.43596876, -0.33547812],
[ 0.52228563, -0.07829004],
[-0.74021626, 0.69073979],
[ 0.14143421, -0.96216474],
[-0.01232964, -0.44637732],
[ 0.03127718, 0.59255484],
[ 0.99364869, 0.27982066],
[-0.18414512, -0.99035158],
[ 0.54579185, -0.25882925],
[-0.13671296, -0.47664594],
[ 0.96293316, -0.24369943],
[ 0.22053192, 0.94049554],
[ 0.13456141, 0.96892017],
[ 0.54318483, -0.10069751],
[-0.90865032, -0.51321456],
[ 0.52426154, 0.88526869],
[-0.59509512, -0.81616855],
[-0.40528105, 0.3586756 ],
[-0.44002986, -0.31479919],
[ 0.58592072, 0.77720927],
[-0.45571474, -0.30274737],
[-0.13577566, -1.00554878],
[ 0.54534681, 0.00701705],
[ 0.58276748, 0.8282682 ],
[ 0.49214564, -0.91369578],
[-0.23883742, 0.39578519],
[-0.17179549, -0.49845162],
[ 0.96705504, 0.1774597 ],
[ 0.03558397, -0.46870657],
[ 0.38261942, -0.9385663 ],
[-0.58585572, -0.0749575 ],
[ 0.25652673, -0.97942541],
[-0.2568849, -0.96338131],
[ 0.23175292, 0.43964005],
[ 0.18793452, -0.48943807],
[-0.06038332, -0.98325349],
[-0.07991506, -0.45199567],
[-0.42355005, 0.31370069],
[ 0.75861845, -0.69828335],
[ 0.31702228, -0.29388411],
[-0.16420653, 0.96867346],
[-0.23132902, -0.41628431],
[ 0.12762936, -0.90762729],
[ 0.26127362, 0.51078398],
[-0.58859981, 0.90302169],
[ 0.44967937, 0.25823284],
[-0.90538749, -0.31421374],
[-0.44442499, 0.11615424],
[-0.98202463, -0.13272486],
[ 0.09358626, -0.95046911],
[ 0.44032686, 0.18786131],
[ 0.32878062, -0.13953035],
[ 0.32901894, 0.30503217],
[ 0.89370795, -0.43480685],
[-1.01819, 0.24834398],
[-0.43110059, -0.20234513],
[-0.25197032, -1.003905, ],
[ 0.58083042, 0.83850753],
[-0.19944479, 0.52911844],
[-0.9290056, 0.53112885],
[-0.56539956, -0.92226939],
[-0.48406081, -0.16403145],
[-0.38986359, -0.35667623],
[ 0.90234631, -0.50371304],
[-0.58862124, -0.06075657],
[ 0.9070039, 0.0985257 ],
[-0.42772243, 0.21413245],
[-0.47901835, 0.15749598],
[-0.98017141, 0.3355808 ],
[-0.22274177, -0.44705987],
[ 0.50616982, 0.01663005],
[-0.4954058, 0.77223108],
[ 0.1177808, 0.47797509],
[-0.20315252, 0.37490655],
[-0.10791302, 0.59864878],
[-0.14766524, 0.42562171],
[-0.68038827, -0.73011205],
[-0.06388193, 0.39128144],
[ 1.04393036, -0.33163864],
[ 0.60786751, 0.6877835 ],
[ 0.31852347, -0.8949132 ],
[-0.32183722, 0.31103734],
[ 0.27651201, -0.40982249],
[ 0.16349853, -1.04189845],
[ 0.45248871, -0.23900479],
[ 0.41189636, -0.17538074],
[-0.89873514, 0.53432066],
[ 0.49609358, -0.00740275],
[-0.08118801, -0.47932057],
[ 0.44645675, -0.2511372 ],
[-0.44730263, -0.83504854],
[ 0.41993049, -0.23496123],
[ 0.84224513, 0.52841239],
[ 0.65402116, -0.72440225],
[ 0.19516456, -0.58565313],
[-0.12078951, -1.01116636],
[-0.29981029, 0.95302722],
[ 0.48550252, 0.11889069],
[-0.08568355, -0.54429957],
[-0.27626113, 0.47129766],
[ 0.69212322, -0.77468622],
[ 0.05452724, -0.5365723 ],
[-0.82186748, -0.69799309],
[-0.12166907, 0.53518166],
[ 0.00646861, -0.48846653],
[-0.04968372, 0.48183614],
[-0.00895853, -0.98926047],
[ 0.44668537, -0.25006832],
[ 0.45687719, -0.2383445 ],
[-0.9933947, -0.14618752],
[-0.32158083, 0.93673544],
[-0.45007812, 0.86488038],
[ 0.84592601, -0.54471485],
[ 0.32794014, 0.31996783],
[ 0.03628921, 0.51655663],
[ 0.41693318, 0.3620207 ],
[ 0.47527562, 0.00622237],
[ 0.21832199, 0.4713744 ],
[-0.21707463, 0.42053665],
[ 0.42759703, -0.30252435],
[ 0.46146947, -0.05661769],
[-0.94303057, -0.18803561],
[ 0.86006109, -0.58366379],
[-0.45452486, -0.91237881],
[-0.09213083, -0.96162269],
[-0.68903702, 0.79204447],
[-0.27036433, -0.99218402],
[-0.48564327, -0.11028021],
[-0.48093924, -0.89760863],
[-0.01389724, -0.50723082],
[-0.39983395, -0.87774611],
[ 0.94984882, -0.30206082],
[ 0.47744817, 0.22041532],
[-0.97277573, -0.10202589],
[-0.8943491, 0.52532424],
[-0.56137384, -0.8238755 ],
[-0.28981288, -0.46007255],
[-0.04202433, 1.06536715],
[ 0.38413857, -0.3170383 ],
[-0.74135351, -0.62501631],
[-0.79495437, 0.55788132],
[-0.60223318, -0.78406689],
[ 0.37447767, 0.91523741],
[-0.96038665, 0.16348704],
[ 0.43863396, 0.27010124],
[-0.51377795, -0.15825917],
[-0.63353812, -0.72638143],
[ 0.84618954, 0.34311468],
[-0.44407294, 0.81693592],
[ 0.45045782, -0.00714345],
[-0.19552, 0.96479525],
[ 0.39005627, -0.0351411 ],
[ 0.48031017, 0.07188678],
[ 0.89063366, 0.39289139],
[-0.00182477, 1.03461596],
[-0.63097034, 0.75971012],
[ 0.82466797, 0.62392135],
[-0.41793786, -0.95270044],
[-0.47060323, 0.12448791],
[-0.9807424, -0.1946212 ],
[-0.99230384, 0.21707581],
[ 0.59542687, 0.75283945],
[ 0.21442203, -0.41052106],
[ 0.11714998, 0.92691976],
[ 0.16155368, -0.51232537],
[-0.34564237, 0.12969752],
[-0.40376296, -0.40431836],
[ 0.25030559, 0.44962345],
[ 0.65361089, -0.69684837],
[-0.91579547, 0.43000921],
[-0.28449383, -0.32211331],
[ 0.46128996, -0.20527907],
[ 0.13463228, 1.01784738],
[-0.33281962, 0.87343958],
[-0.96793209, 0.12618216],
[-0.20716901, 0.47492574],
[ 0.45119104, 0.87262055],
[ 0.42103988, 0.26977943],
[ 0.95391227, 0.13270675],
[-0.56720016, -0.22395632],
[-0.5447603, -0.83505007],
[ 0.78535098, 0.57441748],
[-0.17431307, -0.38352454],
[ 0.15973321, -0.40909346],
[-0.88880786, -0.51431967],
[ 0.48920986, -0.04923981],
[ 0.82741641, -0.39820426],
[ 0.52438692, -0.11722104],
[ 0.37499957, 0.28146171],
[-0.38863816, 0.27350276],
[-0.95438221, 0.16998895],
[ 0.8779083, -0.27194081],
[ 0.22946887, -0.41787183],
[-0.03032576, -0.56655228],
[-0.35641017, -0.27244854],
[-0.35816694, 0.34010298],
[-0.17225246, 1.03028399],
[-0.15859465, 0.50804232],
[ 0.92041803, -0.09264215],
[-0.31660714, 0.93813606],
[ 0.4983579, 0.02806904],
[ 0.71786256, -0.70708168],
[-0.86269125, -0.51707278],
[-0.44551756, 0.22430102],
[ 0.08906699, 0.50241606],
[-0.32360304, -0.37014005],
[-0.4744479, 0.89160265],
[-0.68710282, 0.72915335],
[-0.95960934, -0.22670063],
[ 0.92484015, -0.37460483],
[ 0.40312909, 0.93205487],
[-0.21085954, 0.43589094],
[-0.98273935, -0.25402639],
[ 0.80393692, 0.69369364],
[ 0.26615548, 0.41934931],
[ 0.32169521, -0.9524663 ],
[ 0.9863782, 0.02326576],
[ 0.74147614, -0.60841595],
[-0.45800385, 0.28112552],
[ 0.96996545, 0.29909113],
[-0.61333245, 0.02469482],
[ 0.70640163, -0.69325011],
[-0.79622784, 0.4980434 ],
[ 0.14627088, -0.47635931],
[ 0.9187081, 0.36820839],
[-0.46139504, 0.89091304],
[ 0.33087972, -0.31139916],
[ 0.92717089, -0.41874213],
[ 0.36760043, -0.41105423],
[ 0.02223902, -1.03867994],
[-1.01777467, 0.07365383],
[ 0.84922748, -0.50708897],
[-0.86834856, 0.36351178],
[-0.22880802, -0.37237239],
[-0.43406953, -0.21418113],
[-0.51533409, 0.01512553],
[-1.0123522, -0.01937127],
[-0.52665007, 0.79855837],
[ 0.23099497, 0.44020689],
[ 0.22219189, 0.50038773],
[-0.49258309, 0.03425801],
[ 0.29566038, -0.86242765],
[-0.39366375, -1.074555, ],
[-0.96787024, 0.25307893],
[ 0.50667537, -0.82074538],
[-0.51822489, 0.10710926],
[-0.44921841, 0.05303643],
[-0.73886997, 0.69314955],
[-0.65057682, 0.71703644],
[-0.20945833, -0.51345462],
[ 0.30609008, 1.06471504],
[-0.09309305, 0.54686873],
[ 0.96025353, -0.31033075],
[ 0.31517469, 0.41222027],
[ 0.41769918, 0.91967136],
[-0.45151904, -0.16951853],
[ 0.21247612, 0.8504553 ],
[-0.20391758, 0.50464171],
[-0.08541841, 1.01085682],
[ 0.33593558, 0.28795526],
[ 0.51668183, 0.20712812],
[-0.06924072, -0.47242807],
[ 0.42079655, 0.23820894],
[-0.9344785, -0.14123171],
[-0.57763955, 0.70261927],
[-0.3660437, -0.28365349],
[ 0.79889393, 0.56500084],
[-0.03456715, 0.49169356],
[ 0.40800764, -0.41346366],
[ 0.43494946, 0.26798698],
[-1.01703845, -0.02033391],
[ 0.81301823, 0.5390611 ],
[-0.30196818, 0.298894, ],
[-0.33178443, -0.95078685],
[ 0.31984598, 0.41224372],
[ 0.69018948, -0.75406348],
[-0.47513385, 0.28280982],
[ 0.30685279, -0.41001356],
[ 0.31300529, 0.92291165],
[ 0.21129878, 0.4830463 ],
[-0.43525786, -0.16989984],
[-0.66350184, 0.68843679],
[ 0.16598471, 1.02260722],
[ 0.87590374, -0.45871588],
[ 0.98802762, -0.20959987],
[ 0.2946845, 0.40364272],
[ 0.23297838, 0.46902684],
[-0.93629187, -0.17731698],
[ 0.29858807, 0.34620909],
[ 1.03126084, 0.04906038],
[ 0.83817148, 0.5116337 ],
[ 0.11611717, -0.48328294],
[-0.35143062, 0.413936, ],
[ 0.95840071, -0.13788289],
[-0.57859261, -0.77514727],
[ 0.44681125, -0.17561609],
[-0.44657736, 0.33828908],
[ 0.84502113, -0.6548427 ],
[ 0.64426153, 0.72385296],
[-0.82842061, -0.63703804],
[-0.19140246, -0.94005486],
[-0.0345652, 1.10181154],
[ 0.38856967, -0.89150151],
[ 0.16720914, -1.01583614],
[ 0.35418516, 0.37967449],
[ 1.02780127, -0.02547819],
[-0.49147412, -0.12839289],
[ 0.01867718, -0.45840924],
[ 0.97073934, -0.03255511],
[ 0.16505591, 0.57466849],
[-0.52292984, 0.10659379],
[-0.42163614, 0.11793506],
[ 0.29534966, 0.30767257],
[ 1.00258748, 0.01269169],
[ 0.46836874, 0.05632969],
[-0.70823736, -0.5951114 ],
[ 0.2197343, -0.35281448],
[ 0.01135213, 0.90159057],
[ 0.67604229, 0.76307088],
[ 0.53038591, 0.09035955],
[-0.92222064, -0.19975847],
[ 0.3348529, 0.93270264],
[ 0.02423675, 0.48230342],
[ 0.99565512, -0.05089649],
[ 1.01075032, 0.17356185],
[-0.44100394, -0.23030097],
[ 0.17723448, 0.45018016],
[-0.57498532, -0.79136461],
[-0.04583653, 0.50684066],
[ 0.62783871, -0.80982707],
[-0.2886327, 0.48508333],
[-0.35740045, 0.14167708],
[ 0.58218001, -0.71712762],
[ 0.47194604, -0.0606402 ],
[ 1.0386677, 0.12939339],
[-0.21525902, -0.41727025],
[-0.12301102, 0.92771655],
[-0.02901619, 1.01289595],
[ 0.42328611, -0.39489215],
[ 0.30874463, -0.97231875],
[-0.49016363, 0.09178597],
[-0.3578761, 0.91719369],
[-0.37167518, 0.41351493],
[-0.90585523, -0.32492316],
[ 0.3679306, 0.3024018 ],
[ 0.82852207, 0.4780269 ],
[-0.397282, -0.37048457],
[ 0.61125852, -0.15441117],
[ 0.3572959, -0.87835492],
[-0.1016792, -0.42701253],
[ 0.30922577, 0.40096744],
[ 0.05916747, 1.00322031],
[-0.39874222, 0.07100978],
[ 1.0311691, -0.25989564],
[-0.12461699, -0.46932353],
[ 0.95309764, 0.37724383],
[-0.18960253, 0.39298609],
[-0.29031817, -0.36910673],
[-0.12044893, -0.97674356],
[ 0.24943959, 0.46200549],
[-0.81240344, 0.58417264],
[-0.15950194, 0.98644134],
[ 0.49570081, -0.25478917],
[ 0.56714786, -0.89846318],
[ 0.4414358, -0.12094953],
[-0.27453589, 0.3366278 ],
[-0.80117088, -0.46938304],
[ 0.43888598, -0.9532389 ],
[-0.49589207, 0.2551496 ],
[ 0.54494184, 0.13740967],
[-0.85175513, -0.48948809],
[ 0.42700408, 0.12846901],
[ 0.07371483, -0.48883402],
[-0.02967158, -0.48088284],
[ 0.28682932, 0.54458344],
[ 0.35430111, -0.16498733],
[ 0.57324065, -0.00299866],
[ 0.36013317, 0.98449938],
[-0.29926555, -0.55836183],
[ 0.73620054, 0.59527209],
[-0.42176839, -0.27286968],
[ 0.08656501, 0.56033103],
[-0.71537595, -0.60981537],
[ 0.0174128, -0.94908365],
[-0.43482281, 0.01970927],
[-0.4252309, 0.15997692],
[ 0.30233024, -0.51959534],
[-0.5844854, -0.67077001],
[-0.4577354, -0.12944845],
[ 0.98788159, -0.14323993],
[ 0.96323327, 0.10613243],
[ 0.39377378, 0.13654553],
[ 0.21416166, -1.03103197],
[ 0.27792489, -0.31814482],
[ 0.38051259, 0.34131862],
[ 0.31522577, -0.39487902],
[ 0.41128124, -0.13757233],
[-0.16784203, 0.51267151],
[ 0.75255735, -0.70933455],
[ 0.67170449, 0.8015983 ],
[-0.95245337, -0.02915512],
[-0.11927045, 0.40845872],
[ 1.01173811, 0.20254304],
[ 0.52463484, 0.83718677],
[ 0.4592856, 0.14176783],
[-0.47451611, -0.05559986],
[-0.48341025, 0.03389592],
[ 0.45427327, -0.86182084],
[-0.52507114, 0.24720005],
[ 0.48156686, -0.84924333],
[ 0.98942581, -0.19631589],
[ 0.10917524, 0.46789101],
[-0.43150212, -0.30304845],
[ 0.09338009, 0.61504489],
[-1.01251134, -0.03696613],
[-0.42105177, -0.11245212],
[-0.92896073, 0.42776565],
[-0.96852935, -0.55143461],
[-1.02042043, 0.43510767],
[-0.31217992, -1.00424276],
[ 0.86473193, 0.46134096],
[ 0.02312012, -0.50194704],
[ 0.25482831, -0.37211935],
[ 0.55104743, -0.0178762 ],
[ 0.74376232, -0.68960353],
[ 0.06083883, -0.4560167 ],
[ 0.3275584, -0.34934625],
[ 0.93601654, -0.36773889],
[-0.37107383, -0.30496097],
[ 0.06516518, 1.05044067],
[-0.27092698, -0.9199523 ],
[ 0.10640571, -0.40470704],
[-0.49435476, 0.8573168 ]
]|> Matrex.new
end
def values do
[[
1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0,
0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0,
1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0,
1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1,
0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1,
0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1,
0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1,
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0
]] |> Matrex.new
end
end

+ 70
- 0
lib/p1.ex View File

@ -0,0 +1,70 @@
defmodule P1 do
@moduledoc """
Documentation for `P1`.
"""
@doc """
Run to start app.
"""
@p 2
@topology Matrex.new([[@p, 4, 8, 1]])
def start do
IO.puts inspect create_nn(@topology)
# Matrex.zeros(50)
# |> set_points(Dataset.points |> Matrex.multiply(20) |> Matrex.add(Matrex.new(500, 2, fn -> 25 end)), Dataset.values)
# |> Matrex.heatmap(:color24bit)
Matrex.zeros(10)
|> set_graph(linspace(-5, 5, 10) |> Matrex.new)
|> Matrex.heatmap(:color24bit)
end
def set_points(m, points, values) do
Enum.reduce(1..Enum.count(values), m, fn p, acc ->
x = trunc(points[p][1])
y = trunc(points[p][2])
Matrex.set(acc, x, y, values[p]+2)
end)
end
def set_graph(m, points) do
size = Enum.count(points)
Enum.reduce(1..size, m, fn p, acc ->
Matrex.set(acc,
size - trunc(sigm(trunc(points[p]))* size),
p, 1)
end)
end
def neural_layer(n_conn, n_neur) do
%{
b: Matrex.random(1, n_neur),
w: Matrex.random(n_conn, n_neur)
}
end
def create_nn(topology) do
for n <- 1..Enum.count(topology)-1, do: neural_layer(trunc(topology[n]), trunc(topology[n+1]))
end
# def train(neural_net, X, Y, l2_cost, lr=0.5, tra) do
def sigm(x) do
1 / (1 + Math.pow(Math.e, (-x)))
end
def sigm_i(x) do
x * (1 - x)
end
def cost(yp, yr) do
np.mean((yp - yr) ** 2)
end
def linspace(min, max, size) do
delta = (max - min) / (size - 1)
[[min] ++ (for n <- 1..size-1, do: min + (delta * n))]
end
end

+ 29
- 0
mix.exs View File

@ -0,0 +1,29 @@
defmodule P1.MixProject do
use Mix.Project
def project do
[
app: :p1,
version: "0.1.0",
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
# mod: {P1, []},
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:matrex, "~> 0.6"},
{:math, "~> 0.4.0"}
]
end
end

+ 5
- 0
mix.lock View File

@ -0,0 +1,5 @@
%{
"elixir_make": {:hex, :elixir_make, "0.6.1", "8faa29a5597faba999aeeb72bbb9c91694ef8068f0131192fb199f98d32994ef", [:mix], [], "hexpm"},
"math": {:hex, :math, "0.4.0", "301132614d02f0d17c71ff20a7b260ff542606403972e261ec25dc79d7d17558", [:mix], [], "hexpm"},
"matrex": {:hex, :matrex, "0.6.8", "ccb491e661bae7931ee6b0e68f5e1cd28528e5360a59bc3ab4d759b89be1701e", [:make], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
}

+ 10
- 0
nan.csv View File

@ -0,0 +1,10 @@
16.0,Inf,Inf,Inf,Inf,16.0,Inf,Inf,Inf,Inf,
Inf,4.0,Inf,Inf,Inf,Inf,4.0,Inf,Inf,Inf,
Inf,Inf,12.0,Inf,Inf,Inf,Inf,12.0,Inf,Inf,
Inf,Inf,Inf,25.0,Inf,Inf,Inf,Inf,25.0,Inf,
Inf,Inf,Inf,Inf,8.0,Inf,Inf,Inf,Inf,8.0,
16.0,Inf,Inf,Inf,Inf,16.0,Inf,Inf,Inf,Inf,
Inf,4.0,Inf,Inf,Inf,Inf,4.0,Inf,Inf,Inf,
Inf,Inf,12.0,Inf,Inf,Inf,Inf,12.0,Inf,Inf,
Inf,Inf,Inf,25.0,Inf,Inf,Inf,Inf,25.0,Inf,
Inf,Inf,Inf,Inf,8.0,Inf,Inf,Inf,Inf,8.0,

BIN
rand.mtx View File


+ 8
- 0
test/p1_test.exs View File

@ -0,0 +1,8 @@
defmodule P1Test do
use ExUnit.Case
doctest P1
test "greets the world" do
assert P1.hello() == :world
end
end

+ 1
- 0
test/test_helper.exs View File

@ -0,0 +1 @@
ExUnit.start()

Loading…
Cancel
Save