/// <summary> /// This method initializes the dimension-value pairs and declarative chunks in the <see cref="World"/> /// </summary> static void InitializeWorld(Agent a) { //Initialize the dimension-value pairs for (int i = 1; i <= nodeCount; i++) { dvs.Add(World.NewDistributedDimensionValuePair(a, i)); } //Initializes the declarative chunks for (int i = 0; i < patterns.Length; i++) { //Generates a declarative chunk and specifies that the semantic label associated with the declarative chunk should NOT be added to the //dimension-value pairs of that chunk DeclarativeChunk dc = World.NewDeclarativeChunk(i, addSemanticLabel: false); //Adds the appropriate dimension-value pairs (as indicated by the "patterns" array) for each declarative chunk pattern representation foreach (var dv in dvs) { if (patterns[i].Contains(dv.Value)) { dc.Add(dv); } } //Adds the declarative chunk to the chunks list chunks.Add(dc); } }
static void SetupBPNetwork(Agent reasoner) { //Chunks for the whales, tuna, and bears DeclarativeChunk TunaChunk = World.NewDeclarativeChunk("Tuna"); DeclarativeChunk WhaleChunk = World.NewDeclarativeChunk("Whale"); DeclarativeChunk BearChunk = World.NewDeclarativeChunk("Bear"); //The 2 properties (as DV pairs) DimensionValuePair livesinwater = World.NewDimensionValuePair("lives in", "water"); DimensionValuePair eatsfish = World.NewDimensionValuePair("eats", "fish"); //The BP network to be used in the bottom level of the NACS BPNetwork net = AgentInitializer.InitializeAssociativeMemoryNetwork(reasoner, BPNetwork.Factory); //Adds the properties (as inputs) and chunks (as outputs) to the BP network net.Input.Add(livesinwater); net.Input.Add(eatsfish); net.Output.Add(TunaChunk); net.Output.Add(WhaleChunk); net.Output.Add(BearChunk); reasoner.Commit(net); //Adds the chunks to the GKS reasoner.AddKnowledge(TunaChunk); reasoner.AddKnowledge(WhaleChunk); reasoner.AddKnowledge(BearChunk); //Initializes a trainer to use to train the BP network GenericEquation trainer = ImplicitComponentInitializer.InitializeTrainer(GenericEquation.Factory, (Equation)trainerEQ); //Adds the properties (as inputs) and chunks (as outputs) to the trainer trainer.Input.Add(livesinwater); trainer.Input.Add(eatsfish); trainer.Output.Add(TunaChunk); trainer.Output.Add(WhaleChunk); trainer.Output.Add(BearChunk); trainer.Commit(); //Sets up data sets for each of the 2 properties List <ActivationCollection> sis = new List <ActivationCollection>(); ActivationCollection si = ImplicitComponentInitializer.NewDataSet(); si.Add(livesinwater, 1); sis.Add(si); si = ImplicitComponentInitializer.NewDataSet(); si.Add(eatsfish, 1); sis.Add(si); Console.Write("Training AMN..."); //Trains the BP network to report associative knowledge between the properties and the chunks ImplicitComponentInitializer.Train(net, trainer, sis, ImplicitComponentInitializer.TrainingTerminationConditions.SUM_SQ_ERROR); Console.WriteLine("Finished!"); }
public void Initialize() { // Dimension Value Pairs: sayWhat = World.NewDimensionValuePair("YourAction", "What do you want to do?"); // External Action Chunks: sayCooperate = World.NewExternalActionChunk("Cooperate"); sayDefect = World.NewExternalActionChunk("Defect"); // placeholder // GoalChunk salute = World.NewGoalChunk("Salute"); // GoalChunk bidFarewell = World.NewGoalChunk("Bid Farewell"); // WM Actions: wmuacC = World.NewWorkingMemoryUpdateActionChunk("Remember my opponent cooperated"); wmuacD = World.NewWorkingMemoryUpdateActionChunk("Remember my opponent defected"); DeclarativeChunk dcoc = World.NewDeclarativeChunk("My opponent cooperated"); DeclarativeChunk dcod = World.NewDeclarativeChunk("My opponent defected"); wmuacC.Add(WorkingMemory.RecognizedActions.SET_RESET, dcoc); wmuacD.Add(WorkingMemory.RecognizedActions.SET_RESET, dcod); // Set up a two agent model (meaning two agents with the same setup, playing against each other) Alice = World.NewAgent("Alice"); Bob = World.NewAgent("Bob"); // Simulating environment will determine inputs to each agent based on what each agent does.. // Feedback is determined by payoff matrix.. payoff = new int [2, 2, 2]; // Doing this the hard way. Could set this up all in-line above, but this makes the table // more explicit in terms of how we want to use it. // The payoff matrix here is called "Friend or Foe", about the simplest case // indices mean: FOR-WHICH-AGENT, WHAT-ALICE-DOES, WHAT-BOB-DOES payoff[_ALICE, _COOPERATE, _COOPERATE] = 1; payoff[_ALICE, _COOPERATE, _DEFECT] = 0; payoff[_ALICE, _DEFECT, _COOPERATE] = 2; payoff[_ALICE, _DEFECT, _DEFECT] = 0; payoff[_BOB, _COOPERATE, _COOPERATE] = 1; payoff[_BOB, _COOPERATE, _DEFECT] = 2; payoff[_BOB, _DEFECT, _COOPERATE] = 0; payoff[_BOB, _DEFECT, _DEFECT] = 0; maxpay = 2; results = new int[_TRIALS, 2, 2]; // Set up a Q-learning Net = // -- Eligibility Condition = True if "What do you want to do?" is in input, otherwise False // -- Input = "My opponent cooperated", "My opponent defected", "What do you want to do?" // -- Output = "I want to defect", "I want to cooperate" // // Also, RER is turned ON QBPNetwork net_A = AgentInitializer.InitializeImplicitDecisionNetwork(Alice, QBPNetwork.Factory, QNetEC); net_A.Input.Add(sayWhat); net_A.Input.Add(sayCooperate); net_A.Input.Add(sayDefect); net_A.Output.Add(sayCooperate); net_A.Output.Add(sayDefect); Alice.Commit(net_A); net_A.Parameters.LEARNING_RATE = 1; Alice.ACS.Parameters.PERFORM_RER_REFINEMENT = true; // it's true by default anyway Alice.ACS.Parameters.LEVEL_SELECTION_METHOD = ActionCenteredSubsystem.LevelSelectionMethods.COMBINED; Alice.ACS.Parameters.LEVEL_SELECTION_OPTION = ActionCenteredSubsystem.LevelSelectionOptions.FIXED; Alice.ACS.Parameters.FIXED_FR_LEVEL_SELECTION_MEASURE = 1; Alice.ACS.Parameters.FIXED_BL_LEVEL_SELECTION_MEASURE = 1; Alice.ACS.Parameters.FIXED_RER_LEVEL_SELECTION_MEASURE = 1; Alice.ACS.Parameters.WM_UPDATE_ACTION_PROBABILITY = 1; // Rules (2 rules) = // Rule 1: // -- Condition = "Your opponent cooperated" // -- Action = Set "My opponent cooperated" in WM // Rule 2: // -- Condition = "Your opponent defected" // -- Action = Set "My opponent defect" in WM FixedRule ruleA1 = AgentInitializer.InitializeActionRule(Alice, FixedRule.Factory, wmuacC, FRSC); FixedRule ruleA2 = AgentInitializer.InitializeActionRule(Alice, FixedRule.Factory, wmuacD, FRSC); Alice.Commit(ruleA1); Alice.Commit(ruleA2); QBPNetwork net_B = AgentInitializer.InitializeImplicitDecisionNetwork(Bob, QBPNetwork.Factory, QNetEC); net_B.Input.Add(sayWhat); net_B.Input.Add(sayCooperate); net_B.Input.Add(sayDefect); net_B.Output.Add(sayCooperate); net_B.Output.Add(sayDefect); Bob.Commit(net_B); // Use Weighted Combination // NO partial match on TL net_B.Parameters.LEARNING_RATE = 1; Bob.ACS.Parameters.PERFORM_RER_REFINEMENT = true; Bob.ACS.Parameters.LEVEL_SELECTION_METHOD = ActionCenteredSubsystem.LevelSelectionMethods.COMBINED; Bob.ACS.Parameters.LEVEL_SELECTION_OPTION = ActionCenteredSubsystem.LevelSelectionOptions.FIXED; Bob.ACS.Parameters.FIXED_FR_LEVEL_SELECTION_MEASURE = 1; Bob.ACS.Parameters.FIXED_BL_LEVEL_SELECTION_MEASURE = 1; Bob.ACS.Parameters.FIXED_RER_LEVEL_SELECTION_MEASURE = 1; Bob.ACS.Parameters.WM_UPDATE_ACTION_PROBABILITY = 1; FixedRule ruleB1 = AgentInitializer.InitializeActionRule(Bob, FixedRule.Factory, wmuacC, FRSC); FixedRule ruleB2 = AgentInitializer.InitializeActionRule(Bob, FixedRule.Factory, wmuacD, FRSC); Bob.Commit(ruleB1); Bob.Commit(ruleB2); // Initially using the same parameters for RER as Full Hello World RefineableActionRule.GlobalParameters.SPECIALIZATION_THRESHOLD_1 = -.6; RefineableActionRule.GlobalParameters.GENERALIZATION_THRESHOLD_1 = -.1; RefineableActionRule.GlobalParameters.INFORMATION_GAIN_OPTION = RefineableActionRule.IGOptions.PERFECT; /* * Note -- What should be seems is that when you pass in "Your opponent…", * the agent should return the "Do Nothing" external action * (since it performed an internal WM action).. * However, you can just ignore this either way.. */ }
static void InitializeWorld() { string feature = " "; //Initialize the dimension-value pairs for (int i = 1; i <= nodeCount; i++) { //names for features if (i == 1) { feature = "lactates"; } else if (i == 2) { feature = "hair/fur"; } else if (i == 3) { feature = "warm-blooded"; } else if (i == 4) { feature = "teeth"; } else if (i == 5) { feature = "tails"; } else if (i == 6) { feature = "lives on land"; } else if (i == 7) { feature = "omnivores"; } else if (i == 8) { feature = "herbivores"; } else if (i == 9) { feature = "carnivores"; } else if (i == 10) { feature = "small"; } else if (i == 11) { feature = "large"; } else if (i == 12) { feature = "something"; } else if (i == 13) { feature = "wild"; } else if (i == 14) { feature = "domesticated"; } else if (i == 15) { feature = "swims"; } else if (i == 16) { feature = "horns"; } dvs.Add(World.NewDimensionValuePair(feature, i)); } //Initializes the declarative chunks for (int i = 0; i < patterns.Length; i++) { //Generates a declarative chunk string mammal_name = " "; if (i == 0) { mammal_name = "mammal"; } else if (i == 1) { mammal_name = "hippo"; } else if (i == 2) { mammal_name = "rhino"; } else if (i == 3) { mammal_name = "hamster"; } DeclarativeChunk dc = World.NewDeclarativeChunk(mammal_name, addSemanticLabel: false); //Adds the appropriate dimension-value pairs (as indicated by the "patterns" array) for each declarative chunk pattern representation foreach (var dv in dvs) { if (patterns[i].Contains(dv.Value)) { dc.Add(dv); } } //Adds the declarative chunk to the chunks list chunks.Add(dc); } }
static void InitializeWorld() { string feature = " "; //Initialize the dimension-value pairs for (int i = 1; i <= nodeCount; i++) { //features for DV pairs if (i == 1) { feature = "wings"; } else if (i == 2) { feature = "beaks"; } else if (i == 3) { feature = "lays eggs"; } else if (i == 4) { feature = "bird"; } else if (i == 5) { feature = "flies south for winter"; } else if (i == 6) { feature = "eats berries"; } else if (i == 7) { feature = "eats plants (grass)"; } else if (i == 8) { feature = "swims"; } else if (i == 9) { feature = "builds nests"; } else if (i == 10) { feature = "small"; } else if (i == 11) { feature = "big"; } else if (i == 12) { feature = "red"; } else if (i == 13) { feature = "blue"; } else if (i == 14) { feature = "yellow"; } else if (i == 15) { feature = "brownish"; } dvs.Add(World.NewDimensionValuePair(feature, i)); } //Initializes the declarative chunks for (int i = 0; i < patterns.Length; i++) { //Generates a declarative chunk string bird_name = " "; if (i == 0) { bird_name = "robin"; } else if (i == 1) { bird_name = "sparrow"; } else if (i == 2) { bird_name = "goose"; } DeclarativeChunk dc = World.NewDeclarativeChunk(bird_name, addSemanticLabel: false); //Adds the appropriate dimension-value pairs (as indicated by the "patterns" array) for each declarative chunk pattern representation foreach (var dv in dvs) { if (patterns[i].Contains(dv.Value)) { dc.Add(dv); } } //Adds the declarative chunk to the chunks list chunks.Add(dc); } }
static void InitializeWorld() { string feature = " "; //Initializes the dimension-value pairs for (int i = 1; i <= nodeCount; i++) { if (i == 1) { feature = "wings"; } else if (i == 2) { feature = "flippers"; } else if (i == 3) { feature = "beaks"; } else if (i == 4) { feature = "lays eggs"; } else if (i == 5) { feature = "migrates in winter"; } else if (i == 6) { feature = "eats bugs and berries"; } else if (i == 7) { feature = "eats fish"; } else if (i == 8) { feature = "builds nests"; } else if (i == 9) { feature = "flies"; } else if (i == 10) { feature = "swims"; } else if (i == 11) { feature = "feathers"; } else if (i == 12) { feature = "colorful"; } else if (i == 13) { feature = "lives in trees"; } else if (i == 14) { feature = "lives in the polar regions"; } dvs.Add(World.NewDimensionValuePair(feature, i)); } //Initializes the declarative chunks for (int i = 0; i < patterns.Length; i++) { //Generates a declarative chunk string bird_name = " "; if (i == 0) { bird_name = "birds"; } else if (i == 1) { bird_name = "robins"; } else if (i == 2) { bird_name = "penguins"; } DeclarativeChunk dc = World.NewDeclarativeChunk(bird_name, addSemanticLabel: false); //Adds the appropriate dimension-value pairs (as indicated by the "patterns" array) for each declarative chunk pattern representation foreach (var dv in dvs) { if (patterns[i].Contains(dv.Value)) { dc.Add(dv); } } //Adds the declarative chunk to the chunks list chunks.Add(dc); } }