nz.ac.waikato.mcennis.rat.graph.algorithm.collaborativefiltering
Class Item2Item

java.lang.Object
  extended by nz.ac.waikato.mcennis.rat.graph.model.ModelShell
      extended by nz.ac.waikato.mcennis.rat.graph.algorithm.collaborativefiltering.Item2Item
All Implemented Interfaces:
java.io.Serializable, Component, Algorithm, Model

public class Item2Item
extends ModelShell
implements Algorithm

Performs classic Item to Item collaborative filtering. Modified from the orginal version submitted (under GPL) to audioscrobbler.net in 2003 by adding code for using RAT data structures instead of JDBC calls. Jan 5, 2009 - modified to use new interface Note: Deprecated: Use the following to replace this algorithm with a more configurable algorithm <SimilarityByLink> <Property><Name>Mode</Name><Value>Artist</Value></Property> <Property><Name>Relation</Name><Value>ListensTo</Value></Property> </SimilarityByLink> <AggregateByLink> <Property><Name>Mode</Name><Value>Artist</Value></Property> <Property><Name>Relation</Name><Value>Similarity</Value></Property> <Property><Name>DestinationProperty</Name><Value>Property</Value></Property> </AggregateByLink> <AggregateByLinkProperty> <Property><Name>Mode</Name><Value>User</Value></Property> <Property><Name>SourceProperty</Name><Value>Property</Value></Property> <Property><Name>DestinationProperty</Name><Value>UserProperty</Value></Property> </AggregateByLinkProperty> <PropertyToLink> <Property><Name>SourceProperty</Name><Value>UserProperty</Value></Property> <Property><Name>SourceMode</Name><Value>User</Value></Property> <Property><Name>DestinationMode</Name><Value>Artist</Value></Property> <Property><Name>Relation</Name><Value>Derived</Value></Property> </PropertyToLink>

See Also:
Serialized Form

Field Summary
 
Fields inherited from class nz.ac.waikato.mcennis.rat.graph.model.ModelShell
listener
 
Constructor Summary
Item2Item()
          Create a new generic Item2Item algorithm object with default parameters.
 
Method Summary
protected  double correlation(DoubleMatrix2D userArtist, IntArrayList[] indexArtist, DoubleMatrix1D time, DoubleMatrix1D time2, int a, int b, double[] size)
          calculates the correlation between 2 artists using standard statistical definition of correlation.
protected  void createCorrelation(Graph g, Actor u, double strength, Actor a)
           
protected  void createRecommendation(Graph g, Actor u, double strength, Actor a)
           
protected  double digram(IntArrayList[] indexArtist, DoubleMatrix2D userArtistMatrix, int a, int b, double[] size)
          function to caclualate the digrams needed for calculating relationships between artists.
 void execute(Graph g)
          execute the algorithm against the given graph
 java.util.List<IODescriptor> getInputType()
          The input type describes all the different kinds of graph objects that are utilized (and hence required) by this object.
 java.util.List<IODescriptor> getOutputType()
          The output type describes all the different kinds of graph objects that are created during the execution of this algorithm.
 Properties getParameter()
          List of all parameters this component accepts.
 Parameter getParameter(java.lang.String param)
          Returns the specific parameter identified by its key-name.
 void init(Properties map)
          Parameters:

  • name: name of this algorithm.
  •  Item2Item prototype()
              All Components implement the prototype pattern.
     
    Methods inherited from class nz.ac.waikato.mcennis.rat.graph.model.ModelShell
    addListener, fireChange
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface nz.ac.waikato.mcennis.rat.graph.model.Model
    addListener
     

    Constructor Detail

    Item2Item

    public Item2Item()
    Create a new generic Item2Item algorithm object with default parameters.

    Method Detail

    execute

    public void execute(Graph g)
    Description copied from interface: Algorithm
    execute the algorithm against the given graph

    Specified by:
    execute in interface Algorithm
    Parameters:
    g - graph to be modified

    digram

    protected double digram(IntArrayList[] indexArtist,
                            DoubleMatrix2D userArtistMatrix,
                            int a,
                            int b,
                            double[] size)
    function to caclualate the digrams needed for calculating relationships between artists.

    Parameters:
    a - - artist to be crossed
    b - - artist to be crossed
    size - - double passed by reference using array hack/workaround used to pass back the total number of users listening to either artist a or b
    Returns:
    - sum over all users of product of time in seconds a user listened to artist a and time listened to artist b.

    correlation

    protected double correlation(DoubleMatrix2D userArtist,
                                 IntArrayList[] indexArtist,
                                 DoubleMatrix1D time,
                                 DoubleMatrix1D time2,
                                 int a,
                                 int b,
                                 double[] size)
    calculates the correlation between 2 artists using standard statistical definition of correlation.

    Parameters:
    a - - artist in Matrix
    b - - artist in Matrix
    size - - number of users listening to either artists
    Returns:
    - correlation between listening to artist a and listening to artist b.

    createRecommendation

    protected void createRecommendation(Graph g,
                                        Actor u,
                                        double strength,
                                        Actor a)

    createCorrelation

    protected void createCorrelation(Graph g,
                                     Actor u,
                                     double strength,
                                     Actor a)

    getInputType

    public java.util.List<IODescriptor> getInputType()
    Description copied from interface: Component
    The input type describes all the different kinds of graph objects that are utilized (and hence required) by this object. This result is only guaranteed to be fixed if structural parameters are not modified. This is an empty array if there is no input.

    Specified by:
    getInputType in interface Component
    Returns:
    IODescriptor array for this component
    See Also:
    IODescriptor

    getOutputType

    public java.util.List<IODescriptor> getOutputType()
    Description copied from interface: Component
    The output type describes all the different kinds of graph objects that are created during the execution of this algorithm. The result is only guaranteed to be fixed if structural parameters are not modified. This is an empty array if there is no output.

    Specified by:
    getOutputType in interface Component
    Returns:
    IODescriptor array for this component
    See Also:
    IODescriptor

    getParameter

    public Properties getParameter()
    Description copied from interface: Component
    List of all parameters this component accepts. Each parameter also has a distinct key-name used when initializing the object using the init method. If there are no parameters, null is returned.

    Specified by:
    getParameter in interface Component
    Returns:
    read-only array of Parameters

    getParameter

    public Parameter getParameter(java.lang.String param)
    Description copied from interface: Component
    Returns the specific parameter identified by its key-name. If no parameter is found with this key-name, null is returned.

    Specified by:
    getParameter in interface Component
    Parameters:
    param - key-name of the parameter
    Returns:
    named parameter

    init

    public void init(Properties map)
    Parameters:

    Specified by:
    init in interface Component
    Parameters:
    map - parameters to be loaded - may be null

    prototype

    public Item2Item prototype()
    Description copied from interface: Component
    All Components implement the prototype pattern. The new parameter has no common resources to the original that are not static resources o the class.

    Specified by:
    prototype in interface Component
    Specified by:
    prototype in interface Algorithm
    Returns:
    default-parameter version of the same class as the original.

    Get Relational Analysis Toolkit at SourceForge.net. Fast, secure and Free Open Source software downloads