Ejemplo n.º 1
0
    def ConfigNetView(ss, nv):
        nv.ViewDefaults()
        nv.Scene().Camera.Pose.Pos.Set(
            0, 1.5,
            3.0)  # more "head on" than default which is more "top down"
        nv.Scene().Camera.LookAt(mat32.Vec3(0, 0, 0), mat32.Vec3(0, 1, 0))

        labs = go.Slice_string([
            " Morr Socks Sylv Garf Fuzz Rex Fido Spot Snoop Butch",
            " black white brown orange", "bugs grass scraps shoe",
            "small  med  large", "cat     dog", "string feath bone shoe"
        ])
        nv.ConfigLabels(labs)

        lays = go.Slice_string([
            "Name", "Color", "FavoriteFood", "Size", "Species", "FavoriteToy"
        ])

        li = 0
        for lnm in lays:
            ly = nv.LayerByName(lnm)
            lbl = nv.LabelByName(labs[li])
            lbl.Pose = ly.Pose
            lbl.Pose.Pos.Y += .2
            lbl.Pose.Pos.Z += .02
            lbl.Pose.Scale.SetMul(mat32.Vec3(0.4, 0.08, 0.5))
            li += 1
Ejemplo n.º 2
0
 def SetNStim(ev, n):
     """
     SetNStim initializes env for given number of stimuli, init states
     """
     ev.NStim = n
     ev.Input.SetShape(go.Slice_int([Actions.ActionsN.value + n]), go.nil, go.Slice_string(["N"]))
     ev.Output.SetShape(go.Slice_int([n]), go.nil, go.Slice_string(["N"]))
     ev.Reward.SetShape(go.Slice_int([1]), go.nil, go.Slice_string(["1"]))
     if ev.RewVal == 0:
         ev.RewVal = 1
Ejemplo n.º 3
0
 def SetN(ev, n):
     """
     SetN initializes env for given number of options, and inits states
     """
     ev.N = n
     ev.P = [0.0] * n
     ev.Input.SetShape(go.Slice_int([n]), go.nil, go.Slice_string(["N"]))
     ev.Reward.SetShape(go.Slice_int([1]), go.nil, go.Slice_string(["1"]))
     if ev.RewVal == 0:
         ev.RewVal = 1
Ejemplo n.º 4
0
 def ConfigPats(ss):
     dt = ss.Pats
     sch = etable.Schema(
         [etable.Column("Name", etensor.STRING, go.nil, go.nil),
         etable.Column("Input", etensor.FLOAT32, go.Slice_int([4, 5]), go.Slice_string(["Y", "X"])),
         etable.Column("Output", etensor.FLOAT32, go.Slice_int([4, 5]), go.Slice_string(["Y", "X"]))]
     )
     dt.SetFromSchema(sch, 3)
     ss.Pats.SetMetaData("name", "Pats")
     ss.Pats.SetMetaData("desc", "Training patterns")
     patgen.PermutedBinaryRows(dt.Cols[1], 6, 1, 0)
     patgen.PermutedBinaryRows(dt.Cols[2], 6, 1, 0)
     cn = etensor.String(dt.Cols[0])
     cn.Values.copy(["any", "baker", "cheese"])
