This repository has been archived by the owner on May 25, 2024. It is now read-only.
forked from agrimagsrl/micromlgen
-
Notifications
You must be signed in to change notification settings - Fork 34
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
1 parent
7e5128f
commit 60e7cde
Showing
4 changed files
with
50 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
namespace Eloquent { | ||
namespace ML { | ||
namespace Port { | ||
|
||
class {{ classname }} { | ||
public: | ||
|
||
/** | ||
* Predict class for features vector | ||
*/ | ||
int predict(float *x) { | ||
float votes[{{ classes|length }}] = { 0.0f }; | ||
|
||
{% include 'gaussiannb/vote.jinja' %} | ||
{% include 'vote.jinja' %} | ||
} | ||
|
||
{% include 'classmap.jinja' %} | ||
|
||
protected: | ||
|
||
/** | ||
* Compute gaussian value | ||
*/ | ||
float gauss(float *x, float *theta, float *sigma) { | ||
float gauss = 0.0f; | ||
|
||
for (uint16_t i = 0; i < {{ theta[0]|length }}; i++) { | ||
gauss += log(sigma[i]); | ||
gauss += pow(x[i] - theta[i], 2) / sigma[i]; | ||
} | ||
|
||
return gauss; | ||
} | ||
}; | ||
} | ||
} | ||
} |
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,8 @@ | ||
float theta[{{ theta[0]|length }}] = { 0 }; | ||
float sigma[{{ sigma[0]|length }}] = { 0 }; | ||
|
||
{% for i, (t, s) in f.enumerate(f.zip(theta, sigma)) %} | ||
{% for j, tj in f.enumerate(t) %}theta[{{ j }}] = {{ f.round(tj) }}; {% endfor %} | ||
{% for j, sj in f.enumerate(s) %}sigma[{{ j }}] = {{ f.round(sj) }}; {% endfor %} | ||
votes[{{ i }}] = {{ f.round(prior[i]) }} - gauss(x, theta, sigma); | ||
{% endfor %} |
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