Platform
Resources
Pricing
Sign in
Get started
Enys Mones
data scientist at codescene
Workspace
Fork
Public
By
Enys Mones
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
train
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
XX
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
model
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
y_pred
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
xTypes
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generateParams
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
paramTypes
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generateY
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generateData
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
truncateLayer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
MU
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tf
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ran
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML