algorithmfoundry / Foundry

The Cognitive Foundry is an open-source Java library for building intelligent systems using machine learning
Other
131 stars 41 forks source link

EigenvectorPowerIteration.java #54

Closed srikanthBezawada closed 9 years ago

srikanthBezawada commented 9 years ago

public static Vector estimateEigenvector( final Vector initial, final Matrix A, final double stoppingThreshold, final int maxIterations ) { }

This method takes stoppingThreshold, maxIterations for numerical methods. Any idea what I should pass on to these to achieve similar implementation as here (i.e) Damping parameter for PageRank, default=0.85. ..I have used the default values as of now.

jbasilico commented 9 years ago

This method doesn't have a parameter for doing the dampening. It only adds the initial vector at the beginning. You can probably just take the implementation and tweak it slightly to do the dampening. The only other thing you may want to be careful of is if there is some initial transformation of the input graph into a matrix form.

srikanthBezawada commented 9 years ago

Hi jbasilico,

Thanks for the quick response. Tweaking the library method's implementation seems a cool idea. But, I have no idea how to implement the numerical method with dampening at the moment, so I'm considering to reuse a library's implementation. Thanks!

jbasilico commented 9 years ago

I think this will do it for you with a dampening factor of alpha between 0 and 1:

    public static Vector estimateEigenvector(
        final Vector initial,
        final Matrix A,
        final double alpha,
        final double stoppingThreshold,
        final int maxIterations )
    {
        Vector v = initial.unitVector();

        double normChange;
        int iteration = 0;
        boolean keepGoing = true;
        while (keepGoing)
        {
            final Vector vPrevious = v;
            v = A.times( v );
            v.scaleEquals(alpha);
            v.plusEquals(initial.scale(1.0 - alpha));
            normChange = v.minus( vPrevious ).norm2();
            iteration++;

            if ((normChange <= stoppingThreshold) || (iteration >= maxIterations))
            {
                keepGoing = false;
            }
        }

        return v;

You could make it slightly faster by pre-caching the dampened initial vector (initial.scale(1.0 - alpha)).

srikanthBezawada commented 9 years ago

Thanks for the help jbasilico!