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
def Lesion(ss, lay, locations, units): """ Lesion lesions given set of layers (or unlesions for NoLesion) and locations and number of units (Half = partial = 1/2 units, Full = both units) """ ss.InitWts(ss.Net) if lay == NoLesion: return if lay == LesionSpat1 or lay == LesionSpat12: sp1 = leabra.LeabraLayer(ss.Net.LayerByName("Spat1")) ss.LesionUnit(sp1, 3, 1) ss.LesionUnit(sp1, 4, 1) if units == LesionFull: ss.LesionUnit(sp1, 3, 0) ss.LesionUnit(sp1, 4, 0) if locations == LesionFull: ss.LesionUnit(sp1, 0, 1) ss.LesionUnit(sp1, 1, 1) ss.LesionUnit(sp1, 2, 1) if units == LesionFull: ss.LesionUnit(sp1, 0, 0) ss.LesionUnit(sp1, 1, 0) ss.LesionUnit(sp1, 2, 0) if lay == LesionSpat2 or lay == LesionSpat12: sp2 = leabra.LeabraLayer(ss.Net.LayerByName("Spat2")) ss.LesionUnit(sp2, 2, 1) if units == LesionFull: ss.LesionUnit(sp2, 2, 0) if locations == LesionFull: ss.LesionUnit(sp2, 0, 1) ss.LesionUnit(sp2, 1, 1) if units == LesionFull: ss.LesionUnit(sp2, 0, 0) ss.LesionUnit(sp2, 1, 0)
def LogTstCyc(ss, dt, cyc): """ LogTstCyc adds data from current cycle to the TstCycLog table. log always contains number of testing items """ if dt.Rows <= cyc: dt.SetNumRows(cyc + 1) row = cyc harm = ss.Harmony(ss.Net) ly = leabra.LeabraLayer(ss.Net.LayerByName("NeckerCube")).AsLeabra() dt.SetCellFloat("Cycle", row, float(cyc)) dt.SetCellFloat("Harmony", row, float(harm)) # dt.SetCellFloat("GknaFast", row, float(ly.Neurons[0].GknaFast)) # dt.SetCellFloat("GknaMed", row, float(ly.Neurons[0].GknaMed)) # dt.SetCellFloat("GknaSlow", row, float(ly.Neurons[0].GknaSlow)) for lnm in ss.TstRecLays: tsr = ss.ValsTsr(lnm) ly = leabra.Layer(ss.Net.LayerByName(lnm)) ly.UnitValsTensor(tsr, "Act") dt.SetCellTensor(lnm, row, tsr) if cyc % 10 == 0: ss.TstCycPlot.GoUpdate()
def ConfigTstTrlLog(ss, dt): dt.SetMetaData("name", "TstTrlLog") dt.SetMetaData("desc", "Record of testing per input pattern") dt.SetMetaData("read-only", "true") dt.SetMetaData("precision", str(LogPrec)) nt = ss.TestEnv.Table.Len() # number in view sch = etable.Schema( [etable.Column("Trial", etensor.INT64, go.nil, go.nil), etable.Column("TrialName", etensor.STRING, go.nil, go.nil)] ) for lnm in ss.TstRecLays: ly = leabra.LeabraLayer(ss.Net.LayerByName(lnm)).AsLeabra() sch.append(etable.Column(lnm, etensor.FLOAT32, ly.Shp.Shp, go.nil)) dt.SetFromSchema(sch, nt)
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)
def ConfigTstCycLog(ss, dt): dt.SetMetaData("name", "TstCycLog") dt.SetMetaData("desc", "Record of testing per cycle") dt.SetMetaData("read-only", "true") dt.SetMetaData("precision", str(LogPrec)) nt = 100 sch = etable.Schema([ etable.Column("Cycle", etensor.INT64, go.nil, go.nil), etable.Column("TrialName", etensor.STRING, go.nil, go.nil), etable.Column("Harmony", etensor.FLOAT64, go.nil, go.nil), etable.Column("GknaFast", etensor.FLOAT64, go.nil, go.nil), etable.Column("GknaMed", etensor.FLOAT64, go.nil, go.nil), etable.Column("GknaSlow", etensor.FLOAT64, go.nil, go.nil) ]) for lnm in ss.TstRecLays: ly = leabra.LeabraLayer(ss.Net.LayerByName(lnm)).AsLeabra() sch.append(etable.Column(lnm, etensor.FLOAT64, ly.Shp.Shp, go.nil)) dt.SetFromSchema(sch, nt)