def eval_byexp(model_name, size, partition, userstrata=-1, window=50, sliding_step=50, write=False): exp_filter = ExpFilter(size, partition, userstrata=userstrata) device_and_exps = exp_filter.get_expId_bydevice() convnet = cPickle.load(open('../models/%s.pkl' % model_name)) results = {} results['total'] = [0, 0] for device, exp in device_and_exps: dataset = load_data([exp], window=window, sliding_step=sliding_step) if dataset.start_idx < 1: continue sharedset = shared_dataset(dataset) convnet_inst_num = dataset.start_idx convnet_scores = convnet.score(sharedset) convnet_errors = 1 - convnet_scores res = (dataset.start_idx, convnet_errors) results[exp] = res results['total'][0] = results['total'][0] + res[0] results['total'][1] = results['total'][1] + res[0] * res[1] if write is False: return with open("../../results/%s_results.txt" % model_name, 'w') as f: line = "The total error is %r" % (results['total'][1] / results['total'][0]) f.write(line + "\n") print line for device, exp in device_and_exps: res = results.get(exp, None) if res is None: "%s, %s skipped" % (device, exp) continue line = "%s, %s the error is %r for %i insts" % (device, exp, res[1], res[0]) f.write(line + "\n") print line
def eval_exps(self, exp_ids): preparedset = load_prepared_data(exp_ids) prepared_x = preparedset[0] prepared_y = numpy.asarray(preparedset[1][:,0], 'int32') mv_logreg_error = 1-self.mv_logreg.score(prepared_x, prepared_y) # dataset = load_data(exp_ids, window=self.window, sliding_step=self.sliding_step) # if dataset is None: # return 0, 0, 0, 0 # sharedset = shared_dataset(dataset, self.convnet.static_sensor) # convnet_inst_num = dataset[1].shape[0] dataset = cc_preprocessor.load_data(exp_ids, window=self.window, sliding_step=self.sliding_step) if dataset.start_idx < 1: return 0, 0, 0, 0 sharedset = cc_multimodal_conv.shared_dataset(dataset) convnet_inst_num = dataset.start_idx """ shared_x = theano.shared(prepared_x, borrow=True) shared_y = theano.shared(prepared_y, borrow=True) sharedset = [shared_x, shared_y] """ if self.mv_rf is None: convnet_scores = self.convnet.score(sharedset) print convnet_scores else: repr_x, repr_y = self.convnet.input_to_feature(sharedset, layer=self.layer) print repr_x.shape convnet_scores = self.mv_rf.score(repr_x, repr_y[:,0]) convnet_errors = 1-convnet_scores logreg_inst_num = len(preparedset[1]) return logreg_inst_num, mv_logreg_error, convnet_inst_num, convnet_errors
y_preds = [predict_model(i) for i in xrange(n_test_batches)] y_preds.append(predict_remainder()) y_preds = numpy.reshape(y_preds, (n_test_batches * batch_size + batch_size, len(self.label_struct))) y_preds = y_preds[:test_size,] return y_preds def shared_dataset(data, borrow=True): shared_a = theano.shared(numpy.asarray(data.accData.get(), dtype=theano.config.floatX), borrow=borrow) shared_l = theano.shared(numpy.asarray(data.linData.get(), dtype=theano.config.floatX), borrow=borrow) shared_g = theano.shared(numpy.asarray(data.gyroData.get(), dtype=theano.config.floatX), borrow=borrow) shared_m = theano.shared(numpy.asarray(data.magData.get(), dtype=theano.config.floatX), borrow=borrow) shared_y = theano.shared(numpy.asarray(data.targetData.get(), dtype='int32'), borrow=borrow) return shared_a, shared_l, shared_g, shared_m, shared_y if __name__ == '__main__': data_size = 3 # 0: mini, 1: small, 2: medium, 3: large sliding_step = 50 window = 50 train_set = load_data(ExpFilter(data_size, 'train').get_expId(), window=window, sliding_step=sliding_step) train_shared = shared_dataset(train_set) valid_shared = None label_struct = [2] ccnet = ConvNet(label_struct, train_set.n_features(), filter_h=1, presample_size=1, nkerns=[10,10,10,30]) ccnet.learn(train_shared, valid_shared, learning_rate=0.05, momentum_params={'start':0.05, 'end':0.95, 'interval':100}, n_epochs=200)