def gate_and(x, y, z1, z2): assert _validdims_gate(x, y, z1, z2) return amnet.Mu(amnet.Mu( x, y, z1, ), y, z2)
def triplexer(phi, a, b, c, d, e, f): assert phi.outdim == 1 assert all([len(p) == 4 for p in [a, b, c, d, e, f]]) x = [None] * 4 y = [None] * 4 z = [None] * 4 w = [None] * 4 # Layer 1 weights for i in range(3): x[i] = amnet.Affine( np.array(a[i]).reshape((1, 1)), phi, np.array(b[i]).reshape((1, ))) y[i] = amnet.Affine( np.array(c[i]).reshape((1, 1)), phi, np.array(d[i]).reshape((1, ))) z[i] = amnet.Affine( np.array(e[i]).reshape((1, 1)), phi, np.array(f[i]).reshape((1, ))) # Layer 1 nonlinearity for i in range(3): w[i] = amnet.Mu(x[i], y[i], z[i]) # Layer 2 weights x[3] = amnet.Affine( np.array(a[3]).reshape((1, 1)), w[1], np.array(b[3]).reshape((1, ))) y[3] = amnet.Affine( np.array(c[3]).reshape((1, 1)), w[2], np.array(d[3]).reshape((1, ))) z[3] = amnet.Affine( np.array(e[3]).reshape((1, 1)), w[0], np.array(f[3]).reshape((1, ))) # Layer 2 nonlinearity w[3] = amnet.Mu(x[3], y[3], z[3]) return w[3]
def test_SmtEncoder_mu_small(self): xyz = amnet.Variable(3, name='xyz') x = amnet.atoms.select(xyz, 0) y = amnet.atoms.select(xyz, 1) z = amnet.atoms.select(xyz, 2) w = amnet.Mu(x, y, z) def true_mu(fpin): x, y, z = fpin return x if z <= 0 else y self.validate_outputs( phi=w, onvals=itertools.product(self.floatvals2, repeat=w.indim), true_f=true_mu )
def cmp_ge(x, y, z): assert _validdims_mu(x, y, z) return amnet.Mu(x, y, neg(z))
def cmp_le(x, y, z): assert _validdims_mu(x, y, z) return amnet.Mu(x, y, z)
def gate_xor(x, y, z1, z2): assert _validdims_gate(x, y, z1, z2) return amnet.Mu(amnet.Mu(y, x, z1), amnet.Mu(x, y, z1), z2)
def gate_not(x, y, z): assert _validdims_mu(x, y, z) return amnet.Mu(y, x, z)
def min2_1(x, y): """ main 1-d min method on which all min routines rely """ assert x.outdim == 1 and y.outdim == 1 return amnet.Mu(y, x, sub2(y, x))
def max2_1(x, y): """ main 1-d max method on which all max routines rely """ assert x.outdim == 1 and y.outdim == 1 return amnet.Mu(x, y, sub2(y, x))
import numpy as np import amnet import amnet.vis # a two-dimensional input variable x = amnet.Variable(2, name='x') # choose components x0 = amnet.Linear(np.array([[1, 0]]), x) x1 = amnet.Linear(np.array([[0, 1]]), x) # subtract x0 from x1 z = amnet.Linear(np.array([[-1, 1]]), x) # maximum of x0 and x1 phimax = amnet.Mu(x0, x1, z) print phimax print phimax.eval([1, -2]) # returns: 1 # visualize dot = amnet.vis.amn2gv(phimax, title='max2(var0)') dot.render(filename='max.gv', directory='vis') print dot