Skip to content

Repository files navigation

CSDmL

GitHub Actions Test Badge Forks Issues

Basic machine learning library for CSDL. WARNING: WIP - This library is still under development and may not be stable.

Installation

Installation instructions for users

For direct installation with all dependencies, run on the terminal or command line

pip install git+https://github.com/HgXe/CSDmL.git

Installing JAX and optax is highly recommended for the library to work properly. See JAX, Optax for installation instructions.

Tested with Python 3.8 and 3.9. Other versions may work but are not guaranteed.

Installation instructions for developers

To install csdml, first clone the repository and install using pip. On the terminal or command line, run

git clone https://github.com/HgXe/CSDmL.git
pip install -e ./CSDmL

Usage

To use the library, import the package and use the functions as needed.

import csdml
import optax
import numpy as np
import csdl_alpha as csdl

# start csdl recorder
rec = csdl.Recorder(inline=True)
rec.start()

# generate training and test data
X = np.random.rand(10000, 1)*2*np.pi
y = np.sin(X)

X_test = np.linspace(0, 1, 100).reshape(-1, 1)*2*np.pi
Y_test = np.sin(X_test)

# define neural network
activation = ['relu', 'tanh', 'tanh', 'tanh', 'tanh']
model = csdml.FCNN(1, [20, 20, 20, 20], 1, activation=activation)
loss_data = X, y

# train model
optimizer = optax.adam(1e-3)
model.train_jax_opt(optimizer, loss_data, test_data=(X_test, Y_test), num_epochs=1000)

# plot results
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

y_pred = model.forward(X_test).value
__=ax.plot(X_test, y_pred)
__=ax.plot(X_test, Y_test)

ax.legend(['Predicted', 'True'])

plt.show()

For Developers

For details on documentation, refer to the README in docs directory.

For details on testing/pull requests, refer to the README in tests directory.

License

This project is licensed under the terms of the GNU Lesser General Public License v3.0.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages