Last active
June 7, 2019 15:46
-
-
Save rikyperdana/0695f28d980b20a0d67eb628ce6fb938 to your computer and use it in GitHub Desktop.
Re-engineered version of adadgio:neural-data-normalizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Neural Data Normalizer by utilizing recursion | |
| # Works well for Synaptic JS | |
| # But require list of strings to be defined beforehand | |
| # Written in LiveScript and with lodash methods | |
| obj = name: \workout, duration: 120, tags: <[gym weights]> | |
| opts = | |
| <[sleep lunch workout]> | |
| <[romance bed wine salad weights gym]> | |
| normalize = (opts = [[]], obj) -> | |
| binarize = (word) -> | |
| selections = opts.find -> it.find -> it is word | |
| [til selections.length]map (i) -> | |
| if selections[i] is word then 1 else 0 | |
| combine = (arr) -> [til arr.0.length]map (i, j) -> | |
| cond = arr.find -> it.find (k, l) -> | |
| _.every [(k is 1), (l is j)] | |
| if cond then 1 else 0 | |
| decimalize = -> it / Math.pow 10, 10 | |
| recurse = (val) -> | |
| if _.isString val then binarize val | |
| else if _.isNumber val then decimalize val | |
| else if _.isArray val then combine val.map -> recurse it | |
| else if _.isObject val then _.map val, -> recurse it | |
| recurse obj | |
| console.log _.flatten normalize opts, obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment