Last active
March 5, 2020 11:52
-
-
Save jzstark/1c6aec846100454961549475cf641ba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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