def key_press_U(self,obj,event): ''' Key event u: last solution data - show last soultion data set ''' key = obj.GetKeyCode() if key=='u' or key=='U': self.solutionPosition = self.solutionPosition - 1 if self.solutionPosition < 0: self.solutionPosition = len(self.solutionName) - 1 # recalculate the range of the lookuptable ## self.scalarPosition = 0 minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL) #set time self.endTime = len(self.areaSolution[self.solutionPosition][0]) #set name of the solution if self.pauseBool == False: self.engine.scenes[0].name = str(self.vascularNetwork.name +' - '+'paused'+' - '+self.solutionName[self.solutionPosition]) else: self.engine.scenes[0].name = str(self.vascularNetwork.name +' - '+'running'+' - '+'t = 0.000' +' - '+self.solutionName[self.solutionPosition]) #restart simulation self.currentTime = 0
def visualize(self): ''' Start the visualisation of the simulation result. Set up Upgrade method and starts the main loop. Use only if the simulation result was set! ''' # update the lookuptables and set them minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL) for actor in self.vizActors.itervalues(): actor.module_manager.scalar_lut_manager.data_range = [self.SourceMin, self.SourceMax] #self.vizActors[0].module_manager.scalar_lut_manager.data_name = self.scalarNames[self.solutionPosition][self.scalarPosition] #self.vizActors[0].module_manager.scalar_lut_manager.show_scalar_bar = True timer = Timer(0.03, self.update) gui = GUI() gui.busy = True gui.start_event_loop()
def to_uint32(self, array, colname): if colname in {"open", "high", "low", "close"}: # Data is stored as 1000 * raw value. assert array.max() < (UINT_32_MAX / 1000), "Test data overflow!" return array * 1000 else: assert colname in ("volume", "day"), "Unknown column: %s" % colname return array
def to_uint32(self, array, colname): if colname in {'open', 'high', 'low', 'close'}: # Data is stored as 1000 * raw value. assert array.max() < (UINT_32_MAX / 1000), "Test data overflow!" return array * 1000 else: assert colname in ('volume', 'day'), "Unknown column: %s" % colname return array
def add_array(self, array, bounds=False, normalized=False): a = {} a['count'] = array.shape[0] if len(array.shape) == 1: t = 'SCALAR' elif array.shape[1] == 3: t = 'VEC3' elif array.shape[1] == 4: t = 'VEC4' else: raise glTFError( 'glTF buffer shape %s not allowed, must be 1 dimensional or N by 3' % repr(tuple(array.shape))) a['type'] = t a['componentType'] = self.value_types[array.dtype.type] a['bufferView'] = len(self.buffer_views) if normalized: a['normalized'] = True # Required for COLOR_0 if bounds: nd = array.ndim # TODO: Handle integer min/max if nd == 2: a['min'], a['max'] = (tuple( float(x) for x in array.min(axis=0)), tuple( float(x) for x in array.max(axis=0))) else: a['min'], a['max'] = float(array.min(axis=0)), float( array.max(axis=0)) self.accessors.append(a) b = array.tobytes() nb = len(b) self.buffer_bytes.append(b) bv = {"byteLength": nb, "byteOffset": self.nbytes, "buffer": 0} self.buffer_views.append(bv) self.nbytes += nb return len(self.accessors) - 1
def to_uint32(self, array, colname): arrmax = array.max() if colname in OHLC: self.check_uint_safe(arrmax * 1000, colname) return (array * 1000).astype(uint32) elif colname == 'volume': self.check_uint_safe(arrmax, colname) return array.astype(uint32) elif colname == 'day': nanos_per_second = (1000 * 1000 * 1000) self.check_uint_safe(arrmax.view(int) / nanos_per_second, colname) return (array.view(int) / nanos_per_second).astype(uint32)
def key_press_V(self,obj,event): ''' Key event V: open vessels and show vectorfields ''' key = obj.GetKeyCode() if key=='v' or key=='V': if self.vecBool == False: self.vecBool = True for glyph in self.glyph.itervalues(): glyph.actor.actor.visibility = self.vecBool self.scalarPosition = 3 minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL) self.vizActors[0].module_manager.scalar_lut_manager.show_scalar_bar = False self.glyph[0].module_manager.scalar_lut_manager.data_range = [0, self.SourceMax] self.glyph[0].module_manager.scalar_lut_manager.show_scalar_bar = True self.glyph[0].module_manager.scalar_lut_manager.data_name = self.scalarNames[self.solutionPosition][self.scalarPosition] print " .. velocity profile enabled" else: self.vecBool = False for glyph in self.glyph.itervalues(): glyph.actor.actor.visibility = self.vecBool print " .. velocity profile disabled" self.scalarPosition = 3 minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL) self.vizActors[0].module_manager.scalar_lut_manager.data_name = self.scalarNames[self.solutionPosition][3] self.vizActors[0].module_manager.scalar_lut_manager.show_scalar_bar = True
def key_press_N(self,obj,event): ''' Key event n: next lookup table - change the lookup and scalar mapping ''' key = obj.GetKeyCode() if key=='n' or key=='N': self.scalarPosition = self.scalarPosition + 1 if self.scalarPosition == len(self.scalarNames[self.solutionPosition]): self.scalarPosition = 0 minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL)
def key_press_J(self,obj,event): ''' Key event j: last lookup table - change the lookup and scalar mapping ''' key = obj.GetKeyCode() if key=='j' or key=='J': self.scalarPosition = self.scalarPosition - 1 if self.scalarPosition < 0: self.scalarPosition = len(self.scalarNames[self.solutionPosition]) - 1 # recalculate the range of the lookuptable ## Note: change this in further version to save memory -> (list) minL = [] maxL = [] for array in self.scalarSolution[self.solutionPosition][self.scalarPosition].itervalues(): minL.append(array.min()) maxL.append(array.max()) self.SourceMin = min(minL) self.SourceMax = max(maxL)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) cost_history = np.empty(shape=[1], dtype=float) y_true, y_pred = None, None with tf.Session() as sess: sess.run(init) for epoch in range(training_epochs): _, cost = sess.run([optimizer, cost_function], feed_dict={ X: tr_features, Y: tr_labels }) cost_history = np.append(cost_history, cost) y_pred = sess.run(tf.argmax(y_, 1), feed_dict={X: ts_features}) y_true = sess.run(tf.argmax(ts_labels, 1)) print( "Test accuracy: ", round(sess.run(accuracy, feed_dict={ X: ts_features, Y: ts_labels }), 3)) fig = plt.figure(figsize=(10, 8)) plt.plot(cost_history) plt.axis([0, training_epochs, 0, np.max(cost_history)]) plt.show() p, r, f, s = precision_recall_fscore_support(y_true, y_pred, average="micro") print "F-Score:", round(f, 3)