Coder Social home page Coder Social logo

fvalle1 / hopfield Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 203 KB

hopfield network implementation in C++

License: MIT License

Makefile 0.48% C++ 43.61% Metal 0.38% Objective-C++ 55.17% CMake 0.36%
hopfield-network gpu-computing metal network

hopfield's Introduction

Compile w/o Metal Build CMake Linux Build CMake Macos Run Linux

hopfield

hopfield network implementation in C++

compile

mkdir build && cd build
cmake ..
make

Linux

This repository uses the Metal framework to offload jobs to GPU. This works only on Apple machines and it is not supported by other systems. If you are running under Linux, please compile using

make all_nometal CXX=g++

it will ceate an executable called hopfield_nometal.out

Alternatively you can use cmake which automatically handles libraries

mkdir build && cd build
cmake ..
make

Run

./hopfield

On Apple devices be sure to run from the home folder (shaders are required to be in the correct path at runtime)

Example

    // Create a dataset with memories
    std::vector<Memory> training_dataset;
    training_dataset.emplace_back(Memory(6, 1, 1, 0, 0, 1, 1));
    training_dataset.emplace_back(Memory(6, 1, 1, 1, 1, 1, 1));

    //Create a model
    auto model = Model(training_dataset.size(), training_dataset[0].size());
    model.load_memories(training_dataset);


    // Build a corrupted memory
    spin corrupted_data[] = {1, 1, 1, 1, 1, 0};
    Memory corrupted_memory;
    std::memmove(corrupted_memory.fData, corrupted_data, corrupted_memory.size_of());

    // Train the model. Use can use kNull, kCPU, kGPU, kMultiThread, kOMP
    // If the chosen device is not available another one is automatically picked up
    model.train(kCPU);
    model.reconstruct(corrupted_memory);

    cout << "Reconstructed: " << endl;
    for (uint8_t i = 0; i < corrupted_memory.size(); i++) cout << corrupted_memory.fData[i] << " ";

    cout << model;

More examples are in the tests folder.

With images

Example with a corrupted image of an "8" hanwritten.

corrupted image

After it is reconstructed the black band disappears.

reconstructed image

Issues

The Github Action RunMacOS sometime fails due to lack of GPU access.

License

See LICENSE

hopfield's People

Contributors

fvalle1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.