forked from gizatechxyz/orion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
503 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
|
||
//fn log2(self: T) -> T; | ||
|
||
//fn log10(self: T) -> T; | ||
|
||
# ComplexTrait::to_polar | ||
|
||
```rust | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
docs/framework/operators/machine-learning/linear-regressor/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Linear Regressor | ||
|
||
`LinearRegressorTrait` provides a trait definition for linear regression problem. | ||
|
||
```rust | ||
use orion::operators::ml::LinearRegressorTrait; | ||
``` | ||
|
||
### Data types | ||
|
||
Orion supports currently only fixed point data types for `LinearRegressorTrait`. | ||
|
||
| Data type | dtype | | ||
| -------------------- | ------------------------------------------------------------- | | ||
| Fixed point (signed) | `LinearRegressorTrait<FP8x23 \| FP16x16 \| FP64x64 \| FP32x32>` | | ||
|
||
|
||
*** | ||
|
||
| function | description | | ||
| --- | --- | | ||
| [`linear_regressor.predict`](linear_regressor.predict.md) | Performs the generalized linear regression evaluation. | | ||
|
130 changes: 130 additions & 0 deletions
130
...amework/operators/machine-learning/linear-regressor/linear_regressor.predict.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# LinearRegressorTrait::predict | ||
|
||
```rust | ||
fn predict(ref self: LinearRegressor<T>, X: Tensor<T>) -> Tensor<T>; | ||
``` | ||
|
||
Linear Regressor. Performs the generalized linear regression evaluation. | ||
|
||
## Args | ||
|
||
* `self`: LinearRegressor<T> - A LinearRegressor object. | ||
* `X`: Input 2D tensor. | ||
|
||
## Returns | ||
|
||
* Tensor<T> containing the generalized linear regression evaluation of the input X. | ||
|
||
## Type Constraints | ||
|
||
`LinearRegressor` and `X` must be fixed points | ||
|
||
## Examples | ||
|
||
```rust | ||
use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, FP16x16TensorAdd}; | ||
use orion::operators::ml::linear::linear_regressor::{ | ||
LinearRegressorTrait, POST_TRANSFORM, LinearRegressor | ||
}; | ||
use orion::numbers::{FP16x16, FixedTrait}; | ||
|
||
fn example_linear_regressor() -> Tensor<FP16x16> { | ||
|
||
let mut X: Tensor<FP16x16> = TensorTrait::new( | ||
array![3, 2].span(), | ||
array![ | ||
FP16x16 { mag: 0, sign: false }, | ||
FP16x16 { mag: 65536, sign: false }, | ||
FP16x16 { mag: 131072, sign: false }, | ||
FP16x16 { mag: 196608, sign: false }, | ||
FP16x16 { mag: 262144, sign: false }, | ||
FP16x16 { mag: 327680, sign: false }, | ||
] | ||
.span() | ||
); | ||
|
||
let coefficients: Span<FP16x16> = array![ | ||
FP16x16 { mag: 19661, sign: false }, | ||
FP16x16 { mag: 50463, sign: true }, | ||
|
||
] | ||
.span(); | ||
|
||
let intercepts: Span<FP16x16> = array![ | ||
FP16x16 { mag: 32768, sign: false }, | ||
|
||
] | ||
.span(); | ||
let intercepts = Option::Some(intercepts); | ||
|
||
let target : usize = 1; | ||
let post_transform = POST_TRANSFORM::NONE; | ||
|
||
let mut regressor: LinearRegressor<FP16x16> = LinearRegressor { | ||
coefficients, | ||
intercepts, | ||
target, | ||
post_transform | ||
}; | ||
|
||
let scores = LinearRegressorTrait::predict(ref regressor, X); | ||
|
||
scores | ||
} | ||
|
||
>>> | ||
[[-0.27], [-1.21], [-2.15]] | ||
|
||
|
||
|
||
fn example_linear_regressor_2() -> Tensor<FP16x16> { | ||
|
||
let mut X: Tensor<FP16x16> = TensorTrait::new( | ||
array![3, 2].span(), | ||
array![ | ||
FP16x16 { mag: 0, sign: false }, | ||
FP16x16 { mag: 65536, sign: false }, | ||
FP16x16 { mag: 131072, sign: false }, | ||
FP16x16 { mag: 196608, sign: false }, | ||
FP16x16 { mag: 262144, sign: false }, | ||
FP16x16 { mag: 327680, sign: false }, | ||
] | ||
.span() | ||
); | ||
|
||
let coefficients: Span<FP16x16> = array![ | ||
FP16x16 { mag: 19661, sign: false }, | ||
FP16x16 { mag: 50463, sign: true }, | ||
FP16x16 { mag: 19661, sign: false }, | ||
FP16x16 { mag: 50463, sign: true }, | ||
|
||
] | ||
.span(); | ||
|
||
let intercepts: Span<FP16x16> = array![ | ||
FP16x16 { mag: 32768, sign: false }, | ||
FP16x16 { mag: 45875, sign: false }, | ||
|
||
] | ||
.span(); | ||
let intercepts = Option::Some(intercepts); | ||
|
||
let target = 2; | ||
let post_transform = POST_TRANSFORM::NONE; | ||
|
||
let mut regressor: LinearRegressor<FP16x16> = LinearRegressor { | ||
coefficients, | ||
intercepts, | ||
target, | ||
post_transform | ||
}; | ||
|
||
let scores = LinearRegressorTrait::predict(ref regressor, X); | ||
|
||
scores | ||
} | ||
|
||
>>> | ||
[[-0.27, -0.07], [-1.21, -1.01], [-2.15, -1.95]] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
mod tree_ensemble; | ||
mod linear; | ||
|
||
use orion::operators::ml::tree_ensemble::core::{ | ||
TreeEnsemble, TreeEnsembleAttributes, TreeEnsembleImpl, NODE_MODES | ||
}; | ||
use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ | ||
TreeEnsembleClassifier, TreeEnsembleClassifierImpl, TreeEnsembleClassifierTrait, POST_TRANSFORM | ||
}; | ||
|
||
use orion::operators::ml::linear::linear_regressor::{LinearRegressorTrait, LinearRegressorImpl, LinearRegressor}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod linear_regressor; |
Oops, something went wrong.