Ejemplo n.º 5
0
Archivo: attn.py Proyecto: mewbak/axon
    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.
        """
        if sheet == "":
            ss.Params.ValidateSheets(go.Slice_string(["Network", "Sim"]))

        spo = ss.Params.SetByName("Base").SheetByName("Network").SelByName(
            ".SpatToObj")
        spo.Params.SetParamByName("Prjn.WtScale.Rel", ("%g" % (ss.SpatToObj)))

        vsp = ss.Params.SetByName("Base").SheetByName("Network").SelByName(
            "#V1ToSpat1")
        vsp.Params.SetParamByName("Prjn.WtScale.Rel", ("%g" % (ss.V1ToSpat1)))

        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)
        if ss.KNaAdapt:
            ss.SetParamsSet("KNaAdapt", sheet, setMsg)
Ejemplo n.º 6
0
    def SetParams(ss, sheet, setMsg):
        """
        SetParams sets the params for "Base" and then current ParamSet.

        # this is important for catching typos and ensuring that all sheets can be used
        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.
        """
        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)
        ly = leabra.Layer(ss.Net.LayerByName("Neuron"))
        ly.Act.Gbar.E = float(ss.GbarE)
        ly.Act.Gbar.L = float(ss.GbarL)
        ly.Act.Erev.E = float(ss.ErevE)
        ly.Act.Erev.L = float(ss.ErevL)
        ly.Act.Noise.Var = float(ss.Noise)
        ly.Act.KNa.On = ss.KNaAdapt
        ly.Act.Update()
        ss.SpikeParams.CopyFromAct(ly.Act)  # keep sync'd
Ejemplo n.º 7
0
 def Init(ev, run):
     ev.Input.SetShape(go.Slice_int([3, ev.TotTime]), go.nil,
                       go.Slice_string(["3", "TotTime"]))
     ev.Reward.SetShape(go.Slice_int([1]), go.nil, go.Slice_string(["1"]))
     ev.Run.Scale = env.Run
     ev.Epoch.Scale = env.Epoch
     ev.Trial.Scale = env.Trial
     ev.Event.Scale = env.Event
     ev.Run.Init()
     ev.Epoch.Init()
     ev.Trial.Init()
     ev.Event.Init()
     ev.Run.Cur = run
     ev.Event.Max = ev.TotTime
     ev.Event.Cur = -1
     ev.TrialUpdt()
Ejemplo n.º 8
0
Archivo: inhib.py Proyecto: mewbak/axon
    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.
        """
        if sheet == "":
            ss.Params.ValidateSheets(go.Slice_string(["Network", "Sim"]))
        nt = ss.Net()
        err = ss.SetParamsSet("Base", sheet, setMsg)
        if ss.TrainedWts:
            ss.SetParamsSet("Trained", sheet, setMsg)
        else:
            ss.SetParamsSet("Untrained", sheet, setMsg)
        ffinhsc = ss.FFinhibWtScale
        if nt == ss.NetBidir:
            ffinhsc *= 0.5  # 2 inhib prjns so .5 ea

        hid = leabra.LeabraLayer(nt.LayerByName("Hidden")).AsLeabra()
        hid.Act.Gbar.I = ss.HiddenGbarI
        hid.Act.Dt.GTau = ss.HiddenGTau
        hid.Act.Update()
        inh = leabra.LeabraLayer(nt.LayerByName("Inhib")).AsLeabra()
        inh.Act.Gbar.I = ss.InhibGbarI
        inh.Act.Dt.GTau = ss.InhibGTau
        inh.Act.Update()
        ff = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Input")).AsLeabra()
        ff.WtScale.Rel = ffinhsc
        fb = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Hidden")).AsLeabra()
        fb.WtScale.Rel = ss.FBinhibWtScale
        hid.Inhib.Layer.On = ss.FFFBInhib
        inh.Inhib.Layer.On = ss.FFFBInhib
        fi = leabra.LeabraPrjn(hid.RcvPrjns.SendName("Inhib")).AsLeabra()
        fi.WtScale.Abs = ss.FmInhibWtScaleAbs
        fi = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Inhib")).AsLeabra()
        fi.WtScale.Abs = ss.FmInhibWtScaleAbs
        if nt == ss.NetBidir:
            hid = leabra.LeabraLayer(nt.LayerByName("Hidden2")).AsLeabra()
            hid.Act.Gbar.I = ss.HiddenGbarI
            hid.Act.Dt.GTau = ss.HiddenGTau
            hid.Act.Update()
            inh = leabra.LeabraLayer(nt.LayerByName("Inhib2")).AsLeabra()
            inh.Act.Gbar.I = ss.InhibGbarI
            inh.Act.Dt.GTau = ss.InhibGTau
            inh.Act.Update()
            hid.Inhib.Layer.On = ss.FFFBInhib
            inh.Inhib.Layer.On = ss.FFFBInhib
            fi = leabra.LeabraPrjn(hid.RcvPrjns.SendName("Inhib2")).AsLeabra()
            fi.WtScale.Abs = ss.FmInhibWtScaleAbs
            fi = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Inhib2")).AsLeabra()
            fi.WtScale.Abs = ss.FmInhibWtScaleAbs
            ff = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Hidden")).AsLeabra()
            ff.WtScale.Rel = ffinhsc
            fb = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Hidden2")).AsLeabra()
            fb.WtScale.Rel = ss.FBinhibWtScale
            inh = leabra.LeabraLayer(nt.LayerByName("Inhib")).AsLeabra()
            ff = leabra.LeabraPrjn(inh.RcvPrjns.SendName("Hidden2")).AsLeabra()
            ff.WtScale.Rel = ffinhsc
        return err
