Skip to content

Instantly share code, notes, and snippets.

@jzstark
Last active March 5, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzstark/1c6aec846100454961549475cf641ba7 to your computer and use it in GitHub Desktop.
Save jzstark/1c6aec846100454961549475cf641ba7 to your computer and use it in GitHub Desktop.
open Owl
open Algodiff.D
let rec desc ?(eta=F 0.01) ?(eps=1e-6) f x =
let g = (diff f) x in
if (unpack_flt g) < eps then x
else desc ~eta ~eps f Maths.(x - eta * g)
let _ =
let f = Maths.sin in
let y = desc f (F (Stats.std_uniform_rvs ())) in
Owl_log.info "argmin f(x) = %g" (unpack_flt y)
open Owl
open Algodiff.D
let rec newton ?(eta=F 0.01) ?(eps=1e-6) f x =
let g, h = (gradhessian f) x in
if (Maths.l2norm' g |> unpack_flt) < eps then x
else newton ~eta ~eps f Maths.(x - eta * g *@ (inv h))
let _ =
let f x = Maths.(cos x |> sum') in
let y = newton f (Mat.uniform 1 2) in
Mat.print y
let _, ys = Ode.odeint custom_solver f y0 tspec ()
import numpy as np
import onnxruntime as rt
sess = rt.InferenceSession("test.onnx")
input_name_x = sess.get_inputs()[0].name
input_name_shape = sess.get_inputs()[0].shape
input_x = np.ones(input_name_shape , dtype="float32")
pred_onx = sess.run(None, {input_name_x: input_x})[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment