-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Fix bugs under loading networks 2. separate weights initialization module
- Loading branch information
Showing
11 changed files
with
150 additions
and
121 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
gen_layers.js | ||
|
||
zws5.js | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
// syntactic sugar function for getting default parameter values | ||
function getopt(opt, field_name, default_value) { | ||
if (typeof field_name === 'string') { | ||
// case of single string | ||
return (typeof opt[field_name] !== 'undefined') ? opt[field_name] : default_value; | ||
} else { | ||
// assume we are given a list of string instead | ||
var ret = default_value; | ||
for (var i = 0; i < field_name.length; i++) { | ||
var f = field_name[i]; | ||
if (typeof opt[f] !== 'undefined') { | ||
ret = opt[f]; // overwrite return value | ||
} | ||
} | ||
return ret; | ||
} | ||
} | ||
|
||
function load_opt(self, opt) { | ||
|
||
// required is a list of string | ||
opt.required.forEach(function(key) { | ||
if (typeof opt[key] !== 'undefined') { | ||
self[key] = opt[key]; | ||
} else { | ||
console.error('cannot find necessary value of "' + key +'"'); | ||
} | ||
}); | ||
|
||
opt.optional.forEach(function(pair) { | ||
let v = pair.find(x => typeof x !== 'undefined') | ||
pair.forEach(function(key) { | ||
self[key] = v; | ||
}); | ||
}); | ||
|
||
// pair is a list whose values should be same | ||
opt.bind.forEach(function(pair) { | ||
let v = pair.find(x => typeof opt[x] !== 'undefined') | ||
pair.forEach(function(key) { | ||
self[key] = v; | ||
}); | ||
}); | ||
|
||
|
||
|
||
} | ||
|
||
export { | ||
randf, | ||
randi, | ||
randn, | ||
zeros, | ||
maxmin, | ||
randperm, | ||
weightedSample, | ||
arrUnique, | ||
arrContains, | ||
getopt, | ||
assert, | ||
indexOfMax | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { randn } from 'util.js'; | ||
|
||
// weight normalization is done to equalize the output | ||
// variance of every neuron, otherwise neurons with a lot | ||
// of incoming connections have outputs of larger variance | ||
|
||
function norm_weights(V) { | ||
let scale = Math.sqrt(1.0 / V.size); | ||
for (let i = 0; i < n; i++) V.w[i] = randn(0.0, scale); | ||
} | ||
|
||
function get_norm_weights(size) { | ||
let scale = Math.sqrt(1.0 / size); | ||
let w = new Array(size) | ||
for (let i = 0; i < size; i++) w[i] = randn(0.0, scale); | ||
return w; | ||
} | ||
|
||
export { norm_weights, get_norm_weights }; |