Ejemplo n.º 9
0
    def LogRun(ss, dt):
        """
        LogRun adds data from current run to the RunLog table.
        """
        run = ss.TrainEnv.Run.Cur # this is NOT triggered by increment yet -- use Cur
        row = dt.Rows
        dt.SetNumRows(row + 1)

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

        params = "Std"
        if ss.AvgLGain != 2.5:
            params += "_AvgLGain=%s" % (ss.AvgLGain)
        if ss.InputNoise != 0:
            params += "_InVar=%s" % (ss.InputNoise)

        dt.SetCellFloat("Run", row, float(run))
        dt.SetCellString("Params", row, params)
        dt.SetCellFloat("UniqPats", row, agg.Mean(epcix, "UniqPats")[0])

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

        # note: essential to use Go version of update when called from another goroutine
        ss.RunPlot.GoUpdate()
Ejemplo n.º 10
0
 def __init__(self):
     super(ProbeEnv, self).__init__()
     self.Nm = str()
     self.SetTags("Nm", 'desc:"name of this environment"')
     self.Dsc = str()
     self.SetTags("Dsc", 'desc:"description of this environment"')
     self.Words = go.Slice_string()
     self.SetTags(
         "Words",
         'desc:"list of words used for activating state units according to index"'
     )
     self.WordState = etensor.Float32()
     self.SetTags("WordState", 'desc:"current sentence activation state"')
     self.Run = env.Ctr()
     self.SetTags(
         "Run",
         'view:"inline" desc:"current run of model as provided during Init"'
     )
     self.Epoch = env.Ctr()
     self.SetTags(
         "Epoch",
         'view:"inline" desc:"number of times through Seq.Max number of sequences"'
     )
     self.Trial = env.Ctr()
     self.SetTags(
         "Trial",
         'view:"inline" desc:"trial is the step counter within sequence - how many steps taken within current sequence -- it resets to 0 at start of each sequence"'
     )
Ejemplo n.º 11
0
 def ScanWords(ev, txt):
     ev.Words = go.Slice_string()
     lns = txt.splitlines()
     for ln in lns:
         sp = ln.split()
         for s in sp:
             ev.Words.append(s)
     ev.WordMapFmWords()
