def neural_network_test(): ''' Classifier test ''' x = Placeholder() w = Variable([1, 1]) b = Variable(-5) z = add(matmul(w, x), b) a = Sigmoid(z) sess = Session() assert sess.run(operation=a, feed_dict={x: [8, 10]}) > 0.9 assert sess.run(operation=a, feed_dict={x: [4, -10]}) < 0.1
def basic_test(): ''' basic test for z = Ax + b ''' g = Graph() A = Variable(10, default_graph=g) b = Variable(1, default_graph=g) x = Placeholder(default_graph=g) y = multiply(A, x) z = add(y, b) sess = Session() result = sess.run(operation=z, feed_dict={x: 10}) print(result) assert result == 101
def index(): width = request.query.getone('width') height = request.query.getone('height') or width color = request.query.getone('color') or 'grey' response.content_type= 'image/png' try: width = int(width) height = int(height) except: width = 320 height = 240 color = 'grey' print color return Placeholder(width=width,height=height,color=color).get_binary()
def matrix_multiplication_test(): ''' test for matrix multiplication ''' A = Variable([[10, 20], [30, 40]]) b = Variable([1, 2]) x = Placeholder() y = matmul(A, x) z = add(y, b) sess = Session() result = sess.run(operation=z, feed_dict={x: 10}) assert len(result) == 2 assert len(result[0]) == 2 assert result[0][0] == 101 assert result[0][1] == 202 assert result[1][0] == 301 assert result[1][1] == 402
def create_new_placeholder(self, nodes_enough_resource): placeholder = Placeholder() # placeholder.node = random.choice(nodes_enough_resource).metadata.name placeholder.node = nodes_enough_resource[-1].metadata.name self.placeholders.append(placeholder) return placeholder
from compgraph import Compgraph from placeholder import Placeholder from variable import Variable import operations as op from tensor import Tensor if __name__ == '__main__': #nuestros tensores para las variables de entrada y el placeholder X = Tensor([x for x in range(0, 10)]).reshape((10)) dos = Tensor(2) c = Compgraph() v_1 = c.add_variable(Variable(dos, "DOS")) x_1 = c.add_placeholder(Placeholder("X")) o_1 = c.add_operation(op.sin(x_1)) e_1 = c.add_operation(op.Multiply(o_1, v_1)) print(c.to_dot()) x_1.set_value(X) res = c.run(e_1) print(res) exit(0)
data = make_blobs(n_samples=50, n_features=2, centers=2, random_state=75) features = data[0] labels = data[1] plt.scatter(features[:, 0], features[:, 1], c=labels, cmap='coolwarm') x = np.linspace(0, 11, 10) y = -x + 5 plt.plot(x, y) g = Graph() graphObject = g.set_as_default() # Initialize function wx - b | [1,1] * x - 5 x = Placeholder() graphObject.placeholders.append(x) # append placeholder x w = Variables([1, 1]) graphObject.variables.append(w) # append variable w b = Variables(-5) graphObject.variables.append(b) # append variable b z = Addition(MatrixMultiplication(w, x, graphObject), b, graphObject) # Apply activation function a = Sigmoid(z, graphObject) # Execute neural network sess = Session() print(sess.run(a, {x: [0, -10]})) plt.show()
def initialize(x, y): global grid for i in range(x): for j in range(y): grid = [[Placeholder() for _ in range(y)] for _ in range(x)]