GithubHelp home page GithubHelp logo

mwt-ds-explore-java's Issues

GSON not in pom.xml

I found two issues when trying to compile the project using maven. The first is that GSON is required in com.mwt.tests.BlackBox but is not in the pom.xml file. A second issue that is com.mwt.tests.BlackBox uses java 1.7 classes. To fix these, I would put the com.mwt.tests package in src/test/java and I would update the pom.xml to have the dependencies:

<dependencies>
...
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.4</version>
      <scope>test</scope>
    </dependency>
...
</dependencies>

This way, GSON is not a runtime dependency of the library since it's only used in the test code.

Additionally, I'd change com.mwt.tests.BlackBox to import

  1. org.apache.commons.io.IOUtils
  2. java.io.File

Then I would remove the java.nio imports and I would change the first line in the try inside the main method to

String content = IOUtils.toString(new File(args[0]).toURI());

This would fix everything and put tests in the proper subdirectory according to maven convention. I'd be happy to submit a pull request if you'd like.

Refactor code to avoid random access where it's unnecessary

There are a lot of places where java.util.List iteration follows the pattern:

java.util.List<X> lst = ...
for (int i = 0; i < lst.size; i++) {
  doSomething( lst.get(i) );
}

In most or all situations, these can be replaced with for each-style iteration. Changing this isn't just for stylistic reasons. It can actually have implications on performance guarantees too. Specifically, there are places in the code base like in com/mwt/explorers/BootstrapExplorer.java where you see the following code:

public class BootstrapExplorer<T> implements Explorer<T>, ConsumePolicies<T> {
  private List<Policy<T>> policies;

  public DecisionTuple chooseAction(long saltedSeed, T context) {
    for (int currentBag = 0; currentBag < policies.size(); currentBag++) {
      actionFromBag = policies.get(currentBag).chooseAction(context);  // line 61
    }
  }
}

The problem is on line 61, actionFromBag = policies.get(currentBag).chooseAction(context). Since there's no random access guarantee at an API level for policies because it's a java.util.List, this loop has a worst case runtime of _O(_P 2) rather than the desired _O(_P) runtime.

By changing standard C-style for loops to for each-style loops, we can make tighten the runtime guarantees while not changing the MWT APIs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.