def train(self, training_dataset): feature_summary = {"class_1": [], "class_2": []} for cls, feature_matrix in training_dataset.iteritems(): for feature in feature_matrix: # Append the whole feature vector (all values for the feature in the class for the training data feature_summary[cls].append((feature, util.stdev(feature))) return feature_summary
def run_sim(): global t, i state['series'] = [] t = config.DATE_START - timedelta(days=1) i = -1 while t < datetime.now() + timedelta(days=365): t += timedelta(days=1) if t not in btc.usd_d: continue for code in scripts: exec_script(code) i += 1 state['series'].append((t, state['base_tether'] + state['base_ntx'])) std = util.stdev(state['series'][100:-365], btc.mcap) if std < best['stdev']: best['series'] = state['series'] best['stdev'] = std best['world'] = copy.deepcopy(world) print() print("stdev = ", best['stdev']) pprint(best['world']) lines['sim'].set_ydata([a[1] for a in best['series']]) fig.canvas.draw() fig.canvas.flush_events()
def markerReliabilityCheck(self, markerCount, alphaWeight=1, betaWeight=5, lengthWeight=2): markers = {} for i in range(markerCount): ms = super(Tobo, self).see_cube() for m in ms: mCode = str(m.info.code) if mCode in markers: markers[mCode]["marker"].append(m) markers[mCode]["alpha"].append(m.centre.rot_y) markers[mCode]["beta"].append(m.orientation.rot_y) markers[mCode]["length"].append(m.centre.dist) else: markers.update({ mCode: { "marker": [m], "alpha": [m.centre.rot_y], "beta": [m.orientation.rot_y], "length": [m.centre.dist] } }) for key in list(markers): mDict = markers[key] sqrtN = math.sqrt(len(mDict["marker"])) alphaXBar = util.mean(mDict["alpha"]) alphaSd = util.stdev(mDict["alpha"]) / sqrtN betaXBar = util.mean(mDict["beta"]) betaSd = util.stdev(mDict["beta"]) / sqrtN lengthXBar = util.mean(mDict["length"]) lengthSd = util.stdev(mDict["length"]) / sqrtN error = (alphaWeight * alphaSd + betaWeight * betaSd + lengthWeight * lengthSd) / (alphaWeight + betaWeight + lengthWeight) for m in mDict["marker"]: m.error = error
def get_power(tx, mcap0, mcap, ref_mcap): delta = 0.01 p = 1 - delta best = (2**256, 0) while p < 2.4: p += delta s = [(a[0], (mcap[i][1] / mcap0) * a[1]**p) for i, a in enumerate(tx)] stdev = util.stdev(s, ref_mcap) if stdev < best[0]: best = (stdev, p) return best[1]
def train(self, training_dataset): """ Calculates the mean and stdev of each feature in each class :param training_dataset: A n*m matrix of n features and m training items :return: a dictionary containing lists of the expected value and standard deviation for each feature in each class """ feature_summary = {"class_1": [], "class_2": []} for cls, feature_matrix in training_dataset.iteritems(): for feature in feature_matrix: feature_summary[cls].append((util.mean(feature), util.stdev(feature))) self.training_params = feature_summary return feature_summary
import util import math NUM_TESTS = 10 def startBench(coroutines) -> int: return int(util.run('bench0', [coroutines])[2]) print('--Start go bench--') util.build_go('go/bench0.go') time = [startBench('100000') for i in range(NUM_TESTS)] mean, std = util.stdev(time) print('Result: {} +/- {}'.format(mean, std)) util.remove('bench0')
import util import math NUM_TESTS = 10 def startBench(coroutines) -> int: return int(util.run('benchSwitch', [coroutines])[7]) print('--Start go bench--') util.build_go('go/benchSwitch.go') switchesPerSecond = [startBench('100') for i in range(NUM_TESTS)] mean, std = util.stdev(switchesPerSecond) print('Result: {} +/- {}'.format(mean, std)) util.remove('benchSwitch')