Code Monkey home page Code Monkey logo

learnergy's People

Contributors

dependabot[bot] avatar gugarosa avatar mateusroder avatar nlahaye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learnergy's Issues

a method for getting samples of synthesized visible units

Pre-checkings

  • [x ] Check that you are up-to-date with the master branch of Learnergy. You can update with:
    pip install git+git://github.com/gugarosa/learnergy.git --upgrade --no-deps

  • [x ] Check that you have read all of our README.

Description

I look and could not find existing methods for sampling visible units from a trained Gaussian RBM model. The procedure should be starting with a random input dataset to feed into the visible layer, do hidden and visible sampling back and forth until convergence, then take the final visible unit values as the synthetic data.

Since I could not find such a method, I wrote my own and tested on a particular class of the MNIST dataset. The results are quite awful. you could hardly make out a 4, but very distorted and noisy. The training process does appear to have reached convergence after about 100 epochs. and I tried a number of values for iterations in the synthetic sampling run.

My questions:

  1. maybe such a method already exists, but I don't find it.
  2. has this test been done before using the MNIST dataset and yielded good synthetic results?
  3. any feeling what could be wrong with my procedure? Do I need to add dropouts?

Steps to Reproduce

  1. train one class of the MNIST dataset, I used 4. train multiple epochs until convergence
  2. wrote my own sampling routine which starts with random values for the visible layer, and then iteratively sample between hidden and visible layers for iterations from 10 to 400.
  3. visualize the resulting image, receive a very distorted 4
  4. next I tried not sampling from random, but simply calling the reconstruct() method, and the reconstructed image is also poor. Could this mean the training simply isn't complete, or unable to reach high quality capture of the distribution.

nan in probs

Hello,

Thank you very much for developing this superb library!!

I believe that I found an issue, but I am not able to find the root cause.

From time to time I receive this error:

Traceback (most recent call last):
File "/Users/supermario/LNIssue/run_rbm.py", line 26, in
epochs=1000000)
File "/Users/supermario/LNIssue/venv/lib/python3.7/site-packages/learnergy/models/bernoulli/rbm.py", line 495, in fit
_, _, _, _, visible_states = self.gibbs_sampling(samples)
File "/Users/supermario/LNIssue/venv/lib/python3.7/site-packages/learnergy/models/bernoulli/rbm.py", line 379, in gibbs_sampling
neg_hidden_states, True)
File "/Users/supermario/LNIssue/venv/lib/python3.7/site-packages/learnergy/models/bernoulli/rbm.py", line 352, in visible_sampling
states = torch.bernoulli(probs)
RuntimeError: Expected p_in >= 0 && p_in <= 1 to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)

Here is the code to reproduce the error:

import numpy as np
import torch
from torch.utils.data import Dataset
from learnergy.models.bernoulli.rbm import RBM

np.random.seed(16)
torch.manual_seed(16)

class CustomDataset(Dataset):

def __init__(self, custom_data):
    self.custom_data = torch.from_numpy(custom_data)
    self.dummy_y = torch.from_numpy(np.array([0.0]))

def __getitem__(self, index):
    return self.custom_data[index], self.dummy_y[0]

def __len__(self):
    return self.custom_data.shape[0]

rbm = RBM(n_visible=32, n_hidden=64, steps=1, learning_rate=0.0001, momentum=0.9, decay=0.00001, temperature=0, use_gpu=False)

data = np.random.choice(a=[False, True], size=(5755, 32)).astype(np.float32)
data_train = CustomDataset(data)

rbm.fit(dataset=data_train, batch_size=20, epochs=1000000)

And requirements:
astroid==2.8.4
attrs==21.2.0
coverage==6.1.1
cycler==0.11.0
imageio==2.10.3
importlib-metadata==4.8.2
iniconfig==1.1.1
isort==5.10.1
kiwisolver==1.3.2
lazy-object-proxy==1.6.0
learnergy==1.1.1
matplotlib==3.4.3
mccabe==0.6.1
networkx==2.6.3
numpy==1.21.4
packaging==21.2
Pillow==8.4.0
platformdirs==2.4.0
pluggy==1.0.0
py==1.11.0
pylint==2.11.1
pyparsing==2.4.7
pytest==6.2.5
python-dateutil==2.8.2
PyWavelets==1.2.0
scikit-image==0.18.3
scipy==1.7.2
six==1.16.0
tifffile==2021.11.2
toml==0.10.2
torch==1.9.0
tqdm==4.62.3
typed-ast==1.4.3
typing-extensions==3.10.0.2
wrapt==1.13.3
zipp==3.6.0

