Public
Edited
Aug 28, 2024
Insert cell
Insert cell
Insert cell
train = generateData(100)
Insert cell
XX = tf.tensor2d([[1,2,3],[4,5,6]])
Insert cell
model = {
// Create model, add layers.
const model = tf.sequential()
model.add(tf.layers.dense({
units: 2,
inputShape: [3]
}))
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
})

// Train model.
const [X, y] = train
model.fit(X, y, {
epochs: 100
})
//model.add(tf.layers.dense({units: 1, inputShape: [1]}));

// Model loss.
//model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

// Syntetic data.
//const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]);
//const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);

//model.fit(xs, ys, {epochs: 250});
return model
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
paramTypes = xTypes.map(generateParams)
Insert cell
Insert cell
Insert cell
function truncateLayer(x) {
// Extract mu and sigma.
let [mus, sigmas] = x.unstack(1)

// Expand dimensions
mus = mus.expandDims(1)
sigmas = sigmas.expandDims(1)

// Apply activations.
mus = tf.sigmoid(mus)
sigmas = tf.softplus(sigmas)
}
Insert cell
Insert cell
tf.sigmoid(MU)
Insert cell
Insert cell
tf = require("@tensorflow/tfjs")
Insert cell
ran = require("ranjs")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more