Exemple #1
0
    def open(ss):
        """
        open opens the window of this gui
        """
        width = 1600
        height = 1200

        win = gi.NewMainWindow("netview", "eTorch NetView", width, height)
        ss.Win = win

        vp = win.WinViewport2D()
        ss.vp = vp
        updt = vp.UpdateStart()

        mfr = win.SetMainFrame()

        nv = netview.NetView()
        mfr.AddChild(nv)
        nv.Var = "Act"
        nv.SetNet(ss.Net)
        ss.NetView = nv

        # main menu
        appnm = gi.AppName()
        mmen = win.MainMenu
        mmen.ConfigMenus(go.Slice_string([appnm, "File", "Edit", "Window"]))

        amen = gi.Action(win.MainMenu.ChildByName(appnm, 0))
        amen.Menu.AddAppMenu(win)

        emen = gi.Action(win.MainMenu.ChildByName("Edit", 1))
        emen.Menu.AddCopyCutPaste(win)
        win.MainMenuUpdated()
        vp.UpdateEndNoSig(updt)
        win.GoStartEventLoop()
Exemple #2
0
    def ConfigPats(ss):
        dt = ss.Pats
        dt.SetMetaData("name", "TrainPats")
        dt.SetMetaData("desc", "Training patterns")
        sch = etable.Schema([
            etable.Column("Name", etensor.STRING, go.nil, go.nil),
            etable.Column("Input", etensor.FLOAT32, go.Slice_int([5, 5]),
                          go.Slice_string(["Y", "X"])),
            etable.Column("Output", etensor.FLOAT32, go.Slice_int([5, 5]),
                          go.Slice_string(["Y", "X"]))
        ])
        dt.SetFromSchema(sch, 25)

        patgen.PermutedBinaryRows(dt.Cols[1], 6, 1, 0)
        patgen.PermutedBinaryRows(dt.Cols[2], 6, 1, 0)
        # dt.SaveCSV("random_5x5_25_gen.csv", etable.Comma, etable.Headers)
        ss.ConfigTPats()
Exemple #3
0
def ItemsFromEnum(cb, enm):
    nms = []
    typ = type(enm)
    nnm = typ.__name__ + "N" # common convention of using the type name + N for last item in list
    for en in typ:
        if en.name != nnm:
            nms.append(en.name)
    cb.ItemsFromStringList(go.Slice_string(nms), False, 0)
    cb.SetCurVal(enm.name)
Exemple #4
0
    def LogRun(ss, dt):
        """
        LogRun adds data from current run to the RunLog table.
        """
        epclog = ss.TrnEpcLog
        epcix = etable.NewIdxView(epclog)
        if epcix.Len() == 0:
            return

        run = ss.TrainEnv.Run.Cur  # this is NOT triggered by increment yet -- use Cur
        row = dt.Rows
        dt.SetNumRows(row + 1)

        # compute mean over last N epochs for run level
        nlast = 5
        if nlast > epcix.Len() - 1:
            nlast = epcix.Len() - 1
        epcix.Idxs = epcix.Idxs[epcix.Len() - nlast:]

        params = ss.RunName()  # includes tag

        dt.SetCellFloat("Run", row, float(run))
        dt.SetCellString("Params", row, params)
        dt.SetCellFloat("FirstZero", row, float(ss.FirstZero))
        dt.SetCellFloat("SSE", row, agg.Mean(epcix, "SSE")[0])
        dt.SetCellFloat("PctErr", row, agg.Mean(epcix, "PctErr")[0])
        dt.SetCellFloat("PctCor", row, agg.Mean(epcix, "PctCor")[0])

        runix = etable.NewIdxView(dt)
        spl = split.GroupBy(runix, go.Slice_string(["Params"]))
        split.Desc(spl, "FirstZero")
        split.Desc(spl, "PctCor")
        ss.RunStats = spl.AggsToTable(etable.AddAggName)

        # note: essential to use Go version of update when called from another goroutine
        if ss.RunPlot != 0:
            ss.RunPlot.GoUpdate()
        if ss.RunFile != 0:
            if row == 0:
                dt.WriteCSVHeaders(ss.RunFile, etable.Tab)
            dt.WriteCSVRow(ss.RunFile, row, etable.Tab)