The error should appear at epoch 221/1000000.

If I add the following torch.nan_to_num in visible_sampling() method, then the error is not present anymore.

probs = torch.nan_to_num(probs, nan=0.0)
Sampling current states
states = torch.bernoulli(probs)

macosx, python 3.7.0

Thank you! Please let me know if you need additional info.

[REG] Basis for classification architecture

Regarding the basic Bernoulli RBM for classification, could I check what is the basis of your implementation?
From what I can tell, the training is broken up in two sections:

  1. RBM will perform unsupervised learning to minimize energy (RBM::fit), basically like a feature extractor.
  2. The whole model is then considered as a 2-layer neural network with a sigmoid layer (RBM::forward) and linear transformation layer.

So, it seems like the RBM is just used as an initializer for the neural network.

In addition, I noticed that RBM::fit's epoch defaults to 1. Increasing the epoch number does not seem to improve performance. Does this mean that there is no use in training the RBM?

Lastly, was there any prior work that implemented RBM in this way, or is this your original idea? Are there any published results or study into this architecture? Thank you!

[REG] what mse do you get from the mnist examples

Template when making a new issue

Please, make sure that the following boxes are checked before submitting a new issue. There is a small chance that you can solve it by your own or even that it was already addressed by someone.

Thank you!

Pre-checkings

  • [ x] Check that you are up-to-date with the master branch of Learnergy. You can update with:
    pip install git+git://github.com/gugarosa/learnergy.git --upgrade --no-deps

  • [ x] Check that you have read all of our README.

Description

[Description of the issue]

Link

I ran through the example code in gaussian_rbm_training.py.
after 5 epochs, the mse is at 253.189896
then I followed up with reconstruction, and the mse jumps to 253349.031250, which is of course useless.

I can increase the epoch counts, but for now, I just want to make sure I am repeating what you see on your side.

Steps to Reproduce

  1. [First Step] copy the code from gaussian_rbm_training.py, and run it inside a jupyter notebook
  2. [Second Step] run thru training without any parameter change. get mse = 253.189896
  3. [...] then run the reconstruction code as is, get mse == 253349.031250,

Expected behavior: [It should be what you expect to happen]
mse value a lot closer to the training loop values

Actual behavior: [What actually happens]
mse is orders of magnitude worse on reconstruction

Reproduces how often: [How much does it occur? Show us your percentage]

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

[REG] The purpose of applying Softplus function in RBM

I found in the comments of file learnergy/learnergy/models/bernoulli/rbm.py (line 401), you said

Creating a Softplus function for numerical stability

The form of Softplus function is
f(x) = log(1+exp(x)),
which fits the form of the log term of marginal energy of RBM

E(v)= \sum_i a_i v_i + \sum_j ( log( 1 + exp( \sum_i v_i \lambda_{ij} +b_j ) ) ).

So I suppose the Softplus function is not used to ensure the numerical stability, but to calculate the marginal energy. I am a beginner to RBM, if I have any wrong perceptions, please point it out.

Thank you!

Probabilistic Max Pooling

Hi Gustavo!

I hope you are doing well!

I was wondering if you had looked into / planned to add probabilistic max-pooling, as descibed in:
H. Lee, et al.,
Convolutional Deep Belief Networksfor Scalable Unsupervised Learning of Hierarchical Representations
Proceedings of the 26th annual international conference on machine learning (2009).

I am happy to help, but figured it would be best to consult you first.

Thanks!
Nick

Naming of models' class attributes

The variable names used in the getters and setters of each model class are different than what is initialized in the constructor.

Screen Shot 2021-06-14 at 7 37 42 PM

Note that the name 'W' is used in init, but '_W' is used as the variable name in the getters and setters, both of which have the same name as the variable initialized in init 'W'. This issue is the same for all member variables. I have tested the DBN and GaussianVarianceRBM subclasses as well, and it looks like the issue persists across all other subclasses.

Screen Shot 2021-06-14 at 7 38 32 PM

  • OS: CentOS 7.8
  • Virtual Environment conda 4.10.1
  • Python Version 3.8

This causes issues when trying to make copies of classes for things like multi-GPU training via torch.nn.DistributedDataParallel

how to connect model.fit() to convergence.plot()?

