Exemple #1
0
    def _show_placeholder(self, title, body):
        """
		We have no memories, add a single page with the given title and message.
		"""
        placeholder = Placeholder(title, body, gtk.STOCK_DIALOG_WARNING)
        placeholder.show()
        self.append_page(placeholder)
        self.set_show_tabs(False)
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
Exemple #4
0
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
Exemple #6
0
 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)
Exemple #8
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 add_placeholder(self, ph: Placeholder) -> Placeholder:
     if not ph.name:
         ph.set_name("Placeholder_{}".format(self.nplaceholders))
     self.graph.add_node(ph)
     self.nplaceholders += 1
     return ph
Exemple #10
0
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)]
Exemple #11
0
	def architecture_changed(self):
		"""
		Called when the architecture changes, deals with all the
		architecture-specific changes which need to be made to the GUI.
		"""
		self.treeviews = {}
		
		# Remove the previous widget
		if self.widget:
			self.remove(self.widget)
			self.widget.destroy()
			self.widget = None
		
		# Add a new page for each memory
		if self.system.architecture is None:
			self.widget = Placeholder("Unknown Architecture",
				"The current architecture is not known and thus no "+
				"memories containing symbols can be displayed.",
				gtk.STOCK_DIALOG_WARNING)
		elif len(self.system.architecture.memories) == 0:
			self.widget = Placeholder("No Memories",
				"The current architecture does not have any memories"+
				"thus no symbols can be present.",
				gtk.STOCK_DIALOG_WARNING)
		else:
			self.widget = gtk.Notebook()
			for memory in self.system.architecture.memories:
				# Add a page with a symbol listing for each memory
				label = gtk.Label(memory.name)
				# One hidden column stores the integer version of the value so that when
				# refresh is called we just convert this rather than re-requesting the
				# symbols.
				liststore = gtk.ListStore(str, str, str, object)
				self.treeviews[memory]  = gtk.TreeView(liststore)
				scroller = gtk.ScrolledWindow()
				scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
				scroller.add(self.treeviews[memory])
				self.widget.append_page(scroller, label)
				
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				column = gtk.TreeViewColumn("Symbol")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 0)
				self.treeviews[memory].append_column(column)
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				cell_renderer.set_property("alignment", pango.ALIGN_RIGHT)
				cell_renderer.set_property("xalign", 1.0)
				column = gtk.TreeViewColumn("Value")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 1)
				self.treeviews[memory].append_column(column)
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				column = gtk.TreeViewColumn("Type")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 2)
				self.treeviews[memory].append_column(column)
		
		self.pack_start(self.widget, fill = True, expand=True)
		
		self.refresh_symbols()
		
		self.show_all()
		
		self.refresh()
Exemple #12
0
class SymbolViewer(gtk.VBox):
	
	def __init__(self, system):
		"""
		A GTK widget that displays all program symbols.
		"""
		gtk.VBox.__init__(self)
		
		self.system = system
		
		self.set_border_width(5)
		
		# The widget being displayed
		self.widget = None
		
		# Mapping from memories to treeviews
		self.treeviews = {}
		
		self.architecture_changed()
	
	
	def refresh(self):
		"""
		Refresh information in the widget, particularly, refresh all values incase
		the base being displayed was changed.
		"""
		if self.system.architecture is None:
			return
		
		for memory, treeview in self.treeviews.iteritems():
			liststore = treeview.get_model()
			for row in range(len(liststore)):
				liststore[row][1] = format_number(liststore[row][3],
				                                  self.system.architecture.word_width_bits)
			treeview.columns_autosize()
	
	
	def refresh_symbols(self):
		"""
		Refreshes the list of available symbols. Call when the list changes.
		"""
		if self.system.architecture is None:
			return
		
		for memory, treeview in self.treeviews.iteritems():
			liststore = treeview.get_model()
			liststore.clear()
			symbols = self.system.image_symbols.get(memory,{})
			for symbol, (value, symbol_type) in symbols.iteritems():
				liststore.append((symbol,
				                  "",
				                  symbol_type,
				                  value))
		
		self.refresh()
	
	
	def architecture_changed(self):
		"""
		Called when the architecture changes, deals with all the
		architecture-specific changes which need to be made to the GUI.
		"""
		self.treeviews = {}
		
		# Remove the previous widget
		if self.widget:
			self.remove(self.widget)
			self.widget.destroy()
			self.widget = None
		
		# Add a new page for each memory
		if self.system.architecture is None:
			self.widget = Placeholder("Unknown Architecture",
				"The current architecture is not known and thus no "+
				"memories containing symbols can be displayed.",
				gtk.STOCK_DIALOG_WARNING)
		elif len(self.system.architecture.memories) == 0:
			self.widget = Placeholder("No Memories",
				"The current architecture does not have any memories"+
				"thus no symbols can be present.",
				gtk.STOCK_DIALOG_WARNING)
		else:
			self.widget = gtk.Notebook()
			for memory in self.system.architecture.memories:
				# Add a page with a symbol listing for each memory
				label = gtk.Label(memory.name)
				# One hidden column stores the integer version of the value so that when
				# refresh is called we just convert this rather than re-requesting the
				# symbols.
				liststore = gtk.ListStore(str, str, str, object)
				self.treeviews[memory]  = gtk.TreeView(liststore)
				scroller = gtk.ScrolledWindow()
				scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
				scroller.add(self.treeviews[memory])
				self.widget.append_page(scroller, label)
				
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				column = gtk.TreeViewColumn("Symbol")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 0)
				self.treeviews[memory].append_column(column)
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				cell_renderer.set_property("alignment", pango.ALIGN_RIGHT)
				cell_renderer.set_property("xalign", 1.0)
				column = gtk.TreeViewColumn("Value")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 1)
				self.treeviews[memory].append_column(column)
				
				cell_renderer = gtk.CellRendererText()
				cell_renderer.set_property("font", "monospace")
				column = gtk.TreeViewColumn("Type")
				column.pack_start(cell_renderer)
				column.add_attribute(cell_renderer, "text", 2)
				self.treeviews[memory].append_column(column)
		
		self.pack_start(self.widget, fill = True, expand=True)
		
		self.refresh_symbols()
		
		self.show_all()
		
		self.refresh()