Exemple #5
0
    def SetParams(ss, sheet, setMsg):
        """
        SetParams sets the params for "Base" and then current ParamSet.
        If sheet is empty, then it applies all avail sheets (e.g., Network, Sim)
        otherwise just the named sheet
        if setMsg = true then we output a message for each param that was set.
        """

        for param_group in ss.Optimizer.param_groups:
            param_group['lr'] = ss.Lrate

        # todo: fancy params stuff not yet supported...
        return

        if sheet == "":
            ss.Params.ValidateSheets(go.Slice_string(["Network", "Sim"]))
        ss.SetParamsSet("Base", sheet, setMsg)
        if ss.ParamSet != "" and ss.ParamSet != "Base":
            sps = ss.ParamSet.split()
            for ps in sps:
                ss.SetParamsSet(ps, sheet, setMsg)
Exemple #6
0
    def __init__(self):
        super(Sim, self).__init__()
        self.TorchNet = 0
        self.SetTags("TorchNet", 'view:"-" desc:"the Torch network"')
        self.Optimizer = 0
        self.SetTags("Optimizer", 'view:"-" desc:"the Torch optimizer"')
        self.Criterion = 0
        self.SetTags("Criterion", 'view:"-" desc:"the Torch criterion"')

        self.Lrate = 0.2
        self.SetTags("Lrate", 'desc:"the learning rate"')
        self.ErrThr = 0.2
        self.SetTags(
            "ErrThr",
            'desc:"threshold for counting a trial as an error -- using current loss"'
        )

        self.Net = etorch.Network()
        self.SetTags(
            "Net",
            'view:"no-inline" desc:"the network -- click to view / edit parameters for layers, prjns, etc"'
        )

        self.Pats = etable.Table()
        self.SetTags("Pats",
                     'view:"no-inline" desc:"the training patterns to use"')
        self.TInPats = torch.FloatTensor()
        self.SetTags("TInPats",
                     'view:"-" desc:"the input training patterns to use"')
        self.TOutPats = torch.FloatTensor()
        self.SetTags("TOutPats",
                     'view:"-" desc:"the output training patterns to use"')
        self.TInPatsTrl = torch.FloatTensor()
        self.SetTags("TInPatsTrl",
                     'view:"-" desc:"the input training patterns to use"')
        self.TOutPatsTrl = torch.FloatTensor()
        self.SetTags("TOutPatsTrl",
                     'view:"-" desc:"the output training patterns to use"')

        self.TrnEpcLog = etable.Table()
        self.SetTags("TrnEpcLog",
                     'view:"no-inline" desc:"training epoch-level log data"')
        self.TstEpcLog = etable.Table()
        self.SetTags("TstEpcLog",
                     'view:"no-inline" desc:"testing epoch-level log data"')
        self.TstTrlLog = etable.Table()
        self.SetTags("TstTrlLog",
                     'view:"no-inline" desc:"testing trial-level log data"')
        self.TstErrLog = etable.Table()
        self.SetTags(
            "TstErrLog",
            'view:"no-inline" desc:"log of all test trials where errors were made"'
        )
        self.TstErrStats = etable.Table()
        self.SetTags(
            "TstErrStats",
            'view:"no-inline" desc:"stats on test trials where errors were made"'
        )
        self.RunLog = etable.Table()
        self.SetTags("RunLog",
                     'view:"no-inline" desc:"summary log of each run"')
        self.RunStats = etable.Table()
        self.SetTags("RunStats",
                     'view:"no-inline" desc:"aggregate stats on all runs"')
        self.Params = params.Sets()
        self.SetTags("Params",
                     'view:"no-inline" desc:"full collection of param sets"')
        self.ParamSet = str()
        self.SetTags(
            "ParamSet",
            'desc:"which set of *additional* parameters to use -- always applies Base and optionaly this next if set -- can use multiple names separated by spaces (don\'t put spaces in ParamSet names!)"'
        )
        self.Tag = str()
        self.SetTags(
            "Tag",
            'desc:"extra tag string to add to any file names output from sim (e.g., weights files, log files, params for run)"'
        )
        self.MaxRuns = int(10)
        self.SetTags("MaxRuns",
                     'desc:"maximum number of model runs to perform"')
        self.MaxEpcs = int(100)
        self.SetTags("MaxEpcs",
                     'desc:"maximum number of epochs to run per model run"')
        self.NZeroStop = int(5)
        self.SetTags(
            "NZeroStop",
            'desc:"if a positive number, training will stop after this many epochs with zero SSE"'
        )
        self.TrainEnv = env.FixedTable()
        self.SetTags(
            "TrainEnv",
            'desc:"Training environment -- contains everything about iterating over input / output patterns over training"'
        )
        self.TestEnv = env.FixedTable()
        self.SetTags(
            "TestEnv",
            'desc:"Testing environment -- manages iterating over testing"')
        self.ViewOn = True
        self.SetTags(
            "ViewOn",
            'desc:"whether to update the network view while running"')
        self.ViewWts = True
        self.SetTags(
            "ViewWts",
            'desc:"whether to update the network weights view while running -- slower than acts"'
        )
        self.TestInterval = int(5)
        self.SetTags(
            "TestInterval",
            'desc:"how often to run through all the test patterns, in terms of training epochs -- can use 0 or -1 for no testing"'
        )
        self.LayStatNms = go.Slice_string(["Hidden1", "Hidden2", "Output"])
        self.SetTags(
            "LayStatNms",
            'desc:"names of layers to collect more detailed stats on (avg act, etc)"'
        )

        # statistics: note use float64 as that is best for etable.Table
        self.TrlErr = float()
        self.SetTags(
            "TrlErr",
            'inactive:"+" desc:"1 if trial was error, 0 if correct -- based on SSE = 0 (subject to .5 unit-wise tolerance)"'
        )
        self.TrlSSE = float()
        self.SetTags("TrlSSE",
                     'inactive:"+" desc:"current trial\'s sum squared error"')
        self.EpcSSE = float()
        self.SetTags(
            "EpcSSE",
            'inactive:"+" desc:"last epoch\'s total sum squared error"')
        self.EpcPctErr = float()
        self.SetTags("EpcPctErr",
                     'inactive:"+" desc:"last epoch\'s average TrlErr"')
        self.EpcPctCor = float()
        self.SetTags("EpcPctCor",
                     'inactive:"+" desc:"1 - last epoch\'s average TrlErr"')
        self.EpcPerTrlMSec = float()
        self.SetTags(
            "EpcPerTrlMSec",
            'inactive:"+" desc:"how long did the epoch take per trial in wall-clock milliseconds"'
        )
        self.FirstZero = int()
        self.SetTags(
            "FirstZero",
            'inactive:"+" desc:"epoch at when SSE first went to zero"')
        self.NZero = int()
        self.SetTags(
            "NZero",
            'inactive:"+" desc:"number of epochs in a row with zero SSE"')

        # internal state - view:"-"
        self.SumErr = float()
        self.SetTags(
            "SumErr",
            'view:"-" inactive:"+" desc:"sum to increment as we go through epoch"'
        )
        self.SumSSE = float()
        self.SetTags(
            "SumSSE",
            'view:"-" inactive:"+" desc:"sum to increment as we go through epoch"'
        )

        self.Win = 0
        self.SetTags("Win", 'view:"-" desc:"main GUI window"')
        self.NetView = 0
        self.SetTags("NetView", 'view:"-" desc:"the network viewer"')
        self.ToolBar = 0
        self.SetTags("ToolBar", 'view:"-" desc:"the master toolbar"')
        self.TrnEpcPlot = 0
        self.SetTags("TrnEpcPlot", 'view:"-" desc:"the training epoch plot"')
        self.TstEpcPlot = 0
        self.SetTags("TstEpcPlot", 'view:"-" desc:"the testing epoch plot"')
        self.TstTrlPlot = 0
        self.SetTags("TstTrlPlot", 'view:"-" desc:"the test-trial plot"')
        self.TstCycPlot = 0
        self.SetTags("TstCycPlot", 'view:"-" desc:"the test-cycle plot"')
        self.RunPlot = 0
        self.SetTags("RunPlot", 'view:"-" desc:"the run plot"')
        self.TrnEpcFile = 0
        self.SetTags("TrnEpcFile", 'view:"-" desc:"log file"')
        self.RunFile = 0
        self.SetTags("RunFile", 'view:"-" desc:"log file"')
        self.ValsTsrs = {}
        self.SetTags("ValsTsrs", 'view:"-" desc:"for holding layer values"')
        self.SaveWts = False
        self.SetTags(
            "SaveWts",
            'view:"-" desc:"for command-line run only, auto-save final weights after each run"'
        )
        self.NoGui = False
        self.SetTags("NoGui", 'view:"-" desc:"if true, runing in no GUI mode"')
        self.LogSetParams = False
        self.SetTags(
            "LogSetParams",
            'view:"-" desc:"if true, print message for all params that are set"'
        )
        self.IsRunning = False
        self.SetTags("IsRunning", 'view:"-" desc:"true if sim is running"')
        self.StopNow = False
        self.SetTags("StopNow", 'view:"-" desc:"flag to stop running"')
        self.NeedsNewRun = False
        self.SetTags(
            "NeedsNewRun",
            'view:"-" desc:"flag to initialize NewRun if last one finished"')
        self.RndSeed = int(1)
        self.SetTags("RndSeed", 'view:"-" desc:"the current random seed"')
        self.LastEpcTime = int()
        self.SetTags("LastEpcTime", 'view:"-" desc:"timer for last epoch"')
        self.vp = 0
        self.SetTags("vp", 'view:"-" desc:"viewport"')
