Coder Social home page Coder Social logo

scalastan's People

Contributors

brendon- avatar elijahsummers avatar garimajajoo avatar jfklingler avatar joelsk avatar joewing avatar pritchett avatar schmidmt avatar triton11 avatar wgillett avatar williamyaoh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dotneet

scalastan's Issues

Better type checking for sample statements

Right now it's possible to generate invalid Stan code using ~. For example:

        val x = data(real())
        val model = new Model {
          x ~ stan.poisson(1.0)
        }

The Stan for this will not compile because x is real. Changing x to int fixes the problem. ScalaStan should identify this before generating Stan code (ideally at Scala compile time).

why the compile goes wrong?

I tried to use the ScalaStan for some work, but when I running the examples,the IDEA told me like this:
I thought it might be something wrong when compiling the model, I can find the model.stan file and model.hpp,and I can use CmdStan to compile them successfully;
My OS is Windows,I guess it may can't compile for windows shell according to the codes.
Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:281) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) at java.io.BufferedReader.readLine(BufferedReader.java:389) at scala.io.BufferedSource$BufferedLineIterator.hasNext(BufferedSource.scala:70) at scala.collection.Iterator.foreach(Iterator.scala:937) at scala.collection.Iterator.foreach$(Iterator.scala:937) at scala.collection.AbstractIterator.foreach(Iterator.scala:1425) at com.cibo.scalastan.CommandRunner.runCommand(CommandRunner.scala:21) at com.cibo.scalastan.CommandRunner.runCommand$(CommandRunner.scala:18) at com.cibo.scalastan.run.CmdStanCompiler$.runCommand(CmdStanCompiler.scala:20) at com.cibo.scalastan.run.CmdStanCompiler$.runMake(CmdStanCompiler.scala:79) at com.cibo.scalastan.run.CmdStanCompiler$.compile(CmdStanCompiler.scala:155) at com.cibo.scalastan.TransformedModel.compile(TransformedModel.scala:26) at com.cibo.scalastan.StanModel.compile(StanModel.scala:241) at com.cibo.scalastan.StanModel.compile$(StanModel.scala:241) at com.huawei.algtech.ai.stan.MyModel$.compile(MyApp.scala:15) at com.huawei.algtech.ai.stan.MyApp$.delayedEndpoint$com$huawei$algtech$ai$stan$MyApp$1(MyApp.scala:33) at com.huawei.algtech.ai.stan.MyApp$delayedInit$body.apply(MyApp.scala:27) at scala.Function0.apply$mcV$sp(Function0.scala:34) at scala.Function0.apply$mcV$sp$(Function0.scala:34) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App.$anonfun$main$1$adapted(App.scala:76) at scala.collection.immutable.List.foreach(List.scala:388) at scala.App.main(App.scala:76) at scala.App.main$(App.scala:74)

Fix type checking of `lkj_corr`

The type checking of the lkj_corr distribution doesn't work quite right because we don't know the size of the matrix when the distribution is created. So ScalaStan has a second version that takes the size as an explicit argument. It would be nice if we didn't have to do that.

Better handling of transformed parameters that aren't referenced from the model

ScalaStan won't generate code for a transformed parameter that isn't referenced in the model. The assumption being that it's not used, but you could still reference the output of a transformed parameter (using it as a generated quantity). ScalaStan should either raise an exception when this happens or just handle it like we handle generated quantities.

Add the ability to specify initial values

CmdStan supports an init argument to specify either the range of values to try for initialization or a file with initial values. ScalaStan should support both of these, perhaps as an optional argument to run.

Better CSV support

CSVDataSource currently does its own CSV parsing in a very simple way. In the interest of supporting a larger variety of CSV files, it might be worth considering a CSV library (opencsv?).

Bypass Command Stan

Requested from the Stan forums. Using Command Stan requires that ScalaStan read/write files. It would be nice to avoid using the file system.

Run ScalaStan Example Fail

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/cibo/scalastan/Implicits$class

here is my code, copy for example:

import com.cibo.scalastan.ScalaStan

object myModel extends App with ScalaStan {
  val n = data(int(lower = 0))
  val x = data(vector(n))
  val y = data(vector(n))

  val b = parameter(real())
  val m = parameter(real())
  val sigma = parameter(real(lower = 0))

  val model = new Model {
    sigma ~ stan.cauchy(0, 1)
    y ~ stan.normal(m * x + b, sigma)
  }

  val xs: Seq[Double] = ???
  val ys: Seq[Double] = ???
  val results = model
    .withData(x, xs)
    .withData(y, ys)
    .run(chains = 5)

  results.summary(System.out)
}

maven pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xxx</groupId>
    <artifactId>gmm</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.github.cibotech</groupId>
            <artifactId>ScalaStan</artifactId>
            <version>v0.5.9-rc1</version>
        </dependency>
    </dependencies>

</project>

Macros not found in Jupyter

I'm getting the following error trying to use ScalaStan inside Jupyter with the almond.sh kernel.

macro implementation not found: generate

Full screenshot:

Screen Shot 2020-02-23 at 8 37 36 AM

Improve scoping of Generated Quantities

Currently, generated quantities are somewhat special in ScalaStan because code generation is tied to the Model object and generated quantities exist completely outside of the model. To deal with this, ScalaStan simply outputs all generated quantities created within the ScalaStan trait. One way around this would be to move the code for generated quantities inside the model block. Unfortunately, this would break backwards compatibility.

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.