简体   繁体   中英

Erlang spawn process error (artificial neural network)

Hi Erlang beginner here trying to implement a basic ANN (artificial neural network) following this tutorial from Wil Chung. The code is exactly as in his github repo .

Running this:

1> ann_test:run().

causes a bunch (five to be precise) errors like this:

=ERROR REPORT==== 18-Feb-2015::07:11:49 === Error in process <0.60.0> with exit value: {undef,[{ann,perceptron,[[],[],[]],[]}]}
=ERROR REPORT==== 18-Feb-2015::07:11:49 === Error in process <0.61.0> with exit value: {undef,[{ann,perceptron,[[],[],[]],[]}]}

Somehow spawning the processes here in ann_test.erl :

X1_pid = spawn(ann, perceptron, [[],[],[]]),

causes the trouble but I'm not sure how to trace it. Tried locating the issue with redbug pointing it at ann_test:run and ann:perceptron but it doesn't show anything. Also tried adding process_flag(trap_exit, true) into run() but nothing again. Also tried adding -compile(export_all) just in case.

Could anyone point me into right direction? Many thanks.

This code is bugged. This error means that there is no exported function ann:perceptron/3 which matches arguments. There is only ann:perceptron/4 . It is used properly in ann_test:setup/0 so to fix it, just add another empty list:

run() -> 
  ann_graph:start(),
  X1_pid = spawn(ann, perceptron, [[],[],[]]),
  X2_pid = spawn(ann, perceptron, [[],[],[]]),
  H1_pid = spawn(ann, perceptron, [[],[],[]]),
  H2_pid = spawn(ann, perceptron, [[],[],[]]),

  O_pid = spawn(ann, perceptron,  [[],[],[]]),

change to:

run() -> 
  ann_graph:start(),
  X1_pid = spawn(ann, perceptron, [[],[],[],[]]),
  X2_pid = spawn(ann, perceptron, [[],[],[],[]]),
  H1_pid = spawn(ann, perceptron, [[],[],[],[]]),
  H2_pid = spawn(ann, perceptron, [[],[],[],[]]),

  O_pid = spawn(ann, perceptron,  [[],[],[],[]]),

Note that this code doesn't clean after execution and there are errors after eventual re-execution in the same session. To kill registered process ann_grapher you can use exit(whereis(ann_grapher), kill).

You can read this error message {undef,[{ann,perceptron,[[],[],[]],[]}]} this way:

  • there is no function ( undef )
  • in module ann
  • called perceptron
  • that takes three arguments, which all are empty lists [[], [], []]

And that is correct, because there is only one definition, which takes 4 arguments, not three. In ann_test:setup , perceptron is spawned with four empty lists. You could try that.

In other words, the tuple inside the error massege has structure {Module, Function, ListOfArguments, NotSureWhatThatIs}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM