alizelib/README.md
2023-02-21 00:48:56 -05:00

93 lines
1.9 KiB
Markdown

# AlizeLib
Calculate the averages, total & best of labelled data, import and export the model for later use.
## Installation
The library can be installed using ncc:
```bash
ncc install -p "nosial/libs.alize=latest@n64"
```
or by adding the following to your project.json file under
the `build.dependencies` section:
```json
{
"name": "net.nosial.alizelib",
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.alize=latest@n64"
}
```
If you don't have the n64 source configured you can add it
by running the following command:
```bash
ncc source add --name n64 --type gitlab --host git.n64.cc
```
## Compiling from source
The library can be compiled from source using ncc:
```bash
ncc build --config release
```
or by running the following command:
```bash
make release
```
## Usage
```php
// ncc
require 'ncc';
import('net.nosial.alizelib');
// Create a new model
$size = 100; // The size of the model
$model = new \AlizeLib\GeneralizationModel($size);
// We are intentionally adding more data to the model
// than the model can hold, this is to demonstrate
// how old data is removed from the model.
// Add random high float values to the model under label "en" x 150 times
for($i = 0; $i < 150; $i++)
{
$model->add("en", random_float(0.5, 1));
}
// Add random low float values to the model under label "zh" x 150 times
for($i = 0; $i < 150; $i++)
{
$model->add("zh", random_float(0, 0.5));
}
// Add random very low float values to the model under label "fr" x 150 times
for($i = 0; $i < 150; $i++)
{
$model->add("fr", random_float(0, 0.1));
}
// Add random very high float values to the model under label "de" x 150 times
for($i = 0; $i < 150; $i++)
{
$model->add("de", random_float(0.9, 1));
}
// Best label should be "de" or second best "en"
var_dump($model->calculateBestLabels());
```
# License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details