def go(kargs, type): """ Execute SP. @param kargs: The params for the SP. @param type: Run type. @return: The new sp and the execution time. """ # Run the SP t = time.time() for _ in xrange(n_iters): sp = SPRegion(**kargs) sp.c_sboost = 0 # Ensure that no permanence boosting occurs sp.execute(ds, store=False) t = time.time() - t # Dump the permanence matrix with open(os.path.join(p, '{0}-permanence.pkl'.format(type)), 'wb') \ as f: cPickle.dump(sp.p, f, cPickle.HIGHEST_PROTOCOL) # Dump the details kargs['density'] = density kargs['seed'] = seed kargs['time'] = t with open(os.path.join(p, '{0}-details.json'.format(type)), 'wb') as f: f.write(json.dumps(kargs, sort_keys=True, indent=4, separators=(',', ': '))) return sp, t
def main(ds, p, ncols=2048, duty_cycle=100, nepochs=10, global_inhibition=True, seed=123456789): """Run an experiment. @param ds: The dataset. @param p: The full path to the directory to save the results. @param ncols: The number of columns. @param duty_cycle: The duty cycle. @param nepochs: The number of epochs @param global_inhibition: If True use global inhibition otherwise use local inhibition. @param seed: The random seed. """ # Get some parameters ninputs = ds.shape[1] density = np.sum(ds[0]) / float(ninputs) # Make the directory if it doesn't exist try: os.makedirs(p) except OSError: pass # Initializations np.random.seed(seed) kargs = { 'ninputs': ninputs, 'ncolumns': ncols, 'nsynapses': 40, 'random_permanence': True, 'pinc': 0.03, 'pdec': 0.05, 'seg_th': 15, 'nactive': int(0.02 * ncols), 'duty_cycle': duty_cycle, 'max_boost': 10, 'global_inhibition': global_inhibition, 'trim': 1e-4 } # Create the region delattr(SPRegion, '_phase3') setattr(SPRegion, '_phase3', _phase3) sp = SPRegion(**kargs) sp.iter, sp.out_path = 1, p # Train the region t = time.time() for i in range(nepochs): for j, x in enumerate(ds): sp.execute(x) sp.iter += 1 t = time.time() - t # Dump the details kargs['density'] = density kargs['seed'] = seed kargs['nepochs'] = nepochs kargs['time'] = t with open(os.path.join(p, 'details.json'), 'w') as f: f.write( json.dumps(kargs, sort_keys=True, indent=4, separators=(',', ': ')))
def main(ds, p, ncols=2048, duty_cycle=100, nepochs=10, global_inhibition=True, seed=123456789): """ Run an experiment. @param ds: The dataset. @param p: The full path to the directory to save the results. @param ncols: The number of columns. @param duty_cycle: The duty cycle. @param nepochs: The number of epochs @param global_inhibition: If True use global inhibition otherwise use local inhibition. @param seed: The random seed. """ # Get some parameters ninputs = ds.shape[1] density = np.sum(ds[0]) / float(ninputs) # Make the directory if it doesn't exist try: os.makedirs(p) except OSError: pass # Initializations np.random.seed(seed) kargs = { 'ninputs': ninputs, 'ncolumns': ncols, 'nsynapses': 40, 'random_permanence': True, 'pinc':0.03, 'pdec':0.05, 'seg_th': 15, 'nactive': int(0.02 * ncols), 'duty_cycle': duty_cycle, 'max_boost': 10, 'global_inhibition': global_inhibition, 'trim': 1e-4 } # Create the region delattr(SPRegion, '_phase3') setattr(SPRegion, '_phase3', _phase3) sp = SPRegion(**kargs) sp.iter, sp.out_path = 1, p # Train the region t = time.time() for i in xrange(nepochs): for j, x in enumerate(ds): sp.execute(x) sp.iter += 1 t = time.time() - t # Dump the details kargs['density'] = density kargs['seed'] = seed kargs['nepochs'] = nepochs kargs['time'] = t with open(os.path.join(p, 'details.json'), 'wb') as f: f.write(json.dumps(kargs, sort_keys=True, indent=4, separators=(',', ': ')))