gradboard 0.1.10__tar.gz → 0.1.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gradboard might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: gradboard
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: Easily snowboard down gnarly loss gradients
5
5
  License: MIT
6
6
  Author: Nicholas Bailey
@@ -37,6 +37,28 @@ def cosine(step: int, total_steps: int) -> float:
37
37
  return round((math.cos(angle) + 1) / 2, 8)
38
38
 
39
39
 
40
+ def semicircle(step: int, total_steps: int) -> float:
41
+ """
42
+ Get a sequence of numbers between 0 and 1 in the shape of a semi-circle with
43
+ diameter `total_steps'.
44
+ """
45
+ assert total_steps != 0
46
+ x = step / (total_steps - 0.999)
47
+ # x^2 + y^2 = r^2 = 1
48
+ # Therefore y^2 = 1 - x^2
49
+ # Therefore y^2 = (1 + x)(1 - x)
50
+ y_squared = (1 - x) * (1 + x)
51
+ return math.sqrt(y_squared)
52
+
53
+
54
+ def half_semicircle(step: int, total_steps: int) -> float:
55
+ """
56
+ Get a sequence of numbers between 0 and 1 in the shape of the descending
57
+ half of a cosine wave with wavelength 2*`total_steps`.
58
+ """
59
+ return semicircle(step, (total_steps * 2) - 1)
60
+
61
+
40
62
  def half_cosine(step: int, total_steps: int) -> float:
41
63
  """
42
64
  Get a sequence of numbers between 0 and 1 in the shape of the descending
@@ -112,19 +134,7 @@ class Cycle:
112
134
 
113
135
  self.reflect = reflect
114
136
 
115
- if callable(generating_function):
116
- self._generating_function = generating_function
117
- elif generating_function == "ascent":
118
- self._generating_function = ascent
119
- elif generating_function == "triangle":
120
- self._generating_function = triangle
121
- elif generating_function == "cosine":
122
- self._generating_function = cosine
123
- elif generating_function == "half_cosine":
124
- self._generating_function = half_cosine
125
- elif generating_function == "half_cycloid":
126
- self._generating_function = half_cycloid
127
- else:
137
+ if not callable(generating_function):
128
138
  raise NotImplementedError(
129
139
  "`generating_function` must be a callable object or one of "
130
140
  '"ascent", "triangle", "cosine", "half_cosine" or "half_cycloid"'
@@ -221,7 +231,12 @@ class Cycle:
221
231
 
222
232
 
223
233
  class CycleProduct(Cycle):
224
- def __init__(self, cycles: List[Cycle], reflect=False):
234
+ def __init__(self, cycles: List[Cycle], reflect=False, normalise: bool = False):
235
+ """
236
+ Args:
237
+ normalise: if true, the square root of the product is returned (i.e.
238
+ the geometric mean of the two cycles that were multiplied together)
239
+ """
225
240
  main_training_examples = cycles[0].training_examples
226
241
  main_batch_size = cycles[0].batch_size
227
242
 
@@ -230,11 +245,14 @@ class CycleProduct(Cycle):
230
245
 
231
246
  self.cycles = cycles
232
247
  self.reflect = reflect
248
+ self.normalise = normalise
233
249
 
234
250
  def generating_function(step: int, total_steps: int) -> float:
235
251
  output = self.cycles[0](step)
236
252
  for c in self.cycles[1:]:
237
253
  output *= c(step % c.total_steps)
254
+ if self.normalise:
255
+ output = math.sqrt(output)
238
256
  return output
239
257
 
240
258
  super().__init__(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gradboard"
3
- version = "0.1.10"
3
+ version = "0.1.12"
4
4
  description = "Easily snowboard down gnarly loss gradients"
5
5
  authors = [
6
6
  {name = "Nicholas Bailey"}
File without changes
File without changes