Exemple #7
0
    def ConfigGui(ss):
        """
        ConfigGui configures the GoGi gui interface for this simulation,
        """
        width = 1600
        height = 1200

        gi.SetAppName("etra25")
        gi.SetAppAbout(
            'This demonstrates a basic eTorch model. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>'
        )

        win = gi.NewMainWindow("etra25", "eTorch Random Associator", width,
                               height)
        ss.Win = win

        vp = win.WinViewport2D()
        ss.vp = vp
        updt = vp.UpdateStart()

        mfr = win.SetMainFrame()

        tbar = gi.AddNewToolBar(mfr, "tbar")
        tbar.SetStretchMaxWidth()
        ss.ToolBar = tbar

        split = gi.AddNewSplitView(mfr, "split")
        split.Dim = mat32.X
        split.SetStretchMax()

        cv = ss.NewClassView("sv")
        cv.AddFrame(split)
        cv.Config()

        tv = gi.AddNewTabView(split, "tv")

        nv = netview.NetView()
        tv.AddTab(nv, "NetView")
        nv.Var = "Act"
        nv.SetNet(ss.Net)
        ss.NetView = nv

        nv.Scene().Camera.Pose.Pos.Set(
            0, 1, 2.75)  # more "head on" than default which is more "top down"
        nv.Scene().Camera.LookAt(mat32.Vec3(0, 0, 0), mat32.Vec3(0, 1, 0))

        plt = eplot.Plot2D()
        tv.AddTab(plt, "TrnEpcPlot")
        ss.TrnEpcPlot = ss.ConfigTrnEpcPlot(plt, ss.TrnEpcLog)

        plt = eplot.Plot2D()
        tv.AddTab(plt, "TstTrlPlot")
        ss.TstTrlPlot = ss.ConfigTstTrlPlot(plt, ss.TstTrlLog)

        plt = eplot.Plot2D()
        tv.AddTab(plt, "TstEpcPlot")
        ss.TstEpcPlot = ss.ConfigTstEpcPlot(plt, ss.TstEpcLog)

        plt = eplot.Plot2D()
        tv.AddTab(plt, "RunPlot")
        ss.RunPlot = ss.ConfigRunPlot(plt, ss.RunLog)

        split.SetSplitsList(go.Slice_float32([.2, .8]))

        recv = win.This()

        tbar.AddAction(
            gi.ActOpts(
                Label="Init",
                Icon="update",
                Tooltip=
                "Initialize everything including network weights, and start over.  Also applies current params.",
                UpdateFunc=UpdtFuncNotRunning), recv, InitCB)

        tbar.AddAction(
            gi.ActOpts(
                Label="Train",
                Icon="run",
                Tooltip=
                "Starts the network training, picking up from wherever it may have left off.  If not stopped, training will complete the specified number of Runs through the full number of Epochs of training, with testing automatically occuring at the specified interval.",
                UpdateFunc=UpdtFuncNotRunning), recv, TrainCB)

        tbar.AddAction(
            gi.ActOpts(
                Label="Stop",
                Icon="stop",
                Tooltip=
                "Interrupts running.  Hitting Train again will pick back up where it left off.",
                UpdateFunc=UpdtFuncRunning), recv, StopCB)

        tbar.AddAction(
            gi.ActOpts(Label="Step Trial",
                       Icon="step-fwd",
                       Tooltip="Advances one training trial at a time.",
                       UpdateFunc=UpdtFuncNotRunning), recv, StepTrialCB)

        tbar.AddAction(
            gi.ActOpts(
                Label="Step Epoch",
                Icon="fast-fwd",
                Tooltip=
                "Advances one epoch (complete set of training patterns) at a time.",
                UpdateFunc=UpdtFuncNotRunning), recv, StepEpochCB)

        tbar.AddAction(
            gi.ActOpts(Label="Step Run",
                       Icon="fast-fwd",
                       Tooltip="Advances one full training Run at a time.",
                       UpdateFunc=UpdtFuncNotRunning), recv, StepRunCB)

        tbar.AddSeparator("test")

        tbar.AddAction(
            gi.ActOpts(Label="Test Trial",
                       Icon="step-fwd",
                       Tooltip="Runs the next testing trial.",
                       UpdateFunc=UpdtFuncNotRunning), recv, TestTrialCB)

        tbar.AddAction(
            gi.ActOpts(
                Label="Test Item",
                Icon="step-fwd",
                Tooltip=
                "Prompts for a specific input pattern name to run, and runs it in testing mode.",
                UpdateFunc=UpdtFuncNotRunning), recv, TestItemCB)

        tbar.AddAction(
            gi.ActOpts(Label="Test All",
                       Icon="fast-fwd",
                       Tooltip="Tests all of the testing trials.",
                       UpdateFunc=UpdtFuncNotRunning), recv, TestAllCB)

        tbar.AddSeparator("log")

        tbar.AddAction(
            gi.ActOpts(
                Label="Reset RunLog",
                Icon="reset",
                Tooltip=
                "Resets the accumulated log of all Runs, which are tagged with the ParamSet used"
            ), recv, ResetRunLogCB)

        tbar.AddSeparator("misc")

        tbar.AddAction(
            gi.ActOpts(
                Label="New Seed",
                Icon="new",
                Tooltip=
                "Generate a new initial random seed to get different results.  By default, Init re-establishes the same initial seed every time."
            ), recv, NewRndSeedCB)

        tbar.AddAction(
            gi.ActOpts(
                Label="README",
                Icon="file-markdown",
                Tooltip=
                "Opens your browser on the README file that contains instructions for how to run this model."
            ), recv, ReadmeCB)

        # main menu
        appnm = gi.AppName()
        mmen = win.MainMenu
        mmen.ConfigMenus(go.Slice_string([appnm, "File", "Edit", "Window"]))

        amen = gi.Action(win.MainMenu.ChildByName(appnm, 0))
        amen.Menu.AddAppMenu(win)

        emen = gi.Action(win.MainMenu.ChildByName("Edit", 1))
        emen.Menu.AddCopyCutPaste(win)
        win.MainMenuUpdated()
        vp.UpdateEndNoSig(updt)
        win.GoStartEventLoop()
