home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ApiTest.java)

This example Java source code file (ApiTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

apitest, barneshuttsne, baseuiservertest, classpathresource, exception, fileinputstream, ignore, indarray, list, objectmapper, string, test, urlresource, util

The ApiTest.java Java example source code

package org.deeplearning4j.ui;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.canova.api.util.ClassPathResource;
import org.deeplearning4j.plot.BarnesHutTsne;
import org.deeplearning4j.ui.api.UrlResource;
import org.junit.Ignore;
import org.junit.Test;
import org.nd4j.linalg.api.buffer.DataBuffer;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.indexing.NDArrayIndex;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import static org.junit.Assert.*;

 * @author Adam Gibson
public class ApiTest extends BaseUiServerTest {
    public void testUpdateCoords() throws Exception {
        BarnesHutTsne b = new BarnesHutTsne.Builder().stopLyingIteration(250)

        ClassPathResource resource = new ClassPathResource("/mnist2500_X.txt");
        File f = resource.getFile();
        INDArray data = Nd4j.readNumpy(f.getAbsolutePath(),"   ").get(NDArrayIndex.interval(0, 100),NDArrayIndex.interval(0,784));

        ClassPathResource labels = new ClassPathResource("mnist2500_labels.txt");
        List<String> labelsList = IOUtils.readLines(labels.getInputStream()).subList(0, 100);
        b.plot(data, 2, labelsList, "coords.csv");
        String coords =  client.target("http://localhost:8080").path("api").path("update")
                .post(Entity.entity(new UrlResource("http://localhost:8080/api/coords.csv"), MediaType.APPLICATION_JSON))
        ObjectMapper mapper = new ObjectMapper();
        List<String> testLines = mapper.readValue(coords,List.class);
        List<String> lines = IOUtils.readLines(new FileInputStream("coords.csv"));


Other Java examples (source code examples)

Here is a short list of links related to this Java ApiTest.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.