Skip to content
Snippets Groups Projects
Commit bb4ab7ac authored by Isabelle Sanchez's avatar Isabelle Sanchez
Browse files

add break in while loop + add vignette

parent 4f5c1e46
No related branches found
No related tags found
No related merge requests found
Pipeline #57821 passed
...@@ -308,15 +308,13 @@ kfino_fit<-function(datain,Tvar,Yvar, ...@@ -308,15 +308,13 @@ kfino_fit<-function(datain,Tvar,Yvar,
N_etape_EM=10 N_etape_EM=10
t=1 t=1
for (m0_tmp in seq(bornem0[1],bornem0[2],2) ){ for (m0_tmp in seq(bornem0[1],bornem0[2],2) ){
print(t)
t=t+1 t=t+1
m_tmp=m0_tmp m_tmp=m0_tmp
p_tmp=0.5 p_tmp=0.5
diff_m0=diff_mm=diff_p=2 diff_m0=diff_mm=diff_p=2
k=1 k=1
#for (k in 1:N_etape_EM){ #for (k in 1:N_etape_EM){
while (k <= N_etape_EM || (diff_m0 > 0.5 && diff_p > 0.0001) ){ while (diff_m0 > 0.5 && diff_p > 0.0001){
print("passage")
Res_EM=KBO_EM(param=list(mm=m_tmp, Res_EM=KBO_EM(param=list(mm=m_tmp,
pp=p_tmp, pp=p_tmp,
m0=m0_tmp, m0=m0_tmp,
...@@ -330,19 +328,16 @@ kfino_fit<-function(datain,Tvar,Yvar, ...@@ -330,19 +328,16 @@ kfino_fit<-function(datain,Tvar,Yvar,
kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,dix=dix) kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,dix=dix)
diff_m0=abs(m0_tmp - Res_EM$m0[[1]]) diff_m0=abs(m0_tmp - Res_EM$m0[[1]])
diff_p=abs(p_tmp - Res_EM$pp) diff_p=abs(p_tmp - Res_EM$pp)
print(diff_m0)
print(diff_p)
k<-k+1 k<-k+1
m0_tmp=Res_EM$m0[[1]] m0_tmp=Res_EM$m0[[1]]
m_tmp=Res_EM$mm[[1]] m_tmp=Res_EM$mm[[1]]
p_tmp=Res_EM$pp p_tmp=Res_EM$pp
if (k==N_etape_EM) break
} }
V=Res_EM$likelihood V=Res_EM$likelihood
print(m0_tmp)
if (V > Vopt){ if (V > Vopt){
#print("EM converged.")
Vopt=V Vopt=V
m0opt=m0_tmp m0opt=m0_tmp
mmopt=m_tmp mmopt=m_tmp
......
This diff is collapsed.
...@@ -30,7 +30,7 @@ Tvar can be expressed as a proportion of day in seconds} ...@@ -30,7 +30,7 @@ Tvar can be expressed as a proportion of day in seconds}
default TRUE} default TRUE}
\item{method}{character, the method used to optimize the initial parameters: \item{method}{character, the method used to optimize the initial parameters:
Expectation-Maximization algorithm `"EM"` or Maximization Expectation-Maximization algorithm `"EM"` or Maximization
Likelihhod `"ML"`, default `"ML"`} Likelihhod `"ML"`, default `"ML"`}
\item{threshold}{numeric, threshold to qualify an observation as outlier \item{threshold}{numeric, threshold to qualify an observation as outlier
...@@ -81,7 +81,7 @@ are initialized according to the input data (between the expert ...@@ -81,7 +81,7 @@ are initialized according to the input data (between the expert
range) using quantile of the Y distribution (varying between 0.2 and 0.8 for range) using quantile of the Y distribution (varying between 0.2 and 0.8 for
m0 and 0.5 for mm). pp is a sequence varying between 0.5 and 0.7. A m0 and 0.5 for mm). pp is a sequence varying between 0.5 and 0.7. A
sub-sampling is performed to speed the algorithm if the number of possible sub-sampling is performed to speed the algorithm if the number of possible
observations studied is greater than 500. Optimization is performed using observations studied is greater than 500. Optimization is performed using
`"EM"` or `"ML"` methods. `"EM"` or `"ML"` methods.
} }
\examples{ \examples{
......
---
title: "How to perform a kfino outlier detection using the EM or ML method"
author: "B. Cloez & I. Sanchez"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: yes
toc_float: true
number_sections: true
vignette: >
%\VignetteIndexEntry{How to perform a kfino outlier detection using the EM or ML method}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(kfino)
library(dplyr)
library(ggplot2)
```
This vignette describes how to use the **kfino** algorithm on time courses in order to detect impulse noised outliers and predict the parameter of interest.
EM or ML methods
# Description of the `spring1` dataset
blablabla
```{r}
data(spring1)
# Dimension of this dataset
dim(spring1)
head(spring1)
```
# Kfino algorithm with optimized initial parameters
```{r}
# --- With Optimisation on initial parameters
param1<-list(m0=NULL,
mm=NULL,
pp=NULL,
aa=0.001,
expertMin=30,
expertMax=75,
sigma2_m0=1,
sigma2_mm=0.05,
sigma2_pp=5,
K=2,
seqp=seq(0.5,0.7,0.1))
```
## Maximized Likelihood (ML) method
```{r,error=TRUE}
resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="ML",param=param1)
# flags are qualitative
kfino_plot(resuin=resu1,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu1,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu1,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
## Expectation-Maximization (EM) method
```{r,error=TRUE}
resu2<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1)
# flags are qualitative
kfino_plot(resuin=resu2,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu2,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu2,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment