add graph-based traversal density

simu_flags
Clemens Klug 2017-11-07 12:50:45 +01:00
parent b4c52ac655
commit 1748ce1f67
5 changed files with 75 additions and 8 deletions

View File

@ -9,7 +9,7 @@ from .analyzer.locomotion import LocomotionActionAnalyzer, CacheSequenceAnalyzer
from .analyzer.mask import MaskSpatials
from .render import Render
from .render.biogames import SimulationRoundsRender, BoardDurationHistRender, BoardDurationBoxRender, \
ActivityMapperRender, StoreRender, SimulationOrderRender
ActivityMapperRender, StoreRender, SimulationOrderRender, SimulationGroupRender
from .render.default import PrintRender, JSONRender, TrackRender, HeatMapRender
from .render.locomotion import LocomotionActionRelativeRender, LocomotionActionAbsoluteRender, \
LocomotionActionRatioRender
@ -49,7 +49,8 @@ __MAPPING__ = {
],
SimulationOrderAnalyzer: [
JSONRender,
SimulationOrderRender
#SimulationOrderRender,
SimulationGroupRender
]
}

View File

@ -4,22 +4,73 @@ from typing import List, Tuple
import matplotlib.pyplot as plt
import os
import numpy as np
from scipy.interpolate import interp1d
import networkx as nx
import itertools
from analyzers import Store, BiogamesStore, SimulationOrderAnalyzer
from . import Render
from .. import Result, SimulationRoundsAnalyzer, BoardDurationAnalyzer, ActivityMapper
def add_edge(graph, src, dest):
if graph.has_edge(src, dest):
weight = graph.get_edge_data(src, dest)['weight'] + 1
else:
weight = 1
graph.add_edge(tuple(src),tuple(dest),weight=weight)
def pairs(iterable):
a,b = itertools.tee(iterable)
next(b,None)
return zip(a,b)
def plot(src_data: List[Tuple[str, List[int]]], ylabel="simulation rounds", title="simulation retries",
rotation='vertical'):
names, datas = list(zip(*src_data))
plt.boxplot(datas, labels=names)
#plt.boxplot(datas, labels=names, showfliers=False, showmeans=True, meanline=True)
rand = np.random.rand(len(datas),len(datas[0]))
plt.plot(datas+rand, linewidth=.2)
plt.xticks(rotation=rotation)
# plt.margins()
plt.ylabel(ylabel)
plt.title(title)
plt.show()
def graph_plot(src_data: List[Tuple[str, List[int]]], ylabel="simulation rounds", title="sequential simulation retries",
rotation='vertical'):
g = nx.Graph()
for group in src_data:
for i in pairs(enumerate(group)):
add_edge(g, i[0], i[1])
positions = {}
for node in g.nodes():
positions[node] = node
widths = [x[2]/10.0 for x in g.edges.data('weight')]
print(max(widths))
nx.draw_networkx_edges(g, positions, width=widths)
#rand = np.random.rand(len(datas),len(datas[0]))
#plt.plot(datas+rand, linewidth=.2)
plt.xticks(rotation=rotation)
# plt.margins()
plt.ylabel(ylabel)
plt.title(title)
plt.show()
def graph_fit(src_data, deg=5):
plt.title("polyfit(x,y,deg="+str(deg)+")")
for i in src_data:
#plt.plot(i)
count = len(i)
xp = np.linspace(0, count-1, num=count, endpoint=True)
#fit = np.poly1d(np.polyfit(range(len(i)), i, deg=deg))
#plt.plot(xp, fit(xp), linewidth=0.1)
xnew = np.linspace(0, count-1, num=count*20, endpoint=True)
f = interp1d(xp, i, kind='quadratic')
plt.plot(range(count), i, '.', markersize=1)
plt.plot(xnew, f(xnew), linewidth=0.2)
plt.show()
class SimulationRoundsRender(Render):
def render(self, results: List[Result]):
@ -101,4 +152,13 @@ class SimulationOrderRender(Render):
#plot(enumerate([r.get() for r in self.filter(results)]))
plot(list(data.items()), ylabel="simulation retries", title="sequential simulation retries", rotation=None)
result_types = [SimulationOrderAnalyzer]
class SimulationGroupRender(Render):
def render(self, results: List[Result]):
data = [r.get() for r in self.filter(results)]
#graph_plot(list(data), ylabel="simulation retries", title="sequential simulation retries", rotation=None)
graph_fit(list(data))
result_types = [SimulationOrderAnalyzer]

View File

@ -68,8 +68,8 @@
"type": "Biogames",
"url": "http://0.0.0.0:5000/game2/instance/log/list/",
"login_url": "http://localhost:5000/game2/auth/json-login",
"username": "dev",
"password": "dev",
"username": "ba",
"password": "853451",
"host":"http://0.0.0.0:5000"
}
}

View File

@ -17,6 +17,7 @@ requests_log.setLevel(logging.WARN)
def process_log(log_id: str, settings: LogSettings) -> List[Analyzer]:
logfile: str = "data/inst_{id}.{format}".format(id=log_id, format=settings.log_format)
logfile = log_id
loader = LOADERS[settings.log_format]()
try:
loader.load(logfile)
@ -54,6 +55,11 @@ if __name__ == '__main__':
# "fe1331481f85560681f86827ec",
"fe1331481f85560681f86827ec"]
#"fec57041458e6cef98652df625", ]
log_ids = []
with open("/home/clemens/git/ma/test/filtered") as src:
for line in src:
line = line.strip()
log_ids.append(line)
store: ResultStore = ResultStore()
for log_id in log_ids:
for analysis in process_log(log_id, settings):

View File

@ -1,11 +1,11 @@
$.getJSON("tmp3.json", function (data) {
var list = $("<ul />");
var maps = {};
$.each(data, function (key, value) {
$.each(data, function (index, entry) {
//key: instance_id, value: AnlysisResult
//value.result.instance: InstanceConfig_id
// console.log(key, value[0].result.store[0].timestamp);
$.each(value[0].result.store, function (index, entry) {
//$.each(value[0].result.store, function (index, entry) {
//console.log(entry);
var time = new Date(entry.timestamp);
var item = $("<li>", {html: entry.sequence + " @ " + time.toLocaleDateString() + " "+ time.toLocaleTimeString()});
@ -44,7 +44,7 @@ $.getJSON("tmp3.json", function (data) {
});
container.appendTo(item);
item.appendTo(list);
});
//});
});
list.appendTo("body");
var slider = $("<input />", {type: "range" })