Object Detection using Template

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables
MyProcess.java
Go to the documentation of this file.
1 package cz.vutbr.feec.novak68.rapidminer;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.EmptyStackException;
6 import java.util.List;
7 import java.util.Vector;
8
9 import com.rapidminer.Process;
10 import com.rapidminer.RapidMiner;
11 import com.rapidminer.RapidMiner.ExecutionMode;
12 import com.rapidminer.example.Attribute;
13 import com.rapidminer.example.Attributes;
14 import com.rapidminer.example.Example;
15 import com.rapidminer.example.ExampleSet;
16 import com.rapidminer.example.table.AttributeFactory;
17 import com.rapidminer.example.table.DataRow;
18 import com.rapidminer.example.table.DataRowFactory;
19 import com.rapidminer.example.table.MemoryExampleTable;
20 import com.rapidminer.operator.IOContainer;
21 import com.rapidminer.operator.OperatorException;
22 import com.rapidminer.tools.Ontology;
23 import com.rapidminer.tools.XMLException;
24
30 public class MyProcess {
31 final String SEPARATOR = File.separator;
32 final String RPM_FILE = "rapidminer" + SEPARATOR + "labelProc.rmp";
33 ExampleSet inputEs;
34 ExampleSet outputEs;
35 public MyProcess(boolean useVariance){
36 inputEs = ExampleSetHeader(useVariance);
37 }
41 public ExampleSet runProcess(){
42 if(inputEs.size() == 0){
43 throw new EmptyStackException();
44 }
45
46 System.out.println("Starting RapidMiner...");
47
48 if (System.getProperty("os.name").toLowerCase().equals("linux"))
49 System.setProperty("rapidminer.home", "/opt/rapidminer");
50 RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
51
52 RapidMiner.init();
53 Process process = null;
54 IOContainer outputs = null;
55 IOContainer inputs = new IOContainer(inputEs);
56 try {
57 process = new Process(new File(RPM_FILE));
58 outputs = process.run(inputs);
59 } catch (IOException | XMLException | OperatorException e) {
60 e.printStackTrace();
61 }
62 outputEs = (ExampleSet) outputs.getElementAt(0);
63 return outputEs;
64
65 }
66 public void printAllRecords(){
67 final String RECORD_SEPARATOR = " ";
68 for (Example example : outputEs) {
69 System.out.println(example.getValueAsString(outputEs.getAttributes().getRegular("coordinates")) + RECORD_SEPARATOR +
70 example.getValueAsString(outputEs.getAttributes().getRegular("simpleC")) + RECORD_SEPARATOR +
71 example.getValueAsString(outputEs.getAttributes().getRegular("symetryC")) + RECORD_SEPARATOR +
72 example.getValueAsString(outputEs.getAttributes().getRegular("xsymetry")) + RECORD_SEPARATOR +
73 example.getValueAsString(outputEs.getAttributes().getRegular("ysymetry")) + RECORD_SEPARATOR +
74 example.getValueAsString(outputEs.getAttributes().getRegular("allElementC")) + RECORD_SEPARATOR +
75 example.getValueAsString(outputEs.getAttributes().getRegular("hElementC")) + RECORD_SEPARATOR +
76 example.getValueAsString(outputEs.getAttributes().getRegular("vElementC")) + RECORD_SEPARATOR +
77 example.getValueAsString(outputEs.getAttributes().getRegular("otherElementC")) + RECORD_SEPARATOR +
78 "prediction: " + example.getValueAsString(outputEs.getAttributes().getPredictedLabel()) + RECORD_SEPARATOR +
79 "confidence p: " + example.getValueAsString(outputEs.getAttributes().getConfidence("p")) + RECORD_SEPARATOR +
80 "confidence n: " + example.getValueAsString(outputEs.getAttributes().getConfidence("n")));
81
82 }
83 }
84
88 public ExampleSet getInputExampleSet(){
89 return inputEs;
90 }
94 public ExampleSet getOutputExampleSet(){
95 if (outputEs.size() == 0)
96 return null;
97 return outputEs;
98 }
99
113 public ExampleSet addValues (String clazz, String coordinates,
114 double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC,int vElementC, int otherElementC) {
115 return addValues(clazz, inputEs, coordinates, simpleC, symetryC, xsymetry, ysymetry, allElementC, hElementC, vElementC, otherElementC);}
116 public ExampleSet addValues (String clazz, String coordinates,
117 double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC,int vElementC, int otherElementC, double variance) {
118 return addValues(clazz, inputEs, coordinates, simpleC, symetryC, xsymetry, ysymetry, allElementC, hElementC, vElementC, otherElementC, variance);
119 }
120 public ExampleSet addValues (String clazz, ExampleSet exampleSet, String coordinates,
121 double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC,int vElementC, int otherElementC) {
122
123 char decimalSeperator = '.';
124 DataRowFactory ROW_FACTORY = new DataRowFactory(0, decimalSeperator);
125 MemoryExampleTable table = (MemoryExampleTable) exampleSet
126 .getExampleTable();
127
128 int numOfAttrib = table.getNumberOfAttributes();
129
130 Object values[] = new Object[numOfAttrib];
131
132 values[0] = clazz;
133 values[1] = coordinates;
134 values[2] = simpleC;
135 values[3] = symetryC;
136 values[4] = xsymetry;
137 values[5] = ysymetry;
138 values[6] = allElementC;
139 values[7] = hElementC;
140 values[8] = vElementC;
141 values[9] = otherElementC;
142
143 DataRow row = ROW_FACTORY.create(values, table.getAttributes());
144 table.addDataRow(row);
145 return exampleSet;
146 }
147 public ExampleSet addValues (String clazz, ExampleSet exampleSet, String coordinates,
148 double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC,int vElementC, int otherElementC, double variance) {
149
150 char decimalSeperator = '.';
151 DataRowFactory ROW_FACTORY = new DataRowFactory(0, decimalSeperator);
152 MemoryExampleTable table = (MemoryExampleTable) exampleSet
153 .getExampleTable();
154
155 int numOfAttrib = table.getNumberOfAttributes();
156
157 Object values[] = new Object[numOfAttrib];
158
159 values[0] = clazz;
160 values[1] = coordinates;
161 values[2] = simpleC;
162 values[3] = symetryC;
163 values[4] = xsymetry;
164 values[5] = ysymetry;
165 values[6] = allElementC;
166 values[7] = hElementC;
167 values[8] = vElementC;
168 values[9] = otherElementC;
169 values[10] = variance;
170
171 DataRow row = ROW_FACTORY.create(values, table.getAttributes());
172 table.addDataRow(row);
173 return exampleSet;
174 }
175
176 private static ExampleSet ExampleSetHeader(boolean useVariance) {
177 List<Attribute> attributes = new Vector<Attribute>();
178
179 Attribute prediction = null;
180
181 Attribute attPred = AttributeFactory.createAttribute("prediction",
182 Ontology.NOMINAL);
183 attributes.add(attPred);
184 prediction = attPred;
185 attPred.setName(Attributes.PREDICTION_NAME);
186
187 Attribute att2 = AttributeFactory.createAttribute("coordinates",
188 Ontology.STRING);
189 attributes.add(att2);
190 Attribute att3 = AttributeFactory.createAttribute("simpleC",
191 Ontology.REAL);
192 attributes.add(att3);
193 Attribute att4 = AttributeFactory.createAttribute("symetryC",
194 Ontology.REAL);
195 attributes.add(att4);
196 Attribute att5 = AttributeFactory.createAttribute("xsymetry",
197 Ontology.INTEGER);
198 attributes.add(att5);
199 Attribute att6 = AttributeFactory.createAttribute("ysymetry",
200 Ontology.INTEGER);
201 attributes.add(att6);
202 Attribute att7 = AttributeFactory.createAttribute("allElementC",
203 Ontology.INTEGER);
204 attributes.add(att7);
205 Attribute att8 = AttributeFactory.createAttribute("hElementC",
206 Ontology.INTEGER);
207 attributes.add(att8);
208 Attribute att9 = AttributeFactory.createAttribute("vElementC",
209 Ontology.INTEGER);
210 attributes.add(att9);
211 Attribute att10 = AttributeFactory.createAttribute("otherElementC",
212 Ontology.INTEGER);
213 attributes.add(att10);
214 if(useVariance){
215 Attribute att11 = AttributeFactory.createAttribute("variance",
216 Ontology.REAL);
217 attributes.add(att11);
218 }
219 Attribute attConfidence = AttributeFactory.createAttribute("confidence",
220 Ontology.NUMERICAL);
221 attConfidence.setName(Attributes.CONFIDENCE_NAME);
222 attributes.add(attConfidence);
223
224 MemoryExampleTable table = new MemoryExampleTable(attributes);
225
226 ExampleSet es = table.createExampleSet();
227 es.getAttributes().setPredictedLabel(prediction);
228 return es;
229 }
230
231 }
cz.vutbr.feec.novak68.rapidminer.MyProcess.addValues
ExampleSet addValues(String clazz, ExampleSet exampleSet, String coordinates, double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC, int vElementC, int otherElementC, double variance)
Definition: MyProcess.java:147
cz.vutbr.feec.novak68.rapidminer.MyProcess.addValues
ExampleSet addValues(String clazz, String coordinates, double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC, int vElementC, int otherElementC)
Definition: MyProcess.java:113
cz.vutbr.feec.novak68.rapidminer.MyProcess.runProcess
ExampleSet runProcess()
Definition: MyProcess.java:41
cz.vutbr.feec.novak68.rapidminer.MyProcess.addValues
ExampleSet addValues(String clazz, ExampleSet exampleSet, String coordinates, double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC, int vElementC, int otherElementC)
Definition: MyProcess.java:120
cz.vutbr.feec.novak68.rapidminer.MyProcess.printAllRecords
void printAllRecords()
Definition: MyProcess.java:66
cz.vutbr.feec.novak68.rapidminer.MyProcess
Definition: MyProcess.java:30
cz.vutbr.feec.novak68.rapidminer.MyProcess.ExampleSetHeader
static ExampleSet ExampleSetHeader(boolean useVariance)
Definition: MyProcess.java:176
cz.vutbr.feec.novak68.rapidminer.MyProcess.getInputExampleSet
ExampleSet getInputExampleSet()
Definition: MyProcess.java:88
cz.vutbr.feec.novak68.rapidminer.MyProcess.addValues
ExampleSet addValues(String clazz, String coordinates, double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC, int vElementC, int otherElementC, double variance)
Definition: MyProcess.java:116
cz.vutbr.feec.novak68.rapidminer.MyProcess.MyProcess
MyProcess(boolean useVariance)
Definition: MyProcess.java:35
cz.vutbr.feec.novak68.rapidminer.MyProcess.getOutputExampleSet
ExampleSet getOutputExampleSet()
Definition: MyProcess.java:94