synaptic icon indicating copy to clipboard operation
synaptic copied to clipboard

from.connected is not a function

Open elipticOrbit opened this issue 9 years ago • 7 comments

This looks like a great project, but:

When attempting the tutorial code, I keep getting this error: from.connected is not a function

I'm trying to run directly in the browser.

elipticOrbit avatar Mar 26 '17 09:03 elipticOrbit

What code are you exactly running? We can't help you if we don't no what is going wrong...

wagenaartje avatar Mar 26 '17 12:03 wagenaartje

Thanks for your reply

I'm running html/js code with the html loading synaptic as follows:

The javascript is as follows: var Neuron = synaptic.Neuron, Layer = synaptic.Layer, Network = synaptic.Network, Trainer = synaptic.Trainer, Architect = synaptic.Architect; var myNetwork = new Architect.Perceptron(2, 2, 1);

elipticOrbit avatar Mar 26 '17 15:03 elipticOrbit

Seems to working fine here... jsfiddle

wagenaartje avatar Mar 26 '17 17:03 wagenaartje

Thanks for your trouble - after reviewing your fiddle, I realised that when i comment out one of the js files that was I loading in my project - which does some prototype changing - it works.

I have tracked down the specific overloads / prototype changes that created the conflict. I am pasting here in case other coders are using these overloads. There were two conflicting codeblocks: // Number 1 /////////////////////////////////////////////////////// if (!Array.prototype.joinWith) { +function () { Array.prototype.joinWith = function(that, by, select, omit) { var together = [], length = 0; if (select) select.map(function(x){select[x] = 1;}); function fields(it) { var f = {}, k; for (k in it) { if (!select) { f[k] = 1; continue; } if (omit ? !select[k] : select[k]) f[k] = 1; } return f; } function add(it) { var pkey = '.'+it[by], pobj = {}; if (!together[pkey]) together[pkey] = pobj, together[length++] = pobj; pobj = together[pkey]; for (var k in fields(it)) pobj[k] = it[k]; } this.map(add); that.map(add); return together; } }(); }

// Number 2 ////////////////////////////////////////////////////////// Array.prototype.clone = function() { return jQuery.extend(true, [], this); };

Many thanks for your help. This is an excellent library!

elipticOrbit avatar Mar 26 '17 18:03 elipticOrbit

I'm seeing the same error with EmberJS, which seems to alter the built-in Array. This creates a __proto__ attribute in any array that will also get iterated over when you do for (var x in y).

I would like to see synaptic drop the use of for (var x in y) for iterating over arrays (layers, neurons, etc.), since it is generally not recommended. See discussion here, for example: https://stackoverflow.com/a/500531/1571826

nicodv avatar Jun 15 '17 03:06 nicodv

I have actually created a PR yesterday that removes all those incorrect loops. So stay tuned :)

wagenaartje avatar Jun 15 '17 05:06 wagenaartje

That's awesome news. I see it's been merged. Bedankt!

nicodv avatar Jun 16 '17 03:06 nicodv