Return-Path: X-Original-To: apmail-mahout-commits-archive@www.apache.org Delivered-To: apmail-mahout-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 23E734D85 for ; Thu, 2 Jun 2011 16:33:32 +0000 (UTC) Received: (qmail 87710 invoked by uid 500); 2 Jun 2011 16:33:32 -0000 Delivered-To: apmail-mahout-commits-archive@mahout.apache.org Received: (qmail 87604 invoked by uid 500); 2 Jun 2011 16:33:32 -0000 Mailing-List: contact commits-help@mahout.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mahout.apache.org Delivered-To: mailing list commits@mahout.apache.org Received: (qmail 87597 invoked by uid 99); 2 Jun 2011 16:33:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 16:33:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 16:33:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3A02F23889E7; Thu, 2 Jun 2011 16:33:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1130639 - in /mahout/trunk: core/pom.xml core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java pom.xml Date: Thu, 02 Jun 2011 16:33:07 -0000 To: commits@mahout.apache.org From: srowen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110602163307.3A02F23889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: srowen Date: Thu Jun 2 16:33:06 2011 New Revision: 1130639 URL: http://svn.apache.org/viewvc?rev=1130639&view=rev Log: In spirit of MAHOUT-718, update Google Guava, and use its collections to replace the one use of Commons Collections Modified: mahout/trunk/core/pom.xml mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java mahout/trunk/pom.xml Modified: mahout/trunk/core/pom.xml URL: http://svn.apache.org/viewvc/mahout/trunk/core/pom.xml?rev=1130639&r1=1130638&r2=1130639&view=diff ============================================================================== --- mahout/trunk/core/pom.xml (original) +++ mahout/trunk/core/pom.xml Thu Jun 2 16:33:06 2011 @@ -218,9 +218,5 @@ test - - commons-collections - commons-collections - Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java?rev=1130639&r1=1130638&r2=1130639&view=diff ============================================================================== --- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java (original) +++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/HmmModel.java Thu Jun 2 16:33:06 2011 @@ -20,8 +20,8 @@ package org.apache.mahout.classifier.seq import java.util.Map; import java.util.Random; -import org.apache.commons.collections.BidiMap; -import org.apache.commons.collections.bidimap.TreeBidiMap; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import org.apache.mahout.common.RandomUtils; import org.apache.mahout.math.DenseMatrix; import org.apache.mahout.math.DenseVector; @@ -33,6 +33,47 @@ import org.apache.mahout.math.Vector; */ public class HmmModel implements Cloneable { + /** Bi-directional Map for storing the observed state names */ + private BiMap outputStateNames; + + /** Bi-Directional Map for storing the hidden state names */ + private BiMap hiddenStateNames; + + /* Number of hidden states */ + private int nrOfHiddenStates; + + /** Number of output states */ + private int nrOfOutputStates; + + /** + * Transition matrix containing the transition probabilities between hidden + * states. TransitionMatrix(i,j) is the probability that we change from hidden + * state i to hidden state j In general: P(h(t+1)=h_j | h(t) = h_i) = + * transitionMatrix(i,j) Since we have to make sure that each hidden state can + * be "left", the following normalization condition has to hold: + * sum(transitionMatrix(i,j),j=1..hiddenStates) = 1 + */ + private Matrix transitionMatrix; + + /** + * Output matrix containing the probabilities that we observe a given output + * state given a hidden state. outputMatrix(i,j) is the probability that we + * observe output state j if we are in hidden state i Formally: P(o(t)=o_j | + * h(t)=h_i) = outputMatrix(i,j) Since we always have an observation for each + * hidden state, the following normalization condition has to hold: + * sum(outputMatrix(i,j),j=1..outputStates) = 1 + */ + private Matrix emissionMatrix; + + /** + * Vector containing the initial hidden state probabilities. That is + * P(h(0)=h_i) = initialProbabilities(i). Since we are dealing with + * probabilities the following normalization condition has to hold: + * sum(initialProbabilities(i),i=1..hiddenStates) = 1 + */ + private Vector initialProbabilities; + + /** * Get a copy of this model */ @@ -41,10 +82,10 @@ public class HmmModel implements Cloneab super.clone(); HmmModel model = new HmmModel(transitionMatrix.clone(), emissionMatrix.clone(), initialProbabilities.clone()); if (hiddenStateNames != null) { - model.hiddenStateNames = new TreeBidiMap(hiddenStateNames); + model.hiddenStateNames = HashBiMap.create(hiddenStateNames); } if (outputStateNames != null) { - model.outputStateNames = new TreeBidiMap(outputStateNames); + model.outputStateNames = HashBiMap.create(outputStateNames); } return model; } @@ -169,11 +210,6 @@ public class HmmModel implements Cloneab } /** - * Number of hidden states - */ - private int nrOfHiddenStates; - - /** * Getter Method for the number of hidden states * * @return Number of hidden states @@ -183,11 +219,6 @@ public class HmmModel implements Cloneab } /** - * Number of output states - */ - private int nrOfOutputStates; - - /** * Getter Method for the number of output states * * @return Number of output states @@ -197,16 +228,6 @@ public class HmmModel implements Cloneab } /** - * Transition matrix containing the transition probabilities between hidden - * states. TransitionMatrix(i,j) is the probability that we change from hidden - * state i to hidden state j In general: P(h(t+1)=h_j | h(t) = h_i) = - * transitionMatrix(i,j) Since we have to make sure that each hidden state can - * be "left", the following normalization condition has to hold: - * sum(transitionMatrix(i,j),j=1..hiddenStates) = 1 - */ - private Matrix transitionMatrix; - - /** * Getter function to get the hidden state transition matrix * * @return returns the model's transition matrix. @@ -216,16 +237,6 @@ public class HmmModel implements Cloneab } /** - * Output matrix containing the probabilities that we observe a given output - * state given a hidden state. outputMatrix(i,j) is the probability that we - * observe output state j if we are in hidden state i Formally: P(o(t)=o_j | - * h(t)=h_i) = outputMatrix(i,j) Since we always have an observation for each - * hidden state, the following normalization condition has to hold: - * sum(outputMatrix(i,j),j=1..outputStates) = 1 - */ - private Matrix emissionMatrix; - - /** * Getter function to get the output state probability matrix * * @return returns the models emission matrix. @@ -235,14 +246,6 @@ public class HmmModel implements Cloneab } /** - * Vector containing the initial hidden state probabilities. That is - * P(h(0)=h_i) = initialProbabilities(i). Since we are dealing with - * probabilities the following normalization condition has to hold: - * sum(initialProbabilities(i),i=1..hiddenStates) = 1 - */ - private Vector initialProbabilities; - - /** * Getter function to return the vector of initial hidden state probabilities * * @return returns the model's init probabilities. @@ -252,17 +255,12 @@ public class HmmModel implements Cloneab } /** - * Bi-Directional Map for storing the hidden state names - */ - private BidiMap hiddenStateNames; - - /** * Getter method for the hidden state Names map * * @return hidden state names. */ public Map getHiddenStateNames() { - return (Map) hiddenStateNames; + return hiddenStateNames; } /** @@ -273,7 +271,7 @@ public class HmmModel implements Cloneab */ public void registerHiddenStateNames(String[] stateNames) { if (stateNames != null) { - hiddenStateNames = new TreeBidiMap(); + hiddenStateNames = HashBiMap.create(); for (int i = 0; i < stateNames.length; ++i) { hiddenStateNames.put(stateNames[i], i); } @@ -287,7 +285,7 @@ public class HmmModel implements Cloneab */ public void registerHiddenStateNames(Map stateNames) { if (stateNames != null) { - hiddenStateNames = new TreeBidiMap(stateNames); + hiddenStateNames = HashBiMap.create(stateNames); } } @@ -302,7 +300,7 @@ public class HmmModel implements Cloneab if (hiddenStateNames == null) { return null; } - return (String) hiddenStateNames.getKey(id); + return hiddenStateNames.inverse().get(id); } /** @@ -316,22 +314,17 @@ public class HmmModel implements Cloneab if (hiddenStateNames == null) { return -1; } - Integer tmp = (Integer) hiddenStateNames.get(name); + Integer tmp = hiddenStateNames.get(name); return tmp == null ? -1 : tmp; } /** - * Bi-directional Map for storing the observed state names - */ - private BidiMap outputStateNames; - - /** * Getter method for the output state Names map * * @return names of output states. */ public Map getOutputStateNames() { - return (Map) outputStateNames; + return outputStateNames; } /** @@ -342,7 +335,7 @@ public class HmmModel implements Cloneab */ public void registerOutputStateNames(String[] stateNames) { if (stateNames != null) { - outputStateNames = new TreeBidiMap(); + outputStateNames = HashBiMap.create(); for (int i = 0; i < stateNames.length; ++i) { outputStateNames.put(stateNames[i], i); } @@ -356,7 +349,7 @@ public class HmmModel implements Cloneab */ public void registerOutputStateNames(Map stateNames) { if (stateNames != null) { - outputStateNames = new TreeBidiMap(stateNames); + outputStateNames = HashBiMap.create(stateNames); } } @@ -371,7 +364,7 @@ public class HmmModel implements Cloneab if (outputStateNames == null) { return null; } - return (String) outputStateNames.getKey(id); + return outputStateNames.inverse().get(id); } /** @@ -385,7 +378,7 @@ public class HmmModel implements Cloneab if (outputStateNames == null) { return -1; } - Integer tmp = (Integer) outputStateNames.get(name); + Integer tmp = outputStateNames.get(name); return tmp == null ? -1 : tmp; } Modified: mahout/trunk/pom.xml URL: http://svn.apache.org/viewvc/mahout/trunk/pom.xml?rev=1130639&r1=1130638&r2=1130639&view=diff ============================================================================== --- mahout/trunk/pom.xml (original) +++ mahout/trunk/pom.xml Thu Jun 2 16:33:06 2011 @@ -138,7 +138,7 @@ ${project.groupId} ${project.version} - + mahout-buildtools ${project.groupId} @@ -308,12 +308,6 @@ - commons-collections - commons-collections - 3.2.1 - - - org.uncommons.watchmaker watchmaker-framework 0.6.2 @@ -333,7 +327,7 @@ com.google.guava guava - r03 + r09