def get_path_rnd(x, initpv=valley, maxtrials=300):
    pv = [initpv]
    count = 0
    while count < maxtrials:
        pv += [cf.get_next_pv(pv[-1][0], pv[-1][1], get_a_rnd(x, *pv[-1]))]
        count += 1
    return np.array(pv)
def get_path_rnd(x, initpv=valley, maxtrials=300):
    pv = [initpv]
    count = 0
    while count < maxtrials:
        pv += [cf.get_next_pv(pv[-1][0], pv[-1][1], get_a_rnd(x, *pv[-1]))]
        count += 1
    return np.array(pv)
Exemple #3
0
    def parallel_sampling_keepU(self, step, eta, run, rate, T=500, r0=.5, tm=20, ts=2,
                                reset=0, gamma=1, trials=1000, mode='fix',  maxsteps=300,
                                initpv=None, initW=None, samples=100):
        np.random.seed(run)
        if initW is None:
            self.unlearn(r0, mode)
        else:
            self.W = initW
        if isinstance(T, (int, long, float, complex)):
            Tmax = T
        else:
            Tmax = T[1]
        seq = [[None]] * trials  # sequences might have differnt length -> list instead array
        scount = np.zeros((trials, self.K))
        uinit = np.zeros(self.K)
        uinit[self.r] = rate / 1000.
        for t in xrange(trials):
            print 'run', run, '  trial', t, '/', trials
            stdout.flush()
            pvls = [[8, 16]] if initpv is None else [initpv]
            a = []
            r = []
            res = cfn.runpopU_js(self.W / self.pop_size, uinit, step, self.pop_size, rate,
                                 Tmax, tm, ts, 1. * reset / self.pop_size, run)
            uinit = res[1]
            scount[t] = np.sum(res[0], axis=0)
            for counter in xrange(maxsteps):
                a += [self.get_a(scount[t], *pvls[-1])]
                pvls += [cf.get_next_pv(pvls[-1][0], pvls[-1][1], a[-1])]
                r += [cf.get_R(*pvls[-1])]
            seq[t] = [pvls[:-1], a, r]
            for i in range(samples):
                p = 16 * np.random.rand()
                v = 32 * np.random.rand()
                for a in range(3):
                    pvs = cf.get_next_pvs(p, v, a, self.steps)
                    rr = cf.get_R(*pvs)
                    self.update_weights_continuous([p, v], a, rr, pvs,
                                                   eta, gamma**self.steps)

        return np.array([scount, np.array(seq), np.copy(self.W)])