/** * Feeds the {@link Network with the final phrase consisting of the first * two words of the final question "fox, eats, ...". * * @param network the current {@link Network} object * @param it an {@link Iterator} over the input source file lines * @return */ Term feedQuestion(Network network, String[] phrase) { for (int i = 0; i < 2; i++) { int[] sdr = getFingerprintSDR(phrase[i]); network.compute(sdr); } int[] sdr = new int[128 * 128]; Arrays.fill(sdr, 1); Layer<?> layer = network.lookup("Region 1").lookup("Layer 2/3"); Set<Cell> predictiveCells = layer.getConnections().getPredictiveCells(); System.out.println("predictiveCells " + predictiveCells.toString()); int[] prediction = SDR.cellsAsColumnIndices(predictiveCells, layer.getConnections().getCellsPerColumn()); network.compute(sdr); Set<Cell> ffActive = layer.getActiveCells(); System.out.println("activeCells " + ffActive.toString()); int[] paPrediction = SDR.cellsAsColumnIndices(ffActive, layer.getConnections().getCellsPerColumn()); Term term = getClosestTerm(prediction); Term paterm = getClosestTerm(paPrediction); System.out.println(paterm.toString()); cache.put(term.getTerm(), term); return term; }
@Ignore public void testPlayground() { final int NUM_CYCLES = 600; final int INPUT_GROUP_COUNT = 7; // Days of Week /////////////////////////////////////// // Load a Network // /////////////////////////////////////// Network network = getLoadedDayOfWeekNetwork(); int cellsPerCol = (int) network.getParameters().get(KEY.CELLS_PER_COLUMN); network .observe() .subscribe( new Observer<Inference>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) { e.printStackTrace(); } @SuppressWarnings("unused") @Override public void onNext(Inference inf) { /** see {@link #createDayOfWeekInferencePrintout()} */ int cycle = dayOfWeekPrintout.apply(inf, cellsPerCol); } }); Publisher pub = network.getPublisher(); network.start(); int cycleCount = 0; for (; cycleCount < NUM_CYCLES; cycleCount++) { for (double j = 0; j < INPUT_GROUP_COUNT; j++) { pub.onNext("" + j); } network.reset(); } // Test network output try { Region r1 = network.lookup("r1"); r1.lookup("1").getLayerThread().join(2000); } catch (Exception e) { e.printStackTrace(); } }
/** * Feeds the {@link Network with the final phrase consisting of the first * two words of the final question "fox, eats, ...". * * @param network the current {@link Network} object * @param it an {@link Iterator} over the input source file lines * @return */ Term feedQuestion(Network network, String[] phrase) { for (int i = 0; i < 2; i++) { int[] sdr = getFingerprintSDR(phrase[i]); network.compute(sdr); } Layer<?> layer = network.lookup("Region 1").lookup("Layer 2/3"); Set<Cell> predictiveCells = layer.getPredictiveCells(); int[] prediction = SDR.cellsAsColumnIndices(predictiveCells, layer.getConnections().getCellsPerColumn()); Term term = getClosestTerm(prediction); cache.put(term.getTerm(), term); return term; }