Dear scikit-learners,

Thank you first of all for writing such a wonderful machine learning
package for python. I've used scikit-learn quite a lot in the past and
it seemed to always would right away.

Yet, now I'm trying to get started with the BernoulliRBM in
scikit-learn, and I seem to be missing something. My first attempt was
to check if I could recover known components from data that I generated.
For some reason, this does not seem to work at all.

Here is what I did::

    import numpy as np
    import sklearn.neural_network as NN

    # Ground truth parameter values
    a = np.array([-.2,.2,0])
    b = np.array([.1,-.1])
    w = np.array([[1.,.1,.3],
        [-.1,-.7,.3]])

    # Generate data with known values
    V = np.random.rand(1000,3)<.3 # As an initial state
    rbm_gt = NN.BernoulliRBM(n_components=2,n_iter=1)
    rbm_gt.components_ = w
    rbm_gt.intercept_visible_ = a
    rbm_gt.intercept_hidden_ = b
    for i in xrange(200):
        V = rbm_gt.gibbs(V)

    # Fit an rbm
    rbm = 
NN.BernoulliRBM(n_components=2,n_iter=100,learning_rate=0.01,verbose=1)
    rbm.fit(V)

    # Compare the values
    print "True intercept visible",rbm_gt.intercept_visible_
    print "Fit  intercept visible",rbm.intercept_visible_
    print "="*20
    print "True intercept hidden",rbm_gt.intercept_hidden_
    print "Fit  intercept hidden",rbm.intercept_hidden_
    print "="*20
    print "True components",rbm_gt.components_
    print "Fit  components",rbm.components_

Yet, when running this code (with np.random.seed(0)), the resulting
parameter estimates are totally off::

    True intercept visible [-0.2  0.2  0. ]
    Fit  intercept visible [ 0.241  0.012  0.227]
    ====================
    True intercept hidden [ 0.1 -0.1]
    Fit  intercept hidden [-0.00291364 -0.00424846]
    ====================
    True components [[ 1.   0.1  0.3]
     [-0.1 -0.7  0.3]]
     Fit  components [[ 0.1667071   0.08699367  0.15336245]
      [ 0.12761852  0.04939561  0.13522931]]

This is not just some roundoff error, the estimated components seem to
me to be absolutely unrelated to my ground truth values. Am I
misunderstanding something here? But what? I feel that my code is not
particularly far from the example code here:
http://scikit-learn.org/stable/auto_examples/plot_rbm_logistic_classification.html
Or should I just not expect to get my generating parameters out?

Any help would be greatly appreciated.

Best,

Ingo

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to