This file contains 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
const Task = require('data.task') | |
const { List, Map } = require('immutable-ext') | |
const { Pair, Sum, Intersection } = require('./monoid') | |
const { findArtist, relatedArtists } = require('./spotify') | |
const Bulk = (...xs) => ({ | |
xs, | |
concat: ys => Bulk(...xs.map( (x, idx) => x.concat(ys.xs[idx]) )), | |
bulkMap: (...fs) => Bulk(...xs.map((x, idx) => fs[idx](x))), | |
toList: _ => xs, |
This file contains 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
/* | |
- Goal: | |
implmenting something like Pair(a, b) but could accommodate any amount of arguments | |
- Usage: | |
Bulk( Sum(2), Sum(3), Sum(4) ) | |
.concat(Bulk(Sum(1), Sum(1), Sum(1))) | |
This file contains 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
const Mapp = val => ({ | |
val, | |
// {a: 'aa', b: 'bb'} | |
// f :: v -> value | |
map: f => { | |
const o = {} | |
// let resultArr = Object.keys(val).map((key, idx) => ({ [key]: f(val[key]) })) // 錯的,會變成[{}, {}] | |
Object.keys(val).map((key, idx) => o[key] = f(val[key]) ) |
This file contains 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
function weight( | |
currentWeight = 82, | |
currentRatio = 0.23, | |
targetRatio = 0.2, | |
dailyBurn = 400 | |
) { | |
const currentFat = currentWeight * currentRatio | |
const currentMuscle = currentWeight - currentFat | |
const targetWeight = currentMuscle / (1 - targetRatio) | |
const loseFat = currentWeight - targetWeight // kg |
This file contains 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
function weight( | |
currentWeight = 82, | |
currentRatio = 0.23, | |
targetRatio = 0.2, | |
dailyBurn = 400, | |
) { | |
const currentFat = currentWeight * currentRatio | |
const currentMuscle = currentWeight - currentFat | |
const targetWeight = currentMuscle / (1 - targetRatio) | |
const loseFat = currentWeight - targetWeight // kg |
This file contains 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
/* | |
Usage: | |
import SVGIcon from './Icons.jsx' | |
<SVGIcon kind='edit' style={{width: 48, height:48, fill:'green'}} /> | |
*/ | |
import React, { Component, PropTypes } from 'react' | |
// base icon style | |
const styles = { |
This file contains 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
import hyperarray from 'hyper-array' | |
import memdb from 'memdb' | |
const dag = hyperarray( memdb() ) | |
// step 1 | |
// api: array.insert(value, [before], [after], [cb=function (err, entry) {}]) | |
dag.insert( 'abc', null, null, ( err, node ) => { | |
conole.log( node ) |
This file contains 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
--[[ | |
- here's a better way to train RNNLM with large dataset, | |
- persist the weights from LookupTable into file | |
- and load it back later to use in sentiment analysis tasks | |
- detailed discussion here: https://github.com/torch/nn/issues/747 | |
- thanks @fmassa for pointing out the direct direction |
This file contains 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
local THNN = require 'nn.THNN' | |
local LookupTable, parent = torch.class('nn.LookupTable', 'nn.Module') | |
LookupTable.__version = 4 | |
-- added 3rd argument, to pass in pre-trained weights | |
function LookupTable:__init(nIndex, nOutput, odlWeights ) | |
parent.__init(self) |
This file contains 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
-- simple case to reproduce GPU crash bug | |
require 'paths' | |
require 'rnn' | |
require 'nngraph' | |
require 'cltorch' | |
require 'clnn' | |
cltorch.setDevice(1) | |
------------------------------------------------------------------------------------ |