Skip to content

Commit

Permalink
GraphProperties: log scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
falsifian committed Mar 7, 2012
1 parent a7baff3 commit 46a1c74
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/recommend/analysis/GraphProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ void report(String msg) {
appendHtml("<p>" + StringEscapeUtils.escapeHtml(msg) + "</p>\n");
}

void reportPlot(DoubleMatrix1D values) {
void reportPlot(DoubleMatrix1D values, boolean logX, boolean logY) {
appendHtml("<div class=\"plot_me\">");
for (int i = 0; i < values.size(); ++i)
appendHtml(" " + values.get(i));
if (logX) appendHtml("s:logX ");
if (logY) appendHtml("s:logY ");
for (int i = 0; i < values.size(); ++i) {
appendHtml((0 == i ? "" : " ") + i + "," + (values.get(i) + 2.0));
}
appendHtml("</div>\n");
}

Expand All @@ -73,7 +76,7 @@ void dynMain(String[] argv) throws Throwable {

DoubleMatrix1D termFreqs = algebra.mult(termDoc, ones(numDocs));
report("Sorted term frequencies:");
reportPlot(termFreqs.viewSorted());
reportPlot(termFreqs.viewSorted(), false, true);

endReport();
}
Expand Down
44 changes: 40 additions & 4 deletions viz/GraphProperties.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
var GraphProperties = (function(){
main = function() {
var logt = function (x) { return Math.log(x); };
var expt = function (x) { return Math.exp(x); };
var logTicks = function(axis) {
var t;
var res = [];
var logMin = Math.log(axis.min);
var logMax = Math.log(axis.max);
for (t = 0.0; t <= 1.0; t += 0.25) {
res.push(Math.exp(logMin * (1.0 - t) + logMax * t));
}
return res;
}

var main = function() {
var toPlot = $(".plot_me");
toPlot.css("width", "512px");
toPlot.css("height", "256px");
toPlot.each(function (index, div) {
valueStrs = $(div).text().split(" ").filter(function (x) { return 0 != x.length; });
values = valueStrs.map(function (x, index) { return [index, parseFloat(x)]; });
$.plot($(div), [values]);
var pointStrs = $(div).text().split(" ");
var points = [];
var mins = [Infinity, Infinity];
var maxs = [-Infinity, -Infinity];
var logX = false;
var logY = false;
var i;
for (i = 0; i < pointStrs.length; ++i) {
s = pointStrs[i];
if ("s:logX" == s)
logX = true;
else if ("s:logY" == s)
logY = true;
else {
p = s.split(",").map(function (x, i) {
mins[i] = Math.min(mins[i], x);
maxs[i] = Math.max(maxs[i], x);
return parseFloat(x);
});
points.push(p);
}
}
$.plot($(div), [points], {
xaxis: logX ? {transform: logt, inverseTransform: expt, min: mins[0], max: maxs[0], ticks: logTicks} : {},
yaxis: logY ? {transform: logt, inverseTransform: expt, min: mins[1], max: maxs[1], ticks: logTicks} : {}
});
});
}

Expand Down

0 comments on commit 46a1c74

Please sign in to comment.