| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
package weka.classifiers.bayes.net; |
| 23 | |
|
| 24 | |
import java.util.Enumeration; |
| 25 | |
import java.util.Random; |
| 26 | |
import java.util.Vector; |
| 27 | |
|
| 28 | |
import weka.classifiers.bayes.net.estimate.DiscreteEstimatorBayes; |
| 29 | |
import weka.core.Attribute; |
| 30 | |
import weka.core.DenseInstance; |
| 31 | |
import weka.core.FastVector; |
| 32 | |
import weka.core.Instance; |
| 33 | |
import weka.core.Instances; |
| 34 | |
import weka.core.Option; |
| 35 | |
import weka.core.OptionHandler; |
| 36 | |
import weka.core.RevisionUtils; |
| 37 | |
import weka.core.Utils; |
| 38 | |
import weka.estimators.Estimator; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public class BayesNetGenerator extends EditableBayesNet { |
| 88 | |
|
| 89 | 0 | int m_nSeed = 1; |
| 90 | |
|
| 91 | |
|
| 92 | |
Random random; |
| 93 | |
|
| 94 | |
|
| 95 | |
static final long serialVersionUID = -7462571170596157720L; |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
public BayesNetGenerator() { |
| 101 | 0 | super(); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public void generateRandomNetwork () throws Exception { |
| 111 | 0 | if (m_otherBayesNet == null) { |
| 112 | |
|
| 113 | 0 | Init(m_nNrOfNodes, m_nCardinality); |
| 114 | 0 | generateRandomNetworkStructure(m_nNrOfNodes, m_nNrOfArcs); |
| 115 | 0 | generateRandomDistributions(m_nNrOfNodes, m_nCardinality); |
| 116 | |
} else { |
| 117 | |
|
| 118 | 0 | m_nNrOfNodes = m_otherBayesNet.getNrOfNodes(); |
| 119 | 0 | m_ParentSets = m_otherBayesNet.getParentSets(); |
| 120 | 0 | m_Distributions = m_otherBayesNet.getDistributions(); |
| 121 | |
|
| 122 | |
|
| 123 | 0 | random = new Random(m_nSeed); |
| 124 | |
|
| 125 | 0 | FastVector attInfo = new FastVector(m_nNrOfNodes); |
| 126 | |
|
| 127 | |
|
| 128 | 0 | for (int iNode = 0; iNode < m_nNrOfNodes; iNode++) { |
| 129 | 0 | int nValues = m_otherBayesNet.getCardinality(iNode); |
| 130 | 0 | FastVector nomStrings = new FastVector(nValues + 1); |
| 131 | 0 | for (int iValue = 0; iValue < nValues; iValue++) { |
| 132 | 0 | nomStrings.addElement(m_otherBayesNet.getNodeValue(iNode, iValue)); |
| 133 | |
} |
| 134 | 0 | Attribute att = new Attribute(m_otherBayesNet.getNodeName(iNode), nomStrings); |
| 135 | 0 | attInfo.addElement(att); |
| 136 | |
} |
| 137 | |
|
| 138 | 0 | m_Instances = new Instances(m_otherBayesNet.getName(), attInfo, 100); |
| 139 | 0 | m_Instances.setClassIndex(m_nNrOfNodes - 1); |
| 140 | |
} |
| 141 | 0 | } |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
public void Init(int nNodes, int nValues) throws Exception { |
| 150 | 0 | random = new Random(m_nSeed); |
| 151 | |
|
| 152 | 0 | FastVector attInfo = new FastVector(nNodes); |
| 153 | |
|
| 154 | 0 | FastVector nomStrings = new FastVector(nValues + 1); |
| 155 | 0 | for (int iValue = 0; iValue < nValues; iValue++) { |
| 156 | 0 | nomStrings.addElement("Value" + (iValue + 1)); |
| 157 | |
} |
| 158 | |
|
| 159 | 0 | for (int iNode = 0; iNode < nNodes; iNode++) { |
| 160 | 0 | Attribute att = new Attribute("Node" + (iNode + 1), nomStrings); |
| 161 | 0 | attInfo.addElement(att); |
| 162 | |
} |
| 163 | 0 | m_Instances = new Instances("RandomNet", attInfo, 100); |
| 164 | 0 | m_Instances.setClassIndex(nNodes - 1); |
| 165 | 0 | setUseADTree(false); |
| 166 | |
|
| 167 | |
|
| 168 | 0 | initStructure(); |
| 169 | |
|
| 170 | |
|
| 171 | 0 | m_Distributions = new Estimator[nNodes][1]; |
| 172 | 0 | for (int iNode = 0; iNode < nNodes; iNode++) { |
| 173 | 0 | m_Distributions[iNode][0] = |
| 174 | |
new DiscreteEstimatorBayes(nValues, getEstimator().getAlpha()); |
| 175 | |
} |
| 176 | 0 | m_nEvidence = new FastVector(nNodes); |
| 177 | 0 | for (int i = 0; i < nNodes; i++) { |
| 178 | 0 | m_nEvidence.addElement(-1); |
| 179 | |
} |
| 180 | 0 | m_fMarginP = new FastVector(nNodes); |
| 181 | 0 | for (int i = 0; i < nNodes; i++) { |
| 182 | 0 | double[] P = new double[getCardinality(i)]; |
| 183 | 0 | m_fMarginP.addElement(P); |
| 184 | |
} |
| 185 | |
|
| 186 | 0 | m_nPositionX = new FastVector(nNodes); |
| 187 | 0 | m_nPositionY = new FastVector(nNodes); |
| 188 | 0 | for (int iNode = 0; iNode < nNodes; iNode++) { |
| 189 | 0 | m_nPositionX.addElement(iNode%10 * 50); |
| 190 | 0 | m_nPositionY.addElement(((int)(iNode/10)) * 50); |
| 191 | |
} |
| 192 | 0 | } |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
public void generateRandomNetworkStructure(int nNodes, int nArcs) |
| 201 | |
throws Exception |
| 202 | |
{ |
| 203 | 0 | if (nArcs < nNodes - 1) { |
| 204 | 0 | throw new Exception("Number of arcs should be at least (nNodes - 1) = " + (nNodes - 1) + " instead of " + nArcs); |
| 205 | |
} |
| 206 | 0 | if (nArcs > nNodes * (nNodes - 1) / 2) { |
| 207 | 0 | throw new Exception("Number of arcs should be at most nNodes * (nNodes - 1) / 2 = "+ (nNodes * (nNodes - 1) / 2) + " instead of " + nArcs); |
| 208 | |
} |
| 209 | 0 | if (nArcs == 0) {return;} |
| 210 | |
|
| 211 | |
|
| 212 | 0 | generateTree(nNodes); |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | 0 | for (int iArc = nNodes - 1; iArc < nArcs; iArc++) { |
| 218 | 0 | boolean bDone = false; |
| 219 | 0 | while (!bDone) { |
| 220 | 0 | int nNode1 = random.nextInt(nNodes); |
| 221 | 0 | int nNode2 = random.nextInt(nNodes); |
| 222 | 0 | if (nNode1 == nNode2) {nNode2 = (nNode1 + 1) % nNodes;} |
| 223 | 0 | if (nNode2 < nNode1) {int h = nNode1; nNode1 = nNode2; nNode2 = h;} |
| 224 | 0 | if (!m_ParentSets[nNode2].contains(nNode1)) { |
| 225 | 0 | m_ParentSets[nNode2].addParent(nNode1, m_Instances); |
| 226 | 0 | bDone = true; |
| 227 | |
} |
| 228 | 0 | } |
| 229 | |
} |
| 230 | |
|
| 231 | 0 | } |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
void generateTree(int nNodes) { |
| 242 | 0 | boolean [] bConnected = new boolean [nNodes]; |
| 243 | |
|
| 244 | 0 | int nNode1 = random.nextInt(nNodes); |
| 245 | 0 | int nNode2 = random.nextInt(nNodes); |
| 246 | 0 | if (nNode1 == nNode2) {nNode2 = (nNode1 + 1) % nNodes;} |
| 247 | 0 | if (nNode2 < nNode1) {int h = nNode1; nNode1 = nNode2; nNode2 = h;} |
| 248 | 0 | m_ParentSets[nNode2].addParent(nNode1, m_Instances); |
| 249 | 0 | bConnected[nNode1] = true; |
| 250 | 0 | bConnected[nNode2] = true; |
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | 0 | for (int iArc = 2; iArc < nNodes; iArc++ ) { |
| 256 | 0 | int nNode = random.nextInt(nNodes); |
| 257 | 0 | nNode1 = 0; |
| 258 | 0 | while (nNode >= 0) { |
| 259 | 0 | nNode1 = (nNode1 + 1) % nNodes; |
| 260 | 0 | while (!bConnected[nNode1]) { |
| 261 | 0 | nNode1 = (nNode1 + 1) % nNodes; |
| 262 | |
} |
| 263 | 0 | nNode--; |
| 264 | |
} |
| 265 | 0 | nNode = random.nextInt(nNodes); |
| 266 | 0 | nNode2 = 0; |
| 267 | 0 | while (nNode >= 0) { |
| 268 | 0 | nNode2 = (nNode2 + 1) % nNodes; |
| 269 | 0 | while (bConnected[nNode2]) { |
| 270 | 0 | nNode2 = (nNode2 + 1) % nNodes; |
| 271 | |
} |
| 272 | 0 | nNode--; |
| 273 | |
} |
| 274 | 0 | if (nNode2 < nNode1) {int h = nNode1; nNode1 = nNode2; nNode2 = h;} |
| 275 | 0 | m_ParentSets[nNode2].addParent(nNode1, m_Instances); |
| 276 | 0 | bConnected[nNode1] = true; |
| 277 | 0 | bConnected[nNode2] = true; |
| 278 | |
} |
| 279 | 0 | } |
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
void generateRandomDistributions(int nNodes, int nValues) { |
| 288 | |
|
| 289 | 0 | int nMaxParentCardinality = 1; |
| 290 | 0 | for (int iAttribute = 0; iAttribute < nNodes; iAttribute++) { |
| 291 | 0 | if (m_ParentSets[iAttribute].getCardinalityOfParents() > nMaxParentCardinality) { |
| 292 | 0 | nMaxParentCardinality = m_ParentSets[iAttribute].getCardinalityOfParents(); |
| 293 | |
} |
| 294 | |
} |
| 295 | |
|
| 296 | |
|
| 297 | 0 | m_Distributions = new Estimator[m_Instances.numAttributes()][nMaxParentCardinality]; |
| 298 | |
|
| 299 | |
|
| 300 | 0 | for (int iAttribute = 0; iAttribute < nNodes; iAttribute++) { |
| 301 | 0 | int [] nPs = new int [nValues + 1]; |
| 302 | 0 | nPs[0] = 0; |
| 303 | 0 | nPs[nValues] = 1000; |
| 304 | 0 | for (int iParent = 0; iParent < m_ParentSets[iAttribute].getCardinalityOfParents(); iParent++) { |
| 305 | |
|
| 306 | 0 | for (int iValue = 1; iValue < nValues; iValue++) { |
| 307 | 0 | nPs[iValue] = random.nextInt(1000); |
| 308 | |
} |
| 309 | |
|
| 310 | 0 | for (int iValue = 1; iValue < nValues; iValue++) { |
| 311 | 0 | for (int iValue2 = iValue + 1; iValue2 < nValues; iValue2++) { |
| 312 | 0 | if (nPs[iValue2] < nPs[iValue]) { |
| 313 | 0 | int h = nPs[iValue2]; nPs[iValue2] = nPs[iValue]; nPs[iValue] = h; |
| 314 | |
} |
| 315 | |
} |
| 316 | |
} |
| 317 | |
|
| 318 | 0 | DiscreteEstimatorBayes d = new DiscreteEstimatorBayes(nValues, getEstimator().getAlpha()); |
| 319 | 0 | for (int iValue = 0; iValue < nValues; iValue++) { |
| 320 | 0 | d.addValue(iValue, nPs[iValue + 1] - nPs[iValue]); |
| 321 | |
} |
| 322 | 0 | m_Distributions[iAttribute][iParent] = d; |
| 323 | |
} |
| 324 | |
} |
| 325 | 0 | } |
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
public void generateInstances () throws Exception { |
| 335 | 0 | int [] order = getOrder(); |
| 336 | 0 | for (int iInstance = 0; iInstance < m_nNrOfInstances; iInstance++) { |
| 337 | 0 | int nNrOfAtts = m_Instances.numAttributes(); |
| 338 | 0 | Instance instance = new DenseInstance(nNrOfAtts); |
| 339 | 0 | instance.setDataset(m_Instances); |
| 340 | 0 | for (int iAtt2 = 0; iAtt2 < nNrOfAtts; iAtt2++) { |
| 341 | 0 | int iAtt = order[iAtt2]; |
| 342 | |
|
| 343 | 0 | double iCPT = 0; |
| 344 | |
|
| 345 | 0 | for (int iParent = 0; iParent < m_ParentSets[iAtt].getNrOfParents(); iParent++) { |
| 346 | 0 | int nParent = m_ParentSets[iAtt].getParent(iParent); |
| 347 | 0 | iCPT = iCPT * m_Instances.attribute(nParent).numValues() + instance.value(nParent); |
| 348 | |
} |
| 349 | |
|
| 350 | 0 | double fRandom = random.nextInt(1000) / 1000.0f; |
| 351 | 0 | int iValue = 0; |
| 352 | 0 | while (fRandom > m_Distributions[iAtt][(int) iCPT].getProbability(iValue)) { |
| 353 | 0 | fRandom = fRandom - m_Distributions[iAtt][(int) iCPT].getProbability(iValue); |
| 354 | 0 | iValue++ ; |
| 355 | |
} |
| 356 | 0 | instance.setValue(iAtt, iValue); |
| 357 | |
} |
| 358 | 0 | m_Instances.add(instance); |
| 359 | |
} |
| 360 | 0 | } |
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
int [] getOrder() throws Exception { |
| 366 | 0 | int nNrOfAtts = m_Instances.numAttributes(); |
| 367 | 0 | int [] order = new int[nNrOfAtts]; |
| 368 | 0 | boolean [] bDone = new boolean[nNrOfAtts]; |
| 369 | 0 | for (int iAtt = 0; iAtt < nNrOfAtts; iAtt++) { |
| 370 | 0 | int iAtt2 = 0; |
| 371 | 0 | boolean allParentsDone = false; |
| 372 | 0 | while (!allParentsDone && iAtt2 < nNrOfAtts) { |
| 373 | 0 | if (!bDone[iAtt2]) { |
| 374 | 0 | allParentsDone = true; |
| 375 | 0 | int iParent = 0; |
| 376 | 0 | while (allParentsDone && iParent < m_ParentSets[iAtt2].getNrOfParents()) { |
| 377 | 0 | allParentsDone = bDone[m_ParentSets[iAtt2].getParent(iParent++)]; |
| 378 | |
} |
| 379 | 0 | if (allParentsDone && iParent == m_ParentSets[iAtt2].getNrOfParents()) { |
| 380 | 0 | order[iAtt] = iAtt2; |
| 381 | 0 | bDone[iAtt2] = true; |
| 382 | |
} else { |
| 383 | 0 | iAtt2++; |
| 384 | |
} |
| 385 | 0 | } else { |
| 386 | 0 | iAtt2++; |
| 387 | |
} |
| 388 | |
} |
| 389 | 0 | if (!allParentsDone && iAtt2 == nNrOfAtts) { |
| 390 | 0 | throw new Exception("There appears to be a cycle in the graph"); |
| 391 | |
} |
| 392 | |
} |
| 393 | 0 | return order; |
| 394 | |
} |
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
public String toString() { |
| 402 | 0 | if (m_bGenerateNet) { |
| 403 | 0 | return toXMLBIF03(); |
| 404 | |
} |
| 405 | 0 | return m_Instances.toString(); |
| 406 | |
} |
| 407 | |
|
| 408 | |
|
| 409 | 0 | boolean m_bGenerateNet = false; |
| 410 | 0 | int m_nNrOfNodes = 10; |
| 411 | 0 | int m_nNrOfArcs = 10; |
| 412 | 0 | int m_nNrOfInstances = 10; |
| 413 | 0 | int m_nCardinality = 2; |
| 414 | 0 | String m_sBIFFile = ""; |
| 415 | |
|
| 416 | 0 | void setNrOfNodes(int nNrOfNodes) {m_nNrOfNodes = nNrOfNodes;} |
| 417 | 0 | void setNrOfArcs(int nNrOfArcs) {m_nNrOfArcs = nNrOfArcs;} |
| 418 | 0 | void setNrOfInstances(int nNrOfInstances) {m_nNrOfInstances = nNrOfInstances;} |
| 419 | 0 | void setCardinality(int nCardinality) {m_nCardinality = nCardinality;} |
| 420 | 0 | void setSeed(int nSeed) {m_nSeed = nSeed;} |
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
public Enumeration listOptions() { |
| 428 | 0 | Vector newVector = new Vector(6); |
| 429 | |
|
| 430 | 0 | newVector.addElement(new Option("\tGenerate network (instead of instances)\n", "B", 0, "-B")); |
| 431 | 0 | newVector.addElement(new Option("\tNr of nodes\n", "N", 1, "-N <integer>")); |
| 432 | 0 | newVector.addElement(new Option("\tNr of arcs\n", "A", 1, "-A <integer>")); |
| 433 | 0 | newVector.addElement(new Option("\tNr of instances\n", "M", 1, "-M <integer>")); |
| 434 | 0 | newVector.addElement(new Option("\tCardinality of the variables\n", "C", 1, "-C <integer>")); |
| 435 | 0 | newVector.addElement(new Option("\tSeed for random number generator\n", "S", 1, "-S <integer>")); |
| 436 | 0 | newVector.addElement(new Option("\tThe BIF file to obtain the structure from.\n", "F", 1, "-F <file>")); |
| 437 | |
|
| 438 | 0 | return newVector.elements(); |
| 439 | |
} |
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
public void setOptions(String[] options) throws Exception { |
| 481 | 0 | m_bGenerateNet = Utils.getFlag('B', options); |
| 482 | |
|
| 483 | 0 | String sNrOfNodes = Utils.getOption('N', options); |
| 484 | 0 | if (sNrOfNodes.length() != 0) { |
| 485 | 0 | setNrOfNodes(Integer.parseInt(sNrOfNodes)); |
| 486 | |
} else { |
| 487 | 0 | setNrOfNodes(10); |
| 488 | |
} |
| 489 | |
|
| 490 | 0 | String sNrOfArcs = Utils.getOption('A', options); |
| 491 | 0 | if (sNrOfArcs.length() != 0) { |
| 492 | 0 | setNrOfArcs(Integer.parseInt(sNrOfArcs)); |
| 493 | |
} else { |
| 494 | 0 | setNrOfArcs(10); |
| 495 | |
} |
| 496 | |
|
| 497 | 0 | String sNrOfInstances = Utils.getOption('M', options); |
| 498 | 0 | if (sNrOfInstances.length() != 0) { |
| 499 | 0 | setNrOfInstances(Integer.parseInt(sNrOfInstances)); |
| 500 | |
} else { |
| 501 | 0 | setNrOfInstances(10); |
| 502 | |
} |
| 503 | |
|
| 504 | 0 | String sCardinality = Utils.getOption('C', options); |
| 505 | 0 | if (sCardinality.length() != 0) { |
| 506 | 0 | setCardinality(Integer.parseInt(sCardinality)); |
| 507 | |
} else { |
| 508 | 0 | setCardinality(2); |
| 509 | |
} |
| 510 | |
|
| 511 | 0 | String sSeed = Utils.getOption('S', options); |
| 512 | 0 | if (sSeed.length() != 0) { |
| 513 | 0 | setSeed(Integer.parseInt(sSeed)); |
| 514 | |
} else { |
| 515 | 0 | setSeed(1); |
| 516 | |
} |
| 517 | |
|
| 518 | 0 | String sBIFFile = Utils.getOption('F', options); |
| 519 | 0 | if ((sBIFFile != null) && (sBIFFile != "")) { |
| 520 | 0 | setBIFFile(sBIFFile); |
| 521 | |
} |
| 522 | 0 | } |
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
public String[] getOptions() { |
| 530 | 0 | String[] options = new String[13]; |
| 531 | 0 | int current = 0; |
| 532 | 0 | if (m_bGenerateNet) { |
| 533 | 0 | options[current++] = "-B"; |
| 534 | |
} |
| 535 | |
|
| 536 | 0 | options[current++] = "-N"; |
| 537 | 0 | options[current++] = "" + m_nNrOfNodes; |
| 538 | |
|
| 539 | 0 | options[current++] = "-A"; |
| 540 | 0 | options[current++] = "" + m_nNrOfArcs; |
| 541 | |
|
| 542 | 0 | options[current++] = "-M"; |
| 543 | 0 | options[current++] = "" + m_nNrOfInstances; |
| 544 | |
|
| 545 | 0 | options[current++] = "-C"; |
| 546 | 0 | options[current++] = "" + m_nCardinality; |
| 547 | |
|
| 548 | 0 | options[current++] = "-S"; |
| 549 | 0 | options[current++] = "" + m_nSeed; |
| 550 | |
|
| 551 | 0 | if (m_sBIFFile.length() != 0) { |
| 552 | 0 | options[current++] = "-F"; |
| 553 | 0 | options[current++] = "" + m_sBIFFile; |
| 554 | |
} |
| 555 | |
|
| 556 | |
|
| 557 | 0 | while (current < options.length) { |
| 558 | 0 | options[current++] = ""; |
| 559 | |
} |
| 560 | |
|
| 561 | 0 | return options; |
| 562 | |
} |
| 563 | |
|
| 564 | |
|
| 565 | |
|
| 566 | |
|
| 567 | |
protected static void printOptions(OptionHandler o) { |
| 568 | 0 | Enumeration enm = o.listOptions(); |
| 569 | |
|
| 570 | 0 | System.out.println("Options for " + o.getClass().getName() + ":\n"); |
| 571 | |
|
| 572 | 0 | while (enm.hasMoreElements()) { |
| 573 | 0 | Option option = (Option) enm.nextElement(); |
| 574 | 0 | System.out.println(option.synopsis()); |
| 575 | 0 | System.out.println(option.description()); |
| 576 | 0 | } |
| 577 | 0 | } |
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
public String getRevision() { |
| 585 | 0 | return RevisionUtils.extract("$Revision: 8034 $"); |
| 586 | |
} |
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
static public void main(String [] args) { |
| 594 | 0 | BayesNetGenerator b = new BayesNetGenerator(); |
| 595 | |
try { |
| 596 | 0 | if ( (args.length == 0) || (Utils.getFlag('h', args)) ) { |
| 597 | 0 | printOptions(b); |
| 598 | 0 | return; |
| 599 | |
} |
| 600 | 0 | b.setOptions(args); |
| 601 | |
|
| 602 | 0 | b.generateRandomNetwork(); |
| 603 | 0 | if (!b.m_bGenerateNet) { |
| 604 | 0 | b.generateInstances(); |
| 605 | |
} |
| 606 | 0 | System.out.println(b.toString()); |
| 607 | 0 | } catch (Exception e) { |
| 608 | 0 | e.printStackTrace(); |
| 609 | 0 | printOptions(b); |
| 610 | 0 | } |
| 611 | 0 | } |
| 612 | |
|
| 613 | |
} |