Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suggestible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
Suggestible
Commits
f5fb5275
Commit
f5fb5275
authored
8 months ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
Add Basic Decay
parent
133cf670
No related branches found
Branches containing commit
No related tags found
1 merge request
!11
Resolve "Implement Decay for Training Data"
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main.rs
+3
-1
3 additions, 1 deletion
src/main.rs
src/predictors/basic_markov.rs
+4
-0
4 additions, 0 deletions
src/predictors/basic_markov.rs
src/predictors/basic_set.rs
+22
-0
22 additions, 0 deletions
src/predictors/basic_set.rs
src/predictors/mod.rs
+1
-0
1 addition, 0 deletions
src/predictors/mod.rs
with
30 additions
and
1 deletion
src/main.rs
+
3
−
1
View file @
f5fb5275
...
...
@@ -49,6 +49,7 @@ fn main() -> Result<(), io::Error> {
.unwrap_or
(
basic_set
::
SetPredictor
::
new
());
markov_chain
=
read_from_db
(
config
.clone
(),
markov_chain
);
markov_chain
.decay
();
// let term_frequency_threshold = match config.get("term_frequency_threshold") {
// Some(toml::Value::Integer(n)) if *n >= 0 => *n as usize,
...
...
@@ -106,6 +107,7 @@ fn main() -> Result<(), io::Error> {
let
now
=
std
::
time
::
SystemTime
::
now
();
let
elapsed
=
now
.duration_since
(
last_update
)
.expect
(
"Time went backwards"
);
if
elapsed
>=
std
::
time
::
Duration
::
from_secs
(
24
*
60
*
60
)
{
markov_chain
.decay
();
markov_chain
=
read_from_db
(
config
.clone
(),
markov_chain
);
last_update
=
now
;
}
...
...
@@ -128,7 +130,7 @@ fn read_from_db(config: HashMap<String, String>, mut predictor: SetPredictor) ->
match
client
{
Ok
(
mut
c
)
=>
{
let
mut
count
=
0
;
match
c
.query
(
"SELECT query FROM public.logs_partitioned ORDER BY time DESC LIMIT
5
000"
,
&
[])
{
match
c
.query
(
"SELECT query FROM public.logs_partitioned ORDER BY time DESC LIMIT
100
000"
,
&
[])
{
Ok
(
rows
)
=>
{
for
row
in
rows
{
let
query
:
&
str
=
row
.get
(
0
);
...
...
This diff is collapsed.
Click to expand it.
src/predictors/basic_markov.rs
+
4
−
0
View file @
f5fb5275
...
...
@@ -60,6 +60,10 @@ impl Predictor for MarkovChainPredictor {
Ok
(())
}
fn
decay
(
&
mut
self
)
->
()
{
//TODO
}
fn
predict
(
&
self
,
query
:
&
str
,
n
:
usize
)
->
String
{
if
let
Some
(
top_words
)
=
get_top_following_words
(
...
...
This diff is collapsed.
Click to expand it.
src/predictors/basic_set.rs
+
22
−
0
View file @
f5fb5275
...
...
@@ -61,6 +61,28 @@ impl Predictor for SetPredictor {
Ok
(())
}
fn
decay
(
&
mut
self
)
->
()
{
let
keys_to_remove
:
Vec
<
String
>
=
self
.set
.iter_mut
()
.filter_map
(|(
key
,
value
)|
{
if
*
value
>
0
{
*
value
-=
1
;
if
*
value
<
1
{
Some
(
key
.clone
())
}
else
{
None
}
}
else
{
Some
(
key
.clone
())
}
})
.collect
();
for
key
in
keys_to_remove
{
self
.set
.remove
(
&
key
);
}
}
fn
predict
(
&
self
,
query
:
&
str
,
n
:
usize
)
->
String
{
if
let
Some
(
top_words
)
=
get_top_completions
(
...
...
This diff is collapsed.
Click to expand it.
src/predictors/mod.rs
+
1
−
0
View file @
f5fb5275
...
...
@@ -7,6 +7,7 @@ pub trait Predictor {
fn
predict
(
&
self
,
query
:
&
str
,
n
:
usize
)
->
String
;
fn
update
(
&
mut
self
,
query
:
&
str
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
;
fn
decay
(
&
mut
self
)
->
();
fn
new
()
->
Self
where
Self
:
Sized
;
fn
new_from_config
(
config
:
HashMap
<
String
,
impl
Into
<
String
>>
)
->
Self
where
Self
:
Sized
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment