Exemple #1
0
 def node_imp(self):
     self._node1 = [None] + [
         nodes.mul_node() for _ in range(self._feature_dim)
     ]
     self._node2 = [None] + [
         nodes.plus_node() for _ in range(self._feature_dim)
     ]
from dataset_generator import dataset_generator

plt.style.use('seaborn')
np.random.seed(0)


dataset_gen = dataset_generator()

dataset_gen.set_coefficient([5,2])
x_data, y_data = dataset_gen.make_dataset()
data = np.hstack((x_data, y_data))


# model implementation
node1 = nodes.mul_node()
node2 = nodes.plus_node()

# square loss/MSE cost implementation
node3 = nodes.minus_node()
node4 = nodes.square_node()

th1, th0 = 1,0
lr = 0.01
epochs = 2

th1_list, th0_list = [], []
loss_list = []

for epoch in range(epochs):
    for data_idx, (x,y) in enumerate(data):
Exemple #3
0
dataset_gen = dataset_generator(feature_dim = 2, n_sample = 100)
dataset_gen.set_coefficient([3,3,3])
distribution_params = {'feature_0': {'mean':0,'std':1}, 'feature_1': {'mean':0,'std':1}}

dataset_gen.set_distribution_params(distribution_params)
data = dataset_gen.make_dataset()

x_data, y_data = data[:,:-1], data[:,-1].reshape(-1,1)

data = np.hstack((x_data, y_data))

##### Model/Loss Implementation
# Model
node1_1 = nodes.mul_node()
node1_2 = nodes.mul_node()
node2_1 = nodes.plus_node()
node2_2 = nodes.plus_node()

# Loss
node3 = nodes.minus_node()
node4 = nodes.square_node()

th2, th1, th0 = 0.5, 0.5, 0.5
epochs, lr = 3, 0.005
th_accum = np.array([th2, th1, th0]).reshape(-1,1)
loss_list = []

for epoch in range(epochs):
    for data_idx, (x2, x1, y) in enumerate(data):
        z1_1 = node1_1.forward(th1, x1)
        z1_2 = node1_2.forward(th2, x2)
Exemple #4
0
    },
}
##### End Your Code(Dataset Setting) #####

##### Start Your Code(Dataset Generation) #####
data_gen = LR_dataset_generator(feature_dim=3)
data_gen.set_coefficient(coefficient_list)
data_gen.set_distribution_params(distribution_params)
x_data, y_data = data_gen.make_dataset()
dataset = np.hstack((x_data, y_data))
##### End Your Code(Dataset Generation) #####

#%%
feature_dim = 3
node1 = [None] + [nodes.mul_node() for _ in range(feature_dim)]
node2 = [None] + [nodes.plus_node() for _ in range(feature_dim)]
node3 = nodes.minus_node()
node4 = nodes.square_node()
node5 = nodes.mean_node()

#%%
th3, th2, th1, th0 = 0.1, 0.1, 0.1, 0.1
batch_size = 8
batch_idx = 0
n_batch = int(np.ceil(dataset.shape[0] / batch_size))

batch = get_data_batch(dataset, batch_idx, batch_size, n_batch)
print("batch.shape : ", batch.shape)
X, Y = batch[:, :-1], batch[:, -1]
print("X.shape : ", X.shape)
print("Y.shape : ", Y.shape, '\n')
 def model_imp(self):
     self.node1 = nodes.mul_node()
     self.node2 = nodes.plus_node()
Exemple #6
0
 def node_imp(self):
     self._node1 = nodes.mul_node()
     self._node2 = nodes.plus_node()