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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more