Skip to content

Commit

Permalink
1. fix kernel_matrix in new style. 2. fix the curve animation in gp d…
Browse files Browse the repository at this point in the history
…emo.
  • Loading branch information
foulwall committed Jul 9, 2013
1 parent ea70146 commit a3a4c81
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
6 changes: 4 additions & 2 deletions demo/kernel_matrix.py
Expand Up @@ -28,7 +28,7 @@ def entrance(request):
'argument_type': 'button-group',
'argument_items': [{'button_name': 'generate',
'button_type': 'json_up_down_load'},
{'button_name': 'Clear'}]},
{'button_name': 'clear'}]},
]
properties = { 'title': 'Kernel Matrix Visualization',
'template': {'type': 'coordinate-2dims',
Expand Down Expand Up @@ -56,6 +56,8 @@ 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',
Expand Down Expand Up @@ -85,7 +87,7 @@ def _process(x1_set, x2_set, kernel_width, kernel_name, degree):
feat_train = sg.RealFeatures(examples)

# construct covariance function
if kernelname == "LinearKernel":
if kernel_name == "LinearKernel":
kernel = sg.LinearKernel(feat_train, feat_train)
elif kernel_name == "PolynomialKernel":
kernel = sg.PolyKernel(feat_train, feat_train, degree, True)
Expand Down
21 changes: 13 additions & 8 deletions templates/gp/index.html
Expand Up @@ -15,15 +15,20 @@
{
json = $.parseJSON(data);
if (svg.selectAll(".line")[0].length == 0)
{
svg.append("path")
.attr("class", "line")
.attr("d", start(json))
.style("stroke-width", "2")
.style("stroke", "green")
.style("fill", "none");
svg.selectAll(".line")
.transition().duration(1000)
.attr("d", end(json));
.attr("class", "line")
.attr("d", start(json))
.style("stroke-width", "2")
.style("stroke", "green")
.style("fill", "none");
svg.selectAll(".line")
.transition().duration(1000)
.attr("d", end(json));
}else{
svg.selectAll(".line")
.attr("d", end(json));
}
svg.selectAll(".area")
.remove();
svg.append("path")
Expand Down
28 changes: 17 additions & 11 deletions templates/kernel_matrix/index.html
@@ -1,7 +1,7 @@
{% extends "default.html" %}
{% block javascript %}
<script>
function Clear_action()
function clear_action()
{
svg.selectAll(".dot").remove();
$("#heatmap").remove();
Expand All @@ -27,17 +27,23 @@
var dx = z[0].length;
var dy = z.length;
var index = 0;


color.domain([0, 1]);
x.domain([0, dx]);
y.domain([dy, 0]);

svg.selectAll(".heatmap")
.data(z)
.data(z).enter()
.append('g')
.selectAll('.box')
.data(Object)
.enter()
.append("rect")
.style("fill", function(d) {return color(z); })
.attr("class", "heatmap")
.attr("x", index % dx)
.attr("y", index ++ / dx)
.attr("width",1 )
.attr("height",1 );
.append('rect')
.attr("fill", function(d) { return color(d);})
.attr("x", function(d,i,j){ return x(i);})
.attr("y", function(d,i,j){ return y(j);})
.attr("width", width/dx)
.attr("height", height/dy);
svg.selectAll(".grid")
.each(function(d, i) {
this.parentNode.appendChild(this);
Expand All @@ -52,7 +58,7 @@
});
svg.selectAll(".grid .tick.major line")
.style("stroke", "grey");
$('#legend').html("<span id='lower' style='float:left; color:white;'>" + Math.round({{ domain[0] }}) + "</span><span id='upper' style='float:right; color:white;'>" + Math.round({{ domain[1] }}) + "</span>") ;
$('#legend').html("<span id='lower' style='float:left; color:white;'>" + Math.round(domain[0]) + "</span><span id='upper' style='float:right; color:white;'>" + Math.round(domain[1]) + "</span>") ;
}
</script>
{% endblock %}

0 comments on commit a3a4c81

Please sign in to comment.