public String toCSV() { if (dataset == null) { return ""; } String out = "Experiment name: " + this.context.getExpContext().getExperimentName() + "\nRaw data dir: " + this.context.getExpContext().getRawDir() + "\n" + region + "\n"; int nr = dataset.getSeriesCount(); for (int s = 0; s < nr; s++) { out += dataset.getSeriesKey(s); if (s + 1 < nr) { out += ", "; } else { out += "\n"; } } if (nr > 0) { for (int f = 0; f < dataset.getItemCount(0); f++) { double x = dataset.getXValue(0, f); out += x + ","; for (int s = 0; s < nr; s++) { if (s < dataset.getSeriesCount() && f < dataset.getItemCount(s)) { out += dataset.getY(s, f); if (s + 1 < nr) { out += ", "; } else { out += "\n"; } } else out += "\n"; } } } return out; }
// See McClelland 1991 for details. // given two phonemes and some parameters, returns which of the two phonemes is most active // according to the rule. // result is of the form: model_input phon1 win/lose phon2 win/lose // winner=1, loser=0. public String runningAverageMetricReport( String phon1, String phon2, String input, double lambda, double init, String[] labels) { int p1_idx = -1, p2_idx = -1; for (int i = 0; i < labels.length; i++) { if (labels[i].equals(phon1)) p1_idx = i; if (labels[i].equals(phon2)) p2_idx = i; } // case: one or both of the phonemes was not found in the array of labels. if (p1_idx == -1 || p2_idx == -1) return ""; double p1_val = init, p2_val = init; int length = Math.min(data.getItemCount(p1_idx), data.getItemCount(p2_idx)); for (int i = 0; i < length; i++) { p1_val = (lambda * data.getY(p1_idx, i).doubleValue()) + ((1 - lambda) * p1_val); p2_val = (lambda * data.getY(p2_idx, i).doubleValue()) + ((1 - lambda) * p2_val); } String result = input + "\t"; result += phon1 + "\t"; if (p1_val > p2_val) result += "1\t"; else result += "0\t"; result += phon2 + "\t"; if (p2_val > p1_val) result += "1\t"; else result += "0\t"; return result; }