Skip to content

Commit

Permalink
rebuild RGD vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Jun 18, 2024
1 parent a5b60be commit 71f6691
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
Binary file modified inst/python/__pycache__/cpd_disc.cpython-39.pyc
Binary file not shown.
38 changes: 18 additions & 20 deletions vignettes/RGD.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ library(terra)

``` r
library(tidyverse)
## ── Attaching core tidyverse packages ────────────────────────────────── tidyverse 2.0.0 ──
## ── Attaching core tidyverse packages ─────────────────────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ──────────────────────────────────────────────────── tidyverse_conflicts() ──
## ── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract() masks terra::extract()
## ✖ dplyr::filter() masks gdverse::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
Expand Down Expand Up @@ -63,8 +63,8 @@ fvc

``` r
names(fvc)
## [1] "fvc" "premax" "premin" "presum" "tmpmax" "tmpmin" "tmpavg" "pop" "ntl"
## [10] "lulc" "elev" "slope" "aspect"
## [1] "fvc" "premax" "premin" "presum" "tmpmax" "tmpmin" "tmpavg" "pop" "ntl" "lulc"
## [11] "elev" "slope" "aspect"
```

### Convert data from `SpatRaster` to `tibble`
Expand All @@ -91,11 +91,10 @@ We can use `robust_disc()` to discretize them based on offline change point dete


``` r
set.seed(12345678)
tictoc::tic()
new.fvc = robust_disc(fvc ~ .,data = select(fvc,-lulc),discnum = 15,cores = 6)
tictoc::toc()
## 2745.55 sec elapsed
## 2595.78 sec elapsed
```


Expand All @@ -117,25 +116,25 @@ new.fvc
## # ℹ 5,230 more rows
```

The `new.fvc` is the discrete result,we can combine it with `fvc` and `lulc` col in `fvc` tibble now.
The `new.fvc` is the discrete result,we can combine it with `fvc` and `lulc` col in `fvc` tibble now.


``` r
new.fvc = bind_cols(select(fvc,fvc,lulc),new.fvc)
new.fvc
## # A tibble: 5,240 × 13
## fvc lulc premax premin presum tmpmax tmpmin tmpavg pop ntl elev slope aspect
## <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 0.188 10 group10 group1 group1 group8 group4 group5 group7 grou… grou… grou… group4
## 2 0.162 10 group10 group1 group1 group9 group4 group7 group10 grou… grou… grou… group…
## 3 0.168 10 group11 group1 group1 group8 group4 group5 group8 grou… grou… grou… group…
## 4 0.186 10 group13 group1 group1 group8 group2 group4 group7 grou… grou… grou… group…
## 5 0.189 10 group10 group1 group1 group8 group4 group5 group1 grou… grou… grou… group7
## 6 0.171 10 group10 group1 group1 group9 group4 group5 group2 grou… grou… grou… group7
## 7 0.153 10 group10 group1 group1 group9 group4 group7 group8 grou… grou… grou… group4
## 8 0.163 10 group10 group1 group1 group9 group4 group7 group8 grou… grou… grou… group…
## 9 0.176 10 group10 group1 group1 group8 group4 group5 group10 grou… grou… grou… group…
## 10 0.177 10 group11 group1 group1 group8 group4 group5 group9 grou… grou… grou… group…
## fvc lulc premax premin presum tmpmax tmpmin tmpavg pop ntl elev slope aspect
## <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 0.188 10 group10 group1 group1 group8 group4 group5 group7 group14 group13 group… group4
## 2 0.162 10 group10 group1 group1 group9 group4 group7 group10 group14 group11 group… group…
## 3 0.168 10 group11 group1 group1 group8 group4 group5 group8 group14 group13 group… group…
## 4 0.186 10 group13 group1 group1 group8 group2 group4 group7 group14 group13 group… group…
## 5 0.189 10 group10 group1 group1 group8 group4 group5 group1 group14 group13 group… group7
## 6 0.171 10 group10 group1 group1 group9 group4 group5 group2 group14 group11 group… group7
## 7 0.153 10 group10 group1 group1 group9 group4 group7 group8 group14 group9 group6 group4
## 8 0.163 10 group10 group1 group1 group9 group4 group7 group8 group14 group9 group… group…
## 9 0.176 10 group10 group1 group1 group8 group4 group5 group10 group14 group13 group… group…
## 10 0.177 10 group11 group1 group1 group8 group4 group5 group9 group14 group9 group… group…
## # ℹ 5,230 more rows
```

Expand Down Expand Up @@ -332,7 +331,6 @@ gd(fvc ~ .,data = new.fvc,type = 'interaction')


``` r
set.seed(12345678)
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 15,
discvar = names(select(fvc,-c(fvc,lulc))),
cores = 6, type = c('factor','interaction'))
Expand Down
4 changes: 1 addition & 3 deletions vignettes/RGD.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Only `lulc` is a discrete category variable in the `fvc` data, we need to discre
We can use `robust_disc()` to discretize them based on offline change point detection.

```{r}
set.seed(12345678)
tictoc::tic()
new.fvc = robust_disc(fvc ~ .,data = select(fvc,-lulc),discnum = 15,cores = 6)
tictoc::toc()
Expand All @@ -64,7 +63,7 @@ tictoc::toc()
new.fvc
```

The `new.fvc` is the discrete result,we can combine it with `fvc` and `lulc` col in `fvc` tibble now.
The `new.fvc` is the discrete result,we can combine it with `fvc` and `lulc` col in `fvc` tibble now.

```{r}
new.fvc = bind_cols(select(fvc,fvc,lulc),new.fvc)
Expand All @@ -83,7 +82,6 @@ gd(fvc ~ .,data = new.fvc,type = 'interaction')
### You can also use `rgd()` in one time to get result above.

```{r}
set.seed(12345678)
fvc_rgd = rgd(fvc ~ ., data = fvc, discnum = 15,
discvar = names(select(fvc,-c(fvc,lulc))),
cores = 6, type = c('factor','interaction'))
Expand Down

0 comments on commit 71f6691

Please sign in to comment.