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 55 class HyperCube extends java.lang.Object { 56 final private Resource corners[]; 57 final private int dim; 58 final private Model model; 59 60 private int id = 2000; 61 62 public HyperCube(int dimension,Model m) { 63 dim = dimension; 64 model = m; 65 corners = new Resource[1<<dim]; 66 for (int i=0;i<corners.length;i++) { 67 corners[i] = m.createResource(); 68 } 70 for (int i=0;i<corners.length;i++) 71 add(i,corners[i]); 72 } 73 74 private void add(int corner,Resource r) { 75 for (int j=0;j<dim;j++) { 76 int bit = 1<<j; 77 model.add(r,RDF.value,corners[corner^bit]); 78 } 79 } 80 81 HyperCube dupe(int corner) { 82 Resource dup = model.createResource(); 83 add(corner,dup); 85 return this; 86 } 87 88 HyperCube toggle(int from,int to) { 89 Resource f = corners[from]; 90 Resource t = corners[to]; 91 Statement s = model.createStatement(f,RDF.value,t); 92 if ( model.contains(s) ) { 93 model.remove(s); 94 } else { 95 model.add(s); 96 } 97 return this; 98 } 99 100 static int bitCount(int i) { 101 return java.math.BigInteger.valueOf(i).bitCount(); 102 } 103 111 static boolean equal(int a1, int a2, int b1, int b2) { 112 return bitCount(a1^a2)==bitCount(b1^b2); 113 } 114 115 } 116 | Popular Tags |