Ejemplo n.º 12
0
    def __init__(self):
        super(Sim, self).__init__()
        self.SpatToObj = float(2)
        self.SetTags("SpatToObj", 'def:"2" desc:"spatial to object projection WtScale.Rel strength -- reduce to 1.5, 1 to test"')
        self.V1ToSpat1 = float(0.6)
        self.SetTags("V1ToSpat1", 'def:"0.6" desc:"V1 to Spat1 projection WtScale.Rel strength -- reduce to .55, .5 to test"')
        self.KNaAdapt = False
        self.SetTags("KNaAdapt", 'def:"false" desc:"sodium (Na) gated potassium (K) channels that cause neurons to fatigue over time"')
        self.CueDur = int(100)
        self.SetTags("CueDur", 'def:"100" desc:"number of cycles to present the cue -- 100 by default, 50 to 300 for KNa adapt testing"')
        self.Net = leabra.Network()
        self.SetTags("Net", 'view:"no-inline" desc:"the network -- click to view / edit parameters for layers, prjns, etc"')
        self.Test = TestType.MultiObjs
        self.SetTags("Test", 'desc:"select which type of test (input patterns) to use"')
        self.MultiObjs = etable.Table()
        self.SetTags("MultiObjs", 'view:"no-inline" desc:"click to see these testing input patterns"')
        self.StdPosner = etable.Table()
        self.SetTags("StdPosner", 'view:"no-inline" desc:"click to see these testing input patterns"')
        self.ClosePosner = etable.Table()
        self.SetTags("ClosePosner", 'view:"no-inline" desc:"click to see these testing input patterns"')
        self.ReversePosner = etable.Table()
        self.SetTags("ReversePosner", 'view:"no-inline" desc:"click to see these testing input patterns"')
        self.ObjAttn = etable.Table()
        self.SetTags("ObjAttn", 'view:"no-inline" desc:"click to see these testing input patterns"')
        self.TstTrlLog = etable.Table()
        self.SetTags("TstTrlLog", 'view:"no-inline" desc:"testing trial-level log data -- click to see record of network\'s response to each input"')
        self.TstStats = etable.Table()
        self.SetTags("TstStats", 'view:"no-inline" desc:"aggregate stats on testing data"')
        self.Params = params.Sets()
        self.SetTags("Params", 'view:"no-inline" desc:"full collection of param sets -- not really interesting for this model"')
        self.ParamSet = str()
        self.SetTags("ParamSet", 'view:"-" 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.TestEnv = env.FixedTable()
        self.SetTags("TestEnv", 'desc:"Testing environment -- manages iterating over testing"')
        self.Time = leabra.Time()
        self.SetTags("Time", 'desc:"leabra timing parameters and state"')
        self.ViewUpdt = leabra.TimeScales.FastSpike
        self.SetTags("ViewUpdt", 'desc:"at what time scale to update the display during testing?  Change to AlphaCyc to make display updating go faster"')
        self.TstRecLays = go.Slice_string(["Input", "V1", "Spat1", "Spat2", "Obj1", "Obj2", "Output"])
        self.SetTags("TstRecLays", 'desc:"names of layers to record activations etc of during testing"')

        # internal state - view:"-"
        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.TstTrlPlot = 0
        self.SetTags("TstTrlPlot", 'view:"-" desc:"the test-trial plot"')
        self.ValsTsrs = {}
        self.SetTags("ValsTsrs", 'view:"-" desc:"for holding layer values"')
        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.vp  = 0 
        self.SetTags("vp", 'view:"-" desc:"viewport"')
Ejemplo n.º 13
0
    def ConfigGui(ss):
        """
        ConfigGui configures the GoGi gui interface for this simulation,
        """
        width = 1600
        height = 1200

        gi.SetAppName("pyet")
        gi.SetAppAbout('testing of converting etable data between Go and Python. See <a href="https://github.com/emer/etable/blob/master/examples/pyet/README.md">README.md on GitHub</a>.</p>')

        win = gi.NewMainWindow("pyet", "PyEt Testing", 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")

        tabv = etview.TableView()
        tv.AddTab(tabv, "Pats")
        tabv.SetTable(ss.Pats, go.nil)
        ss.PatsTable = tabv

        split.SetSplitsList(go.Slice_float32([.2, .8]))
        recv = win.This()

        tbar.AddAction(gi.ActOpts(Label="Test", Icon="update", Tooltip="run the test."), recv, TestCB)

        # 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()
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def WordsFmWordMap(ev):
     ev.Words = go.Slice_string()
     ctr = 0
     for wrd in ev.WordMap:
         ev.Words.append(wrd)
         ctr += 1
     ev.Words.sort()
     for i, wrd in enumerate(ev.Words):
         ev.WordMap[wrd] = i
Ejemplo n.º 16
0
    def __init__(self):
        super(Sim, self).__init__()
        self.Net = leabra.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:"click to see the full face testing input patterns to use"')
        self.PartPats = etable.Table()
        self.SetTags("PartPats", 'view:"no-inline" desc:"click to see the partial face testing input patterns to use"')
        self.TstTrlLog = etable.Table()
        self.SetTags("TstTrlLog", 'view:"no-inline" desc:"testing trial-level log data -- click to see record of network\'s response to each input"')
        self.PrjnTable = etable.Table()
        self.SetTags("PrjnTable", 'view:"no-inline" desc:"projection of testing data"')
        self.Params = params.Sets()
        self.SetTags("Params", 'view:"no-inline" desc:"full collection of param sets -- not really interesting for this model"')
        self.ParamSet = str()
        self.SetTags("ParamSet", 'view:"-" 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.TestEnv = env.FixedTable()
        self.SetTags("TestEnv", 'desc:"Testing environment -- manages iterating over testing"')
        self.Time = leabra.Time()
        self.SetTags("Time", 'desc:"leabra timing parameters and state"')
        self.ViewUpdt = leabra.TimeScales.Cycle
        self.SetTags("ViewUpdt", 'desc:"at what time scale to update the display during testing?  Change to AlphaCyc to make display updating go faster"')
        self.TstRecLays = go.Slice_string(["Input", "Emotion", "Gender", "Identity"])
        self.SetTags("TstRecLays", 'desc:"names of layers to record activations etc of during testing"')
        self.ClustFaces = eplot.Plot2D()
        self.SetTags("ClustFaces", 'view:"no-inline" desc:"cluster plot of faces"')
        self.ClustEmote = eplot.Plot2D()
        self.SetTags("ClustEmote", 'view:"no-inline" desc:"cluster plot of emotions"')
        self.ClustGend = eplot.Plot2D()
        self.SetTags("ClustGend", 'view:"no-inline" desc:"cluster plot of genders"')
        self.ClustIdent = eplot.Plot2D()
        self.SetTags("ClustIdent", 'view:"no-inline" desc:"cluster plot of identity"')
        self.PrjnRandom = eplot.Plot2D()
        self.SetTags("PrjnRandom", 'view:"no-inline" desc:"random projection plot"')
        self.PrjnEmoteGend = eplot.Plot2D()
        self.SetTags("PrjnEmoteGend", 'view:"no-inline" desc:"projection plot of emotions & gender"')

        # internal state - view:"-"
        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.TstTrlPlot = 0
        self.SetTags("TstTrlPlot", 'view:"-" desc:"the test-trial plot"')
        self.ValsTsrs = {}
        self.SetTags("ValsTsrs", 'view:"-" desc:"for holding layer values"')
        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.vp  = 0 
        self.SetTags("vp", 'view:"-" desc:"viewport"')
Ejemplo n.º 17
0
Archivo: inhib.py Proyecto: mewbak/axon
 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([10, 10]),
                       go.Slice_string(["Y", "X"]))
     ])
     dt.SetFromSchema(sch, 1)
     patgen.PermutedBinaryRows(dt.Cols[1], int(ss.InputPct), 1, 0)
