public static void main(String[] args) { // modify the code below to call an appropriate constructor for your class DataGenerator wheel = new Wheel(0, 0, 0); // generate data for a specified time with constant delta-t wheel.generateData("wheel-data.csv", 2.0, 0.01); }
/** tests whether setting the options returned by getOptions() works */ public void testOptions() { try { m_Generator.setOptions(m_Generator.getOptions()); } catch (Exception e) { fail("setOptions(getOptions()) does not work: " + e.getMessage()); } }
/** * Sets the options. * * @param options the options * @throws Exception if invalid option */ @Override public void setOptions(String[] options) throws Exception { String tmpStr; super.setOptions(options); tmpStr = Utils.getOption('a', options); if (tmpStr.length() != 0) { setNumAttributes(Integer.parseInt(tmpStr)); } else { setNumAttributes(defaultNumAttributes()); } setClassFlag(Utils.getFlag('c', options)); tmpStr = Utils.getOption('b', options); setBooleanIndices(tmpStr); m_booleanCols.setUpper(getNumAttributes() - 1); tmpStr = Utils.getOption('m', options); setNominalIndices(tmpStr); m_nominalCols.setUpper(getNumAttributes() - 1); // check indices tmpStr = checkIndices(); if (tmpStr.length() > 0) { throw new IllegalArgumentException(tmpStr); } }
/** tests whether data can be generated with the default options */ public void testMakeData() { try { DataGenerator.makeData(m_Generator, new String[0]); } catch (Exception e) { fail("Generation of data failed: " + e.getMessage()); } }
@Test public void refresh_table_sizeShouldUpdate() throws SQLException { assertEquals(4, container.size()); DataGenerator.addFiveThousandPeople(connectionPool); container.refresh(); assertEquals(5000, container.size()); }
@Test public void allIdsFound_table5000RowsLastId_shouldSucceed() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); for (int i = 0; i < 5000; i++) { assertTrue(container.containsId(container.getIdByIndex(i))); } }
/** * Called by JUnit before each test method. This implementation creates the default datagenerator * to test. * * @throws Exception if an error occurs */ @Override protected void setUp() throws Exception { m_Generator = getGenerator(); m_Output = new StringWriter(); m_Generator.setOutput(new PrintWriter(m_Output)); m_OptionTester = getOptionTester(); m_GOETester = getGOETester(); }
@Test public void isLastId_table5000RowsLastId_returnsTrue() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); if (SQLTestsConstants.db == DB.ORACLE) { assertTrue(container.isLastId(new RowId(new Object[] {new BigDecimal(4999 + offset)}))); } else { assertTrue(container.isLastId(new RowId(new Object[] {4999 + offset}))); } }
@Test public void correctItemIsFetchedFromMultipleRows() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); Item item = container.getItem(getRowId(1337)); assertThat((Integer) item.getItemProperty(ID).getValue(), is(equalTo(1337 + offset))); assertThat(item.getItemProperty(NAME).getValue().toString(), is("Person 1337")); }
@Test public void refresh_tableWithoutCallingRefresh_sizeShouldNotUpdate() throws SQLException { // Yeah, this is a weird one. We're testing that the size doesn't update // after adding lots of items unless we call refresh inbetween. This to // make sure that the refresh method actually refreshes stuff and isn't // a NOP. assertEquals(4, container.size()); DataGenerator.addFiveThousandPeople(connectionPool); assertEquals(4, container.size()); }
@Test public void getIdByIndex_table5000rowsIndex1337_returnsRowId1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { assertEquals(new RowId(new Object[] {1337 + offset}).toString(), itemId.toString()); } else { assertEquals(new RowId(new Object[] {1337 + offset}), itemId); } }
@Test public void lastItemId_table5000Rows_returnsItemId4999() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); if (SQLTestsConstants.db == DB.ORACLE) { assertEquals( new RowId(new Object[] {4999 + offset}).toString(), container.lastItemId().toString()); } else { assertEquals(new RowId(new Object[] {4999 + offset}), container.lastItemId()); } }
/** Perform the sub task */ public void execute() { m_random = new Random(m_rowNumber * 11); m_dataGenerator.setSeed(m_rowNumber * 11); m_result = new RemoteResult(m_rowNumber, m_panelWidth); m_status.setTaskResult(m_result); m_status.setExecutionStatus(TaskStatusInfo.PROCESSING); try { m_numOfSamplesPerGenerator = (int) Math.pow(m_samplesBase, m_trainingData.numAttributes() - 3); if (m_trainingData == null) { throw new Exception("No training data set (BoundaryPanel)"); } if (m_classifier == null) { throw new Exception("No classifier set (BoundaryPanel)"); } if (m_dataGenerator == null) { throw new Exception("No data generator set (BoundaryPanel)"); } if (m_trainingData.attribute(m_xAttribute).isNominal() || m_trainingData.attribute(m_yAttribute).isNominal()) { throw new Exception( "Visualization dimensions must be numeric " + "(RemoteBoundaryVisualizerSubTask)"); } m_attsToWeightOn = new boolean[m_trainingData.numAttributes()]; m_attsToWeightOn[m_xAttribute] = true; m_attsToWeightOn[m_yAttribute] = true; // generate samples m_weightingAttsValues = new double[m_attsToWeightOn.length]; m_vals = new double[m_trainingData.numAttributes()]; m_predInst = new Instance(1.0, m_vals); m_predInst.setDataset(m_trainingData); System.err.println("Executing row number " + m_rowNumber); for (int j = 0; j < m_panelWidth; j++) { double[] preds = calculateRegionProbs(j, m_rowNumber); m_result.setLocationProbs(j, preds); m_result.setPercentCompleted((int) (100 * ((double) j / (double) m_panelWidth))); } } catch (Exception ex) { m_status.setExecutionStatus(TaskStatusInfo.FAILED); m_status.setStatusMessage("Row " + m_rowNumber + " failed."); System.err.print(ex); return; } // finished m_status.setExecutionStatus(TaskStatusInfo.FINISHED); m_status.setStatusMessage("Row " + m_rowNumber + " completed successfully."); }
@Test public void prevItemId_tableCurrentItem1337_returns1336() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { assertEquals( new RowId(new Object[] {1336 + offset}).toString(), container.prevItemId(itemId).toString()); } else { assertEquals(new RowId(new Object[] {1336 + offset}), container.prevItemId(itemId)); } }
@Test public void indexOfId_table5000RowsWithParameter1337_returns1337() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); if (SQLTestsConstants.db == DB.ORACLE) { container.getItem(new RowId(new Object[] {new BigDecimal(1337 + offset)})); assertEquals( 1337, container.indexOfId(new RowId(new Object[] {new BigDecimal(1337 + offset)}))); } else { container.getItem(new RowId(new Object[] {1337 + offset})); assertEquals(1337, container.indexOfId(new RowId(new Object[] {1337 + offset}))); } }
@Test public void nextItemId_tableCurrentItem1337_returnsItem1338() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object itemId = container.getIdByIndex(1337); if (SQLTestsConstants.db == DB.ORACLE) { assertEquals( new RowId(new Object[] {1338 + offset}).toString(), container.nextItemId(itemId).toString()); } else { assertEquals(new RowId(new Object[] {1338 + offset}), container.nextItemId(itemId)); } }
@Before public void setUp() throws SQLException { try { connectionPool = new ValidatingSimpleJDBCConnectionPool( SQLTestsConstants.dbDriver, SQLTestsConstants.dbURL, SQLTestsConstants.dbUser, SQLTestsConstants.dbPwd, 2, 2); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } DataGenerator.addPeopleToDatabase(connectionPool); query = getTableQuery("people"); container = new SQLContainer(query); }
/** tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { if (SerializationHelper.needsUID(m_Generator.getClass())) { fail("Doesn't declare serialVersionUID!"); } }
private double[] calculateRegionProbs(int j, int i) throws Exception { double[] sumOfProbsForRegion = new double[m_trainingData.classAttribute().numValues()]; for (int u = 0; u < m_numOfSamplesPerRegion; u++) { double[] sumOfProbsForLocation = new double[m_trainingData.classAttribute().numValues()]; m_weightingAttsValues[m_xAttribute] = getRandomX(j); m_weightingAttsValues[m_yAttribute] = getRandomY(m_panelHeight - i - 1); m_dataGenerator.setWeightingValues(m_weightingAttsValues); double[] weights = m_dataGenerator.getWeights(); double sumOfWeights = Utils.sum(weights); int[] indices = Utils.sort(weights); // Prune 1% of weight mass int[] newIndices = new int[indices.length]; double sumSoFar = 0; double criticalMass = 0.99 * sumOfWeights; int index = weights.length - 1; int counter = 0; for (int z = weights.length - 1; z >= 0; z--) { newIndices[index--] = indices[z]; sumSoFar += weights[indices[z]]; counter++; if (sumSoFar > criticalMass) { break; } } indices = new int[counter]; System.arraycopy(newIndices, index + 1, indices, 0, counter); for (int z = 0; z < m_numOfSamplesPerGenerator; z++) { m_dataGenerator.setWeightingValues(m_weightingAttsValues); double[][] values = m_dataGenerator.generateInstances(indices); for (int q = 0; q < values.length; q++) { if (values[q] != null) { System.arraycopy(values[q], 0, m_vals, 0, m_vals.length); m_vals[m_xAttribute] = m_weightingAttsValues[m_xAttribute]; m_vals[m_yAttribute] = m_weightingAttsValues[m_yAttribute]; // classify the instance m_dist = m_classifier.distributionForInstance(m_predInst); for (int k = 0; k < sumOfProbsForLocation.length; k++) { sumOfProbsForLocation[k] += (m_dist[k] * weights[q]); } } } } for (int k = 0; k < sumOfProbsForRegion.length; k++) { sumOfProbsForRegion[k] += (sumOfProbsForLocation[k] * sumOfWeights); } } // average Utils.normalize(sumOfProbsForRegion); // cache double[] tempDist = new double[sumOfProbsForRegion.length]; System.arraycopy(sumOfProbsForRegion, 0, tempDist, 0, sumOfProbsForRegion.length); return tempDist; }
private SQLContainer getGarbageContainer() throws SQLException { DataGenerator.createGarbage(connectionPool); return new SQLContainer(getTableQuery("garbage")); }