use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.
the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.
/**
* Method loadDataSet_TabDelim
*/
private void loadTimeSeriesDataSet() {
// select a file to load using the file chooser
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(this.editor);
// get the file
File file = chooser.getSelectedFile();
Preferences.userRoot().put("fileSaveLocation", file.getParent());
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
StringTokenizer st;
// read in variable name and set up DataSet.
List<Node> variables = new LinkedList<>();
st = new StringTokenizer(in.readLine());
while (st.hasMoreTokens()) {
String name = st.nextToken();
ContinuousVariable var = new ContinuousVariable(name);
variables.add(var);
}
DataSet dataSet = new ColtDataSet(0, variables);
int row = -1;
while ((line = in.readLine()) != null) {
int col = -1;
st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String literal = st.nextToken();
if (literal.length() == 0) {
continue;
}
dataSet.setObject(row, ++col, literal);
}
}
TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
editor.getDataWrapper().setDataModel(dataSet3);
firePropertyChange("modelChanged", null, null);
editor.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.
the class ScatterPlot method getRegressionResult.
private RegressionResult getRegressionResult() {
List<Node> regressors = new ArrayList<>();
regressors.add(dataSet.getVariable(x));
Node target = dataSet.getVariable(y);
Regression regression = new RegressionDataset(dataSet);
RegressionResult result = regression.regress(target, regressors);
System.out.println(result);
return result;
}
use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.
the class ScatterPlot method removeConditioningVariable.
/**
* Removes a conditioning variable.
*
* @param variable The name of the conditioning variable to remove.
*/
public void removeConditioningVariable(String variable) {
Node node = dataSet.getVariable(variable);
if (!(continuousIntervals.containsKey(node))) {
throw new IllegalArgumentException("Not a conditioning node: " + variable);
}
continuousIntervals.remove(node);
}
use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.
the class PcSearchParamEditor method setup.
public void setup() {
/*
The variable names from the object being searched over (usually data).
*/
List<String> varNames = (List<String>) params.get("varNames", null);
DataModel dataModel1 = null;
Graph graph = null;
for (Object parentModel1 : this.parentModels) {
if (parentModel1 instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel1;
dataModel1 = dataWrapper.getSelectedDataModel();
}
if (parentModel1 instanceof GraphWrapper) {
GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
graph = graphWrapper.getGraph();
}
if (parentModel1 instanceof DagWrapper) {
DagWrapper dagWrapper = (DagWrapper) parentModel1;
graph = dagWrapper.getDag();
}
if (parentModel1 instanceof SemGraphWrapper) {
SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
graph = semGraphWrapper.getGraph();
}
}
if (dataModel1 != null) {
varNames = new ArrayList<>(dataModel1.getVariableNames());
} else if (graph != null) {
Iterator<Node> it = graph.getNodes().iterator();
varNames = new ArrayList();
Node temp;
while (it.hasNext()) {
temp = it.next();
if (temp.getNodeType() == NodeType.MEASURED) {
varNames.add(temp.getName());
}
}
} else {
throw new NullPointerException("Null model (no graph or data model " + "passed to the search).");
}
this.params.set("varNames", varNames);
IntTextField depthField = new IntTextField(this.params.getInt("depth", -1), 4);
depthField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
PcSearchParamEditor.this.params.set("depth", value);
Preferences.userRoot().putInt("depth", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
double alpha = params.getDouble("alpha", 0.001);
if (!Double.isNaN(alpha)) {
alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
PcSearchParamEditor.this.params.set("alpha", 0.001);
Preferences.userRoot().putDouble("alpha", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
}
setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
if (!Double.isNaN(alpha)) {
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Alpha Value:"));
b2.add(Box.createGlue());
b2.add(alphaField);
add(b2);
add(Box.createVerticalStrut(10));
}
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Search Depth:"));
b3.add(Box.createGlue());
b3.add(depthField);
add(b3);
add(Box.createVerticalStrut(10));
}
use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.
the class ScoredGraphsDisplay method pasteSubsession.
public void pasteSubsession(List sessionElements, Point upperLeft) {
getWorkbench().pasteSubgraph(sessionElements, upperLeft);
getWorkbench().deselectAll();
for (int i = 0; i < sessionElements.size(); i++) {
Object o = sessionElements.get(i);
if (o instanceof GraphNode) {
Node modelNode = (Node) o;
getWorkbench().selectNode(modelNode);
}
}
getWorkbench().selectConnectingEdges();
}
Aggregations