-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
100 lines (66 loc) · 4.24 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<style>
.page-header {
padding-bottom: 0;
margin: 0;
border-bottom: 0px solid;
}
.jumbotron {
margin-top: 30px;
}
</style>
<div class="jumbotron">
# Ruta <img src="https://raw.githubusercontent.com/fdavidcl/ruta/master/docs/images/logo/ruta_logo64.png" align="right">
Software for unsupervised deep architectures
[](https://www.r-project.org/)
[](https://cranlogs.r-pkg.org/downloads/total/last-month/ruta)
[](https://travis-ci.org/fdavidcl/ruta)
[](https://www.gnu.org/licenses/gpl.html)
---
Get uncomplicated access to unsupervised deep neural networks, from building their architecture to their training and evaluation
[[]{.fa .fa-code} Get started](/articles/examples/autoencoder_basic.html){.btn .btn-primary}
</div>
## How to install
In order to develop Ruta models, you will need to install its dependencies first and then get the package from CRAN.
### Dependencies
Ruta is based in the well known open source deep learning library [Keras](https://keras.io) and its [R interface](https://cran.r-project.org/package=keras), which is integrated in [Tensorflow](https://www.tensorflow.org/). In order to install them easily, you can use the [`keras::install_keras()`](https://tensorflow.rstudio.com/reference/keras/install_keras) function. Depending on whether you want to use the system installation, a Conda environment or a Virtualenv, you may need to call [`use_condaenv()` or `use_virtualenv()` from `reticulate`](https://rstudio.github.io/reticulate/articles/versions.html).
Another straightforward way to install these dependencies is to use global system-wide (`sudo pip install`) or user-wide (`pip install --user`) installation with `pip`. This is generally not recommended unless you are sure you will not need alternative versions or clash with other packages. The following shell command would install all libraries expected by Keras:
```sh
$ pip install --user tensorflow tensorflow-hub tensorflow-datasets scipy requests pyyaml Pillow h5py pandas pydot
```
Otherwise, you can follow the official installation guides:
- [Installing TensorFlow](https://www.tensorflow.org/install/)
Check whether Keras is accesible from R by running:
```r
keras::is_keras_available() # should return TRUE
```
### Ruta package
From an R interpreter such as the R REPL or the RStudio console, run one of the following commands to get the Ruta package:
```r
# Just get Ruta from the CRAN
install.packages("ruta")
# Or get the latest development version from GitHub
devtools::install_github("fdavidcl/ruta")
```
All R dependencies will be automatically installed. These include the Keras R interface and [`purrr`](https://purrr.tidyverse.org/).
## First steps
The easiest way to start working with Ruta is to use the `autoencode()` function. It allows for selecting a type of autoencoder and transforming the feature space of a data set onto another one with some desirable properties depending on the chosen type.
```r
iris[, 1:4] |> as.matrix() |> autoencode(2, type = "denoising")
```
You can learn more about different variants of autoencoders by reading [*A practical tutorial on autoencoders for nonlinear feature fusion*](https://arxiv.org/abs/1801.01586).
Ruta provides the functionality to build diverse neural architectures (see `autoencoder()`), train them as autoencoders (see `train()`) and perform different tasks with the resulting models (see `reconstruct()`), including evaluation (see `evaluate_mean_squared_error()`). The following is a basic example of a natural pipeline with an autoencoder:
```r
library(ruta)
# Shuffle and normalize dataset
x <- iris[, 1:4] |> sample() |> as.matrix() |> scale()
x_train <- x[1:100, ]
x_test <- x[101:150, ]
autoencoder(
input() + dense(256) + dense(36, "tanh") + dense(256) + output("sigmoid"),
loss = "mean_squared_error"
) |>
make_contractive(weight = 1e-4) |>
train(x_train, epochs = 40) |>
evaluate_mean_squared_error(x_test)
```
For more details, see [other examples](https://ruta.software/articles/examples/) and [the documentation](https://ruta.software/reference/).