예제 #1
0
파일: jax2tf_test.py 프로젝트: wayfeng/jax
 def test_jit(self):
     f_jax = jax.jit(lambda x: jnp.sin(jnp.cos(x)))
     self.ConvertAndCompare(f_jax, 0.7)
예제 #2
0
 def f2(x):
   y = 2 * np.sin(x)
   z = api.remat(lambda x: np.cos(x) * np.sin(y))(x)
   return z
예제 #3
0
파일: Problem_8.py 프로젝트: leakec/tfc
# Create the loss function:
ur = egrad(u, 1)
u2r = egrad(ur, 1)
u2th = egrad(egrad(u, 2), 2)
L = lambda xi: u2r(xi, *x) + 1. / x[0] * ur(xi, *x) + 1. / x[0]**2 * u2th(
    xi, *x)

# Solve the problem:
xi = np.zeros(H(*x).shape[1])
xi, it, time = NLLS(xi, L, timer=True)

# Print out statistics:
print("Solution time: {0} seconds".format(time))

# Plot the solution:
R, Th = np.meshgrid(np.linspace(r0, rf, 50), np.linspace(th0, thf, 200))
dark = (R.flatten(), Th.flatten())

X = R * np.cos(Th)
Y = R * np.sin(Th)
U = u(xi, *dark).reshape((200, 50))
p = MakePlot("x", "y", zlabs="u(x,y,g(x,y))")
p.Surface(x=X, y=Y, z=U, showscale=False)
p.show()

# Plot the error
err = np.abs(realSoln(R, Th) - U)
p = MakePlot("x", "y", zlabs="Error")
p.Surface(x=X, y=Y, z=err, showscale=False)
p.show()
예제 #4
0
 def f(c, a):
   a1, a2 = a
   c1, c2 = c
   b = np.sum(np.cos(a1)) * np.sum(np.tan(c2 * a2))
   c = c1 * np.sin(np.sum(a1 * a2)), c2 * np.cos(np.sum(a1))
   return c, b
예제 #5
0
def _cosine_interpolate(start: float, end: float, pct: float):
    return end + (start - end) / 2.0 * (jnp.cos(jnp.pi * pct) + 1)
예제 #6
0
 def bar(y):
     return np.cos(y) * x
예제 #7
0
 def schedule(step):
   t = step / total_steps
   return 0.5 * init_lr * (1 + jnp.cos(t * onp.pi))
예제 #8
0
def standard_students_t_4_icdf(u):
    """Inverse cumulative distribution function of standard Student's t with dof = 4."""
    sqrt_α = np.sqrt(4 * u * (1 - u))
    return 2 * np.sign(u - 0.5) * np.sqrt(
        np.cos(np.arccos(sqrt_α) / 3) / sqrt_α - 1)
예제 #9
0
def ackley_1d(x, y=0):
    out = (-20 * jnp.exp(-0.2 * jnp.sqrt(0.5 * (x**2 + y**2))) -
           jnp.exp(0.5 * (jnp.cos(2 * jnp.pi * x) + jnp.cos(2 * jnp.pi * y))) +
           jnp.e + 20)
    return out
예제 #10
0
파일: api_test.py 프로젝트: njtwomey/jax
 def f1(x, y):
     return np.sin(x) * np.cos(y) * np.sin(x) * np.cos(y)
예제 #11
0
 def h(x):
   return np.sin(np.cos(x))
예제 #12
0
 def f(z):
   return np.cos(np.linalg.norm(2 * z))
예제 #13
0
 def f(z):
   return np.sum(np.cos(np.abs(z)))
예제 #14
0
 def test_variable_input(self):
     f_jax = lambda x: jnp.sin(jnp.cos(x))
     f_tf = jax2tf.convert(f_jax)
     v = tf.Variable(0.7)
     self.assertIsInstance(f_tf(v), tf.Tensor)
     self.assertAllClose(f_jax(0.7), f_tf(v))
예제 #15
0
 def schedule(step):
   t = jnp.minimum(step / burnin_steps, 1.)
   coef = (1 + jnp.cos(t * onp.pi)) * 0.5
   return coef * init_lr + (1 - coef) * final_lr
예제 #16
0
 def test_function(self):
     f_jax = jax.jit(lambda x: jnp.sin(jnp.cos(x)))
     self.ConvertAndCompare(f_jax, 0.7, with_function=True)
예제 #17
0
 def schedule(step):
   t = jnp.maximum(step - burnin_steps - 1, 0.)
   t = (t % cycle_length) / cycle_length
   return 0.5 * init_lr * (1 + jnp.cos(t * onp.pi))
예제 #18
0
 def schedule(count):
     count = jnp.minimum(count, decay_steps)
     cosine_decay = 0.5 * (1 + jnp.cos(jnp.pi * count / decay_steps))
     decayed = (1 - alpha) * cosine_decay + alpha
     return init_value * decayed
예제 #19
0
 def log_prob(self, value):
     return -(jnp.log(2 * jnp.pi) + jnp.log(i0e(self.concentration))) + \
         self.concentration * (jnp.cos((value - self.loc) % (2 * jnp.pi)) - 1)
예제 #20
0
def fun_with_call_closure(x):
    def foo(y, z):
        return (x * x) * np.sin(y) * z

    return call(foo, x, np.cos(x)) + x
예제 #21
0
 def test_function(self):
   f_jax = jax.jit(lambda x: jnp.sin(jnp.cos(x)))
   self.ConvertAndCompare(f_jax, jnp.float_(0.7))
예제 #22
0
 def foo(x):
     return np.sin(x) + np.cos(x)
예제 #23
0
 def test_variable_input(self):
   f_jax = lambda x: jnp.sin(jnp.cos(x))
   f_tf = jax2tf.convert(f_jax)
   v = tf.Variable(0.7, dtype=dtypes.canonicalize_dtype(jnp.float_))
   self.assertIsInstance(f_tf(v), tf.Tensor)
   self.assertAllClose(f_jax(0.7), f_tf(v))
예제 #24
0
 def f(c, a):
   b = np.sin(c * np.sum(np.cos(d * a)))
   c = 0.9 * np.cos(d * np.sum(np.sin(c * a)))
   return c, b
예제 #25
0
def cosine_decay(lr, step, total_steps):
  ratio = jnp.maximum(0., step / total_steps)
  mult = 0.5 * (1. + jnp.cos(jnp.pi * ratio))
  return mult * lr
예제 #26
0
 def fn(a):
     return np.cos(a)
예제 #27
0
 def test_basics(self):
     f_jax = lambda x: jnp.sin(jnp.cos(x))
     _, res_tf = self.ConvertAndCompare(f_jax, 0.7)
     self.assertIsInstance(res_tf, tf.Tensor)
예제 #28
0
파일: jax2tf_test.py 프로젝트: wayfeng/jax
 def f_callee(x):
     return jnp.cos(x)
예제 #29
0
 def f1(x):
   y = 2 * np.sin(x)
   z = np.cos(x) * np.sin(y)
   return z