[ifcsoft] 4 new revisions pushed by kyle.tha...@gmail.com on 2011-05-24 19:19 GMT

0 views
Skip to first unread message

ifc...@googlecode.com

unread,
May 24, 2011, 3:20:35 PM5/24/11
to ifcsoft--a...@googlegroups.com
4 new revisions:

Revision: 28bbca93961e
Author: kthayer
Date: Tue May 17 09:37:34 2011
Log: Set default SOM cluster selection tolerance to 0
http://code.google.com/p/ifcsoft/source/detail?r=28bbca93961e

Revision: b51d04204f82
Author: kthayer
Date: Thu May 19 13:48:26 2011
Log: For loading CSV files, basic handling of quoted string values
with an ...
http://code.google.com/p/ifcsoft/source/detail?r=b51d04204f82

Revision: 45cdbcc2d695
Author: kthayer
Date: Mon May 23 15:32:41 2011
Log: In loading CSV file, fixed a bug where a value in quotes with no
inter...
http://code.google.com/p/ifcsoft/source/detail?r=45cdbcc2d695

Revision: 92104e7f9d1e
Author: kthayer
Date: Tue May 24 12:18:54 2011
Log: Added option to export SOM and hit histograms (useful for other
automa...
http://code.google.com/p/ifcsoft/source/detail?r=92104e7f9d1e

==============================================================================
Revision: 28bbca93961e
Author: kthayer
Date: Tue May 17 09:37:34 2011
Log: Set default SOM cluster selection tolerance to 0
http://code.google.com/p/ifcsoft/source/detail?r=28bbca93961e

Modified:
/src/ifcSoft/view/som/SOMcluster.fx

=======================================
--- /src/ifcSoft/view/som/SOMcluster.fx Fri Feb 11 10:49:36 2011
+++ /src/ifcSoft/view/som/SOMcluster.fx Tue May 17 09:37:34 2011
@@ -58,7 +58,7 @@
min:0
max:.5
vertical: false
- value: .05
+ value: 0
width: 150
visibleAmount: .1
blockIncrement:.05

==============================================================================
Revision: b51d04204f82
Author: kthayer
Date: Thu May 19 13:48:26 2011
Log: For loading CSV files, basic handling of quoted string values
with an internal comma (eg. "(0,0)", "(1,0)",etc.)
http://code.google.com/p/ifcsoft/source/detail?r=b51d04204f82

Modified:
/src/ifcSoft/model/dataSet/RawData.java

=======================================
--- /src/ifcSoft/model/dataSet/RawData.java Wed Apr 20 08:26:49 2011
+++ /src/ifcSoft/model/dataSet/RawData.java Thu May 19 13:48:26 2011
@@ -383,6 +383,7 @@
}
columnLabels = temp;
}
+ columnLabels = fixQuotes(columnLabels);
}else{//the column labels have been read
float[] thisrow = new float[columnLabels.length];
boolean didLoadRow = true;
@@ -501,6 +502,38 @@
}
System.out.println("length after seg "+ data.size()+": "+ length);
}
+
+ /**
+ * In a csv file, column labels may have a comma in them and be
surrounded by quotes.
+ * eg. name, "(0,0)", "(0,1)", etc.
+ * This should deal with it in most cases, though I'm not sure what the
rule is when
+ * you have more complicated labels with quotes and commas next to each
other
+ * @param columnLabels
+ * @return
+ */
+ private String[] fixQuotes(String[] columnLabels) {
+ LinkedList<String> newLabels = new LinkedList<String>();
+ String currentString = null;
+ for(int i = 0; i < columnLabels.length; i++){
+ if(currentString == null){
+ if(columnLabels[i].startsWith("\"")){ //start of a special case
+ currentString = columnLabels[i];
+ }else{ //normal string value
+ newLabels.add(columnLabels[i]);
+ }
+ }else{ //we are trying to find the end of the string value (ends
with ")
+ if(columnLabels[i].endsWith("\"")){ //end of the string value
+ currentString+= ","+columnLabels[i];
+ newLabels.add(currentString);
+ currentString = null;
+ }else{ //continuing the middle
+ currentString+= ","+columnLabels[i];
+ }
+ }
+ }
+
+ return (String[]) newLabels.toArray(new String[0]);
+ }