Ejemplo n.º 18
0
 def Init(ev, run):
     ev.Draw.Init()
     ev.Run.Scale = env.Run
     ev.Epoch.Scale = env.Epoch
     ev.Trial.Scale = env.Trial
     ev.Run.Init()
     ev.Epoch.Init()
     ev.Trial.Init()
     ev.Run.Cur = run
     ev.Trial.Cur = -1  # init state -- key so that first Step() = 0
     ev.Output.SetShape(go.Slice_int([4, 5]), go.nil,
                        go.Slice_string(["Y", "X"]))
Ejemplo n.º 19
0
    def Init(ev, run):
        ev.Run.Scale = env.Run
        ev.Epoch.Scale = env.Epoch
        ev.Trial.Scale = env.Trial
        ev.Trial.Max = len(ev.Words)
        ev.Run.Init()
        ev.Epoch.Init()
        ev.Trial.Init()
        ev.Run.Cur = run
        ev.Trial.Cur = -1

        ev.WordState.SetShape(go.Slice_int([len(ev.Words)]), go.nil,
                              go.Slice_string(["Words"]))
Ejemplo n.º 20
0
    def Init(ev, run):
        ev.Run.Scale = env.Run
        ev.Epoch.Scale = env.Epoch
        ev.Trial.Scale = env.Trial
        ev.Run.Init()
        ev.Epoch.Init()
        ev.Trial.Init()
        ev.Run.Cur = run
        ev.InitOrder()

        nw = len(ev.Words)
        ev.CurParaState.SetShape(go.Slice_int([nw]), go.nil,
                                 go.Slice_string(["Words"]))
Ejemplo n.º 21
0
 def WtWords(ss):
     if ss.NetView.Data.PrjnLay != "Hidden":
         log.Println("WtWords: must select unit in Hidden layer in NetView")
         return go.nil
     ly = ss.Net.LayerByName(ss.NetView.Data.PrjnLay)
     slay = ss.Net.LayerByName("Input")
     pvals = go.Slice_float32()
     slay.SendPrjnVals(pvals, "Wt", ly, ss.NetView.Data.PrjnUnIdx, "")
     ww = go.Slice_string()
     for i, wrd in enumerate(ss.TrainEnv.Words):
         wv = pvals[i]
         if wv > ss.WtWordsThr:
             ww.append(wrd)
     giv.SliceViewDialogNoStyle(ss.vp, ww, giv.DlgOpts(Title="WtWords Result"), go.nil, go.nil)
