Crates.io | raybnn |
lib.rs | raybnn |
version | 0.1.5 |
source | src |
created_at | 2023-10-08 22:09:54.598403 |
updated_at | 2023-11-15 07:12:20.741357 |
description | RayBNN |
homepage | |
repository | https://github.com/ |
max_upload_size | |
id | 997472 |
size | 1,316,938 |
RayBNN: A 3-D Biological Neural Network Transfer Learning Model
RTX 3090 or more powerful with at least 24GB VRAM
32GB RAM
20 GB of disk space
Docker (https://www.docker.com/)
Rust (https://www.rust-lang.org/)
Arrayfire (https://github.com/arrayfire/arrayfire)
Arrayfire Rust (https://github.com/arrayfire/arrayfire-rust)
Pytorch (https://pytorch.org/)
Pytorch geometric (https://github.com/pyg-team/pytorch_geometric)
Matlab
Sphere Cell Collision Functions to generate sphere and delete collided cells
RayBNN/src/physics/initial_f32.rs
sphere_cell_collision_batch()
: Generates a sphere and detects cell collisions in batch. Where all cells are check at the same timesphere_cell_collision_serial()
: Generates a sphere and detects cell collisions in serial. Where each cell is checked one by onesphere_cell_collision_minibatch()
: Generates a sphere and detects cell collisions in minibatch. Where groups/minibatches of cells are checkedInput Neuron Assignments
RayBNN/src/physics/initial_f32.rs
create_spaced_input_neuron_on_sphere()
: Creates input neurons on the surface of a sphere for 2D images of size (Nx,Ny)create_spaced_input_neuron_on_sphere_1D()
: Creates input neurons on the surface of a sphere for 1D data with random neuron position assignmentRaytracing Algorithms
RayBNN/src/physics/raytrace_f32.rs
RT1_random_rays()
: Raytracing algorithm 1 for creating neural connections. Randomly generates rays of random directions with variable number of random rays
RT2_directly_connected()
: Raytracing algorithm 2 for creating neural connections. Connects all neurons within the neural network sphere at the same time
RT3_distance_limited_directly_connected()
: Raytracing algorithm 3 for creating neural connections. Connects all neurons within minibatches/groups of neurons
Neural Network Training Algorithms
RayBNN/src/neural/network_f32.rs
state_space_forward_batch()
: Forward pass using CSR weighted adjacency sparse matrices and UAF. Generates all internal states and the neural network output
state_space_backward_group2()
: Backward pass using CSR weighted adjacency sparse matrices and UAF. Generates the gradients of the sparse weighted adjacency matrix
Set the $RAYBNN_DIR enviromental variable to a folder that will store all the RayBNN files
For example, setting $RAYBNN_DIR to /opt/
export RAYBNN_DIR=/opt/
Place RayBNN.zip into $RAYBNN_DIR and unzip it to produce:
$RAYBNN_DIR/RayBNN/src/
$RAYBNN_DIR/RayBNN/examples/
$RAYBNN_DIR/RayBNN/matlab_plot/
$RAYBNN_DIR/RayBNN/python_verify/
Make sure Matlab is installed on the host system. Tested on Matlab 2023a
This will download a CUDA Docker Container and link $RAYBNN_DIR directory in the Host Machine to the /workspace/ directory in the Docker Container.
docker run --name raybnn \
--gpus all \
-v $RAYBNN_DIR:/workspace \
-w /workspace \
-it nvcr.io/nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04 bash
Note that you need a GPU with 24 GB or more VRAM to run all of the code. RayBNN was tested on RTX3090. Verify the GPU is detected
nvidia-smi
./install.sh
installs all of the dependencies inside the docker container.
cd /workspace/RayBNN
chmod 700 ./install.sh
bash ./install.sh
exit
Download pytorch docker container Tested on RTX 3090 with i5-8400
docker run --name othermodel \
--gpus all \
-v $RAYBNN_DIR:/workspace \
-w /workspace \
-it pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime bash
pip install scikit-learn matplotlib pandas pytorch-lightning==1.9.0
pip install torch_geometric
pip install pyg_lib torch_scatter \
torch_sparse torch_cluster \
torch_spline_conv \
-f https://data.pyg.org/whl/torch-1.13.0+cu116.html
apt update
apt install wget git curl git-lfs
exit
On the Host Machine, Restart the Docker Container
docker restart raybnn
docker exec -it raybnn bash
cd /workspace/RayBNN
bash run_results_rust.sh
exit
docker restart othermodel
docker exec -it othermodel bash
cd /workspace/RayBNN
bash run_results_fig4_other_models.sh
exit
bash plot_results_matlab.sh
On the Host Machine, Restart the Docker Container
docker restart raybnn
docker exec -it raybnn bash
cd /workspace/RayBNN
Related scripts at
RayBNN/examples/figure1b.rs
RayBNN/matlab_plot/figure1b_plot.m
Figure 1b is an example of a simple neural network with raytraced connections
Inside Docker Container, generate ./figure1_neural_network.csv
that contains the entire neural network
cd /workspace/RayBNN
cargo run --example figure1b --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./figure1_neural_network.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure1b_plot.m
Related scripts at
RayBNN/examples/figure2a.rs
RayBNN/matlab_plot/figure2a_plot.m
The neural network sphere radius is constant, while the number of cells changes. It allows us to plot cell density vs the probability of cell collisions
Inside Docker Container, generate ./initial_cell_num.csv ./final_neuron_num.csv ./final_glia_num.csv ./collision_run_time.csv
cd /workspace/RayBNN
cargo run --example figure2a --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./initial_cell_num.csv ./final_neuron_num.csv ./final_glia_num.csv ./collision_run_time.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2a_plot.m
Related scripts at
RayBNN/examples/figure2b.rs
RayBNN/matlab_plot/figure2b_plot.m
The code runs serial, mini-batch, and batch versions of cell collision detection. It compares the runtimes of those algorithms
Inside Docker Container, generate ./collision_run_time.csv ./collision_run_time_serial.csv ./collision_run_time_batch.csv
cd /workspace/RayBNN
cargo run --example figure2a --release
cargo run --example figure2b --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./collision_run_time.csv ./collision_run_time_serial.csv ./collision_run_time_batch.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2b_plot.m
Related scripts at
RayBNN/examples/figure2c.rs
RayBNN/matlab_plot/figure2c_plot.m
This code generates 240,000 neurons and 240,000 glial cells in a 739.81 radius network It is intended to plot the distribution of cells as a function of radius
Inside Docker Container, generate ./neuron_pos.csv ./glia_pos.csv
cd /workspace/RayBNN
cargo run --example figure2c --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./neuron_pos.csv ./glia_pos.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2c_plot.m
Related scripts at
RayBNN/examples/figure2d.rs
RayBNN/matlab_plot/figure2d_plot.m
This code benchmarks the runtimes of RT-1,RT-2, and RT-3. RT-3 has variable 20, 40, and 60 neuron radii
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure2d --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./RT1_run_time.csv ./RT2_run_time.csv ./RT3_20_run_time.csv ./RT3_40_run_time.csv ./RT3_60_run_time.csv ./neuron_num_list.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2d_plot.m
Related scripts at
RayBNN/examples/figure2e.rs
RayBNN/matlab_plot/figure2e_plot.m
This code uses RT-3 to plot the probability density function of the raylengths compared to the density of the neural network sphere
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure2e --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./WRowIdxCOO_.csv ./WColIdx_.csv ./neuron_pos_.csv ./neuron_idx_.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2e_plot.m
Related scripts at
RayBNN/examples/figure2f.rs
RayBNN/matlab_plot/figure2f_plot.m
This code uses RT-3 to plot the probability density function of the number of neural connections per neuron compared to the density of the neural network sphere
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure2f --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./WRowIdxCOO_.csv ./WColIdx_.csv ./neuron_pos_.csv ./neuron_idx_.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure2f_plot.m
Related scripts at
RayBNN/examples/figure3b.rs
RayBNN/matlab_plot/figure3b_plot.m
RayBNN/matlab_plot/figure3c_plot.m
This code trains a neural network and probabilistically deletes 5% of the smallest weights. The weight distribution and deleted weights are plotted
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure3b --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./before_delete_WRowIdxCOO.csv ./before_delete_WColIdx.csv ./before_delete_WValues.csv ./after_delete_WRowIdxCOO.csv ./after_delete_WColIdx.csv ./after_delete_WValues.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure3b_plot.m
matlab -r figure3c_plot.m
Related scripts at
RayBNN/examples/figure3d.rs
RayBNN/matlab_plot/figure3d_plot.m
RayBNN/matlab_plot/figure3e_plot.m
RayBNN/matlab_plot/figure3f_plot.m
This code trains a neural network and plots the sparsity of weights. It also plots UAF and the weighted adjancency matrix
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure3d --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./sparsenetwork_*.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure3d_plot.m
matlab -r figure3e_plot.m
matlab -r figure3f_plot.m
Alcala Dataset from IndoorLoc Platform
https://web.archive.org/web/20211130114720/http://indoorlocplatform.uji.es/
Related scripts at
RayBNN/examples/figure4_raybnn.rs
RayBNN/matlab_plot/figure4a_plot.m
RayBNN/matlab_plot/figure4b_plot.m
RayBNN/matlab_plot/figure4c_plot.m
RayBNN/matlab_plot/figure4d_plot.m
RayBNN/matlab_plot/figure4e_plot.m
RayBNN/matlab_plot/figure4f_plot.m
Run the 10 Fold Testing for the Alcala Dataset in Figure 4 Note that CUDA has compile the kernels at runtime so the first run is slower. Tested on RTX 3090 with i5-8400
Inside Docker Container, generate all the csv files
cd /workspace/RayBNN
cargo run --example figure4_raybnn --release
mv *.csv ./matlab_plot/
On the Host Machine, Plot ./info_.csv ./test_act_.csv ./test_pred_*.csv using Matlab
cd $RAYBNN_DIR/RayBNN/matlab_plot/
matlab -r figure4a_plot.m
matlab -r figure4b_plot.m
matlab -r figure4c_plot.m
matlab -r figure4d_plot.m
matlab -r figure4e_plot.m
matlab -r figure4f_plot.m
On the Host Machine, Restart the Docker Container
docker restart othermodel
docker exec -it othermodel bash
cd /workspace/RayBNN
Example running the CNNRSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py CNNRSSI.py
python3 ./getresult.py
Example running the GCN2RSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py GCN2RSSI.py
python3 ./getresult.py
Example running the LSTMRSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py LSTMRSSI.py
python3 ./getresult.py
Example running the MLPRSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py MLPRSSI.py
python3 ./getresult.py
Example running the GNNLSTMRSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py GNNLSTMRSSI.py
python3 ./getresult.py
Example running the BILSTMRSSI.py code for 10 fold testing
Inside Docker Container, generate all the .dat files
cd /workspace/RayBNN/python_verify/RSSI2/
python3 ./All_run.py BILSTMRSSI.py
python3 ./getresult.py