SmileLib init
- added smile lib - added "test" to check if it works
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -398,4 +398,5 @@ FodyWeavers.xsd
|
||||
*.sln.iml
|
||||
|
||||
# CUSTOM
|
||||
target
|
||||
target
|
||||
jsmile*
|
||||
|
||||
124
pom.xml
124
pom.xml
@@ -11,8 +11,16 @@
|
||||
<properties>
|
||||
<maven.compiler.source>1.17</maven.compiler.source>
|
||||
<maven.compiler.target>1.17</maven.compiler.target>
|
||||
<smile.version>2.2.0</smile.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bayesfusion-repo</id>
|
||||
<name>BayesFusion Repository</name>
|
||||
<url>https://support.bayesfusion.com/maven-A</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
@@ -20,6 +28,122 @@
|
||||
<version>5.9.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bayesfusion</groupId>
|
||||
<artifactId>jsmile</artifactId>
|
||||
<version>${smile.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- Setting variables/properties for differents OS (mainly for smile API)-->
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>MacNative</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>mac</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<nativeSuffix>macos</nativeSuffix>
|
||||
<smileFile>jsmile.jnilib</smileFile>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>WinNative</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>Windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<nativeSuffix>win64</nativeSuffix>
|
||||
<smileFile>jsmile.dll</smileFile>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>LinuxNative</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>Unix</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<nativeSuffix>linux64</nativeSuffix>
|
||||
<smileFile>jsmile.so</smileFile>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Getting jsmile library (from https://support.bayesfusion.com/docs/Wrappers/)-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>resource-dependencies</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>com.bayesfusion</groupId>
|
||||
<artifactId>jsmile-native-${nativeSuffix}</artifactId>
|
||||
<version>${smile.version}</version>
|
||||
<type>zip</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>*jsmile*</includes>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
<outputDirectory>${project.basedir}/src/main/resources/</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Renaming the jsmile & make a copy to test resources -->
|
||||
<plugin>
|
||||
<groupId>com.coderplus.maven.plugins</groupId>
|
||||
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>rename-file</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>${project.basedir}/src/main/resources/${smileFile}</sourceFile>
|
||||
<destinationFile>${project.basedir}/src/main/resources/jsmile</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-file</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- IDK Why but using 2 files makes the loading work, so i copy them in test too -->
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<sourceFile>${project.basedir}/src/main/resources/jsmile</sourceFile>
|
||||
<destinationFile>${project.basedir}/src/test/resources/jsmile</destinationFile>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<sourceFile>${project.basedir}/src/main/resources/${smileFile}</sourceFile>
|
||||
<destinationFile>${project.basedir}/src/test/resources/${smileFile}</destinationFile>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
62
src/main/java/net/berack/upo/ai/problem3/SmileLib.java
Normal file
62
src/main/java/net/berack/upo/ai/problem3/SmileLib.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package net.berack.upo.ai.problem3;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import smile.Network;
|
||||
|
||||
public class SmileLib {
|
||||
|
||||
public static final String RESOURCE_PATH;
|
||||
|
||||
static {
|
||||
var loader = SmileLib.class.getClassLoader();
|
||||
var wrongPath = loader.getResource("").getFile();
|
||||
var path = wrongPath.substring(1);
|
||||
try {
|
||||
RESOURCE_PATH = URLDecoder.decode(path, "ASCII");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Decodification of path failed!\n" + e.getMessage());
|
||||
}
|
||||
|
||||
System.setProperty("jsmile.native.library", RESOURCE_PATH + "jsmile");
|
||||
new smile.License(
|
||||
"SMILE LICENSE 02a07eb5 5c5fa64a 2a276459 " +
|
||||
"THIS IS AN ACADEMIC LICENSE AND CAN BE USED " +
|
||||
"SOLELY FOR ACADEMIC RESEARCH AND TEACHING, " +
|
||||
"AS DEFINED IN THE BAYESFUSION ACADEMIC " +
|
||||
"SOFTWARE LICENSING AGREEMENT. " +
|
||||
"Serial #: 976arg4ifdszss2oc8kcmru6t " +
|
||||
"Issued for: GIACOMO BERTOLAZZI (20015159@studenti.uniupo.it) " +
|
||||
"Academic institution: Universit\u00e0 del Piemonte Orientale " +
|
||||
"Valid until: 2024-06-16 " +
|
||||
"Issued by BayesFusion activation server",
|
||||
new byte[] {
|
||||
7,-117,-57,124,-91,120,34,-120,-47,101,49,-49,2,-55,118,92,
|
||||
-92,-53,-67,-36,103,17,110,-61,27,116,-99,5,-72,-1,-123,-117,
|
||||
48,-28,49,-92,39,-37,22,15,-68,-7,-56,97,-6,-35,-33,57,
|
||||
114,-81,-56,-11,52,-32,113,91,-84,-33,105,-9,-25,-58,-16,-52
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static Network getNetworkFrom(String file) {
|
||||
var net = new Network();
|
||||
net.readFile(RESOURCE_PATH + file);
|
||||
return net;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
var net = new Network();
|
||||
|
||||
net.readFile(RESOURCE_PATH + "VentureBN.xdsl");
|
||||
net.setEvidence("Forecast", "Moderate");
|
||||
net.updateBeliefs();
|
||||
|
||||
var beliefs = net.getNodeValue("Success");
|
||||
for (var i = 0; i < beliefs.length; i++) {
|
||||
System.out.println(net.getOutcomeId("Success", i) + " = " + beliefs[i]);
|
||||
}
|
||||
|
||||
net.close();
|
||||
}
|
||||
}
|
||||
41
src/main/resources/VentureBN.xdsl
Normal file
41
src/main/resources/VentureBN.xdsl
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<smile version="1.0" id="VentureBN" numsamples="1000">
|
||||
<nodes>
|
||||
<cpt id="Success">
|
||||
<state id="Success" />
|
||||
<state id="Failure" />
|
||||
<probabilities>0.2 0.8</probabilities>
|
||||
</cpt>
|
||||
<cpt id="Forecast">
|
||||
<state id="Good" />
|
||||
<state id="Moderate" />
|
||||
<state id="Poor" />
|
||||
<parents>Success</parents>
|
||||
<probabilities>
|
||||
0.4 0.4 0.2 0.1 0.3 0.6
|
||||
</probabilities>
|
||||
</cpt>
|
||||
</nodes>
|
||||
<extensions>
|
||||
<genie version="1.0" app="GeNIe 2.1.1104.2"
|
||||
name="VentureBN"
|
||||
faultnameformat="nodestate">
|
||||
<node id="Success">
|
||||
<name>Success of the venture</name>
|
||||
<interior color="e5f6f7" />
|
||||
<outline color="0000bb" />
|
||||
<font color="000000" name="Arial" size="8" />
|
||||
<position>54 11 138 62</position>
|
||||
</node>
|
||||
<node id="Forecast">
|
||||
<name>Expert forecast</name>
|
||||
<interior color="e5f6f7" />
|
||||
<outline color="0000bb" />
|
||||
<font color="000000" name="Arial" size="8" />
|
||||
<position>63 105 130 155</position>
|
||||
</node>
|
||||
</genie>
|
||||
</extensions>
|
||||
</smile>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user