Ejemplo n.º 22
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.
     """
     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)
Ejemplo n.º 23
0
 def UpdateEnv(ss):
     if ss.Pats == PatsType.Easy:
         ss.TrainEnv.Table = etable.NewIdxView(ss.Easy)
         ss.TestEnv.Table = etable.NewIdxView(ss.Easy)
     elif ss.Pats == PatsType.Hard:
         ss.TrainEnv.Table = etable.NewIdxView(ss.Hard)
         ss.TestEnv.Table = etable.NewIdxView(ss.Hard)
     elif ss.Pats == PatsType.Impossible:
         ss.TrainEnv.Table = etable.NewIdxView(ss.Impossible)
         ss.TestEnv.Table = etable.NewIdxView(ss.Impossible)
     elif ss.Pats == PatsType.Lines2:
         all = etable.NewIdxView(ss.Lines2)
         splits = split.Permuted(all, go.Slice_float64([.9, .1]), go.Slice_string(["Train", "Test"]))
         ss.TrainEnv.Table = splits.Splits[0]
         ss.TestEnv.Table = splits.Splits[1]
Ejemplo n.º 24
0
    def Init(ev, run):
        ev.Run.Scale = env.Run
        ev.Epoch.Scale = env.Epoch
        ev.Seq.Scale = env.Sequence
        ev.Tick.Scale = env.Tick
        ev.Trial.Scale = env.Trial
        ev.Run.Init()
        ev.Epoch.Init()
        ev.Seq.Init()
        ev.Tick.Init()
        ev.Trial.Init()
        ev.Run.Cur = run
        ev.Trial.Cur = -1  # init state -- key so that first Step() = 0
        ev.SentIdx.Set(-1)

        ev.Rules.Init()
        ev.MapsFmWords()

        ev.WordState.SetShape(go.Slice_int([len(ev.Words)]), go.nil,
                              go.Slice_string(["Words"]))
        ev.RoleState.SetShape(go.Slice_int([len(ev.Roles)]), go.nil,
                              go.Slice_string(["Roles"]))
        ev.FillerState.SetShape(go.Slice_int([len(ev.Fillers)]), go.nil,
                                go.Slice_string(["Fillers"]))
Ejemplo n.º 25
0
    def ApplyInputs(ss, en):
        """
        ApplyInputs applies input patterns from given envirbonment.
        It is good practice to have this be a separate method with appropriate
        args so that it can be used for various different contexts
        (training, testing, etc).
        """
        ss.Net.InitExt()

        lays = go.Slice_string(["Input"])
        for lnm in lays :
            ly = leabra.Layer(ss.Net.LayerByName(lnm))
            pats = en.State(ly.Nm)
            if pats != 0:
                ly.ApplyExt(pats)
Ejemplo n.º 26
0
    def LogTstQuiz(ss, dt):
        trl = ss.TstTrlLog
        epc = ss.TrainEnv.Epoch.Prv # ?

        nper = 4 # number of paras per quiz question: Q, A, B, C
        nt = trl.Rows
        nq = int(nt / nper)
        pctcor = 0.0
        srow = dt.Rows
        dt.SetNumRows(srow + nq + 1)
        for qi in range(nq):
            ri = nper * qi
            qv = etensor.Float64(trl.CellTensor("Hidden", ri))
            mxai = 0
            mxcor = 0.0
            row = srow + qi
            for ai in range(nper - 1):
                av = etensor.Float64(trl.CellTensor("Hidden", ri+ai+1))
                cor = metric.Correlation64(qv.Values, av.Values)
                if cor > mxcor:
                    mxai = ai
                    mxcor = cor
                dt.SetCellTensorFloat1D("Correls", row, ai, cor)
            ans = go.Slice_string(["A", "B", "C"])[mxai]
            err = 1.0
            if mxai == 0: # A
                pctcor += 1
                err = 0

            # note: this shows how to use agg methods to compute summary data from another
            # data table, instead of incrementing on the Sim
            dt.SetCellFloat("Run", row, float(ss.TrainEnv.Run.Cur))
            dt.SetCellFloat("Epoch", row, float(epc))
            dt.SetCellFloat("QNo", row, float(qi))
            dt.SetCellString("Resp", row, ans)
            dt.SetCellFloat("Err", row, err)
        pctcor /= float(nq)
        row = dt.Rows - 1
        dt.SetCellFloat("Run", row, float(ss.TrainEnv.Run.Cur))
        dt.SetCellFloat("Epoch", row, float(epc))
        dt.SetCellFloat("QNo", row, -1)
        dt.SetCellString("Resp", row, "Total")
        dt.SetCellFloat("Err", row, pctcor)

        ss.TstQuizPctCor = pctcor

        # note: essential to use Go version of update when called from another goroutine
        ss.TstQuizPlot.GoUpdate()
Ejemplo n.º 27
0
 def TestAll(ss):
     """
     TestAll runs through the full set of testing items
     """
     err = ss.TestEnv.SetParas(go.Slice_string([ss.Words1, ss.Words2]))
     if err != 0:
         gi.PromptDialog(go.nil, gi.DlgOpts(Title= "Words errors",
             Prompt= err.Error()), gi.AddOk, gi.NoCancel,
             go.nil, go.nil)
         return
     ss.TestEnv.Init(ss.TrainEnv.Run.Cur)
     while True:
         ss.TestTrial(True)
         chg = ss.TestEnv.CounterChg(env.Epoch)
         if chg or ss.StopNow:
             break
Ejemplo n.º 28
0
 def __init__(self):
     super(SemEnv, self).__init__()
     self.Nm = str()
     self.SetTags("Nm", 'desc:"name of this environment"')
     self.Dsc = str()
     self.SetTags("Dsc", 'desc:"description of this environment"')
     self.Sequential = False
     self.SetTags(
         "Sequential",
         'desc:"if true, go sequentially through paragraphs -- else permuted"'
     )
     self.Order = go.Slice_int()
     self.SetTags(
         "Order",
         'desc:"permuted order of paras to present if not sequential -- updated every time through the list"'
     )
     self.TextFiles = []
     self.SetTags("TextFiles", 'desc:"paths to text files"')
     self.Words = go.Slice_string()
     self.SetTags("Words", 'desc:"list of words, in alpha order"')
     self.WordMap = {}
     self.SetTags("WordMap",
                  'view:"-" desc:"map of words onto index in Words list"')
     self.CurParaState = etensor.Float32()
     self.SetTags("CurParaState", 'desc:"current para activation state"')
     self.Paras = []
     self.SetTags("Paras", 'view:"-" desc:"paragraphs"')
     self.ParaLabels = []
     self.SetTags(
         "ParaLabels",
         'view:"-" desc:"special labels for each paragraph (provided in first word of para)"'
     )
     self.Run = env.Ctr()
     self.SetTags(
         "Run",
         'view:"inline" desc:"current run of model as provided during Init"'
     )
     self.Epoch = env.Ctr()
     self.SetTags(
         "Epoch",
         'view:"inline" desc:"number of times through Seq.Max number of sequences"'
     )
     self.Trial = env.Ctr()
     self.SetTags(
         "Trial",
         'view:"inline" desc:"trial is the step counter within epoch -- this is the index into Paras"'
     )
Ejemplo n.º 29
0
    def ApplyInputs(ss, en):
        """
        ApplyInputs applies input patterns from given envirbonment.
        It is good practice to have this be a separate method with appropriate

        # going to the same layers, but good practice and cheap anyway
        args so that it can be used for various different contexts
        (training, testing, etc).
        """
        ss.Net.InitExt()

        lays = go.Slice_string(["Input", "Emotion", "Gender", "Identity"])
        for lnm in lays :
            ly = leabra.LeabraLayer(ss.Net.LayerByName(lnm)).AsLeabra()
            pats = en.State(ly.Nm)
            if pats != 0:
                ly.ApplyExt(pats)
Ejemplo n.º 30
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.
     """
     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)
     ly = leabra.Layer(ss.Net.LayerByName("NeckerCube"))
     ly.Act.Noise.Var = float(ss.Noise)
     ly.Act.KNa.On = ss.KNaAdapt
     ly.Act.Update()
     ss.Time.CycPerQtr = int(ss.CycPerQtr)