Skip to content

Commit

Permalink
Revert "move example to a file (#110)" (#111)
Browse files Browse the repository at this point in the history
This reverts commit 399d655.
  • Loading branch information
prbzrg authored Jan 13, 2023
1 parent 399d655 commit 91ca882
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,44 @@ using Pkg
Pkg.add(url="https://github.com/impICNF/ICNF.jl")
```

See [`simple_example.jl`](examples/simple_example.jl) for a simple example of using this package.
To use this package, here is an example:

```julia
using ICNF
using Distributions, Flux
using DifferentialEquations, SciMLSensitivity

# Parameters
nvars = 1
n = 1024

# Data
data_dist = Beta(2.0, 4.0)
r = rand(data_dist, nvars, n)

# Model
nn = Chain(
Dense(nvars => 4*nvars, tanh),
Dense(4*nvars => nvars, tanh),
) |> f64
icnf = RNODE{Float64, Array}(nn, nvars; tspan=(0.0, 4.0))

# Training
using DataFrames, MLJBase
df = DataFrame(transpose(r), :auto)
model = ICNFModel(icnf; opt_app=SciMLOptApp())
mach = machine(model, df)
fit!(mach)

# Use It
d = ICNFDist(icnf)
actual_pdf = pdf.(data_dist, vec(r))
estimated_pdf = pdf(d, r)
new_data = rand(d, n)

# Evaluation
using LinearAlgebra, Distances
n1 = norm(estimated_pdf - actual_pdf, 1) / n
n2 = norm(estimated_pdf - actual_pdf, 2) / n
tv_dis = totalvariation(estimated_pdf, actual_pdf) / n
```
37 changes: 0 additions & 37 deletions examples/simple_example.jl

This file was deleted.

0 comments on commit 91ca882

Please sign in to comment.