Visual Debugging
This commit is contained in:
@@ -67,7 +67,7 @@ class FixpointExperiment(Experiment):
|
|||||||
net.self_attack()
|
net.self_attack()
|
||||||
i += 1
|
i += 1
|
||||||
if run_id:
|
if run_id:
|
||||||
weights = net.get_weights()
|
weights = net.get_weights_flat()
|
||||||
self.add_trajectory_segment(run_id, weights)
|
self.add_trajectory_segment(run_id, weights)
|
||||||
self.count(net)
|
self.count(net)
|
||||||
|
|
||||||
|
|||||||
7
code/latent_trajectory_plot.html
Normal file
7
code/latent_trajectory_plot.html
Normal file
File diff suppressed because one or more lines are too long
@@ -173,6 +173,7 @@ class FeedForwardNetwork(_BaseNetwork):
|
|||||||
bar.update()
|
bar.update()
|
||||||
return losses
|
return losses
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with Experiment() as exp:
|
with Experiment() as exp:
|
||||||
features, cells, layers = 2, 2, 2
|
features, cells, layers = 2, 2, 2
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ class NeuralNetwork(PrintingObject):
|
|||||||
def get_weights(self):
|
def get_weights(self):
|
||||||
return self.model.get_weights()
|
return self.model.get_weights()
|
||||||
|
|
||||||
|
def get_weights_flat(self):
|
||||||
|
return np.hstack([weight.flatten() for weight in self.get_weights()])
|
||||||
|
|
||||||
def set_weights(self, new_weights):
|
def set_weights(self, new_weights):
|
||||||
return self.model.set_weights(new_weights)
|
return self.model.set_weights(new_weights)
|
||||||
|
|
||||||
@@ -603,9 +606,9 @@ class TrainingNeuralNetworkDecorator(NeuralNetwork):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if False:
|
if True:
|
||||||
with FixpointExperiment() as exp:
|
with FixpointExperiment() as exp:
|
||||||
for run_id in tqdm(range(1)):
|
for run_id in tqdm(range(100)):
|
||||||
# net = WeightwiseNeuralNetwork(width=2, depth=2).with_keras_params(activation='linear')
|
# net = WeightwiseNeuralNetwork(width=2, depth=2).with_keras_params(activation='linear')
|
||||||
# net = AggregatingNeuralNetwork(aggregates=4, width=2, depth=2)\
|
# net = AggregatingNeuralNetwork(aggregates=4, width=2, depth=2)\
|
||||||
net = FFTNeuralNetwork(aggregates=4, width=2, depth=2) \
|
net = FFTNeuralNetwork(aggregates=4, width=2, depth=2) \
|
||||||
|
|||||||
7
code/plot.html
Normal file
7
code/plot.html
Normal file
File diff suppressed because one or more lines are too long
@@ -22,44 +22,39 @@ def build_args():
|
|||||||
|
|
||||||
def plot_latent_trajectories(data_dict, filename='latent_trajectory_plot'):
|
def plot_latent_trajectories(data_dict, filename='latent_trajectory_plot'):
|
||||||
|
|
||||||
# TODO Fist and Last Position Markers
|
|
||||||
|
|
||||||
def norm(val, a=0, b=0.25):
|
|
||||||
return (val - a) / (b - a)
|
|
||||||
|
|
||||||
bupu = cl.scales['9']['seq']['BuPu']
|
bupu = cl.scales['9']['seq']['BuPu']
|
||||||
scale = cl.interp(bupu, len(data_dict)) # Map color scale to N bins
|
scale = cl.interp(bupu, len(data_dict)+1) # Map color scale to N bins
|
||||||
|
|
||||||
# Fit the mebedding space
|
# Fit the mebedding space
|
||||||
transformer = TSNE()
|
transformer = TSNE()
|
||||||
for trajectory in data_dict:
|
for trajectory_id in data_dict:
|
||||||
transformer.fit(trajectory)
|
transformer.fit(np.asarray(data_dict[trajectory_id]))
|
||||||
|
|
||||||
# Transform data accordingly and plot it
|
# Transform data accordingly and plot it
|
||||||
data = []
|
data = []
|
||||||
for t_id, trajectory in enumerate(data_dict):
|
for trajectory_id in data_dict:
|
||||||
transformed = transformer.fit(trajectory)
|
transformed = transformer._fit(np.asarray(data_dict[trajectory_id]))
|
||||||
line_trace = go.Scatter(
|
line_trace = go.Scatter(
|
||||||
x=transformed[:, 0],
|
x=transformed[:, 0],
|
||||||
y=transformed[:, 1],
|
y=transformed[:, 1],
|
||||||
text='Hovertext goes here'.format(),
|
text='Hovertext goes here'.format(),
|
||||||
line=dict(color=scale[t_id]),
|
line=dict(color=scale[trajectory_id]),
|
||||||
# legendgroup='Position -{}'.format(pos),
|
# legendgroup='Position -{}'.format(pos),
|
||||||
# name='Position -{}'.format(pos),
|
# name='Position -{}'.format(pos),
|
||||||
showlegend=False,
|
showlegend=False,
|
||||||
# hoverinfo='text',
|
# hoverinfo='text',
|
||||||
mode='lines')
|
mode='lines')
|
||||||
line_start = go.Scatter(mode='markers', x=transformed[0, 0], y=transformed[0, 1],
|
line_start = go.Scatter(mode='markers', x=[transformed[0, 0]], y=[transformed[0, 1]],
|
||||||
marker=dict(
|
marker=dict(
|
||||||
color='rgb(255, 0, 0)',
|
color='rgb(255, 0, 0)',
|
||||||
size=2
|
size=4
|
||||||
),
|
),
|
||||||
showlegend=False
|
showlegend=False
|
||||||
)
|
)
|
||||||
line_end = go.Scatter(mode='markers', x=transformed[-1, 0], y=transformed[-1, 1],
|
line_end = go.Scatter(mode='markers', x=[transformed[-1, 0]], y=[transformed[-1, 1]],
|
||||||
marker=dict(
|
marker=dict(
|
||||||
color='rgb(0, 0, 0)',
|
color='rgb(0, 0, 0)',
|
||||||
size=2
|
size=4
|
||||||
),
|
),
|
||||||
showlegend=False
|
showlegend=False
|
||||||
)
|
)
|
||||||
@@ -74,30 +69,30 @@ def plot_latent_trajectories(data_dict, filename='latent_trajectory_plot'):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def plot_latent_trajectories_3D(param_dict, filename='plot'):
|
def plot_latent_trajectories_3D(data_dict, filename='plot'):
|
||||||
def norm(val, a=0, b=0.25):
|
def norm(val, a=0, b=0.25):
|
||||||
return (val - a) / (b - a)
|
return (val - a) / (b - a)
|
||||||
|
|
||||||
bupu = cl.scales['9']['seq']['BuPu']
|
bupu = cl.scales['9']['seq']['BuPu']
|
||||||
scale = cl.interp(bupu, len(param_dict.get('trajectories', []))) # Map color scale to N bins
|
scale = cl.interp(bupu, len(data_dict)+1) # Map color scale to N bins
|
||||||
|
|
||||||
max_len = max([len(trajectory) for trajectory in param_dict.get('trajectories', [])])
|
max_len = max([len(trajectory) for trajectory in data_dict.values()])
|
||||||
|
|
||||||
# Fit the mebedding space
|
# Fit the mebedding space
|
||||||
transformer = TSNE()
|
transformer = TSNE()
|
||||||
for trajectory in param_dict.get('trajectories', []):
|
for trajectory_id in data_dict:
|
||||||
transformer.fit(trajectory)
|
transformer.fit(data_dict[trajectory_id])
|
||||||
|
|
||||||
# Transform data accordingly and plot it
|
# Transform data accordingly and plot it
|
||||||
data = []
|
data = []
|
||||||
for t_id, trajectory in enumerate(param_dict.get('trajectories', [])):
|
for trajectory_id in data_dict:
|
||||||
transformed = transformer.fit(trajectory)
|
transformed = transformer._fit(np.asarray(data_dict[trajectory_id]))
|
||||||
trace = go.Scatter3d(
|
trace = go.Scatter3d(
|
||||||
x=transformed[:, 0],
|
x=transformed[:, 0],
|
||||||
y=transformed[:, 1],
|
y=transformed[:, 1],
|
||||||
z=np.arange(max(max_len)),
|
z=np.arange(transformed.shape[0]),
|
||||||
text='Hovertext goes here'.format(),
|
text='Hovertext goes here'.format(),
|
||||||
line=dict(color=scale[t_id]),
|
line=dict(color=scale[trajectory_id]),
|
||||||
# legendgroup='Position -{}'.format(pos),
|
# legendgroup='Position -{}'.format(pos),
|
||||||
# name='Position -{}'.format(pos),
|
# name='Position -{}'.format(pos),
|
||||||
showlegend=False,
|
showlegend=False,
|
||||||
@@ -106,9 +101,9 @@ def plot_latent_trajectories_3D(param_dict, filename='plot'):
|
|||||||
data.append(trace)
|
data.append(trace)
|
||||||
|
|
||||||
layout = go.Layout(scene=dict(aspectratio=dict(x=2, y=2, z=1),
|
layout = go.Layout(scene=dict(aspectratio=dict(x=2, y=2, z=1),
|
||||||
xaxis=dict(tickwidth=1, title='Number of Cells'),
|
xaxis=dict(tickwidth=1, title='Transformed X'),
|
||||||
yaxis=dict(tickwidth=1, title='Number of Layers'),
|
yaxis=dict(tickwidth=1, title='transformed Y'),
|
||||||
zaxis=dict(tickwidth=1, title='Position -pX')),
|
zaxis=dict(tickwidth=1, title='Epoch')),
|
||||||
title='{} - Latent Trajectory Movement'.format('Penis'),
|
title='{} - Latent Trajectory Movement'.format('Penis'),
|
||||||
width=800, height=800,
|
width=800, height=800,
|
||||||
margin=dict(l=0, r=0, b=0, t=0))
|
margin=dict(l=0, r=0, b=0, t=0))
|
||||||
@@ -195,4 +190,8 @@ if __name__ == '__main__':
|
|||||||
in_file = args.in_file[0]
|
in_file = args.in_file[0]
|
||||||
out_file = args.out_file
|
out_file = args.out_file
|
||||||
|
|
||||||
|
with open(in_file, 'rb') as in_f:
|
||||||
|
experiment = dill.load(in_f)
|
||||||
|
plot_latent_trajectories_3D(experiment.data_storage)
|
||||||
|
|
||||||
print('aha')
|
print('aha')
|
||||||
|
|||||||
Reference in New Issue
Block a user