question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Network.evolve() crash at start: "TypeError: Cannot read property 'join' of undefined"

See original GitHub issue

Description

This may be pilot error, but I can’t figure out what’s going wrong.

Network.evolve() (v0.3.12+) crashes immediately with the error:

Trace: TypeError: Cannot read property ‘join’ of undefined at new c (/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:128039) at p.evolve (/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:92265)

Files

carrot.commonjs2.min.js (carrot.commonjs2.js)

To Reproduce

The confusing thing is that Network.evolve() will run the XOR example, even using the same options for when it fails. I include the XOR test in the same code as the failing evolve.

When it fails, it’s evolving a network of >1500 inputs and 3 outputs, as opposed to the XOR’s 2-in, 1-out.

An example of the options passed to evolve() is below. Note that the options are generated randomly, but still fails consistently:

EVOLVE OPTIONS ├─ activation: IDENTITY ├─ amount: 1 ├─ clear: true ├─ cost: BINARY ├─ efficient_mutation: true ├─ elitism: 2 ├─ equal: true ├─ error: 0.03 ├─ growth: 0.00009019971047429265 ├─ iterations: 10 ├─ log: 1 ├─ mutation: FFW ├─ mutation_amount: 1 ├─ mutation_rate: 0.5762620321953104 ├─ popsize: 50 ├─ population_size: 50 ├─ provenance: 0 ├─ schedule │ └─ iterations: 1 └─ threads: 1

Also note that activation, cost, mutation and schedule values are converted to the proper functions/array before evolve().

I’ve checked and double-checked the input data set for proper formatting and data types.

I don’t have this problem using 0.3.11.

I think the problem is in the TestWorker function:

function TestWorker (serialized_dataset, cost_function) {
  // find out if in inspect mode. if so then run children in inspect mode as well
  const argv = process.execArgv.join();
  const is_debug = argv.includes('inspect') || argv.includes('debug');
  if (is_debug) {
    this.worker = cp.fork(path.join(__dirname, '/worker'), [], {
      execArgv: ['--inspect=' + (fork_port++)],
    });
  } else {
    this.worker = cp.fork(path.join(__dirname, '/worker'));
  }

  const cost_is_standard = cost_function.name in standard_cost_functions;
  
  // send the initialization (ie 'constructor') info
  this.worker.send({
      serialized_dataset: serialized_dataset,
      cost_function: cost_is_standard ? cost_function.name : cost_function.toString(),
      cost_is_standard,
    });
}

specifically:

const argv = process.execArgv.join();

where process.execArgv is undefined.

I notice that lots of restructuring happened from 0.3.11 to 0.3.12. Is there something that I need to do to make sure the module is (re)built?

Any help appreciated! Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tracycollinscommented, Sep 18, 2019

I’ll try the update. If it still fails, I’ll post some code.

Thanks for the quick reply!

0reactions
christianechevarriacommented, Sep 27, 2019

Confirmed working as of v0.3.16 using this test:

const neataptic = require("neataptic");
const carrot = require("@liquid-carrot/carrot");

async function main(){

  const numInputs = 2;
  const numOutputs = 1;

  const carrot_network = new carrot.Network(numInputs, numOutputs);
  const npt_network = new neataptic.Network(numInputs, numOutputs);

  const trainingSet = [];

  for(let j=0; j<5; j++){

    const datum = {};
    datum.input = [];
    datum.output = [];

    for(let i=0; i<numInputs; i++){
      const inputValue = Math.round(Math.random());
      datum.input.push(inputValue);
    }

    for(let i=0; i<numOutputs; i++){
      const outputValue = Math.round(Math.random());
      datum.output.push(outputValue);
    }

    trainingSet.push(datum);
  }

  console.log("trainingSet\n" , trainingSet);

  const carrot_options = {
    mutation: carrot.methods.mutation.FFW,
    error: 0.05,
    equal: true,
    elitism: 5,
    mutation_rate: 0.5,
    iterations: 10,
    log: 1,
    threads: 1,
  };

  const npt_options = {
    mutation: neataptic.methods.mutation.FFW,
    error: 0.05,
    equal: true,
    elitism: 5,
    mutation_rate: 0.5,
    iterations: 10,
    log: 1,
    threads: 1,
  };

  console.log("neataptic options\n" , npt_options);

  try{
    const npt_results = await npt_network.evolve(trainingSet, npt_options)
    console.log("neataptic results\n", npt_results);
    console.log("network.activate(trainingSet[0]: " + npt_network.activate(trainingSet[0].input) + ")");
  } catch(err){
    console.trace(err);
    throw err;
  }

  console.log("carrot options\n" , carrot_options);

  try{
    const carrot_results = await carrot_network.evolve(trainingSet, carrot_options)
    console.log("carrot results\n", carrot_results);
    console.log("network.activate(trainingSet[0]: " + carrot_network.activate(trainingSet[0].input) + ")");
    return;
  } catch(err){
    console.trace(err);
    throw err;
  }

}

main();

Noting here that carrot is quite a bit slower than neataptic right now (converges in less generations though). The main culprit is likely Lodash’s deepClone method inside of Network.clone which used heavily in .evolve – working on resolving this by solving https://github.com/liquidcarrot/carrot/issues/152

The approach in https://github.com/liquidcarrot/carrot/issues/152#issuecomment-527934142 is the likely go-to

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'join' of undefined · Issue #3050 · netlify/cli
◈ Loaded function test. ◈ Functions server is listening on 56559 ◈ Starting Netlify Dev with Create React App. However when I hit...
Read more >
Cannot read property 'join' of undefined in Javascript file ...
I do not use webpack or anything else before running my code. I just type "npm start" at the terminal and it runs...
Read more >
Cannot read property 'join' of undefined" but VS code returns ...
Yup, you need to return an array. I'd guess that hankerrank is trying to use .join() on your returned value behind the scenes...
Read more >
Node.js v19.3.0 Documentation
closeSync(); dir.path; dir.read(); dir.read(callback); dir. ... CORS is never checked on the destination server; Cannot load non-network dependencies ...
Read more >
The 10 Most Common JavaScript Issues Developers Face
Uncaught TypeError: undefined is not a function. Why? It's all about context. The reason you get the above error is because, when you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found