概要
convnet.jsの作法を調べる。
convnetjs.Vol
基本単位
ネットへの入力、出力に使用する。
sx,syは、shapeサイズ。
depthは、length.
wは、value.
dwは、weight.
例 var x = new convnetjs.Vol([0, 1, 2, 3, 4]);
+ * : object = [object Object]
| + sx : number = 1
| + sy : number = 1
| + depth : number = 5
| + w : object = 0,1,2,3,4
| + dw : object = 0,0,0,0,0
| + get : function = function (x, y, d) {
var ix = ((this.sx * y) + x) * this.depth + d;
return this.w[ix];
}
| + set : function = function (x, y, d, v) {
var ix = ((this.sx * y) + x) * this.depth + d;
this.w[ix] = v;
}
| + add : function = function (x, y, d, v) {
var ix = ((this.sx * y) + x) * this.depth + d;
this.w[ix] += v;
}
| + get_grad : function = function (x, y, d) {
var ix = ((this.sx * y) + x) * this.depth + d;
return this.dw[ix];
}
| + set_grad : function = function (x, y, d, v) {
var ix = ((this.sx * y) + x) * this.depth + d;
this.dw[ix] = v;
}
| + add_grad : function = function (x, y, d, v) {
var ix = ((this.sx * y) + x) * this.depth + d;
this.dw[ix] += v;
}
| + cloneAndZero : function = function () {
return new Vol(this.sx, this.sy, this.depth, 0.0)
}
| + clone : function = function () {
var V = new Vol(this.sx, this.sy, this.depth, 0.0);
var n = this.w.length;
for (var i = 0; i < n; i++)
{
V.w[i] = this.w[i];
}
return V;
}
| + addFrom : function = function (V) {
for (var k = 0; k < this.w.length; k++)
{
this.w[k] += V.w[k];
}
}
| + addFromScaled : function = function (V, a) {
for (var k = 0; k < this.w.length; k++)
{
this.w[k] += a * V.w[k];
}
}
| + setConst : function = function (a) {
for (var k = 0; k < this.w.length; k++)
{
this.w[k] = a;
}
}
| + toJSON : function = function () {
var json = {}
json.sx = this.sx;
json.sy = this.sy;
json.depth = this.depth;
json.w = this.w;
return json;
}
| + fromJSON : function = function (json) {
this.sx = json.sx;
this.sy = json.sy;
this.depth = json.depth;
var n = this.sx * this.sy * this.depth;
this.w = global.zeros(n);
this.dw = global.zeros(n);
for (var i = 0; i < n; i++)
{
this.w[i] = json.w[i];
//this.dw[i] = json.dw[i];
}
}
調査したコード
function print_r(obj) {
var count_obj = 0;
function _output(str) {
document.writeln(str);
}
function _print_r(obj, name, level) {
var s = "";
if (obj == undefined || level > 1) return;
for (var i = 0; i < level; i++)
{
s += " | ";
}
s += " + " + name + " : " + typeof(obj) + " = " + obj;
_output(s);
if (name == "document" || typeof(obj) != "object") return;
for (key in obj)
{
if (count_obj++ > 100) return;
_print_r(obj[key], key, level + 1);
}
}
document.writeln("<textarea cols=80 rows=40>");
_print_r(obj, "*", 0);
document.writeln("</textarea>");
}
var x = new convnetjs.Vol([0, 1, 2, 3, 4]);
print_r(x);
成果物
以上。