Transfer learning of phase transitions in percolation and directed percolation