Changeset 751
- Timestamp:
- 12/01/2010 04:20:39 PM (10 years ago)
- Location:
- AgentMind/branches/FAtiMA-Modular
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/AdvancedMemoryComponent.java
r750 r751 63 63 private static final String G_MEMORY = "G-MEMORY"; 64 64 65 66 67 private ArrayList<GER> _gers;68 65 private Generalisation _generalisation; 69 66 private CompoundCue _compoundCue; … … 73 70 private long _lastTime; 74 71 72 private ArrayList<String> _gAttributes; 73 private GeneralMemoryPanel _gmPanel; 74 75 75 public AdvancedMemoryComponent() 76 76 { 77 this._gers = new ArrayList<GER>();78 77 this._generalisation = new Generalisation(); 79 78 this._compoundCue = new CompoundCue(); … … 81 80 this._commonalities = new Commonalities(); 82 81 this._lastTime = AgentSimulationTime.GetInstance().Time(); 82 83 this._gAttributes = new ArrayList<String>(); 83 84 } 84 85 … … 93 94 } 94 95 95 /* 96 * Performs generalisation and update the GeneralMemory with frequent item sets 97 */ 98 public void generalise(EpisodicMemory episodicMemory) 99 { 100 ArrayList<AttributeItemSet> itemSet = this._generalisation.generalise(_episodicMemory); 101 this.AddGER(itemSet); 96 public Generalisation getGeneralisation() 97 { 98 return _generalisation; 102 99 } 103 100 … … 116 113 }catch(Exception e){ 117 114 throw new RuntimeException("GeneralMemory Error on Loading the Actions XML File:" + e); 118 }119 }120 121 public void AddGER(ArrayList<AttributeItemSet> itemSet)122 {123 // clearing the list before generalising124 this._gers.clear();125 126 for (int i = 0; i < itemSet.size(); i++)127 {128 AttributeItemSet attrItemSet = itemSet.get(i);129 GER ger = new GER();130 131 // set the coverage (frequency of occurrence) of the item set132 ger.setCoverage(attrItemSet.getCoverage());133 for (int j = 0; j < attrItemSet.getCandidateItemSet().size(); j++)134 {135 AttributeItem attrItem = attrItemSet.getCandidateItemSet().get(j);136 137 if (attrItem.getAttrName() == "subject")138 ger.setSubject(attrItem.getAttrValue());139 else if (attrItem.getAttrName() == "action")140 ger.setAction(attrItem.getAttrValue());141 else if (attrItem.getAttrName() == "target")142 ger.setTarget(attrItem.getAttrValue());143 else if (attrItem.getAttrName() == "desirability")144 ger.setDesirability(attrItem.getAttrValue());145 else if (attrItem.getAttrName() == "praiseworthiness")146 ger.setPraiseworthiness(attrItem.getAttrValue());147 else if (attrItem.getAttrName() == "time")148 ger.setTime(attrItem.getAttrValue());149 150 }151 this._gers.add(ger);152 115 } 153 116 } … … 159 122 * added by Meiyii 19/11/09 160 123 */ 161 private ArrayList<String> ExtractKnownInfo(String known)124 private ArrayList<String> extractKnownInfo(String known) 162 125 { 163 126 ArrayList<String> knownInfo = new ArrayList<String>(); … … 173 136 } 174 137 175 public ArrayList<GER> getAllGERs() 176 { 177 return this._gers; 178 } 179 180 /* 181 * TODO 138 /** 139 * Extract generalisation attributes 140 * @param 141 * @return 142 * added by Meiyii 1/12/10 182 143 */ 183 public String toXML() 184 { 185 String gm = "<GeneralMemory>"; 186 for(ListIterator<GER> li = this._gers.listIterator();li.hasNext();) 187 { 188 189 } 190 gm += "</GeneralMemory>"; 191 return gm; 144 private void extractGAttributes(String attributes) 145 { 146 this._gAttributes.clear(); 147 148 StringTokenizer st = new StringTokenizer(attributes, "*"); 149 while(st.hasMoreTokens()) 150 { 151 String attributeStr = st.nextToken(); 152 _gAttributes.add(attributeStr); 153 System.out.println("gAttribute " + attributeStr); 154 } 155 this._gmPanel.PanelAttributes(_gAttributes); 192 156 } 193 157 … … 210 174 @Override 211 175 public void updateCycle(AgentModel am, long time) { 212 if (time >= _lastTime + 86400000) {176 /*if (time >= _lastTime + 86400000) { 213 177 _lastTime = time; 214 178 215 generalise(am.getMemory().getEpisodicMemory()); 216 } 179 _gAttributes.clear(); 180 _gAttributes.add("subject"); 181 _gAttributes.add("target"); 182 _gAttributes.add("action"); 183 _gAttributes.add("desirability"); 184 _gAttributes.add("praiseworthiness"); 185 _gAttributes.add("time"); 186 187 this._generalisation.generalise(_gAttributes, _episodicMemory); 188 }*/ 217 189 } 218 190 … … 247 219 @Override 248 220 public AgentDisplayPanel createDisplayPanel(AgentModel am) { 249 return new GeneralMemoryPanel(this); 221 222 this._gmPanel = new GeneralMemoryPanel(this); 223 return this._gmPanel; 250 224 } 251 225 … … 276 250 } 277 251 System.out.println("question " + question); 278 ArrayList<String> knownInfo = ExtractKnownInfo(known);252 ArrayList<String> knownInfo = extractKnownInfo(known); 279 253 _spreadActivate.Spread(question, knownInfo, _episodicMemory); 280 254 … … 316 290 } 317 291 ActionDetail ad = _compoundCue.getStrongestResult(); 318 System.out.println(" ID " + ad.getID() + "max evaluation " + _compoundCue.getEvaluation());292 System.out.println("max ID " + ad.getID()); 319 293 System.out.println("\n\n"); 320 294 } 321 295 else if(msgType.equals(G_MEMORY)) 322 296 { 323 generalise(_episodicMemory); 324 } 325 } 326 327 297 extractGAttributes(perception); 298 299 //Performs generalisation and update the GeneralMemory with frequent item sets 300 _generalisation.generalise(_gAttributes, _episodicMemory); 301 302 ArrayList<GER> gers = _generalisation.getAllGERs(); 303 for (GER ger : gers) 304 { 305 System.out.println("GER : " + ger.toString()); 306 } 307 } 308 } 328 309 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/GER.java
r727 r751 40 40 private String _subject; 41 41 private String _action; 42 private String _target; 42 private String _intention; 43 private String _target; 44 private String _object; 43 45 44 46 private String _time; 45 //private String _location;47 private String _location; 46 48 47 49 private String _desirability; … … 53 55 this._subject = ""; 54 56 this._action = ""; 57 this._intention = ""; 55 58 this._target = ""; 59 this._object = ""; 56 60 this._desirability = ""; 57 61 this._praiseworthiness = ""; 62 this._location = ""; 58 63 this._time = ""; 59 64 this._coverage = 0; 60 65 } 61 66 62 public GER(String subject, String action, String target, String desirability, String praiseworthiness, String time)67 public void setSubject(String subject) 63 68 { 64 69 this._subject = subject; 70 } 71 72 public void setAction(String action) 73 { 65 74 this._action = action; 75 } 76 77 public void setIntention(String intention) 78 { 79 this._intention = intention; 80 } 81 82 public void setTarget(String target) 83 { 66 84 this._target = target; 67 this._desirability = desirability; 68 this._praiseworthiness = praiseworthiness; 69 this._time = time; 70 } 71 72 public void setSubject(String subject) 73 { 74 this._subject = subject; 75 } 76 77 public void setAction(String action) 78 { 79 this._action = action; 80 } 81 82 public void setTarget(String target) 83 { 84 this._target = target; 85 } 86 87 public void setObject(String object) 88 { 89 this._object = object; 85 90 } 86 91 … … 95 100 } 96 101 102 public void setLocation(String location) 103 { 104 this._location = location; 105 } 106 97 107 public void setTime(String time) 98 108 { … … 115 125 } 116 126 127 public String getIntention() 128 { 129 return this._intention; 130 } 131 117 132 public String getTarget() 118 133 { … … 120 135 } 121 136 137 public String getObject() 138 { 139 return this._object; 140 } 141 122 142 public String getDesirability() 123 143 { … … 130 150 } 131 151 152 public String getLocation() 153 { 154 return this._location; 155 } 156 132 157 public String getTime() 133 158 { … … 139 164 return this._coverage; 140 165 } 166 167 public String toString() 168 { 169 String ger = ""; 170 171 if(this._subject != "") 172 { 173 ger += "subject " + this._subject + " "; 174 } 175 if(this._action != "") 176 { 177 ger += "action " + this._action + " "; 178 } 179 if(this._intention != "") 180 { 181 ger += "intention " + this._intention + " "; 182 } 183 if(this._target != "") 184 { 185 ger += "target " + this._target + " "; 186 } 187 if(this._object != "") 188 { 189 ger += "object " + this._object + " "; 190 } 191 if(this._desirability != "") 192 { 193 ger += "desirability " + this._desirability + " "; 194 } 195 if(this._praiseworthiness != "") 196 { 197 ger += "praiseworthiness " + this._praiseworthiness + " "; 198 } 199 if(this._location != "") 200 { 201 ger += "location " + this._location + " "; 202 } 203 if(this._time != "") 204 { 205 ger += "time " + this._time + " "; 206 } 207 ger += "coverage " + String.valueOf(this._coverage); 208 209 return ger; 210 } 211 212 public String toXML() 213 { 214 String ger = "<GER>\n"; 215 216 if(this._subject != "") 217 { 218 ger += "<subject>" + this._subject + "</subject>\n"; 219 } 220 if(this._action != "") 221 { 222 ger += "<action>" + this._action + "</action>\n"; 223 } 224 if(this._intention != "") 225 { 226 ger += "<intention>" + this._intention + "</intention>\n"; 227 } 228 if(this._target != "") 229 { 230 ger += "<target>" + this._target + "</target>\n"; 231 } 232 if(this._object != "") 233 { 234 ger += "<object>" + this._object + "</object>\n"; 235 } 236 if(this._desirability != "") 237 { 238 ger += "<desirability>" + this._desirability + "</desirability>\n"; 239 } 240 if(this._praiseworthiness != "") 241 { 242 ger += "<praiseworthiness>" + this._praiseworthiness + "</praiseworthiness>\n"; 243 } 244 if(this._location != "") 245 { 246 ger += "<location>" + this._location + "</location>\n"; 247 } 248 if(this._time != "") 249 { 250 ger += "<time>" + this._time + "</time>\n"; 251 } 252 ger += "<coverage>" + String.valueOf(this._coverage) + "</coverage>\n"; 253 254 ger += "</GER>\n"; 255 return ger; 256 } 141 257 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/GERDisplay.java
r727 r751 3 3 import java.awt.Color; 4 4 import java.awt.Dimension; 5 import java.util.ArrayList; 5 6 6 7 import javax.swing.BorderFactory; 7 8 import javax.swing.BoxLayout; 9 import javax.swing.JLabel; 8 10 import javax.swing.JPanel; 9 11 import javax.swing.JTextField; … … 16 18 JTextField _subject; 17 19 JTextField _action; 20 JTextField _intention; 18 21 JTextField _target; 22 JTextField _object; 19 23 JTextField _desirability; 20 24 JTextField _praiseworthiness; 25 JTextField _location; 21 26 JTextField _time; 22 27 JTextField _coverage; 23 28 24 public GERDisplay(GER ger ) {29 public GERDisplay(GER ger, ArrayList<String> gAttributes) { 25 30 super(); 26 31 this.setBorder(BorderFactory.createRaisedBevelBorder()); … … 29 34 this.setMaximumSize(new Dimension(500,30)); 30 35 31 _subject = new JTextField(ger.getSubject()); 32 _subject.setMinimumSize(new Dimension(50,30)); 33 _subject.setMaximumSize(new Dimension(50,30)); 34 _subject.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 35 this.add(_subject); 36 if (gAttributes.contains("subject")) 37 { 38 _subject = new JTextField(ger.getSubject()); 39 _subject.setMinimumSize(new Dimension(50,30)); 40 _subject.setMaximumSize(new Dimension(50,30)); 41 _subject.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 42 this.add(_subject); 43 } 36 44 37 _action = new JTextField(ger.getAction()); 38 _action.setMinimumSize(new Dimension(80,30)); 39 _action.setMaximumSize(new Dimension(80,30)); 40 _action.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 41 this.add(_action); 45 if (gAttributes.contains("action")) 46 { 47 _action = new JTextField(ger.getAction()); 48 _action.setMinimumSize(new Dimension(80,30)); 49 _action.setMaximumSize(new Dimension(80,30)); 50 _action.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 51 this.add(_action); 52 } 42 53 43 _target = new JTextField(ger.getTarget()); 44 _target.setMinimumSize(new Dimension(80,30)); 45 _target.setMaximumSize(new Dimension(80,30)); 46 _target.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 47 this.add(_target); 54 if (gAttributes.contains("intention")) 55 { 56 _intention = new JTextField(ger.getIntention()); 57 _intention.setMinimumSize(new Dimension(80,30)); 58 _intention.setMaximumSize(new Dimension(80,30)); 59 _intention.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 60 this.add(_intention); 61 } 48 62 49 _desirability = new JTextField(ger.getDesirability()); 50 _desirability.setMinimumSize(new Dimension(80,30)); 51 _desirability.setMaximumSize(new Dimension(80,30)); 52 _desirability.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 53 this.add(_desirability); 63 if (gAttributes.contains("target")) 64 { 65 _target = new JTextField(ger.getTarget()); 66 _target.setMinimumSize(new Dimension(80,30)); 67 _target.setMaximumSize(new Dimension(80,30)); 68 _target.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 69 this.add(_target); 70 } 54 71 55 _praiseworthiness = new JTextField(ger.getPraiseworthiness()); 56 _praiseworthiness.setMinimumSize(new Dimension(80,30)); 57 _praiseworthiness.setMaximumSize(new Dimension(80,30)); 58 _praiseworthiness.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 59 this.add(_praiseworthiness); 72 if (gAttributes.contains("object")) 73 { 74 _object = new JTextField(ger.getObject()); 75 _object.setMinimumSize(new Dimension(80,30)); 76 _object.setMaximumSize(new Dimension(80,30)); 77 _object.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 78 this.add(_object); 79 } 60 80 61 _time = new JTextField(ger.getTime()); 62 _time.setMinimumSize(new Dimension(80,30)); 63 _time.setMaximumSize(new Dimension(80,30)); 64 _time.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 65 this.add(_time); 81 if (gAttributes.contains("desirability")) 82 { 83 _desirability = new JTextField(ger.getDesirability()); 84 _desirability.setMinimumSize(new Dimension(80,30)); 85 _desirability.setMaximumSize(new Dimension(80,30)); 86 _desirability.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 87 this.add(_desirability); 88 } 89 90 if (gAttributes.contains("praiseworthiness")) 91 { 92 _praiseworthiness = new JTextField(ger.getPraiseworthiness()); 93 _praiseworthiness.setMinimumSize(new Dimension(80,30)); 94 _praiseworthiness.setMaximumSize(new Dimension(80,30)); 95 _praiseworthiness.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 96 this.add(_praiseworthiness); 97 } 98 99 if (gAttributes.contains("location")) 100 { 101 _location = new JTextField(ger.getLocation()); 102 _location.setMinimumSize(new Dimension(80,30)); 103 _location.setMaximumSize(new Dimension(80,30)); 104 _location.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 105 this.add(_location); 106 } 107 108 if (gAttributes.contains("time")) 109 { 110 _time = new JTextField(ger.getTime()); 111 _time.setMinimumSize(new Dimension(80,30)); 112 _time.setMaximumSize(new Dimension(80,30)); 113 _time.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 114 this.add(_time); 115 } 66 116 67 117 _coverage = new JTextField(String.valueOf(ger.getCoverage())); … … 69 119 _coverage.setMaximumSize(new Dimension(80,30)); 70 120 _coverage.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 71 this.add(_coverage); 121 this.add(_coverage); 122 72 123 } 73 124 -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/GeneralMemoryPanel.java
r727 r751 4 4 import java.awt.Dimension; 5 5 import java.util.ArrayList; 6 import java.util.Collections; 6 7 import java.util.ListIterator; 7 8 … … 23 24 private ArrayList<GERDisplay> _gerDisplayList; 24 25 private AdvancedMemoryComponent _generalMemory; 26 private ArrayList<String> _gAttributes = new ArrayList<String>(); 27 28 private JPanel _aux; 25 29 26 30 public GeneralMemoryPanel(AdvancedMemoryComponent gm) … … 42 46 43 47 this.add(gerScroll); 48 } 49 50 public void PanelAttributes(ArrayList<String> gAttributes) 51 { 52 _gersPanel.removeAll(); 53 _gerDisplayList.clear(); 44 54 45 JPanel aux = new JPanel(); 46 aux.setLayout(new BoxLayout(aux,BoxLayout.X_AXIS)); 47 aux.setMinimumSize(new Dimension(500,30)); 48 aux.setMaximumSize(new Dimension(500,30)); 49 50 JLabel lbl = new JLabel("Subject"); // Who? 51 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 52 lbl.setMinimumSize(new Dimension(50,30)); 53 lbl.setMaximumSize(new Dimension(50,30)); 54 aux.add(lbl); 55 _aux = new JPanel(); 56 _aux.setLayout(new BoxLayout(_aux,BoxLayout.X_AXIS)); 57 _aux.setMinimumSize(new Dimension(500,30)); 58 _aux.setMaximumSize(new Dimension(500,30)); 59 60 JLabel lbl; 61 _gAttributes = gAttributes; 55 62 56 lbl = new JLabel("Action"); // What? 57 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 58 lbl.setMinimumSize(new Dimension(80,30)); 59 lbl.setMaximumSize(new Dimension(80,30)); 60 aux.add(lbl); 63 if (_gAttributes.contains("subject")) 64 { 65 lbl = new JLabel("Subject"); // Who? 66 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 67 lbl.setMinimumSize(new Dimension(50,30)); 68 lbl.setMaximumSize(new Dimension(50,30)); 69 _aux.add(lbl); 70 } 61 71 62 lbl = new JLabel("Target"); // Whom? 63 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 64 lbl.setMinimumSize(new Dimension(80,30)); 65 lbl.setMaximumSize(new Dimension(80,30)); 66 aux.add(lbl); 72 if (_gAttributes.contains("action")) 73 { 74 lbl = new JLabel("Action"); // What? 75 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 76 lbl.setMinimumSize(new Dimension(80,30)); 77 lbl.setMaximumSize(new Dimension(80,30)); 78 _aux.add(lbl); 79 } 67 80 68 lbl = new JLabel("Desirability"); // Desirable? 69 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 70 lbl.setMinimumSize(new Dimension(80,30)); 71 lbl.setMaximumSize(new Dimension(80,30)); 72 aux.add(lbl); 81 if (_gAttributes.contains("intention")) 82 { 83 lbl = new JLabel("Intention"); // What? 84 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 85 lbl.setMinimumSize(new Dimension(80,30)); 86 lbl.setMaximumSize(new Dimension(80,30)); 87 _aux.add(lbl); 88 } 73 89 74 lbl = new JLabel("Praiseworthiness"); // Praiseworthy? 75 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 76 lbl.setMinimumSize(new Dimension(80,30)); 77 lbl.setMaximumSize(new Dimension(80,30)); 78 aux.add(lbl); 90 if (_gAttributes.contains("target")) 91 { 92 lbl = new JLabel("Target"); // Whom? 93 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 94 lbl.setMinimumSize(new Dimension(80,30)); 95 lbl.setMaximumSize(new Dimension(80,30)); 96 _aux.add(lbl); 97 } 79 98 80 lbl = new JLabel("Time"); // When? 81 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 82 lbl.setMinimumSize(new Dimension(80,30)); 83 lbl.setMaximumSize(new Dimension(80,30)); 84 aux.add(lbl); 99 if (_gAttributes.contains("object")) 100 { 101 lbl = new JLabel("Object"); // What? 102 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 103 lbl.setMinimumSize(new Dimension(80,30)); 104 lbl.setMaximumSize(new Dimension(80,30)); 105 _aux.add(lbl); 106 } 107 108 if (_gAttributes.contains("desirability")) 109 { 110 lbl = new JLabel("Desirability"); // Desirable? 111 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 112 lbl.setMinimumSize(new Dimension(80,30)); 113 lbl.setMaximumSize(new Dimension(80,30)); 114 _aux.add(lbl); 115 } 116 117 if (_gAttributes.contains("praiseworthiness")) 118 { 119 lbl = new JLabel("Praiseworthiness"); // Praiseworthy? 120 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 121 lbl.setMinimumSize(new Dimension(80,30)); 122 lbl.setMaximumSize(new Dimension(80,30)); 123 _aux.add(lbl); 124 } 125 126 if (_gAttributes.contains("location")) 127 { 128 lbl = new JLabel("Location"); // Where? 129 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 130 lbl.setMinimumSize(new Dimension(80,30)); 131 lbl.setMaximumSize(new Dimension(80,30)); 132 _aux.add(lbl); 133 } 134 135 if (_gAttributes.contains("time")) 136 { 137 lbl = new JLabel("Time"); // When? 138 lbl.setBorder(BorderFactory.createLineBorder(new Color(0,0,0))); 139 lbl.setMinimumSize(new Dimension(80,30)); 140 lbl.setMaximumSize(new Dimension(80,30)); 141 _aux.add(lbl); 142 } 85 143 86 144 lbl = new JLabel("Coverage"); // Frequency? … … 88 146 lbl.setMinimumSize(new Dimension(80,30)); 89 147 lbl.setMaximumSize(new Dimension(80,30)); 90 aux.add(lbl);148 _aux.add(lbl); 91 149 92 _gersPanel.add( aux);150 _gersPanel.add(_aux); 93 151 } 94 95 152 153 public boolean Update(AgentCore ag) 96 154 { 97 155 return Update((AgentModel) ag); … … 100 158 public boolean Update(AgentModel am) 101 159 { 102 ListIterator<GER> li = _generalMemory.get AllGERs().listIterator();160 ListIterator<GER> li = _generalMemory.getGeneralisation().getAllGERs().listIterator(); 103 161 104 162 GER ger; 105 163 GERDisplay gerDisplay; 164 106 165 int index; 107 166 108 167 while (li.hasNext()) { 109 168 index = li.nextIndex(); 110 169 ger = (GER) li.next(); 111 170 if(index >= _gerDisplayList.size()) { 112 gerDisplay = new GERDisplay(ger);113 114 171 gerDisplay = new GERDisplay(ger, _gAttributes); 172 _gerDisplayList.add(gerDisplay); 173 _gersPanel.add(gerDisplay.getPanel()); 115 174 } 116 else { 117 gerDisplay = (GERDisplay) _gerDisplayList.get(index); 118 } 119 } 175 } 176 120 177 return true; 121 178 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/java/FAtiMA/advancedMemoryComponent/Generalisation.java
r727 r751 51 51 private EpisodicMemory _episodicMemory; 52 52 private static final int MIN_THRESHOLD = 3; 53 private static final int ITEMSET_SIZE = 6; 53 private int _itemSize; 54 55 private ArrayList<String> _gAttributes; 56 private ArrayList<GER> _gers; 54 57 55 58 public Generalisation() 56 { 59 { 57 60 this._itemSet = new ArrayList<AttributeItemSet>(); 58 61 this._episodicMemory = null; 62 this._gAttributes = new ArrayList<String>(); 63 this._gers = new ArrayList<GER>(); 64 this._itemSize = 0; 59 65 } 60 66 … … 63 69 * of the agent's experiences 64 70 */ 65 public ArrayList<AttributeItemSet> generalise(EpisodicMemory episodicMemory) 66 { 71 public void generalise(ArrayList<String> gAttributes, EpisodicMemory episodicMemory) 72 { 73 //Setting the attributes to generalise on 74 this._gAttributes = gAttributes; 75 this._itemSize = gAttributes.size(); 76 67 77 this._episodicMemory = episodicMemory; 68 78 this._itemSet.clear(); … … 74 84 this.combineItemSet(); 75 85 76 // Returnthe frequent item sets77 return this._itemSet;86 // Create GERs from the frequent item sets 87 this.createGER(this._itemSet); 78 88 } 79 89 … … 91 101 MemoryEpisode event = it.next(); 92 102 ArrayList<ActionDetail> details = event.getDetails(); 93 this.identi tyItems(details);103 this.identifyItems(details); 94 104 } 95 105 96 106 ArrayList<ActionDetail> records = _episodicMemory.getDetails(); 97 this.identi tyItems(records);107 this.identifyItems(records); 98 108 99 109 // discard the non-frequent items from the itemSet … … 109 119 Collections.sort(_itemSet); 110 120 121 /*System.out.println("Frequent item sets"); 111 122 for (int j = 0; j < _itemSet.size(); j++) 112 123 { 113 124 System.out.println(_itemSet.get(j).toString()); 114 } 125 } */ 115 126 } 116 127 … … 118 129 * Obtain all attribute items from the action details list 119 130 */ 120 private void identi tyItems(ArrayList<ActionDetail> details)131 private void identifyItems(ArrayList<ActionDetail> details) 121 132 { 122 133 for (int i = 0; i < details.size(); i++) … … 124 135 ActionDetail ad = details.get(i); 125 136 126 if ( ad.getSubject() != null)137 if (_gAttributes.contains("subject") && (ad.getSubject() != null)) 127 138 { 128 139 // subject field … … 130 141 this.candidateFrequentItems(subject); 131 142 } 132 if ( ad.getAction() != null)143 if (_gAttributes.contains("action") && (ad.getAction() != null)) 133 144 { 134 145 // action field … … 136 147 this.candidateFrequentItems(action); 137 148 } 138 if (ad.getTarget() != null) 149 if (_gAttributes.contains("intention") && (ad.getIntention() != null)) 150 { 151 // intention field 152 AttributeItem intention = new AttributeItem("intention", ad.getAction()); 153 this.candidateFrequentItems(intention); 154 } 155 if (_gAttributes.contains("target") && (ad.getTarget() != null)) 139 156 { 140 157 // target field … … 142 159 this.candidateFrequentItems(target); 143 160 } 144 145 // desirability 146 AttributeItem desirability = new AttributeItem("desirability", ad.getDesirability()>=0 ? "positive":"negative"); 147 this.candidateFrequentItems(desirability); 148 149 // praiseworthiness 150 AttributeItem praiseworthiness = new AttributeItem("praiseworthiness", ad.getPraiseworthiness()>=0 ? "positive":"negative"); 151 this.candidateFrequentItems(praiseworthiness); 152 153 if (ad.getTime() != null) 161 if (_gAttributes.contains("object") && (ad.getObject() != null)) 162 { 163 // object field 164 AttributeItem object = new AttributeItem("object", ad.getAction()); 165 this.candidateFrequentItems(object); 166 } 167 168 if (_gAttributes.contains("desirability")) 169 { 170 // desirability 171 AttributeItem desirability = new AttributeItem("desirability", ad.getDesirability()>=0 ? "positive":"negative"); 172 this.candidateFrequentItems(desirability); 173 } 174 175 if (_gAttributes.contains("praiseworthiness")) 176 { 177 // praiseworthiness 178 AttributeItem praiseworthiness = new AttributeItem("praiseworthiness", ad.getPraiseworthiness()>=0 ? "positive":"negative"); 179 this.candidateFrequentItems(praiseworthiness); 180 } 181 182 if (_gAttributes.contains("location") && (ad.getLocation() != null)) 183 { 184 // location field 185 AttributeItem location = new AttributeItem("location", ad.getLocation()); 186 this.candidateFrequentItems(location); 187 } 188 if (_gAttributes.contains("time") && (ad.getTime() != null)) 154 189 { 155 190 // subject field … … 187 222 ArrayList<AttributeItemSet> tempItemSet = new ArrayList<AttributeItemSet>(); 188 223 189 for (int k = 1; k < Generalisation.ITEMSET_SIZE; k++)224 for (int k = 1; k < _itemSize ; k++) 190 225 { 191 226 for (int i = 0; i < this._itemSet.size()-1; i++) … … 196 231 { 197 232 AttributeItemSet tempAttrItemSet1 = (AttributeItemSet) this._itemSet.get(i).clone(); 198 System.out.println(tempAttrItemSet1.toString());199 233 AttributeItemSet tempAttrItemSet2 = (AttributeItemSet) this._itemSet.get(j).clone(); 200 System.out.println(tempAttrItemSet2.toString());201 234 tempAttrItemSet1.addCandidateItemSet(tempAttrItemSet2.getCandidateItemSet().get(tempAttrItemSet2.getCandidateItemSet().size()-1)); 202 235 tempAttrItemSet1.resetCoverage(); … … 248 281 } 249 282 250 //Collections.sort(_itemSet); 251 252 System.out.println("item sets"); 283 /*System.out.println("item sets with frequency > 3"); 253 284 for (int j = 0; j < tempItemSet.size(); j++) 254 285 { 255 286 System.out.println(tempItemSet.get(j).toString()); 256 } 287 }*/ 257 288 } 258 289 … … 278 309 else if (attrItem.getAttrName() == "action") 279 310 match = attrItem.getAttrValue().equals(ad.getAction()); 311 else if (attrItem.getAttrName() == "intention") 312 match = attrItem.getAttrValue().equals(ad.getIntention()); 280 313 else if (attrItem.getAttrName() == "target") 281 314 match = attrItem.getAttrValue().equals(ad.getTarget()); 315 else if (attrItem.getAttrName() == "object") 316 match = attrItem.getAttrValue().equals(ad.getObject()); 282 317 else if (attrItem.getAttrName() == "desirability") 283 318 match = attrItem.getAttrValue().equals(ad.getDesirability()>=0 ? "positive":"negative"); 284 319 else if (attrItem.getAttrName() == "praiseworthiness") 285 320 match = attrItem.getAttrValue().equals(ad.getPraiseworthiness()>=0 ? "positive":"negative"); 321 else if (attrItem.getAttrName() == "location") 322 match = attrItem.getAttrValue().equals(ad.getLocation()); 286 323 else if (attrItem.getAttrName() == "time") 287 324 match = attrItem.getAttrValue().equals(ad.getTime().getStrRealTime()); … … 297 334 } 298 335 336 private void createGER(ArrayList<AttributeItemSet> itemSet) 337 { 338 // clearing the list before generalising 339 this._gers.clear(); 340 341 for (int i = 0; i < itemSet.size(); i++) 342 { 343 AttributeItemSet attrItemSet = itemSet.get(i); 344 GER ger = new GER(); 345 346 // set the coverage (frequency of occurrence) of the item set 347 ger.setCoverage(attrItemSet.getCoverage()); 348 for (int j = 0; j < attrItemSet.getCandidateItemSet().size(); j++) 349 { 350 AttributeItem attrItem = attrItemSet.getCandidateItemSet().get(j); 351 352 if (attrItem.getAttrName() == "subject") 353 ger.setSubject(attrItem.getAttrValue()); 354 else if (attrItem.getAttrName() == "action") 355 ger.setAction(attrItem.getAttrValue()); 356 else if (attrItem.getAttrName() == "intention") 357 ger.setIntention(attrItem.getAttrValue()); 358 else if (attrItem.getAttrName() == "target") 359 ger.setTarget(attrItem.getAttrValue()); 360 else if (attrItem.getAttrName() == "object") 361 ger.setObject(attrItem.getAttrValue()); 362 else if (attrItem.getAttrName() == "desirability") 363 ger.setDesirability(attrItem.getAttrValue()); 364 else if (attrItem.getAttrName() == "praiseworthiness") 365 ger.setPraiseworthiness(attrItem.getAttrValue()); 366 else if (attrItem.getAttrName() == "location") 367 ger.setLocation(attrItem.getAttrValue()); 368 else if (attrItem.getAttrName() == "time") 369 ger.setTime(attrItem.getAttrValue()); 370 371 } 372 this._gers.add(ger); 373 } 374 } 375 376 public ArrayList<GER> getAllGERs() 377 { 378 return this._gers; 379 } 380 299 381 public Object clone() 300 382 { … … 310 392 } 311 393 394 /* 395 * TODO 396 */ 397 public String toXML() 398 { 399 String gm = "<GeneralMemory>\n"; 400 for(ListIterator<GER> li = this._gers.listIterator();li.hasNext();) 401 { 402 gm += li.next().toXML(); 403 } 404 gm += "</GeneralMemory>"; 405 return gm; 406 } 312 407 } -
AgentMind/branches/FAtiMA-Modular/FAtiMA.AdvancedMemory/src/main/rules/SpreadActivate.drl
r728 r751 20 20 insert (new CandidateEvent($ad, "desirability", 1.0f)); 21 21 retract ($ad); 22 System.out.println("Desirability " + $d1);23 System.out.println("positive desirability " + $ad.getID());22 #System.out.println("Desirability " + $d1); 23 #System.out.println("positive desirability " + $ad.getID()); 24 24 end 25 25 … … 33 33 insert (new CandidateEvent($ad, "desirability", 1.0f)); 34 34 retract ($ad); 35 System.out.println("Desirability " + $d1);36 System.out.println("negative desirability " + $ad.getID());35 #System.out.println("Desirability " + $d1); 36 #System.out.println("negative desirability " + $ad.getID()); 37 37 end 38 38 … … 46 46 insert (new CandidateEvent($ad, "subject", 1.0f)); 47 47 retract ($ad); 48 System.out.println("Subject " + $s1);49 System.out.println("subject-subject " + $ad.getID());48 #System.out.println("Subject " + $s1); 49 #System.out.println("subject-subject " + $ad.getID()); 50 50 end 51 51 … … 59 59 insert (new CandidateEvent($ad, "target", 1.0f)); 60 60 retract ($ad); 61 System.out.println("Target " + $t1);62 System.out.println("target-target " + $ad.getID());61 #System.out.println("Target " + $t1); 62 #System.out.println("target-target " + $ad.getID()); 63 63 end 64 64 … … 72 72 insert (new CandidateEvent($ad, "action", 1.0f)); 73 73 retract ($ad); 74 System.out.println("Action " + $a1);75 System.out.println("action-action " + $ad.getID());74 #System.out.println("Action " + $a1); 75 #System.out.println("action-action " + $ad.getID()); 76 76 end 77 77 … … 85 85 insert (new CandidateEvent($ad, "location", 1.0f)); 86 86 retract ($ad); 87 System.out.println("Location " + $l1);88 System.out.println("location-location " + $ad.getID());87 #System.out.println("Location " + $l1); 88 #System.out.println("location-location " + $ad.getID()); 89 89 end 90 90 … … 98 98 insert (new CandidateEvent($ad, "action", 1.0f)); 99 99 retract ($ad); 100 System.out.println("Intention " + $i1);101 System.out.println("intention-intention " + $ad.getID());100 #System.out.println("Intention " + $i1); 101 #System.out.println("intention-intention " + $ad.getID()); 102 102 end 103 103 … … 111 111 insert (new CandidateEvent($ad, "status", 1.0f)); 112 112 retract ($ad); 113 System.out.println("Status " + $st1);114 System.out.println("status-status " + $ad.getID());113 #System.out.println("Status " + $st1); 114 #System.out.println("status-status " + $ad.getID()); 115 115 end 116 116 … … 124 124 insert (new CandidateEvent($ad, "time", 1.0f)); 125 125 retract ($ad); 126 System.out.println("Time " + $t1);127 System.out.println("time-time " + $ad.getID());126 #System.out.println("Time " + $t1); 127 #System.out.println("time-time " + $ad.getID()); 128 128 end 129 129 … … 137 137 insert (new CandidateEvent($ad, "speechActMeaning", 1.0f)); 138 138 retract ($ad); 139 System.out.println("SpeechActMeaning " + $sa1);140 System.out.println("speechAct-speechAct " + $ad.getID());139 #System.out.println("SpeechActMeaning " + $sa1); 140 #System.out.println("speechAct-speechAct " + $ad.getID()); 141 141 end 142 142 … … 150 150 insert (new CandidateEvent($ad, "multimediaPath", 1.0f)); 151 151 retract ($ad); 152 System.out.println("MultimediaPath " + $m1);153 System.out.println("multimedia-multimedia " + $ad.getID());152 #System.out.println("MultimediaPath " + $m1); 153 #System.out.println("multimedia-multimedia " + $ad.getID()); 154 154 end 155 155 … … 163 163 insert (new CandidateEvent($ad, "object", 1.0f)); 164 164 retract ($ad); 165 System.out.println("Object " + $o1);166 System.out.println("object-object " + $ad.getID());165 #System.out.println("Object " + $o1); 166 #System.out.println("object-object " + $ad.getID()); 167 167 end 168 168 … … 179 179 setExtension("subject") 180 180 } 181 System.out.println("Subject " + $s1);182 System.out.println("subject-subject " + $ad.getID());181 #System.out.println("Subject " + $s1); 182 #System.out.println("subject-subject " + $ad.getID()); 183 183 end 184 184 … … 194 194 setExtension("target") 195 195 } 196 System.out.println("Target " + $t1);197 System.out.println("target-target " + $ad.getID());196 #System.out.println("Target " + $t1); 197 #System.out.println("target-target " + $ad.getID()); 198 198 end 199 199 … … 209 209 setExtension("action") 210 210 } 211 System.out.println("Action " + $a1);212 System.out.println("action-action " + $ad.getID());211 #System.out.println("Action " + $a1); 212 #System.out.println("action-action " + $ad.getID()); 213 213 end 214 214 … … 224 224 setExtension("location") 225 225 } 226 System.out.println("Location " + $l1);227 System.out.println("location-location " + $ad.getID());226 #System.out.println("Location " + $l1); 227 #System.out.println("location-location " + $ad.getID()); 228 228 end 229 229 … … 239 239 setExtension("intention") 240 240 } 241 System.out.println("Intention " + $i1);242 System.out.println("intention-intention " + $ad.getID());241 #System.out.println("Intention " + $i1); 242 #System.out.println("intention-intention " + $ad.getID()); 243 243 end 244 244 … … 254 254 setExtension("status") 255 255 } 256 System.out.println("Status " + $st1);257 System.out.println("status-status " + $ad.getID());256 #System.out.println("Status " + $st1); 257 #System.out.println("status-status " + $ad.getID()); 258 258 end 259 259 … … 269 269 setExtension("time") 270 270 } 271 System.out.println("Time " + $t1);272 System.out.println("time-time " + $ad.getID());271 #System.out.println("Time " + $t1); 272 #System.out.println("time-time " + $ad.getID()); 273 273 end 274 274 … … 284 284 setExtension("speechActMeaning") 285 285 } 286 System.out.println("SpeechActMeaning " + $sa1);287 System.out.println("speechAct-speechAct " + $ad.getID());286 #System.out.println("SpeechActMeaning " + $sa1); 287 #System.out.println("speechAct-speechAct " + $ad.getID()); 288 288 end 289 289 … … 299 299 setExtension("multimediaPath") 300 300 } 301 System.out.println("MultimediaPath " + $m1);302 System.out.println("multimedia-multimedia " + $ad.getID());301 #System.out.println("MultimediaPath " + $m1); 302 #System.out.println("multimedia-multimedia " + $ad.getID()); 303 303 end 304 304 … … 314 314 setExtension("object") 315 315 } 316 System.out.println("Object " + $o1);317 System.out.println("object-object " + $ad.getID());316 #System.out.println("Object " + $o1); 317 #System.out.println("object-object " + $ad.getID()); 318 318 end 319 319 … … 330 330 setExtension("desirability") 331 331 } 332 System.out.println("Desirability " + $d1);333 System.out.println("positive desirability " + $ad.getID());332 #System.out.println("Desirability " + $d1); 333 #System.out.println("positive desirability " + $ad.getID()); 334 334 end 335 335 … … 346 346 setExtension("desirability") 347 347 } 348 System.out.println("Desirability " + $d1);349 System.out.println("negative desirability " + $ad.getID());348 #System.out.println("Desirability " + $d1); 349 #System.out.println("negative desirability " + $ad.getID()); 350 350 end 351 351 … … 360 360 setResultIDs($id) 361 361 } 362 System.out.println("Event ID " + $id);363 System.out.println("Retracted " + $ad.getID() + "\n");362 #System.out.println("Event ID " + $id); 363 #System.out.println("Retracted " + $ad.getID() + "\n"); 364 364 retract ($cad); 365 365 end … … 375 375 setResults($s) 376 376 } 377 System.out.println("Subject " + $s);378 System.out.println("Retracted " + $ad.getID() + "\n");377 #System.out.println("Subject " + $s); 378 #System.out.println("Retracted " + $ad.getID() + "\n"); 379 379 retract ($cad); 380 380 end … … 390 390 setResults($t) 391 391 } 392 System.out.println("Target " + $t);393 System.out.println("Retracted " + $ad.getID() + "\n");392 #System.out.println("Target " + $t); 393 #System.out.println("Retracted " + $ad.getID() + "\n"); 394 394 retract ($cad); 395 395 end … … 405 405 setResults($a) 406 406 } 407 System.out.println("Action " + $a);408 System.out.println("Retracted " + $ad.getID() + "\n");407 #System.out.println("Action " + $a); 408 #System.out.println("Retracted " + $ad.getID() + "\n"); 409 409 retract ($cad); 410 410 end … … 420 420 setResults($l) 421 421 } 422 System.out.println("Location " + $l);423 System.out.println("Retracted " + $ad.getID());422 #System.out.println("Location " + $l); 423 #System.out.println("Retracted " + $ad.getID()); 424 424 retract ($cad); 425 425 end … … 435 435 setResults($i) 436 436 } 437 System.out.println("Intention " + $i);438 System.out.println("Retracted " + $ad.getID());437 #System.out.println("Intention " + $i); 438 #System.out.println("Retracted " + $ad.getID()); 439 439 retract ($cad); 440 440 end … … 450 450 setResults($st) 451 451 } 452 System.out.println("Status " + $st);453 System.out.println("Retracted " + $ad.getID());452 #System.out.println("Status " + $st); 453 #System.out.println("Retracted " + $ad.getID()); 454 454 retract ($cad); 455 455 end … … 466 466 setResults($t) 467 467 } 468 System.out.println("Time " + $t);469 System.out.println("Retracted " +$ad.getID());468 #System.out.println("Time " + $t); 469 #System.out.println("Retracted " +$ad.getID()); 470 470 retract ($cad); 471 471 end … … 481 481 setResults($sa) 482 482 } 483 System.out.println("SpeechActMeaning " + $sa);484 System.out.println("Retracted " + $ad.getID());483 #System.out.println("SpeechActMeaning " + $sa); 484 #System.out.println("Retracted " + $ad.getID()); 485 485 retract ($cad); 486 486 end … … 496 496 setResults($m) 497 497 } 498 System.out.println("MultimediaPath " + $m);499 System.out.println("Retracted " + $ad.getID());498 #System.out.println("MultimediaPath " + $m); 499 #System.out.println("Retracted " + $ad.getID()); 500 500 retract ($cad); 501 501 end … … 511 511 setResults($o) 512 512 } 513 System.out.println("Object " + $o);514 System.out.println("Retracted " + $ad.getID());513 #System.out.println("Object " + $o); 514 #System.out.println("Retracted " + $ad.getID()); 515 515 retract ($cad); 516 516 end … … 526 526 setDetails($ad) 527 527 } 528 System.out.println("Event " + $ad.getID());529 System.out.println("Retracted " + $ad.getID() + "\n");530 retract ($cad); 531 end 528 #System.out.println("Event " + $ad.getID()); 529 #System.out.println("Retracted " + $ad.getID() + "\n"); 530 retract ($cad); 531 end -
AgentMind/branches/FAtiMA-Modular/WorldTest/src/UserInterface.java
r750 r751 45 45 JComboBox _queryOptions; 46 46 JComboBox _eventOptions; 47 JComboBox _attributeOptions; 47 48 JTextField _userSpeech; 48 49 WorldTest _world; … … 237 238 queryBox.add(new JLabel("Query: ")); 238 239 queryBox.add(_queryOptions ); 239 240 241 _attributeOptions = new JComboBox(); 242 _attributeOptions.addItem("subject"); 243 _attributeOptions.addItem("target"); 244 _attributeOptions.addItem("location"); 245 _attributeOptions.addItem("action"); 246 _attributeOptions.addItem("intention"); 247 _attributeOptions.addItem("object"); 248 _attributeOptions.addItem("desirability"); 249 _attributeOptions.addItem("praiseworthiness"); 250 _attributeOptions.addItem("time"); 251 _attributeOptions.addActionListener(new ActionListener(){ 252 public void actionPerformed(ActionEvent arg0) { 253 _world.AddGAttributes(_attributeOptions.getSelectedItem().toString()); 254 WriteLine("=> Add G attribute: " + _attributeOptions.getSelectedItem().toString()); 255 } 256 }); 257 Box attributeBox = new Box(BoxLayout.X_AXIS); 258 queryBox.add(new JLabel("G Attributes: ")); 259 queryBox.add(_attributeOptions ); 240 260 241 261 _userSpeech = new JTextField(); -
AgentMind/branches/FAtiMA-Modular/WorldTest/src/WorldTest.java
r730 r751 399 399 400 400 public void CCMemory(){ 401 SendPerceptionToAll(" CC-MEMORY");401 SendPerceptionToAll("AdvancedMemory CC-MEMORY"); 402 402 } 403 403 404 404 public void SAMemory(String question){ 405 SendPerceptionToAll( "SA-MEMORY " + question + "$" + knownInfo );405 SendPerceptionToAll("AdvancedMemory SA-MEMORY " + question + "$" + knownInfo ); 406 406 knownInfo = ""; 407 407 } 408 408 409 String gAttributes = ""; 410 public void AddGAttributes( String attribute ){ 411 gAttributes = gAttributes + attribute + "*"; 412 } 413 409 414 public void GMemory(){ 410 SendPerceptionToAll("G-MEMORY"); 415 SendPerceptionToAll("AdvancedMemory G-MEMORY " + gAttributes); 416 System.out.println("WorldTest gAttributes " + gAttributes); 417 gAttributes = ""; 411 418 } 412 419
Note: See TracChangeset
for help on using the changeset viewer.