Пример #1
0
    def TrainTrial(ss):
        """
        TrainTrial runs one trial of training using TrainEnv
        """

        if ss.NeedsNewRun:
            ss.NewRun()

        ss.TrainEnv.Step()

        # Key to query counters FIRST because current state is in NEXT epoch
        # if epoch counter has changed
        epc = env.CounterCur(ss.TrainEnv, env.Epoch)
        chg = env.CounterChg(ss.TrainEnv, env.Epoch)

        if chg:
            if ss.ViewOn and ss.TrainUpdt.value > leabra.AlphaCycle:
                ss.UpdateView(True)
            if epc%ss.TestInterval == 0: # note: epc is *next* so won't trigger first time
                ss.TestAll()
            ss.LogTrnEpc(ss.TrnEpcLog)
            if epc >= ss.MaxEpcs:
                # done with training..
                ss.RunEnd()
                if ss.TrainEnv.Run.Incr(): # we are done!
                    ss.StopNow = True
                    return
                else:
                    ss.NeedsNewRun = True
                    return

        ss.SetParamsSet("Hidden2Act", "Network", False) # 2 units active for training
        ss.ApplyInputs(ss.TrainEnv)
        ss.AlphaCyc(True)   # train
        ss.TrialStats(True) # accumulate
Пример #2
0
 def TestAll(ss):
     """
     TestAll runs through the full set of testing items
     """
     ss.TestEnv.Init(0)
     while True:
         ss.TestTrial()
         chg = env.CounterChg(ss.TestEnv, env.Epoch)
         if chg or ss.StopNow:
             break
Пример #3
0
 def TestAll(ss):
     """
     TestAll runs through the full set of testing items
     """
     ss.TestEnv.Init(ss.TrainEnv.Run.Cur)
     while True:
         ss.TestTrial(True)
         chg = env.CounterChg(ss.TestEnv, env.Epoch)
         if chg or ss.StopNow:
             break
     ss.UniqPats = ss.UniquePatStat(ss.TstTrlLog)
Пример #4
0
 def TestAll(ss):
     """
     TestAll runs through the full set of testing items
     """
     ss.SetParams("", False)
     ss.UpdateEnv()
     ss.TestEnv.Init(0)
     while True:
         ss.TestTrial()
         chg = env.CounterChg(ss.TestEnv, env.Epoch)
         if chg or ss.StopNow:
             break
     ss.TestStats()
Пример #5
0
    def TestTrial(ss):
        """
        TestTrial runs one trial of testing -- always sequentially presented inputs
        """
        ss.TestEnv.Step()

        chg = env.CounterChg(ss.TestEnv, env.Epoch)
        if chg:
            if ss.ViewUpdt.value > leabra.AlphaCycle:
                ss.UpdateView()
            return

        ss.ApplyInputs(ss.TestEnv)
        ss.AlphaCyc()
Пример #6
0
    def TestTrial(ss, returnOnChg):
        """
        TestTrial runs one trial of testing -- always sequentially presented inputs
        """
        ss.TestEnv.Step()

        chg = env.CounterChg(ss.TestEnv, env.Epoch)
        if chg:
            if ss.ViewOn and ss.TestUpdt.value > leabra.AlphaCycle:
                ss.UpdateView(False)
            ss.LogTstEpc(ss.TstEpcLog)
            if returnOnChg:
                return

        ss.ApplyInputs(ss.TestEnv)
        ss.AlphaCyc(False)
        ss.TrialStats(False)
        ss.LogTstTrl(ss.TstTrlLog)
Пример #7
0
    def TrainTrial(ss):
        """
        TrainTrial runs one trial of training using TrainEnv
        """
        if ss.NeedsNewRun:
            ss.NewRun()

        ss.TrainEnv.Step()

        # Key to query counters FIRST because current state is in NEXT epoch
        # if epoch counter has changed
        epc = env.CounterCur(ss.TrainEnv, env.Epoch)
        chg = env.CounterChg(ss.TrainEnv, env.Epoch)
        if chg:
            if ss.ViewOn and ss.TrainUpdt.value > leabra.AlphaCycle:
                ss.UpdateView(True)
            if epc >= ss.MaxEpcs:
                # done with training..
                ss.RunEnd()
                if ss.TrainEnv.Run.Incr():  # we are done!
                    ss.StopNow = True
                    return
                else:
                    ss.NeedsNewRun = True
                    return

        rch = leabra.Layer(ss.Net.LayerByName("Reach"))
        if "choice" in ss.TrainEnv.TrialName.Cur:
            rch.SetType(emer.Compare)
        else:
            rch.SetType(emer.Input)

        if ss.TrainEnv.GroupName.Cur != ss.PrvGpName:  # init at start of new group
            ss.Net.InitActs()
            ss.PrvGpName = ss.TrainEnv.GroupName.Cur
        train = True
        if "delay" in ss.TrainEnv.TrialName.Cur:
            train = False  # don't learn on delay trials

        ss.ApplyInputs(ss.TrainEnv)
        ss.AlphaCyc(train)
        ss.TrialStats(True)  # accumulate
        ss.LogTrnTrl(ss.TrnTrlLog, ss.TrainEnv.Trial.Cur,
                     ss.TrainEnv.TrialName.Cur)
Пример #8
0
    def TestTrial(ss):
        """
        TestTrial runs one trial of testing -- always sequentially presented inputs
        """
        ss.TestEnv.Step()

        chg = env.CounterChg(ss.TestEnv, env.Epoch)
        if chg:
            if ss.ViewUpdt.value > leabra.AlphaCycle:
                ss.UpdateView()
            return

        isCue = (ss.TestEnv.TrialName.Cur == "Cue")

        if ss.TestEnv.TrialName.Prv != "Cue":
            ss.Net.InitActs()
        ss.ApplyInputs(ss.TestEnv)
        if isCue:
            ss.AlphaCycCue()
        else:
            ss.AlphaCyc()
            ss.LogTstTrl(ss.TstTrlLog)
Пример #9
0
    def TrainTrial(ss):
        """
        TrainTrial runs one trial of training using TrainEnv
        """

        if ss.NeedsNewRun:
            ss.NewRun()

        ss.TrainEnv.Step()

        # Key to query counters FIRST because current state is in NEXT epoch
        # if epoch counter has changed
        epc = env.CounterCur(ss.TrainEnv, env.Epoch)
        chg = env.CounterChg(ss.TrainEnv, env.Epoch)

        if chg:
            ss.LogTrnEpc(ss.TrnEpcLog)
            if ss.ViewOn and ss.TrainUpdt.value > leabra.AlphaCycle:
                ss.UpdateView(True)
            if ss.TestInterval > 0 and epc % ss.TestInterval == 0:  # note: epc is *next* so won't trigger first time
                ss.TestAll()
            if epc >= ss.MaxEpcs or (ss.NZeroStop > 0
                                     and ss.NZero >= ss.NZeroStop):
                # done with training..
                ss.RunEnd()
                if ss.TrainEnv.Run.Incr():  # we are done!
                    ss.StopNow = True
                    return
                else:
                    ss.NeedsNewRun = True
                    return

        # note: type must be in place before apply inputs
        ss.Net.LayerByName("Output").SetType(emer.Target)
        ss.ApplyInputs(ss.TrainEnv)
        ss.AlphaCyc(True)  # train
        ss.TrialStats(True)  # accumulate