Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] A cppn example #173

Open
skriegman opened this issue Jul 26, 2021 · 2 comments
Open

[FEATURE REQUEST] A cppn example #173

skriegman opened this issue Jul 26, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@skriegman
Copy link

Hi. I'd like to use this library with CPPNs that take as their input xyz and output a 3d tensor of reals.

Wondering if you have a bare bones implementation (e.g. fixed architecture) on hand that you are willing to share, and a paper you'd like to be cited if that example were to be adapted for academic research.

Thanks,
Sam

@skriegman skriegman added the enhancement New feature or request label Jul 26, 2021
@btjanaka
Copy link
Member

Hi Sam! Unfortunately, we don't have any CPPN examples right now, but here are some pointers:

  • pyribs would only work with a fixed architecture, as we assume solutions are a fixed length
  • To make a neural net work with pyribs, you would need to be able to serialize it to a 1D array, and then deserialize it back to a neural net.
  • In PyTorch, this can be done by adding methods to an nn.Module like the following:
    def serialize(self):
        """Returns 1D array with all parameters in the network."""
        return np.concatenate(
            [p.data.cpu().detach().numpy().ravel() for p in self.parameters()])

    def deserialize(self, array):
        """Loads parameters from 1D array."""
        arr_idx = 0
        for param in self.model.parameters():
            shape = tuple(param.data.shape)
            length = np.product(shape)
            block = array[arr_idx:arr_idx + length]
            if len(block) != length:
                raise ValueError("Array not long enough!")
            block = np.reshape(block, shape)
            arr_idx += length
            param.data = torch.from_numpy(block).float()
        return self
  • Finally, we do have this tutorial where we try to train an MNIST network with CMA-ME, but we never finished it (and it uses an outdated pyribs version)

@btjanaka
Copy link
Member

As for citation, you can cite the pyribs library and (if you use it) CMA-ME: https://pyribs.org/citation/

@btjanaka btjanaka modified the milestone: v0.6.0 Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants