1 33 34 package com.hp.hpl.jena.regression; 35 36 import com.hp.hpl.jena.rdf.model.*; 37 import com.hp.hpl.jena.vocabulary.RDF; 38 39 54 class DiHyperCube extends java.lang.Object { 55 final private Resource corners[]; 56 final private int dim; 57 final private Model model; 58 59 private int id = 2000; 60 61 public DiHyperCube(int dimension, Model m) { 62 dim = dimension; 63 model = m; 64 corners = new Resource[1<<dim]; 65 for (int i=0;i<corners.length;i++) { 66 corners[i] = m.createResource(); 67 } 69 for (int i=0;i<corners.length;i++) 70 addDown(i,corners[i]); 71 } 72 73 private void addDown(int corner,Resource r) { 74 for (int j=0;j<dim;j++) { 75 int bit = 1<<j; 76 if ( (corner & bit) != 0 ) { 77 model.add(r,RDF.value,corners[corner^bit]); 78 } 79 } 80 } 81 82 DiHyperCube dupe(int corner) { 83 Resource dup = model.createResource(); 84 for (int j=0;j<dim;j++) { 86 int bit = 1<<j; 87 if ( (corner & bit) != 0 ) { 88 model.add(dup,RDF.value,corners[corner^bit]); 89 } else { 90 model.add(corners[corner^bit],RDF.value,dup); 91 } 92 } 93 return this; 94 } 95 96 static int bitCount(int i) { 97 return java.math.BigInteger.valueOf(i).bitCount(); 98 } 99 105 static boolean equal(int a1, int b1) { 106 return bitCount(a1)==bitCount(b1); 107 } 108 114 static boolean equal(int a1, int a2, int b1, int b2) { 115 return bitCount(a1^a2)==bitCount(b1^b2) 116 && bitCount(a1&a2)==bitCount(b1&b2) 117 && bitCount(a1|a2)==bitCount(b1|b2) 118 && Math.min(bitCount(a1),bitCount(a2))== 119 Math.min(bitCount(b1),bitCount(b2)); 120 } 121 122 } 123 | Popular Tags |