Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍👩‍👧
Working from home

Justin Lin JustinSDK

👨‍👩‍👧
Working from home
View GitHub Profile
@JustinSDK
JustinSDK / AlgebraicType.java
Last active Oct 13, 2021
代數資料型態:子型態多型+模式比對
View AlgebraicType.java
package cc.openhome;
import java.util.Arrays;
sealed interface List permits Nil, Cons {
default Integer head() { return null; }
default List tail() { return null; }
default Integer sum() {
return switch(this) {
@JustinSDK
JustinSDK / AlgebraicType.java
Last active Oct 13, 2021
代數資料型態:子型態多型
View AlgebraicType.java
package ;
import java.util.Arrays;
sealed interface List permits Nil, Cons {
default Integer head() { return null; }
default List tail() { return null; }
Integer sum();
}
@JustinSDK
JustinSDK / AlgebraicType.java
Last active Oct 13, 2021
代數資料型態:Visitor 實現
View AlgebraicType.java
package cc.openhome;
import java.util.Arrays;
interface List {
default Integer head() { return null; }
default List tail() { return null; }
Integer sum();
// 實現模式比對
@JustinSDK
JustinSDK / AlgebraicType.java
Last active Oct 12, 2021
代數資料型態:Java 17
View AlgebraicType.java
package cc.openhome;
import java.util.Arrays;
sealed interface List<T> permits Nil, Cons<T> {
default T head() { return null; }
default List<T> tail() { return null; }
}
final class Nil implements List {
@JustinSDK
JustinSDK / regression_torch4.py
Last active Aug 14, 2021
PyTorch求線性迴歸
View regression_torch4.py
import torch
import cv2
import matplotlib.pyplot as plt
def training_loop(epochs, lr, params, x, y, verbose = False):
mx = torch.unsqueeze(x, 1).float()
my = torch.unsqueeze(y, 1).float()
model = torch.nn.Linear(mx.size(1), my.size(1))
mse_loss = torch.nn.MSELoss()
View regression_torch3.py
import torch
import cv2
import matplotlib.pyplot as plt
def model(x, w, b):
return w * x + b
def mse_loss(p, y):
return ((p - y) ** 2).mean()
@JustinSDK
JustinSDK / regression_torch2.py
Last active Aug 11, 2021
PyTorch反向傳播求梯度
View regression_torch2.py
import torch
import cv2
import matplotlib.pyplot as plt
def model(x, w, b):
return w * x + b
def mse_loss(p, y):
return ((p - y) ** 2).mean()
@JustinSDK
JustinSDK / regression_torch.py
Created Aug 11, 2021
NumPy API至PyTorch API
View regression_torch.py
import torch
import cv2
import matplotlib.pyplot as plt
def model(x, w, b):
return w * x + b
def mse_loss(p, y):
return ((p - y) ** 2).mean()
@JustinSDK
JustinSDK / regression_numpy2.py
Created Aug 11, 2021
NumPy實現線性迴歸(二)
View regression_numpy2.py
import numpy as np
import cv2
import matplotlib.pyplot as plt
def model(x, w, b):
return w * x + b
def mse_loss(p, y):
return ((p - y) ** 2).mean()
@JustinSDK
JustinSDK / regression_numpy.py
Last active Aug 11, 2021
NumPy實現線性迴歸(一)
View regression_numpy.py
import numpy as np
import cv2
import matplotlib.pyplot as plt
def model(x, w, b):
return w * x + b
def mse_loss(p, y):
return ((p - y) ** 2).mean()