def show_bias(self): if len(self.weights) is 1: mp = MyPlot() mp.set_labels('Step', 'Bias') mp.show_list(self.biases) else: print('Cannot show the bias! Call print_bias mehtod.')
def show_weight(self): print('shape=', self.weights) if len(self.weights[0]) is 1: mp = MyPlot() mp.set_labels('Step', 'Weight') mp.show_list(self.weights) else: print('Cannot show the weight! Call print_weight method.')
def __init__(self, *args, **kwargs): super(Wnd, self).__init__(*args, **kwargs) self.t = None self.osc = None self.input_cbox = None self.output_cbox = None left = VContainer() right = VContainer() self.slider = QtWidgets.QSlider(Qt.Horizontal) self.slider.setMinimum(20) self.slider.setMaximum(500) left.addWidget(self.slider) self.slider.valueChanged.connect(self.change_freq) self.addWidget(left) self.addWidget(right) devices = HContainer() devices.addWidget(self.inputCBox()) devices.addWidget(self.outputCBox()) left.addWidget(devices) spf = wave.open("wav.wav", "r") signal = spf.readframes(-1) signal = np.frombuffer(signal, "int16") self.signal = signal self.graphWidget = MyPlot() left.addWidget(self.graphWidget) self.fft = Spec() # self.fft.setYRange(0, 100000, padding=0) left.addWidget(self.fft) self.buttons = HContainer() btn = QtWidgets.QPushButton() btn.setText('Record') self.buttons.addWidget(btn) btn.clicked.connect(self.get_device_num) btn = QtWidgets.QPushButton() btn.setText('Play') self.buttons.addWidget(btn) btn.clicked.connect(self.play_file) left.addWidget(self.buttons) self.logger = LogWrite() right.addWidget(self.logger)
#----- a neuron w = tf.Variable(tf.random_normal([2, 1])) b = tf.Variable(tf.random_normal([1])) hypo = tf.matmul(x, w) + b #----- cost = tf.reduce_mean((hypo - y) * (hypo - y)) train = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(cost) sess = tf.Session() sess.run(tf.global_variables_initializer()) costs = [] for i in range(2001): sess.run(train) if i % 50 == 0: print('hypo:', sess.run(hypo), '|', sess.run(w), sess.run(b), sess.run(cost)) costs.append(sess.run(cost)) hypo2 = tf.matmul([[4., 4]], w) + b print(sess.run(hypo2)) p = MyPlot() p.show_list(costs)
def show_error(self): mp = MyPlot() mp.set_labels('Step', 'Error') mp.show_list(self.costs)
class LineParser(object): __rules = [ 'CREATEVAR', 'SETVAR', 'CALCULATE', 'CREATEPLOT', 'ADDTOPLOT', 'SHOWPLOT', 'CREATEFCT', 'ENDFCT', 'CALL'] __function_create_start = None __variables = Variable() __plots = MyPlot() __functions = Function() def __init__(self, line): self.line = line self.error = 0 self.rule_in_line = '' def update_globals(self, globals): pass def get_rule(self): for __rule in LineParser.__rules: __location = -1 __matching_rules = 0 while __matching_rules <=2: #search multiple identical rules in the same line __location = self.line.find(__rule, __location + 1) if __location == -1: break else: __matching_rules += 1 if __matching_rules == 1: self.rule_in_line = __rule self.error += 1 else: self.error += 1 def implement_rule(self): if LineParser.__function_create_start == None: if self.rule_in_line == 'CREATEVAR': LineParser.__variables.CreateVar((self.line.split(':')[1]).split('\n')[0]) MyPlot.UpdateGlobals(Variable.variables) elif self.rule_in_line == 'SETVAR': LineParser.__variables.SetVar(self.line.split(':')[1], (self.line.split(':')[2]).split('\n')[0]) MyPlot.UpdateGlobals(Variable.variables) elif self.rule_in_line == 'CALCULATE': LineParser.__variables.Calculate(self.line.split(':')[1], (self.line.split(':')[2]).split('\n')[0]) MyPlot.UpdateGlobals(Variable.variables) elif self.rule_in_line == 'CREATEPLOT': LineParser.__plots.CreatePlot((self.line.split(':')[1]).split('\n')[0]) elif self.rule_in_line == 'ADDTOPLOT': LineParser.__plots.AddToPlot(self.line.split(':')[1], self.line.split(':')[2], (self.line.split(':')[3]).split('\n')[0]) elif self.rule_in_line == 'SHOWPLOT': LineParser.__plots.ShowPlot((self.line.split(':')[1]).split('\n')[0]) elif self.rule_in_line == 'CREATEFCT': LineParser.__function_create_start = (self.line.split(':')[1]).split('\n')[0] LineParser.__functions.CreateFunction((self.line.split(':')[1]).split('\n')[0]) elif self.rule_in_line == 'CALL': LineParser.__functions.CallFunction((self.line.split(':')[1]).split('\n')[0]) else: pass else: if self.rule_in_line == 'CREATEVAR': LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'SETVAR': LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'CALCULATE': LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'CREATEPLOT': LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'ADDTOPLOT': LineParser.__functions = Function() LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'SHOWPLOT': LineParser.__functions.AddToFunction(LineParser.__function_create_start, self.line) elif self.rule_in_line == 'ENDFCT': LineParser.__function_create_start = None
from myplot import MyPlot import sys data = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]] print(data) print('Number of arguments:', len(sys.argv), 'arguments.') print('Argument List:', str(sys.argv)) #type_of_graph = int(input("What is the type of graph you want. \n Press 1 for histogram \n Press 2 for bar chart \n Press 3 for scatter plot. \n Press 4 for line plot \n Press 5 for histogram\n Press 6 for pie chart")) #{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'} type_of_graph = int(sys.argv[1]) myplt = MyPlot(type_of_graph, str(sys.argv[2]), data) myplt.plot_graph() #fig, axs = plt.subplots(2, 2, figsize=(5, 5)) #axs[0, 0].hist(data[0]) #axs[1, 0].scatter(data[0], data[1]) #axs[0, 1].plot(data[0], data[1]) #axs[1, 1].hist2d(data[0], data[1])
self.addPoint(state.PosAct) # A worker class for the ros node # To be deprecated soon class WorkerListener(Thread): def __init__(self): Thread.__init__(self) def run(self): rospy.ready(NAME, anonymous=True) rospy.spin() channel = MyChannel() channel2 = MyChannelAct() rospy.TopicSub('ARM_L_PAN_state', RotaryJointState, channel.callback) rospy.TopicSub('ARM_L_PAN_state', RotaryJointState, channel2.callback) app = wx.PySimpleApp(0) worker = WorkerListener() worker.start() frame = wx.Frame(None, -1, "") panel = MyPlot(frame) panel.addChannel(channel) panel.addChannel(channel2) frame.Show() print '>>>>>>>>>>>>>>' app.MainLoop() print '>>>>>>>>>>>>>>' #rospy.spin()
from myplot import MyPlot x_data = [1] y_data = [1] #----- a neuron w = tf.Variable(tf.random_normal([1])) b = tf.Variable(tf.random_normal([1])) hypo = w * x_data + b #----- cost = (hypo - y_data) ** 2 train = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(cost) sess = tf.Session() sess.run(tf.global_variables_initializer()) costs = [] for i in range(1001): sess.run(train) if i % 50 == 0: print(sess.run(w), sess.run(b), sess.run(cost)) costs.append(sess.run(cost)) gildong = MyPlot() gildong.show_list(costs)