/** Test of setParameters method, of class MultivariatePolyaDistribution. */ public void testSetParameters() { System.out.println("setParameters"); MultivariatePolyaDistribution instance = this.createInstance(); Vector p = instance.getParameters().scale(2.0); instance.setParameters(p); assertEquals(p, instance.getParameters()); p.setElement(0, 0.0); try { instance.setParameters(p); fail("Parameters must be > 0.0"); } catch (Exception e) { System.out.println("Good: " + e); } try { instance.setParameters(null); fail("Cannot have null parameters"); } catch (Exception e) { System.out.println("Good: " + e); } try { instance.setParameters(VectorFactory.getDefault().copyValues(1.0)); fail("Must have dimensionality >= 2"); } catch (Exception e) { System.out.println("Good: " + e); } }
public static ArrayList<Vector> readDataAsVector(final String fileName, final int dimensionality) throws IOException { final ArrayList<Vector> result = new ArrayList<Vector>(); final BufferedReader in = new BufferedReader(new FileReader(fileName)); try { String line; while ((line = in.readLine()) != null) { final String[] parts = line.split("\\s"); final int elements = Integer.parseInt(parts[0]); final Vector v = VectorFactory.getSparseDefault().createVectorCapacity(dimensionality, elements); for (int i = 1; i < parts.length; i++) { final String part = parts[i]; final int split = part.indexOf(':'); final int index = Integer.parseInt(part.substring(0, split)); final int value = Integer.parseInt(part.substring(split + 1)); v.setElement(index, value); } result.add(v); } } finally { in.close(); } return result; }
public static Vector diag(Matrix mat) { Vector ret; if (mat.getNumColumns() > mat.getNumRows()) { ret = mat.getRow(0); } else { ret = mat.getColumn(0); } int rowcol = ret.getDimensionality(); for (int rc = 0; rc < rowcol; rc++) { ret.setElement(rc, mat.getElement(rc, rc)); } return ret; }