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
find_grade <- function(score) { | |
if (score >= 90 && score <= 100) { | |
return("A") | |
} else if (score >= 85 && score <= 89) { | |
return("A-") | |
} else if (score >= 80 && score <= 84) { | |
return("B+") | |
} else if (score >= 75 && score <= 79) { | |
return("B") |
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
#install library gapminder dan tidyverse jika belum diinstall | |
#install.packages("gapminder") | |
#install.packages("tidyverse) | |
library(tidyverse) | |
library(gapminder) | |
gapminder_subset <- gapminder %>% | |
filter(year == 2007) |
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
getNumberFromArray <- function(x, idx) { | |
return(x[idx]) | |
} | |
milisecondToTime <- function(x) { | |
x <- x / 1000 | |
result = as.POSIXct(x, origin = "1970-01-01") | |
return(result) | |
} |
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
import torch | |
from torch.nn.functional import softmax | |
def masked_softmax(input: torch.Tensor, bool_mask: torch.Tensor, dim: int = -1, dtype: torch.dtype = None) -> torch.Tensor: | |
min_type_value = torch.finfo(input.dtype).min | |
masked_value = input.masked_fill(bool_mask, min_type_value) | |
return softmax(masked_value, dim = dim, dtype = dtype) | |
## Example |
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
# Pytorch implementation of Hungarian Algorithm | |
# Inspired from here : https://python.plainenglish.io/hungarian-algorithm-introduction-python-implementation-93e7c0890e15 | |
# Despite my effort to parallelize the code, there is still some sequential workflows in this code | |
from typing import Tuple | |
import torch | |
from torch import Tensor | |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') |