Permalink
Browse files

started to add the markov chain analysis method not completed at this…

… time but it is without errors

git-svn-id: https://www.evllabs.com/svn/jgaap/trunk@70 bcaee279-2e94-4b2e-be96-a1d7c6f3fc26
  • Loading branch information...
dvescovi committed Jan 6, 2011
1 parent f195d08 commit 0e255ab89fc64b934583a841ccd30b942b2bc267
Showing with 98 additions and 4 deletions.
  1. +1 −3 .classpath
  2. +1 −1 .project
  3. +96 −0 src/com/jgaap/classifiers/MarkovChainAnalysis.java
View
@@ -2,9 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="unittests"/>
<classpathentry kind="src" path="util"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/external/abbot.jar"/>
<classpathentry kind="lib" path="lib/external/ant.jar"/>
<classpathentry kind="lib" path="lib/external/bcmail-jdk14-132.jar"/>
@@ -26,5 +23,6 @@
<classpathentry kind="lib" path="lib/external/poi-ooxml-3.5-beta3-20080926.jar"/>
<classpathentry kind="lib" path="lib/external/poi-scratchpad-3.5-beta3-20080926.jar"/>
<classpathentry kind="lib" path="lib/external/json_simple-1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jgaap</name>
<name>trunk</name>
<comment></comment>
<projects>
</projects>
@@ -0,0 +1,96 @@
/**
*
*/
package com.jgaap.classifiers;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import com.jgaap.generics.AnalysisDriver;
import com.jgaap.generics.Event;
import com.jgaap.generics.EventSet;
import com.jgaap.generics.Pair;
/**
* @author Darren Vescovi
*
*/
public class MarkovChainAnalysis extends AnalysisDriver{
@Override
public String displayName() {
return "Markov Chain Analysis";
}
@Override
public boolean showInGUI() {
return true;
}
@Override
public String tooltipText() {
return "First Order Markov Chain Analysis";
}
@Override
public List<Pair<String, Double>> analyze(EventSet unknown, List<EventSet> known) {
List<Pair<String, Double>> results = new ArrayList<Pair<String, Double>>();
Iterator<EventSet> setIt = known.iterator();
while(setIt.hasNext()){
Hashtable<Event, Hashtable<Event, Double>> matrix = new Hashtable<Event, Hashtable<Event, Double>>();
EventSet ev = setIt.next();
//Iterate over events to create a matrix with
//counts of each time a event pair sequence
//appears.
Iterator<Event> eventIt = ev.iterator();
if(eventIt.hasNext()){
//get the first event
Event e1 = eventIt.next();
while(eventIt.hasNext()){
//get the next event
Event e2 = eventIt.next();
if(matrix.containsKey(e1)){
if(matrix.get(e1).containsKey(e2)){
//find out if the event sequence is already in the matrix
//if so increment the count by 1;
double tmp = matrix.get(e1).get(e2).doubleValue();
matrix.get(e1).remove(e2);
matrix.get(e1).put(e2, new Double(tmp+1));
}
else{
//add the new sequence provided the first event is already
//in the matrix
matrix.get(e1).put(e2, new Double(1));
}
}else{
//add the new sequence to matrix
matrix.put(e1, new Hashtable<Event, Double>());
matrix.get(e1).put(e2, new Double(1));
}
//reassign e1 to be e2
e1=e2;
}
}
}
return null;//TODO make this return something
}
}

0 comments on commit 0e255ab

Please sign in to comment.