MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / createPolicyNetwork

Method createPolicyNetwork

cart-pole/index.js:76–92  ·  view source on GitHub ↗

* Create the underlying model of this policy network. * * @param {number | number[]} hiddenLayerSizes Size of the hidden layer, as * a single number (for a single hidden layer) or an Array of numbers (for * any number of hidden layers).

(hiddenLayerSizes)

Source from the content-addressed store, hash-verified

74 * any number of hidden layers).
75 */
76 createPolicyNetwork(hiddenLayerSizes) {
77 if (!Array.isArray(hiddenLayerSizes)) {
78 hiddenLayerSizes = [hiddenLayerSizes];
79 }
80 this.policyNet = tf.sequential();
81 hiddenLayerSizes.forEach((hiddenLayerSize, i) => {
82 this.policyNet.add(tf.layers.dense({
83 units: hiddenLayerSize,
84 activation: 'elu',
85 // `inputShape` is required only for the first layer.
86 inputShape: i === 0 ? [4] : undefined
87 }));
88 });
89 // The last layer has only one unit. The single output number will be
90 // converted to a probability of selecting the leftward-force action.
91 this.policyNet.add(tf.layers.dense({units: 1}));
92 }
93
94 /**
95 * Train the policy network's model.

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected