- Timestamp:
- 09/30/11 19:31:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg/commands/CMDefgToMM.java
r206 r227 2 2 3 3 import java.security.InvalidParameterException; 4 import java.util.ArrayList;5 import java.util.Collection;6 import java.util.LinkedList;7 4 import java.util.List; 8 import java.util.Random;9 5 10 import de.ugoe.cs.eventbench.data.Event;11 6 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 12 import de.ugoe.cs.eventbench.efg. data.EFGEvent;7 import de.ugoe.cs.eventbench.efg.EFGModelGenerator; 13 8 import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel; 14 9 import de.ugoe.cs.util.console.Command; 15 10 import de.ugoe.cs.util.console.Console; 16 import edu.umd.cs.guitar.model.GUITARConstants;17 import edu.umd.cs.guitar.model.IO;18 import edu.umd.cs.guitar.model.data.EFG;19 import edu.umd.cs.guitar.model.data.EventGraphType;20 import edu.umd.cs.guitar.model.data.EventType;21 11 22 12 /** … … 47 37 } 48 38 49 EFG efg = (EFG) IO.readObjFromFile(filename, EFG.class); 50 51 // extracting the events from the EFG 52 List<EventType> efgEvents = efg.getEvents().getEvent(); 53 List<Event<?>> myEvents = new ArrayList<Event<?>>(efgEvents.size()); 54 for (EventType event : efgEvents) { 55 /* 56 * the widgetId and eventId are only hash values, the 57 * "interpretation" is found in the GUI file. 58 */ 59 Event<?> myEvent = new EFGEvent(event.getEventId()); 60 /* 61 * The target is currently not set to event.widgetId() because the 62 * WidgetId is not available when loading sequences in form of test 63 * cases. 64 */ 65 // myEvent.setTarget(event.getWidgetId();); 66 myEvents.add(myEvent); 67 } 68 69 // extracting graph structure from the EFG 70 /* 71 * getEventGraph returns an adjacency matrix, i.e., a square matrix of 72 * efgEvents.size(), where a 1 in row i, column j means an edge 73 * efgEvents.get(i)->efgEvents.get(j) exists. 74 */ 75 EventGraphType efgGraph = efg.getEventGraph(); 76 77 FirstOrderMarkovModel model = new FirstOrderMarkovModel(new Random()); 78 Collection<List<Event<?>>> subsequences = new LinkedList<List<Event<?>>>(); 79 80 int efgSize = efgEvents.size(); 81 for (int row = 0; row < efgSize; row++) { 82 for (int col = 0; col < efgSize; col++) { 83 int relation = efgGraph.getRow().get(row).getE().get(col); 84 // otherEvent is followed by currentEvent 85 if (relation != GUITARConstants.NO_EDGE) { 86 List<Event<?>> edge = new LinkedList<Event<?>>(); 87 edge.add(myEvents.get(row)); 88 edge.add(myEvents.get(col)); 89 subsequences.add(edge); 90 } 91 } 92 } 93 model.train(subsequences); 39 EFGModelGenerator modelGenerator = new EFGModelGenerator(); 40 FirstOrderMarkovModel model = modelGenerator 41 .efgToFirstOrderMarkovModel(filename); 94 42 GlobalDataContainer.getInstance().addData(modelname, model); 95 43 }
Note: See TracChangeset
for help on using the changeset viewer.