netkit.classifiers.io
Class PrintEstimateWriter

java.lang.Object
  extended by netkit.classifiers.io.PrintEstimateWriter

public class PrintEstimateWriter
extends java.lang.Object

This class prints label estimates in a user-defined output format. The output format is like a printf statement in c. This format string includes constant information as well as variable information such as value scores and attribute token strings.

The format string is broken up into a list of print segments, where each print segment is one of:

For example, a valid format string could be:
Node %ID is predicted to be %PREDICTLABEL with a score of %PREDICTSCORE. Full estimates are: %ESTIMATE!red %ESTIMATE!blue %ESTIMATE!green
If the label estimates for node 'Ball903' are 0.2 for red, 0.7 for green and 0.1 for blue, then the resulting output string would be (variable segments boldfaced for clarity):
Node Ball903 is predicted to be green with a score of 0.7. Full estimates are: red:0.2 blue:0.1 green:0.7
The default output format (if none are provided) is equivalent to:
%ID %ESTIMATE!class1 ... %ESTIMATE!classK
Where class1 through classK are the possible labels for the class attribute, in the order that they were specified in the schema file or the order in which they were observed in the data

Author:
Sofus A. Macskassy (sofmac@gmail.com)

Constructor Summary
PrintEstimateWriter(java.io.PrintStream ps)
           
PrintEstimateWriter(java.io.PrintStream ps, java.lang.String format)
           
PrintEstimateWriter(java.io.PrintWriter pw)
           
PrintEstimateWriter(java.io.PrintWriter pw, java.lang.String format)
           
 
Method Summary
 java.lang.String getOutputFormat()
           
 void print(Node node, Estimate e)
          Print an estimate of the given node using the given output format and the given current estimates.
 void print(Node node, Estimate e, Classification known)
          Print an estimate of the given node using the given output format and the given current estimates and true labels.
 void println(Node node, Estimate e)
          Print an estimate line of the given node using the given output format and the given current estimates.
 void println(Node node, Estimate e, Classification known)
          Print an estimate line of the given node using the given output format and the given current estimates and true labels.
 void setOutput(java.io.OutputStream os)
          Reset the output to the given outputstream.
 void setOutput(java.io.PrintWriter pw)
          Reset the output to the given printwriter.
 void setOutputFormat(java.lang.String f)
          Reset the output format to the given format string.
 java.lang.String toString(Node node, Estimate e)
          The equivalent of a print, where the output has been set to a string to be returned.
 java.lang.String toString(Node node, Estimate e, Classification known)
          The equivalent of a print, where the output has been set to a string to be returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintEstimateWriter

public PrintEstimateWriter(java.io.PrintWriter pw,
                           java.lang.String format)

PrintEstimateWriter

public PrintEstimateWriter(java.io.PrintWriter pw)

PrintEstimateWriter

public PrintEstimateWriter(java.io.PrintStream ps,
                           java.lang.String format)

PrintEstimateWriter

public PrintEstimateWriter(java.io.PrintStream ps)
Method Detail

setOutput

public void setOutput(java.io.OutputStream os)
Reset the output to the given outputstream.

Parameters:
os - New place to send output

setOutput

public void setOutput(java.io.PrintWriter pw)
Reset the output to the given printwriter.

Parameters:
pw - New place to send output

println

public void println(Node node,
                    Estimate e)
Print an estimate line of the given node using the given output format and the given current estimates.

Parameters:
node - The node whose estimate to print
e - The current estimates
See Also:
print(netkit.graph.Node, netkit.classifiers.Estimate, netkit.classifiers.Classification)

println

public void println(Node node,
                    Estimate e,
                    Classification known)
Print an estimate line of the given node using the given output format and the given current estimates and true labels.

Parameters:
node - The node whose estimate to print
e - The current estimates
known - The true labels
See Also:
print(netkit.graph.Node, netkit.classifiers.Estimate, netkit.classifiers.Classification)

print

public void print(Node node,
                  Estimate e)
Print an estimate of the given node using the given output format and the given current estimates.

Parameters:
node - The node whose estimate to print
e - The current estimates
See Also:
print(netkit.graph.Node, netkit.classifiers.Estimate, netkit.classifiers.Classification)

print

public void print(Node node,
                  Estimate e,
                  Classification known)
Print an estimate of the given node using the given output format and the given current estimates and true labels. This, in effect, loops through all the inferred PrintSegments and calls each of them to output the node estimate in the user-defined output format.

If not output format has been specified, then output in the following format:

%ID %ESTIMATE!class1 ... %ESTIMATE!classK
Where class1 through classK are the possible labels for the class attribute, in the order that they were specified in the schema file or the order in which they were observed in the data

Parameters:
node - The node whose estimate to print
e - The current estimates
known - The true labels

toString

public java.lang.String toString(Node node,
                                 Estimate e,
                                 Classification known)
The equivalent of a print, where the output has been set to a string to be returned. This temporarily resets the output to a StringWriter and prints to there, then resets the output back to the original stream.

Parameters:
node - The node whose estimate needs to be written
e - The current estimates
known - The known true labels
Returns:
The output of the print in a string format.
See Also:
print(netkit.graph.Node, netkit.classifiers.Estimate, netkit.classifiers.Classification)

toString

public java.lang.String toString(Node node,
                                 Estimate e)
The equivalent of a print, where the output has been set to a string to be returned. This temporarily resets the output to a StringWriter and prints to there, then resets the output back to the original stream.

Parameters:
node - The node whose estimate needs to be written
e - The current estimates
Returns:
The output of the print in a string format.
See Also:
toString(netkit.graph.Node, netkit.classifiers.Estimate, netkit.classifiers.Classification)

setOutputFormat

public void setOutputFormat(java.lang.String f)
Reset the output format to the given format string.

Parameters:
f - The new output format string

getOutputFormat

public java.lang.String getOutputFormat()