Pre-checkings

  • [ x] Check that you are up-to-date with the master branch of Learnergy. You can update with:
    pip install git+git://github.com/gugarosa/learnergy.git --upgrade --no-deps

  • [ x] Check that you have read all of our README.

Description

I see the convergence.plot sample code, where you input a static dictionary of the values to be plotted. They are mse, pl and times.
In the gaussian_rbm.fit() method, you did a self.dump() for each epoch, but that only updates an internal structure. And then there is the logging. The fit() call would only return the cumulative mse and pl at the end of all epoch runs. So if you would like to see the convergence rate from epoch to epoch, I can't figure out how you intend to feed the training parameters to the plot routine.

Steps to Reproduce

  1. call a model.fit()
  2. insert some kind of hook to retrieve the mse and pl per epoch
  3. plot those results using convergence.plot()

please explain or give an example how to create such a hook.

probability bug

When I use GaussianRBM to run rbm_classification.py on GPU, these errors appear.

11%|โ–ˆ | 51/469 [00:01<00:07, 58.24it/s]C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [416,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [417,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [418,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [419,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [420,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [421,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [422,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [423,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [424,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [425,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [426,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [427,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [428,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [429,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [430,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [431,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [432,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [433,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [434,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [435,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [436,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [437,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [438,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [439,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [440,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [441,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [442,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [443,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [444,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [445,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [446,0,0] Assertion 0 <= p4 && p4 <= 1 failed.
C:/cb/pytorch_1000000000000/work/aten/src\ATen/native/cuda/DistributionTemplates.h:591: block: [6,0,0], thread: [447,0,0] Assertion 0 <= p4 && p4 <= 1 failed.

RuntimeError: CUDA error: device-side assert triggered

But if I run it on cpu, the error while like this:
RuntimeError: Expected p_in >= 0 && p_in <= 1 to be true, but got false.

It seems like the function hidden_sampling dosen't run correctly.

is a label required for dataset fed into GaussianRBM

Template when making a new issue

Please, make sure that the following boxes are checked before submitting a new issue. There is a small chance that you can solve it by your own or even that it was already addressed by someone.

Thank you!

Pre-checkings

  • [x ] Check that you are up-to-date with the master branch of Learnergy. You can update with:
    pip install git+git://github.com/gugarosa/learnergy.git --upgrade --no-deps

  • [ x] Check that you have read all of our README.

Description

I fed a train Torch Dataset into GaussianRBM, which is derived from a standard DataFrame of real numbers. each dataset.getitem() returns a instance with shape torch.Size([1, 165])
The model.fit() call blows up with
KeyError: 0
I checked your example gaussian_rbm_training.py. There is one notable difference which is you used MNIST sample dataset, which has a label. However, in theory, RBM does not require a label to train.

Can you tell what is wrong with my data, and is the label field really what's causing the error?

Steps to Reproduce

  1. create a pandas DataFrame
  2. split into train, test
  3. wrote a custom torch Dataset to return Torch tensor, one sample at a time
  4. instantiate GaussianRBM
  5. call model.fit()
  6. get error KeyError: 0

Expected behavior: [It should be what you expect to happen]
expect it to just train through all the epochs
Actual behavior: [What actually happens]
throws a key error: 0
Reproduces how often: [How much does it occur? Show us your percentage]
everytime

Additional Information

suspect a label field is needed for the input dataset. But don't understand why if that is the case.

where is the Gaussian?

Pre-checkings

  • Check that you are up-to-date with the master branch of Learnergy. You can update with:
    pip install git+git://github.com/gugarosa/learnergy.git --upgrade --no-deps

  • Check that you have read all of our README.

Description

I am studying through gaussian_rbm.py, but I don't gaussian formulations anywhere.

Link

https://github.com/gugarosa/learnergy/blob/master/learnergy/models/gaussian/gaussian_rbm.py
https://www.jmlr.org/papers/volume12/taylor11a/taylor11a.pdf

Steps to Reproduce

  1. read through the gaussian_rbm.py file
  2. compared the formulation for energy and sampling visible to paper by Taylor
  3. there is no hint of gaussian distribution (which requires the square function), nor gaussian sampling (which requires torch.normal call)

Expected behavior: [It should be what you expect to happen]
gaussian formulation both in energy and sampling of visible nodes

Actual behavior: [What actually happens]
seems everything is treated as binary

is gaussian_rbm.py meant for gaussian visible layer and binary hidden layer?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.