Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Changelog

## v0.2.0

- Optimization module has been refactored. This is a breaking change.
- Added initialization base class, He initialization, and Xavier initialization.
- Added "full-batch" training by setting `batch_size` model parameter to `None`.
- Documentation updated to include overview.
## v0.2.1

- Fixed a bug where `SequentialBuilder`could not do full batch training.
- Added Hinge and Huber loss.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phitodeep"
version = "0.2.0"
version = "0.2.1"
authors = [
{ name = "Ralph Dugue", email = "ralph@phito.dev" }
]
Expand Down
26 changes: 26 additions & 0 deletions src/phitodeep/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,29 @@ def loss_func(self, y_pred, y_true):

def loss_gradient(self, y_pred, y_true):
return (y_pred - y_true) / (y_pred * (1 - y_pred) + 1e-8)

class Hinge(LossBase):
def __init__(self) -> None:
super().__init__("Hinge")

def loss_func(self, y_pred, y_true):
return np.maximum(0, 1 - y_pred * y_true)

def loss_gradient(self, y_pred, y_true):
yz = y_pred * y_true
return np.where(yz < 1, -y_true, 0)

class Huber(LossBase):
def __init__(self, delta=1.0):
super().__init__("Huber")
self.delta = delta

def loss_func(self, y_pred, y_true):
error = y_true - y_pred
L1 = error ** 2 / 2
L2 = self.delta * (np.abs(error) - (self.delta / 2))
return np.where(np.abs(error) > self.delta, L1, L2)

def loss_gradient(self, y_pred, y_true):
error = y_pred - y_true
return np.where(np.abs(error) > self.delta, self.delta * np.sign(error), error)
2 changes: 1 addition & 1 deletion src/phitodeep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self):
self.layers = []
self.alpha_value = 1
self.optimizer_type = o.Adam()
self.batch_size = 1
self.batch_size = None
self.epochs_value = 1000
self.loss_class = ls.MeanSquaredError()

Expand Down
Loading