commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1306001 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo: DefaultKFactorBuilder.java DefaultRankingSelector.java EloRankingCalculator.java KFactorBuilder.java PlayersRank.java RankingSelector.java
Date Tue, 27 Mar 2012 20:11:56 GMT
Author: simonetripodi
Date: Tue Mar 27 20:11:56 2012
New Revision: 1306001

URL: http://svn.apache.org/viewvc?rev=1306001&view=rev
Log:
finally found a way to arrange the ELO algorithm

Added:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultKFactorBuilder.java
      - copied, changed from r1305237, commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
  (with props)
Removed:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java
Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultRankingSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/RankingSelector.java

Copied: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultKFactorBuilder.java
(from r1305237, commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultKFactorBuilder.java?p2=commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultKFactorBuilder.java&p1=commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java&r1=1305237&r2=1306001&rev=1306001&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultKFactorBuilder.java
Tue Mar 27 20:11:56 2012
@@ -23,7 +23,8 @@ import static java.lang.Math.pow;
 
 import org.apache.commons.graph.DirectedGraph;
 
-final class EloRankingCalculator<P>
+final class DefaultKFactorBuilder<P>
+    implements KFactorBuilder<P>
 {
 
     private static final double DEFAULT_POW_BASE = 10;
@@ -36,30 +37,32 @@ final class EloRankingCalculator<P>
 
     private final PlayersRank<P> playerRanking;
 
-    private final int kFactor;
-
-    public EloRankingCalculator( DirectedGraph<P, GameResult> tournamentGraph,
-                                 PlayersRank<P> playerRanking, int kFactor )
+    public DefaultKFactorBuilder( DirectedGraph<P, GameResult> tournamentGraph,
+                                 PlayersRank<P> playerRanking )
     {
         this.tournamentGraph = tournamentGraph;
         this.playerRanking = playerRanking;
-        this.kFactor = kFactor;
     }
 
-    // TODO find a way to improve performances, this impl is just a spike
-    public void calculateRate()
+    public void withDefaultKFactor()
+    {
+        withKFactor( DEFAULT_K_FACTOR );
+    }
+
+    public void withKFactor( int kFactor )
     {
+        // TODO find a way to improve performances, this impl is just a spike
         for ( P player : tournamentGraph.getVertices() )
         {
             for ( P opponent : tournamentGraph.getOutbound( player ) )
             {
                 GameResult gameResult = tournamentGraph.getEdge( player, opponent );
-                evaluateMatch( player, gameResult, opponent );
+                evaluateMatch( player, gameResult, opponent, kFactor );
             }
         }
     }
 
-    private boolean evaluateMatch( P playerA, GameResult gameResult, P playerB )
+    private boolean evaluateMatch( P playerA, GameResult gameResult, P playerB, int kFactor
)
     {
         double qA = calculateQFactor( playerA );
         double qB = calculateQFactor( playerB );
@@ -92,7 +95,7 @@ final class EloRankingCalculator<P>
 
     private double calculateQFactor( P player )
     {
-        double ranking = playerRanking.map( player );
+        double ranking = playerRanking.getRanking( player );
         return pow( DEFAULT_POW_BASE, ranking / DEFAULT_DIVISOR);
     }
 
@@ -103,8 +106,8 @@ final class EloRankingCalculator<P>
 
     private void updateRanking( P player, double kFactor, double sFactor, double eFactor
)
     {
-        double newRanking = playerRanking.map( player ) + ( kFactor * ( sFactor - eFactor
) );
-        playerRanking.update( player, newRanking );
+        double newRanking = playerRanking.getRanking( player ) + ( kFactor * ( sFactor -
eFactor ) );
+        playerRanking.updateRanking( player, newRanking );
     }
 
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultRankingSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultRankingSelector.java?rev=1306001&r1=1306000&r2=1306001&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultRankingSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/DefaultRankingSelector.java
Tue Mar 27 20:11:56 2012
@@ -34,9 +34,10 @@ public final class DefaultRankingSelecto
         this.tournamentGraph = tournamentGraph;
     }
 
-    public void werePlayersArRankedIn( PlayersRank<P> playersRank )
+    public KFactorBuilder<P> werePlayersArRankedIn( PlayersRank<P> playersRank
)
     {
         playersRank = checkNotNull( playersRank, "ELO ranking can not be applied if players
can not be ranked!" );
+        return new DefaultKFactorBuilder<P>( tournamentGraph, playersRank );
     }
 
 }

Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java?rev=1306001&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
(added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
Tue Mar 27 20:11:56 2012
@@ -0,0 +1,29 @@
+package org.apache.commons.graph.elo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public interface KFactorBuilder<P>
+{
+
+    void withDefaultKFactor();
+
+    void withKFactor( int kFactor );
+
+}

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/KFactorBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java?rev=1306001&r1=1306000&r2=1306001&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
Tue Mar 27 20:11:56 2012
@@ -19,12 +19,11 @@ package org.apache.commons.graph.elo;
  * under the License.
  */
 
-import org.apache.commons.graph.Mapper;
-
 public interface PlayersRank<P>
-    extends Mapper<P, Double>
 {
 
-    void update( P player, Double ranking );
+    Double getRanking( P player );
+
+    void updateRanking( P player, Double ranking );
 
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/RankingSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/RankingSelector.java?rev=1306001&r1=1306000&r2=1306001&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/RankingSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/RankingSelector.java
Tue Mar 27 20:11:56 2012
@@ -22,6 +22,6 @@ package org.apache.commons.graph.elo;
 public interface RankingSelector<P>
 {
 
-    void werePlayersArRankedIn( PlayersRank<P> playersRank );
+    KFactorBuilder<P> werePlayersArRankedIn( PlayersRank<P> playersRank );
 
 }



Mime
View raw message