==============================================================================
Revision: 45cdbcc2d695
Author: kthayer
Date: Mon May 23 15:32:41 2011
Log: In loading CSV file, fixed a bug where a value in quotes with no
internal comma loaded improperly.
http://code.google.com/p/ifcsoft/source/detail?r=45cdbcc2d695

Modified:
/src/ifcSoft/model/dataSet/RawData.java

=======================================
--- /src/ifcSoft/model/dataSet/RawData.java Thu May 19 13:48:26 2011
+++ /src/ifcSoft/model/dataSet/RawData.java Mon May 23 15:32:41 2011
@@ -518,6 +518,10 @@
if(currentString == null){
if(columnLabels[i].startsWith("\"")){ //start of a special case
currentString = columnLabels[i];
+ if(columnLabels[i].endsWith("\"")){ //if it also ends with a "
+ newLabels.add(currentString);
+ currentString = null;
+ }
}else{ //normal string value
newLabels.add(columnLabels[i]);
}

==============================================================================
Revision: 92104e7f9d1e
Author: kthayer
Date: Tue May 24 12:18:54 2011
Log: Added option to export SOM and hit histograms (useful for other
automatic clustering methods).
http://code.google.com/p/ifcsoft/source/detail?r=92104e7f9d1e

Added:
/src/ifcSoft/view/som/ExportSOMAndHit.fx
Modified:
/src/ifcSoft/MainApp.fx
/src/ifcSoft/view/som/SOMMediator.java
/src/ifcSoft/view/som/SOMmaps.fx

=======================================
--- /dev/null
+++ /src/ifcSoft/view/som/ExportSOMAndHit.fx Tue May 24 12:18:54 2011
@@ -0,0 +1,172 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package ifcSoft.view.som;
+
+import ifcSoft.MainApp;
+import ifcSoft.view.dialogBox.ifcDialogBox;
+import ifcSoft.view.dialogBox.ifcDialogDirectorySelect;
+import ifcSoft.view.dialogBox.ifcDialogStringInput;
+import ifcSoft.view.dialogBox.ifcDialogCheckBox;
+import ifcSoft.view.dialogBox.ifcDialogIntInput;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import ifcSoft.ApplicationFacade;
+import java.awt.Point;
+
+/**
+ * @author kthayer
+ */
+
+public class ExportSOMAndHit {
+ public-init var app:MainApp;
+ public-init var mediator:SOMMediator;
+ postinit{
+ if(app == null or mediator == null){
+ println("SaveClusterDialog initializer: not initialized fully");
+ }else{
+ initialize();
+ }
+ }
+
+ var exportSOMDialog:ifcDialogBox;
+ var exportSOMDirSelect:ifcDialogDirectorySelect;
+ var fileNameInput:ifcDialogStringInput;
+ var includeHitHistogramInput:ifcDialogCheckBox;
+ var blurrTimesInput:ifcDialogIntInput;
+
+ public function initialize(){
+
+
+ exportSOMDialog = ifcDialogBox{
+ name: "Export SOM and Hit Histogram"
+ okAction: exportSOMOK
+ content: [
+ //string input name
+ fileNameInput = ifcDialogStringInput{
+ name:"File name"
+ }
+
+ exportSOMDirSelect = ifcDialogDirectorySelect{
+ mainApp:app
+ initialDirectory: app.lastFilePath
+ }
+ includeHitHistogramInput = ifcDialogCheckBox{
+ name: "Output Hit Histogram"
+ initialCheck: false
+ }
+ blurrTimesInput = ifcDialogIntInput{
+ name: "Blur passes on hit histograms"
+ initialInt: 0
+ }
+
+ ]
+ cancelAction: function():Void{app.removeDialog(exportSOMDialog);
app.unblockContent();}
+
+ blocksMouse: true
+ };
+
+ app.addDialog(exportSOMDialog);
+ app.blockContent();
+ }
+
+ function exportSOMOK():Void{
+ //TODO: if file already exists, ask permission to overwrite
+
+ var name:String = fileNameInput.getInput();
+ if(name == null or name.length() == 0){
+ app.alert("Error: Filename blank");
+ return;
+ }
+
+
+ var filepath:String = exportSOMDirSelect.getInput();
+ if(filepath == null){
+ app.alert("Error: No directory Selected");
+ return;
+ }
+
+ if(not name.endsWith(".csv"))
+ name+= ".csv";
+
+
+ if(not filepath.endsWith("/"))
+ filepath+= "/";
+ var selectedFile:String = "{filepath}{name}.csv";
+
+
+ var hitHistograms:Object[] = []; //multi-dimensional arrays are hard
in javaFX,
+ //I cast the 2d arrays to objects for
convenience
+ if(includeHitHistogramInput.getInput()){ //get the density maps
+ for(i in [0..mediator.SOMp.getRawSetNames().size() - 1]){
+ insert mediator.getDenseBlurred(i,blurrTimesInput.getInput()) as
Object into hitHistograms;
+ }
+ }
+
+ var bw:BufferedWriter;
+ try {
+ bw = new BufferedWriter(new FileWriter(selectedFile));
+ //write width and height
+ bw.write("Width,{mediator.SOMwidth()}");
+ bw.newLine();
+ bw.write("Height,{mediator.SOMheight()}");
+ bw.newLine();
+
+ //Column headings
+ //x, y, Dim1, Dim2, ... ,Hit Hist1, Hit Hist2, ...
+ bw.write("x,y");
+ for(dimName in mediator.getColNames()){
+ bw.write(",{dimName}");
+ }
+ if(includeHitHistogramInput.getInput()){
+ for(hitHistName in mediator.SOMp.getRawSetNames()){
+ bw.write(",{hitHistName}");
+ }
+ }
+ bw.newLine();
+
+ //now do each node
+
+ for(x in [0..mediator.SOMwidth()-1]){
+ for(y in [0..mediator.SOMheight()-1]){
+ bw.write("{x},{y}");
+ for(i in [0..mediator.getColNames().length-1]){
+ bw.write(",{mediator.SOMp.getCellVals(new Point(x, y))[i]}");
+ }
+ if(includeHitHistogramInput.getInput()){
+ for(i in [0..mediator.SOMp.getRawSetNames().size()-1]){
+ var thisHitHist:nativearray of nativearray of Float =
hitHistograms[i] as (nativearray of nativearray of Float);
+ bw.write(",{thisHitHist[x][y]}");
+ }
+ }
+
+ bw.newLine();
+ }
+ }
+
+
+
+ bw.close();
+
+ } catch (ex:IOException) {
+ app.facade.sendNotification(ApplicationFacade.EXCEPTIONALERT, ex,
null);
+ return;
+ }
+
+ app.removeDialog(exportSOMDialog);
+ app.unblockContent();
+ }
+
+
+ function blurHitHist(hitHistsIn:Object[], blurNum:Integer): Object[] {
+ var hitHists:(nativearray of nativearray of Integer)[] = hitHistsIn as
(nativearray of nativearray of Integer)[];
+
+
+ return null;
+
+ }
+
+}
=======================================
--- /src/ifcSoft/MainApp.fx Tue Apr 19 14:14:33 2011
+++ /src/ifcSoft/MainApp.fx Tue May 24 12:18:54 2011
@@ -96,7 +96,7 @@
*/
public class MainApp extends MainAppI {

- var facade:ApplicationFacade;
+ public-read var facade:ApplicationFacade;
public var mainMediator:MainMediator;

public var scene:Scene;
=======================================
--- /src/ifcSoft/view/som/SOMMediator.java Wed Apr 20 08:26:49 2011
+++ /src/ifcSoft/view/som/SOMMediator.java Tue May 24 12:18:54 2011
@@ -30,6 +30,7 @@
import ifcSoft.model.dataSet.dataSetScalar.LogScaleNormalized;
import ifcSoft.model.dataSet.summaryData.SummaryData;
import ifcSoft.model.dataSet.summaryData.SummaryDataPoint;
+import ifcSoft.model.som.SOMHelperFns;
import ifcSoft.model.som.SOMProxy;
import ifcSoft.model.som.SOMSettings;
import ifcSoft.view.MainMediator;
@@ -793,6 +794,57 @@
return
SOMp.getSubsetDenseMap(setNum)[cellMouseOver.x][cellMouseOver.y];
}
}
+
+ /**
+ * Gets the hit histogram for a data set (by frequency rather than hits)
and
+ * blurs it the given number of times.
+ * @param setNum - which data set to get hit hist of
+ * @param blurNum - number of passes of the blurring algorithm
+ * @return
+ */
+ public float[][] getDenseBlurred(int setNum, int blurNum){
+ int[][] hitHist = SOMp.getSubsetDenseMap(setNum);
+ float numPlaced = 0;
+ for(int i = 0; i < hitHist.length; i++){
+ for(int j = 0; j < hitHist[0].length; j++){
+ numPlaced += hitHist[i][j];
+ }
+ }
+
+ float[][] newHitHist = new float[hitHist.length][hitHist[0].length];
+ for(int i = 0; i < newHitHist.length; i++){
+ for(int j = 0; j < newHitHist[0].length; j++){
+ newHitHist[i][j] = hitHist[i][j] / numPlaced;
+ }
+ }
+
+ for(int i = 0; i < blurNum; i++){
+ newHitHist = blurHitHist(newHitHist);
+ }
+ System.out.println("Num placed was"+numPlaced);
+ System.out.println("getDenseBlurred "+setNum+" "+blurNum+" (0,0)
is "+newHitHist[0][0]);
+ return newHitHist;
+ }
+
+ private float[][] blurHitHist(float[][] oldHitHist){
+ float[][] newHitHist = new
float[oldHitHist.length][oldHitHist[0].length];
+ //make each node an average of itself and its neighbors
+ for(int i = 0; i < newHitHist.length; i++){
+ for(int j = 0; j < newHitHist[0].length; j++){
+ //find all neighbors at distance of 1
+ LinkedList<Point> neighborPoints =
SOMHelperFns.neighborsAtDistance(new Point(i, j), 1, SOMp.getData());
+ double sumVal = oldHitHist[i][j];
+ int numToAvg = 1;
+ while(!neighborPoints.isEmpty()){
+ Point p = neighborPoints.removeFirst();
+ sumVal += oldHitHist[p.x][p.y];
+ numToAvg++;
+ }
+ newHitHist[i][j] = (float) sumVal / numToAvg;
+ }
+ }
+ return newHitHist;
+ }

/**
* Get the number of data points of the given dense map in the node the
mouse is over.
=======================================
--- /src/ifcSoft/view/som/SOMmaps.fx Tue Apr 19 14:14:33 2011
+++ /src/ifcSoft/view/som/SOMmaps.fx Tue May 24 12:18:54 2011
@@ -196,13 +196,10 @@
mapTiles,
rightClickMenu = PopupMenu{
items: [
- //MenuItem { text: "Test File Against SOM", action:
function() { mediator.testFileAgainstSOM(); } }
+ MenuItem { text: "Export SOM and Hit Histograms", action:
function() { ExportSOMAndHit{app:app, mediator:mediator };} }
Separator { }
MenuItem { text: "Clustering Options", action: function() {
mediator.clustOpt(); } }
//MenuItem { text: "Save Cluster", action: function() {
SaveClusterDialog{app:app, mediator:mediator }; } //in order for the menu
not to be in the screenshot, must use the other button
- //MenuItem { text: "Save Cluster", action: function() {
mediator.saveCluster(); } }
- //MenuItem { text: "Save Cluster Stats", action:
saveClusterStats }
- //MenuItem { text: "Save Cluster to File", action:
function() {mediator.saveClusterToFile(); } }
Separator { }
removeTileMenuItem = MenuItem { text: "Remove Map Tile",
disable:true }
Menu{

Reply all
Reply to author
Forward
0 new messages