Skip to content

Commit

Permalink
Update units.py
Browse files Browse the repository at this point in the history
  • Loading branch information
david-thrower authored Jun 13, 2024
1 parent df7b200 commit 0340045
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions cerebros/units/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,7 @@
simple_sigmoid, \
DenseAutoMlStructuralComponent, DenseLateralConnectivity

class TernaryDenseLayer(tf.keras.layers.Layer):
def __init__(self, units, input_dim, **kwargs):
super(TernaryDenseLayer, self).__init__(**kwargs)
self.units = units
self.input_dim = input_dim
self.ternary_weights = self.add_weight(name='ternary_weights',
shape=(input_dim, units),
initializer='glorot_uniform',
trainable=True)

def build(self, input_shape):
# Create a trainable weight variable for the bias
self.bias = self.add_weight(name='bias',
shape=(self.units,),
initializer='zeros',
trainable=True)

def call(self, inputs):
# Apply ternary weights to the input vector
ternary_inputs = tf.cast(tf.sign(inputs), tf.float32) * tf.abs(inputs)
output = tf.matmul(ternary_inputs, self.ternary_weights)
# Add bias and apply activation function
output = tf.nn.bias_add(output, self.bias)
output = tf.nn.relu(output)
return output
from custom.custom import TernaryDenseLayer

class Unit(NeuralNetworkFutureComponent):
def __init__(self,
Expand Down

0 comments on commit 0340045

Please sign in to comment.