Exemple #8
0
    def ConfigGui(ss):
        """
        ConfigGui configures the GoGi gui interface for this simulation,
        """
        width = 1600
        height = 1200

        gi.SetAppName("alexnet")
        gi.SetAppAbout('This tests AlexNet so you can visualize its response to inputs. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>')

        win = gi.NewMainWindow("AlexNet", "eTorch AlexNet", width, height)
        ss.Win = win

        vp = win.WinViewport2D()
        ss.vp = vp
        updt = vp.UpdateStart()

        mfr = win.SetMainFrame()

        tbar = gi.AddNewToolBar(mfr, "tbar")
        tbar.SetStretchMaxWidth()
        ss.ToolBar = tbar

        split = gi.AddNewSplitView(mfr, "split")
        split.Dim = mat32.X
        split.SetStretchMax()

        cv = ss.NewClassView("sv")
        cv.AddFrame(split)
        cv.Config()

        tv = gi.AddNewTabView(split, "tv")

        nv = netview.NetView()
        tv.AddTab(nv, "NetView")
        nv.Var = "Act"
        nv.Params.MaxRecs = 5  # expensive memory-wise..
        nv.SetNet(ss.Net)
        ss.NetView = nv

        nv.Scene().Camera.Pose.Pos.Set(0, 0.87, 2.25)
        nv.Scene().Camera.LookAt(mat32.Vec3(0, -0.16, 0), mat32.Vec3(0, 1, 0))

        plt = eplot.Plot2D()
        tv.AddTab(plt, "TstTrlPlot")
        ss.TstTrlPlot = ss.ConfigTstTrlPlot(plt, ss.TstTrlLog)

        plt = eplot.Plot2D()
        tv.AddTab(plt, "TstEpcPlot")
        ss.TstEpcPlot = ss.ConfigTstEpcPlot(plt, ss.TstEpcLog)

        split.SetSplitsList(go.Slice_float32([.2, .8]))

        recv = win.This()
        
        tbar.AddAction(gi.ActOpts(Label="Init", Icon="update", Tooltip="Initialize everything including network weights, and start over.  Also applies current params.", UpdateFunc=UpdtFuncNotRunning), recv, InitCB)

        tbar.AddAction(gi.ActOpts(Label="Test Trial", Icon="step-fwd", Tooltip="Runs the next testing trial.", UpdateFunc=UpdtFuncNotRunning), recv, TestTrialCB)
        
        tbar.AddAction(gi.ActOpts(Label="Test Item", Icon="step-fwd", Tooltip="Prompts for a specific input pattern name to run, and runs it in testing mode.", UpdateFunc=UpdtFuncNotRunning), recv, TestItemCB)
        
        tbar.AddAction(gi.ActOpts(Label="Test All", Icon="fast-fwd", Tooltip="Tests all of the testing trials.", UpdateFunc=UpdtFuncNotRunning), recv, TestAllCB)

        tbar.AddAction(gi.ActOpts(Label="Stop", Icon="stop", Tooltip="Interrupts running.  Hitting Train again will pick back up where it left off.", UpdateFunc=UpdtFuncRunning), recv, StopCB)
        
        tbar.AddSeparator("log")
        
        tbar.AddAction(gi.ActOpts(Label="README", Icon="file-markdown", Tooltip="Opens your browser on the README file that contains instructions for how to run this model."), recv, ReadmeCB)

        # main menu
        appnm = gi.AppName()
        mmen = win.MainMenu
        mmen.ConfigMenus(go.Slice_string([appnm, "File", "Edit", "Window"]))

        amen = gi.Action(win.MainMenu.ChildByName(appnm, 0))
        amen.Menu.AddAppMenu(win)

        emen = gi.Action(win.MainMenu.ChildByName("Edit", 1))
        emen.Menu.AddCopyCutPaste(win)
        win.MainMenuUpdated()
        vp.UpdateEndNoSig(updt)
        win.GoStartEventLoop()