diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index beb20f7..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "data"] - path = data - url = git@github.com:shogun-toolbox/shogun-data.git - ignore = dirty diff --git a/common/fetch_data.py b/common/fetch_data.py index 23cda14..e4d121c 100644 --- a/common/fetch_data.py +++ b/common/fetch_data.py @@ -3,16 +3,16 @@ import json def get_binary_features(request): try: - class_a_point_set_raw = json.loads(request.POST['mouse_left_click_point_set']) - class_b_point_set_raw = json.loads(request.POST['mouse_right_click_point_set']) + point_set_raw = json.loads(request.POST['point_set']) except: raise ValueError("cannot read click pts") class_a_point_set = [] class_b_point_set = [] - for point in class_a_point_set_raw: - class_a_point_set.append([point['x'], point['y']]) - for point in class_b_point_set_raw: - class_b_point_set.append([point['x'], point['y']]) + for point in point_set_raw: + if point['label'] == 1: + class_a_point_set.append([point['x'], point['y']]) + else: + class_b_point_set.append([point['x'], point['y']]) class_a = np.transpose(np.array(class_a_point_set, dtype=float)) class_b = np.transpose(np.array(class_b_point_set, dtype=float)) diff --git a/data b/data deleted file mode 160000 index 0f47c81..0000000 --- a/data +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f47c817b93664da5845c0dcdb708ffcbdfbf593 diff --git a/data/australian.libsvm.h5 b/data/australian.libsvm.h5 new file mode 100644 index 0000000..c6fe1a0 Binary files /dev/null and b/data/australian.libsvm.h5 differ diff --git a/demo/classification_binary.py b/demo/classification_binary.py index 3c98854..6e344fe 100644 --- a/demo/classification_binary.py +++ b/demo/classification_binary.py @@ -52,7 +52,10 @@ def entrance(request): 'panel_name': 'arguments', 'panel_label': 'Arguments', 'panel_property': arguments - }]} + }, + { + 'panel_name': 'toy_data', + 'panel_label': 'Toy Data'}]} return render_to_response("classification/binary.html", properties, context_instance = RequestContext(request)) @@ -69,8 +72,9 @@ def classify(request): return HttpResponse(json.dumps({"status": e.message})) try: + domain = json.loads(request.POST['axis_domain']) C = float(request.POST["C"]) - x, y, z = classify_svm(sg.LibSVM, features, labels, kernel, C=C) + x, y, z = classify_svm(sg.LibSVM, features, labels, kernel, domain, C=C) except Exception as e: import traceback return HttpResponse(json.dumps({"status": repr(traceback.format_exc())})) @@ -79,13 +83,13 @@ def classify(request): 'domain': [np.min(z), np.max(z)], 'z': z.tolist() })) -def classify_svm(classifier, features, labels, kernel, C=1): +def classify_svm(classifier, features, labels, kernel, domain, C=1): svm = classifier(C, kernel, labels) svm.train(features) size = 100 - x1 = np.linspace(0, 1, size) - y1 = np.linspace(0, 1, size) + x1 = np.linspace(domain['horizontal'][0], domain['horizontal'][1], size) + y1 = np.linspace(domain['vertical'][0], domain['vertical'][1], size) x, y = np.meshgrid(x1, y1) test = sg.RealFeatures(np.array((np.ravel(x), np.ravel(y)))) diff --git a/demo/classification_perceptron.py b/demo/classification_perceptron.py index efb6b85..3cd8f32 100644 --- a/demo/classification_perceptron.py +++ b/demo/classification_perceptron.py @@ -41,7 +41,10 @@ def entrance(request): 'panel_name': 'arguments', 'panel_label': 'Arguments', 'panel_property': arguments - }]} + }, + { + 'panel_name': 'toy_data', + 'panel_label': 'Toy Data'}]} return render_to_response("classification/binary.html", properties, context_instance = RequestContext(request)) diff --git a/demo/clustering.py b/demo/clustering.py index 6933b8c..9d87706 100644 --- a/demo/clustering.py +++ b/demo/clustering.py @@ -28,6 +28,7 @@ def entrance(request): }] properties = { 'title': 'Clustering', 'template': {'type': 'coordinate-2dims', + 'feature': 'binary', 'coordinate_range': {'horizontal': [0, 1], 'vertical': [0, 0.8]}, 'coordinate_system': {'horizontal_axis': {'position': 'bottom', @@ -42,7 +43,10 @@ def entrance(request): 'panel_name': 'arguments', 'panel_label': 'Arguments', 'panel_property': arguments - }]} + }, + { + 'panel_name': 'toy_data', + 'panel_label': 'toy data'}]} return render_to_response("clustering/index.html", properties, context_instance=RequestContext(request)) def cluster(request): @@ -52,40 +56,37 @@ def cluster(request): centers = kmeans.get_cluster_centers() radi = kmeans.get_radiuses() result = {'circle': []} - for i in xrange(arguments[3]): # arguments[3] is k + for i in xrange(arguments[2]): # arguments[3] is k result['circle'].append({'x': centers[0,i], 'y': centers[1,i], 'r': radi[i]}) return HttpResponse(json.dumps(result)) except: + import traceback + print traceback.format_exc() return HttpResponseNotFound() def _read_data(request): k = int(request.POST['number_of_clusters']) if k > 500: raise TypeError - positive = json.loads(request.POST['mouse_left_click_point_set']) - negative = json.loads(request.POST['mouse_right_click_point_set']) + point_set = json.loads(request.POST['point_set']) distance_name = request.POST['distance'] - - if len(positive) == 0 and len(negative) == 0: + + if len(point_set) == 0: raise TypeError - return (positive, negative, distance_name, k) + return (point_set, distance_name, k) -def _train_clustering(positive, negative, distance_name, k): - labels = np.array([1]*len(positive) + [-1]*len(negative), dtype=np.float64) - num_pos = len(positive) - num_neg = len(negative) - features = np.zeros((2, num_pos+num_neg)) - - for i in xrange(num_pos): - features[0, i] = positive[i]['x'] - features[1, i] = positive[i]['y'] - - for i in xrange(num_neg): - features[0, i+num_pos] = negative[i]['x'] - features[1, i+num_pos] = negative[i]['y'] - +def _train_clustering(point_set, distance_name, k): + labels = np.array([0]*len(point_set)) + features = np.zeros((2, len(point_set))) + + print labels + for i in xrange(len(point_set)): + features[0, i] = point_set[i]['x'] + features[1, i] = point_set[i]['y'] + labels[i] = point_set[i]['label'] + lab = sg.BinaryLabels(labels) train = sg.RealFeatures(features) @@ -96,7 +97,7 @@ def _train_clustering(positive, negative, distance_name, k): elif distance_name == "JensenMetric": distance = sg.JensenMetric(train, train) else: - raise TypeError + raise TypeError kmeans = sg.KMeans(k, distance) kmeans.train() diff --git a/demo/gp.py b/demo/gp.py index a6c9b16..264e122 100644 --- a/demo/gp.py +++ b/demo/gp.py @@ -27,14 +27,21 @@ def entrance(request): 'argument_label': 'Kernel Width', 'argument_name': 'sigma', 'argument_default': '2.0'}, + { + 'argument_type': 'decimal', + 'argument_label': 'Noise Level', + 'argument_name': 'noise_level', + 'argument_default': '0.1'}, { 'argument_type': 'button-group', - 'argument_items': [{'button_name': 'TrainGP'}, - {'button_name': 'Clear'}] + 'argument_items': [{'button_name': 'TrainGP', + 'button_type': 'json_up_down_load'}, + {'button_name': 'clear'}] } ] properties = { 'title': 'Gaussian Process Regression Demo', 'template': {'type': 'coordinate-2dims', + 'mouse_click_enabled': 'left', 'coordinate_system': {'horizontal_axis': {'range': [-5, 5]}, 'vertical_axis': {'range': [-5, 5]}}}, 'panels': [ @@ -44,7 +51,7 @@ def entrance(request): 'panel_property': arguments }, { - 'panel_name': 'toy_data_generator', + 'panel_name': 'toy_data', 'panel_label': 'Toy Data' }]} return render_to_response("gp/index.html", properties, context_instance = RequestContext(request)) @@ -62,11 +69,12 @@ def train(request): def _read_toy_data(request): y_set = [] x_set = [] - toy_data = json.loads(request.POST['mouse_left_click_point_set']) + toy_data = json.loads(request.POST['point_set']) for pt in toy_data: y_set.append(float(pt["y"])) x_set.append(float(pt["x"])) noise_level = float(request.POST['noise_level']) + domain = json.loads(request.POST['axis_domain']) labels = np.array(y_set, dtype = np.float64) num = len(x_set) @@ -78,9 +86,9 @@ def _read_toy_data(request): feat_train = sg.RealFeatures(examples) labels = sg.RegressionLabels(labels) kernel = get_kernel(request, feat_train) - return (feat_train, labels, noise_level, kernel) + return (feat_train, labels, noise_level, kernel, domain) -def _process(feat_train, labels, noise_level, kernel): +def _process(feat_train, labels, noise_level, kernel, domain): n_dimensions = 1 likelihood = sg.GaussianLikelihood() @@ -95,7 +103,9 @@ def _process(feat_train, labels, noise_level, kernel): inf = sg.ExactInferenceMethod(SECF, feat_train, zmean, labels, likelihood) # location of unispaced predictions - x_test = np.array([np.linspace(-5, 5, feat_train.get_num_vectors())]) + x_test = np.array([np.linspace(domain['horizontal'][0], + domain['horizontal'][1], + feat_train.get_num_vectors())]) feat_test = sg.RealFeatures(x_test) gp = sg.GaussianProcessRegression(inf) diff --git a/demo/kernel_matrix.py b/demo/kernel_matrix.py index e4aac90..c55ec23 100644 --- a/demo/kernel_matrix.py +++ b/demo/kernel_matrix.py @@ -4,7 +4,7 @@ import modshogun as sg import numpy as np -import scipy as sp +import scipy as spxx import json def entrance(request): @@ -34,10 +34,8 @@ def entrance(request): 'template': {'type': 'coordinate-2dims', 'mouse_click_enabled': 'left', 'heatmap': { 'contour': True }, - 'coordinate_system': {'horizontal_axis': {'range':[-5.0, 5.0], - 'position': 'bottom'}, - 'vertical_axis': {'range':[-4.0, 4.0], - 'position': 'left'}}}, + 'coordinate_system': {'horizontal_axis': {'range':[-5.0, 5.0]}, + 'vertical_axis': {'range':[-4.0, 4.0]}}}, 'panels': [ { 'panel_name': 'arguments', @@ -45,10 +43,9 @@ def entrance(request): 'panel_property': arguments }, { - 'panel_name': 'toy_data_generator', + 'panel_name': 'toy_data', 'panel_label': 'Toy Data' - }, - ] + }]} return render_to_response("kernel_matrix/index.html", properties, context_instance = RequestContext(request)) @@ -59,8 +56,6 @@ def generate(request): arguments = _read_toy_data(request) result = _process(*arguments) except: - import traceback - print traceback.format_exc() raise Http404 return HttpResponse(json.dumps({'status': 'ok', @@ -70,7 +65,7 @@ def generate(request): def _read_toy_data(request): y_set = [] x_set = [] - data = json.loads(request.POST['mouse_left_click_point_set']) + data = json.loads(request.POST['point_set']) for pt in data: y_set.append(float(pt["y"])) x_set.append(float(pt["x"])) @@ -90,7 +85,7 @@ def _process(x1_set, x2_set, kernel_width, kernel_name, degree): feat_train = sg.RealFeatures(examples) # construct covariance function - if kernel_name == "LinearKernel": + if kernelname == "LinearKernel": kernel = sg.LinearKernel(feat_train, feat_train) elif kernel_name == "PolynomialKernel": kernel = sg.PolyKernel(feat_train, feat_train, degree, True) diff --git a/demo/svr.py b/demo/svr.py index f809299..e29b2bc 100644 --- a/demo/svr.py +++ b/demo/svr.py @@ -58,6 +58,10 @@ def entrance(request): 'panel_name': 'arguments', 'panel_label': 'Arguments', 'panel_property': arguments + }, + { + 'panel_name': 'toy_data', + 'panel_label': 'toy data', }]} return render_to_response("svr/index.html", properties, context_instance=RequestContext(request)) @@ -65,11 +69,12 @@ def point(request): try: arguments=_read_data(request) svm=_train_svr(*arguments) - x=np.linspace(0, 1, 100) + domain = json.loads(request.POST['axis_domain']) + x=np.linspace(domain['horizontal'][0], domain['horizontal'][1], 100) y=np.array(svm.apply(sg.RealFeatures(np.array([x]))).get_labels(), dtype=np.float64) line_dot = [] for i in xrange(len(x)): - line_dot.append({'x_value' : x[i], 'y_value' : y[i]}) + line_dot.append({'x' : x[i], 'y' : y[i]}) return HttpResponse(json.dumps(line_dot)) except: raise Http404 @@ -77,7 +82,7 @@ def point(request): def _read_data(request): labels = [] features = [] - data = json.loads(request.POST['mouse_left_click_point_set']) + data = json.loads(request.POST['point_set']) cost = float(request.POST['C']) tubeeps = float(request.POST['tube']) kernel_name = request.POST['kernel'] @@ -92,7 +97,7 @@ def _read_data(request): for i in xrange(num): examples[0,i] = features[i] - + lab = sg.RegressionLabels(labels) train = sg.RealFeatures(examples) kernel = get_kernel(request, train) diff --git a/shogun_demo/settings.py b/shogun_demo/settings.py index ad243d6..2b967d3 100644 --- a/shogun_demo/settings.py +++ b/shogun_demo/settings.py @@ -157,3 +157,7 @@ }, } } + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'toy_data.importer.files', +) diff --git a/shogun_demo/urls.py b/shogun_demo/urls.py index b453faf..97448c9 100644 --- a/shogun_demo/urls.py +++ b/shogun_demo/urls.py @@ -25,10 +25,11 @@ url(r'^gp/entrance', 'demo.gp.entrance'), url(r'^gp/create_toy_data', 'demo.gp.create_toy_data'), url(r'^gp/load_toy_data', 'demo.gp.load_toy_data'), - url(r'^gp/train', 'demo.gp.train'), + url(r'^gp/TrainGP', 'demo.gp.train'), url(r'^kernel_matrix/entrance', 'demo.kernel_matrix.entrance'), url(r'^kernel_matrix/generate', 'demo.kernel_matrix.generate'), url(r'^toy_data/generator/generate', 'toy_data.generator.generate'), + url(r'^toy_data/importer/dump', 'toy_data.importer.dump'), # url(r'^shogun_demo/', include('shogun_demo.foo.urls')), diff --git a/static/js/editors/textfield.js b/static/js/editors/textfield.js deleted file mode 100644 index 70af62b..0000000 --- a/static/js/editors/textfield.js +++ /dev/null @@ -1,30 +0,0 @@ -/*tinyMCE.init({ -mode : "textareas", -theme : "simple" -});*/ - -tinyMCE.init({ - mode : "textareas", - theme : "advanced", - //content_css : "/appmedia/blog/style.css", - theme_advanced_toolbar_location : "top", - theme_advanced_toolbar_align : "left", - theme_advanced_buttons1 : "fullscreen,separator,preview,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,separator,image,cleanup,help,separator,code", - theme_advanced_buttons2 : "", - theme_advanced_buttons3 : "", - theme_advanced_link_targets : "", - auto_cleanup_word : true, - plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,fullscreen", - plugin_insertdate_dateFormat : "%m/%d/%Y", - plugin_insertdate_timeFormat : "%H:%M:%S", - extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],iframe[src|width|height|name|align]", - fullscreen_settings : { - theme_advanced_path_location : "top", - theme_advanced_buttons1 : "fullscreen,separator,preview,separator,cut,copy,paste,separator,undo,redo,separator,search,replace,separator,code,separator,cleanup,separator,bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,help,code", - theme_advanced_buttons2 : "removeformat,styleselect,formatselect,fontselect,fontsizeselect,separator,bullist,numlist,outdent,indent,separator,link,unlink,anchor", - theme_advanced_buttons3 : "sub,sup,separator,image,insertdate,inserttime,separator,tablecontrols,separator,hr,advhr,visualaid,separator,charmap,emotions,iespell,flash,separator,print,code" - }, - width : "550", - height : "400", - verify_html : false -}); diff --git a/templates/button.js b/templates/button.js index 73b09b4..1449518 100644 --- a/templates/button.js +++ b/templates/button.js @@ -6,14 +6,11 @@ {% if button.button_type == 'json_up_down_load' %} function {{ button.button_name }}_action() { - request_data = { + var request_data = { csrfmiddlewaretoken: '{{ csrf_token }}', - {% if template.mouse_click_enabled == 'both' or template.mouse_click_enabled == 'left' %} - mouse_left_click_point_set: JSON.stringify(mouse_left_click_point_set), - {% if template.mouse_click_enabled == 'both' %} - mouse_right_click_point_set: JSON.stringify(mouse_right_click_point_set), - {% endif %} - {% endif %} + point_set: JSON.stringify(point_set), + axis_domain: JSON.stringify({'horizontal': x.domain(), + 'vertical': y.domain()}), {% for panel in panels %} {% if panel.panel_name == 'arguments' %} {% for argument in panel.panel_property %} diff --git a/templates/classification/binary.html b/templates/classification/binary.html index 5c9f94e..e3d843b 100644 --- a/templates/classification/binary.html +++ b/templates/classification/binary.html @@ -13,8 +13,8 @@ var z = data['z']; var domain = data['domain']; - var minimum = domain[0]; - var maximum = domain[1]; + var minimum = Math.floor(domain[0]); + var maximum = Math.ceil(domain[1]); var result = getContour(z, minimum, maximum, domain); var contour = result['contour']; @@ -50,11 +50,13 @@ }); svg.selectAll(".grid .tick.major line") .style("stroke", "grey"); + $('#legend').html("" + Math.floor(domain[0]) + "" + Math.ceil(domain[1]) + "") ; + } function clear_action() { - mouse_left_click_point_set = []; - mouse_right_click_point_set = []; + point_set = []; + point_set = []; svg.selectAll("circle").remove(); svg.selectAll(".heatmap").remove(); svg.selectAll(".grid .tick.major line") diff --git a/templates/clustering/index.html b/templates/clustering/index.html index a1a5354..efeaaa7 100644 --- a/templates/clustering/index.html +++ b/templates/clustering/index.html @@ -9,8 +9,8 @@ .duration(1000) .attr("r", function(d) {return x(0); }) .remove(); - mouse_left_click_point_set = []; - mouse_right_click_point_set = []; + point_set = []; + reset_axis(); } function cluster(data){ svg.selectAll(".line").remove(); @@ -33,17 +33,17 @@ circle.append("line") .attr("class","line") - .attr("x1", function(d) {return x(d.x+0.02);}) - .attr("y1", function(d) {return y(d.y+0.02);}) - .attr("x2", function(d) {return x(d.x-0.02);}) - .attr("y2", function(d) {return y(d.y-0.02);}) + .attr("x1", function(d) {return x(d.x)+5;}) + .attr("y1", function(d) {return y(d.y)+5;}) + .attr("x2", function(d) {return x(d.x)-5;}) + .attr("y2", function(d) {return y(d.y)-5;}) .style("stroke", "gray"); circle.append("line") .attr("class","line") - .attr("x1", function(d) {return x(d.x-0.02);}) - .attr("y1", function(d) {return y(d.y+0.02);}) - .attr("x2", function(d) {return x(d.x+0.02);}) - .attr("y2", function(d) {return y(d.y-0.02);}) + .attr("x1", function(d) {return x(d.x)-5;}) + .attr("y1", function(d) {return y(d.y)+5;}) + .attr("x2", function(d) {return x(d.x)+5;}) + .attr("y2", function(d) {return y(d.y)-5;}) .style("stroke", "gray"); $("#cluster").attr('disabled', false); } diff --git a/templates/coordinate_2dims.js b/templates/coordinate_2dims.js index c019225..3586d1c 100644 --- a/templates/coordinate_2dims.js +++ b/templates/coordinate_2dims.js @@ -4,7 +4,11 @@ var height = 610 - margin.top - margin.bottom; var x = d3.scale.linear().range( [0, width] ); var y = d3.scale.linear().range( [height, 0] ); - +var horizontal_max=1, horizontal_min=0; +var vertical_max=1, vertical_min=0; +var color = d3.scale.linear() + .domain([0,1]) + .range(["blue","red"]); {% if template.coordinate_system.horizontal_axis.range %} x.domain({{ template.coordinate_system.horizontal_axis.range }}).nice(); @@ -14,18 +18,14 @@ x.domain([0, 1]); {% if template.coordinate_system.vertical_axis.range %} y.domain({{ template.coordinate_system.vertical_axis.range }}).nice(); {% else %} -y.domain([0,0.8]); +y.domain([0, 1]); {% endif %} var xAxis = d3.svg.axis().scale(x).orient("bottom"); var yAxis = d3.svg.axis().scale(y).orient("left"); -function make_x_axis(){ - return d3.svg.axis().scale(x).orient("bottom").ticks(10); -} -function make_y_axis(){ - return d3.svg.axis().scale(y).orient("left").ticks(8); -} +var xGrid = d3.svg.axis().scale(x).orient("bottom"); +var yGrid = d3.svg.axis().scale(y).orient("left"); var canvas_div = d3.select(".span9").append("svg") .attr("width", width + margin.left + margin.right) @@ -36,28 +36,24 @@ var svg = canvas_div.append("g") svg.append("g") .attr("class", "grid") + .attr("id", "x_grid") .attr("transform", "translate(0, " + height + ")") - .call(make_x_axis() + .call(xGrid .tickSize(-height, 0, 0) .tickFormat("") ); svg.append("g") .attr("class", "grid") - .call(make_y_axis() + .attr("id", "y_grid") + .call(yGrid .tickSize(-width, 0, 0) .tickFormat("") ); svg.append("g") .attr("class", "axis") -{% if template.coordinate_system.horizontal_axis.position == 'bottom' %} + .attr("id", "x_axis") .attr("transform", "translate(0," + height + ")") -{% elif template.coordinate_system.horizontal_axis.position == 'top' %} - .attr("transform", "translate(0," + 0 + ")") -{% else %} - .attr("transform", "translate(0," + height/2 + ")") -{% endif %} - .call(xAxis) .append("text") .attr("class", "label") @@ -68,12 +64,7 @@ svg.append("g") svg.append("g") .attr("class", "axis") -{% if template.coordinate_system.vertical_axis.position == 'left' %} -{% elif template.coordinate_system.vertical_axis.position == 'right' %} - .attr("transform", "translate(" + width + ")") -{% else %} - .attr("transform", "translate(" + width/2 + ")") -{% endif %} + .attr("id", "y_axis") .call(yAxis) .append("text") .attr("class", "label") @@ -83,10 +74,31 @@ svg.append("g") .style("text-anchor", "end") .text("{{ template.coordinate_system.vertical_axis.label }}"); +function reset_axis(){ + horizontal_max = vertical_max = 1; + horizontal_min = vertical_min = 0; + x.domain([horizontal_min, horizontal_max]); + y.domain([vertical_min, vertical_max]); + var t = svg.transition().duration(750); + t.select("#x_axis").call(xAxis); + t.select("#y_axis").call(yAxis); + t.select("#x_grid").call(xGrid); + t.select("#y_grid").call(yGrid); +} + +var area_end = d3.svg.area() + .x(function(d) { return x(d.x);}) + .y0(function(d) { return y(d.range_lower);}) + .y1(function(d) { return y(d.range_upper);}); +var end = d3.svg.line() + .x(function (d) { return x(d.x); }) + .y(function (d) { return y(d.y); }) + .interpolate('basis'); +var start = d3.svg.line() + .x(function (d) {return x(d.x); }) + .y(function (d) {return y(0); }) + .interpolate('basis'); {% if template.heatmap %} -var color = d3.scale.linear() - .domain([0,1]) - .range(["blue","red"]); var heatmap_legend = document.createElement("div"); $('.span9').append(heatmap_legend); heatmap_legend.id = "legend"; diff --git a/templates/default.html b/templates/default.html index dd1c815..e860ec4 100644 --- a/templates/default.html +++ b/templates/default.html @@ -26,7 +26,7 @@
{% for panel in panels %}
- {% if panel.panel_name == 'toy_data_generator' %} + {% if panel.panel_name == 'toy_data' %} {% include "toy_data_generator_form.html" %} {% elif panel.panel_name == 'arguments' %} {% include "arguments_form.html" %} diff --git a/templates/gp/index.html b/templates/gp/index.html index a85e48b..b0e33eb 100644 --- a/templates/gp/index.html +++ b/templates/gp/index.html @@ -1,79 +1,37 @@ {% extends "default.html" %} {% block javascript %} {% endblock %} diff --git a/templates/heatmap.js b/templates/heatmap.js index c5ecd1f..7fc9f38 100644 --- a/templates/heatmap.js +++ b/templates/heatmap.js @@ -14,7 +14,7 @@ function getContour(z, minimum, maximum, dom) { var zs = d3.range(minimum, maximum, 0.1); var x = d3.scale.linear().range([0, width]).domain([1, z.length-2]); var y = d3.scale.linear().range([height, 0]).domain([1, z[0].length-2]); - var colour_scale = d3.scale.linear().domain(dom).range(["white, white"]); + var colour_scale = d3.scale.linear().domain(dom).range(["blue", "red"]); c.contour(z, 0, xs.length-1, 0, ys.length-1, xs, ys, zs.length, zs); diff --git a/templates/kernel_matrix/index.html b/templates/kernel_matrix/index.html index 4b7a5a6..0c0c679 100644 --- a/templates/kernel_matrix/index.html +++ b/templates/kernel_matrix/index.html @@ -22,26 +22,22 @@ var minimum = domain[0]; var maximum = domain[1]; - var result = getContour(z, minimum, maximum, domain); - var contour = result['contour']; - var x_scale = result['x_scale']; - var y_scale = result['y_scale']; - var color_scale = result['color_scale']; - svg.selectAll(".heatmap").remove(); - + + var dx = z[0].length; + var dy = z.length; + var index = 0; + svg.selectAll(".heatmap") - .data(contour.contourList()) + .data(z) .enter() - .append("path") - .style("fill", function(d) {return color_scale(d.level); }) - .style("stroke", "black") - .style("stroke-width", "1") + .append("rect") + .style("fill", function(d) {return color(z); }) .attr("class", "heatmap") - .attr("d", d3.svg.line() - .x(function(d){ return x_scale(d.x); }) - .y(function(d){ return y_scale(d.y); }) - ); + .attr("x", index % dx) + .attr("y", index ++ / dx) + .attr("width",1 ) + .attr("height",1 ); svg.selectAll(".grid") .each(function(d, i) { this.parentNode.appendChild(this); @@ -56,6 +52,7 @@ }); svg.selectAll(".grid .tick.major line") .style("stroke", "grey"); + $('#legend').html("" + Math.round({{ domain[0] }}) + "" + Math.round({{ domain[1] }}) + "") ; } {% endblock %} diff --git a/templates/mouse_click.js b/templates/mouse_click.js index b379d51..840800f 100644 --- a/templates/mouse_click.js +++ b/templates/mouse_click.js @@ -18,7 +18,7 @@ function mouse_move() { (d3.mouse(this)[1]-margin.top) + ")"); } {% if template.mouse_click_enabled == 'left' or template.mouse_click_enabled == 'both' %} -var mouse_left_click_point_set=[]; +var point_set=[]; function mouse_left_click(event) { if (d3.mouse(this)[0]-margin.left < 0 || d3.mouse(this)[1]-margin.top > height) return; @@ -30,17 +30,18 @@ function mouse_left_click(event) { point[1]-=margin.top; svg.append("circle") .attr("class", "dot") - .attr("r", 2.5) + .attr("r", 1.5) {%if template.mouse_click_enabled == 'both' %} .style("fill", "red") {% endif %} .attr("cx", point[0]) .attr("cy", point[1]); - mouse_left_click_point_set.push( {"x": x.invert(point[0]).toFixed(3),"y": y.invert(point[1]).toFixed(3)}); + point_set.push( {"x": x.invert(point[0]).toFixed(3), + "y": y.invert(point[1]).toFixed(3), + "label": +1}); } {% endif %} {% if template.mouse_click_enabled == 'both' %} -var mouse_right_click_point_set=[]; function mouse_right_click() { if (d3.mouse(this)[0]-margin.left < 0 || d3.mouse(this)[1]-margin.top > height) @@ -50,11 +51,13 @@ function mouse_right_click() point[1]-=margin.top; svg.append("circle") .attr("class", "dot") - .attr("r", 2.5) + .attr("r", 1.5) .attr("cx", point[0]) .attr("cy", point[1]) .style("fill", "blue"); - mouse_right_click_point_set.push( {"x": x.invert(point[0]).toFixed(3),"y": y.invert(point[1]).toFixed(3)}); + point_set.push( {"x": x.invert(point[0]).toFixed(3), + "y": y.invert(point[1]).toFixed(3), + "label": -1}); } d3.select("svg").node().oncontextmenu = function(){return false;}; //disable right click menu {% endif %} diff --git a/templates/svr/index.html b/templates/svr/index.html index 86b2165..d5b0fe5 100644 --- a/templates/svr/index.html +++ b/templates/svr/index.html @@ -6,22 +6,23 @@ svg.selectAll(".line") .remove(); svg.selectAll(".dot").remove(); - mouse_left_click_point_set = []; + point_set = []; + reset_axis(); } var line = d3.svg.line() - .x(function (d) { return x(d.x_value); }) - .y(function (d) { return y(d.y_value); }) + .x(function (d) { return x(d.x); }) + .y(function (d) { return y(d.y); }) .interpolate('basis'); var start = d3.svg.line() - .x(function (d) {return x(d.x_value); }) + .x(function (d) {return x(d.x); }) .y(function (d) {return y(0); }) .interpolate('basis'); function regress(data){ var json = $.parseJSON(data); json.forEach(function(d) { - d.x_value = +d.x_value; - d.y_value = +d.y_value; + d.x = +d.x; + d.y = +d.y; }); if (svg.selectAll(".line")[0].length == 0) curve = svg.append("path") diff --git a/templates/toy_data_generator_form.html b/templates/toy_data_generator_form.html index f3ce574..c22f0ef 100644 --- a/templates/toy_data_generator_form.html +++ b/templates/toy_data_generator_form.html @@ -1,5 +1,6 @@
+ Generator
@@ -9,6 +10,22 @@
+
+
+ Importer + + + + + + + +
+
diff --git a/toy_data/generator.py b/toy_data/generator.py index 028abd4..f4a229e 100644 --- a/toy_data/generator.py +++ b/toy_data/generator.py @@ -27,6 +27,7 @@ def generate(request): toy_data = [] for i in xrange(len(x)): - toy_data.append( { 'x': x[i], 'y': y[i]}) - + toy_data.append( { 'x': x[i], + 'y': y[i], + 'label': '1'}) return HttpResponse(json.dumps(toy_data)) diff --git a/toy_data/importer.py b/toy_data/importer.py new file mode 100644 index 0000000..7c7ab89 --- /dev/null +++ b/toy_data/importer.py @@ -0,0 +1,30 @@ +from django.http import HttpResponse, Http404 +from django.conf import settings +import h5py, json + +TOY_DATA_DIR = 'data/' +TOY_DATA_SET = { + 'australian': 'australian.libsvm.h5', +} + +def files(request): + return {'data_sets': TOY_DATA_SET.keys} + +def dump(request): + try: + data_set = request.POST['data_set'] + feature1 = int(request.POST['feature1']) + feature2 = int(request.POST['feature2']) + f = h5py.File(TOY_DATA_DIR + + TOY_DATA_SET[data_set], 'r') + features = f["/data/data"] + label = f["/data/label"] + except: + raise Http404 + + toy_data = [] + for i in xrange(len(features[0])): + toy_data.append( {'x': features[feature1][i], + 'y': features[feature2][i], + 'label': label[i][0]}) + return HttpResponse(json.dumps(toy_data))