Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Neuron basics</h1>

<p>A neuron is basically the sum of its input synapses. As such, all we need to calculate whether or not a neuron will fire at any given moment is the threshold and a collection of synapses, each with a weight and value.</p>

<p>Using that representation, a simple function can take a neuron's synapses and a threshold as inputs, sum the results, and determine whether or not to fire.</p>
              
            
!

CSS

              
                
              
            
!

JS

              
                /*
A neuron is basically the sum of its synapses.
Along with a trigger threshold, that's all we need to calculate
whether or not it will trigger at any given moment:
*/
const neuron = ({ synapses = [], threshold = 1 } = {}) => ({
  synapses,
  threshold
});

/*
Each synapse has a weight from 0 to 1, and a current value from -1 to +1.
*/
const synapse = ({ weight = .1, value = 0 } = {}) => ({
  weight, value
});

/*
A simple function can take a neuron's threshold and 
synapses as input, sum the results, and determine
whether or not to fire.
*/
const shouldTrigger = ({ threshold, synapses }) => {
  const sum = synapses.reduce(
    (amplitude, { weight, value }) => amplitude + (weight * value), 0);
  return sum >= threshold;
}

const neuron1 = neuron({ synapses: [
    synapse({ value: -.2 }),
    synapse({ weight: 0, value: 1 }), // no effect
    synapse({ weight: .5, value: .8})
  ],
  threshold: .3
});

// Identical except for the threshold
const neuron2 = neuron({ synapses: [
    synapse({ value: -.2 }),
    synapse({ weight: 0, value: 1 }), // no effect
    synapse({ weight: .5, value: .8})
  ],
  threshold: .5
});

const willTriggerN1 = shouldTrigger(neuron1); // true
const willTriggerN2 = shouldTrigger(neuron2); // false

console.log(`
  ${ willTriggerN1 }
  ${ willTriggerN2 }
`);
              
            
!
999px

Console