def loadExperiment(self, experiment): suite = Suite() suite.parse_opt() suite.parse_cfg() experiment_dir = experiment.split('/')[1] params = suite.items_to_params(suite.cfgparser.items(experiment_dir)) self.params = params predictions = suite.get_history(experiment, 0, 'predictions') truth = suite.get_history(experiment, 0, 'truth') self.iteration = suite.get_history(experiment, 0, 'iteration') self.train = suite.get_history(experiment, 0, 'train') self.truth = np.array(truth, dtype=np.float) if params['output_encoding'] == 'likelihood': from nupic.encoders.scalar import ScalarEncoder as NupicScalarEncoder self.outputEncoder = NupicScalarEncoder(w=1, minval=0, maxval=40000, n=22, forced=True) predictions_np = np.zeros((len(predictions), self.outputEncoder.n)) for i in xrange(len(predictions)): if predictions[i] is not None: predictions_np[i, :] = np.array(predictions[i]) self.predictions = predictions_np else: self.predictions = np.array(predictions, dtype=np.float)
predData_TM_n_step = np.roll(np.array(predict_data_ML), _options.stepsAhead) nTest = len(actual_data) - nTrain - _options.stepsAhead NRMSE_TM = NRMSE(actual_data[nTrain:nTrain + nTest], predData_TM_n_step[nTrain:nTrain + nTest]) print "NRMSE on test data: ", NRMSE_TM output.close() # calculate neg-likelihood predictions = np.transpose(likelihoodsVecAll) truth = np.roll(actual_data, -5) from nupic.encoders.scalar import ScalarEncoder as NupicScalarEncoder encoder = NupicScalarEncoder(w=1, minval=0, maxval=40000, n=22, forced=True) from plot import computeLikelihood, plotAccuracy bucketIndex2 = [] negLL = [] minProb = 0.0001 for i in xrange(len(truth)): bucketIndex2.append(np.where(encoder.encode(truth[i]))[0]) outOfBucketProb = 1 - sum(predictions[i, :]) prob = predictions[i, bucketIndex2[i]] if prob == 0: prob = outOfBucketProb if prob < minProb: prob = minProb
def __init__(self): self.encoder = NupicScalarEncoder(w=1, minval=0, maxval=40000, n=22, forced=True)