From ece736581f1a96fca0358ba87b7f2e1960ab2f03 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Fri, 15 Dec 2023 18:05:03 +0100 Subject: [PATCH] SmileLib init - added smile lib - added "test" to check if it works --- .gitignore | 3 +- pom.xml | 124 ++++++++++++++++++ .../net/berack/upo/ai/problem3/SmileLib.java | 62 +++++++++ src/main/resources/VentureBN.xdsl | 41 ++++++ 4 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/berack/upo/ai/problem3/SmileLib.java create mode 100644 src/main/resources/VentureBN.xdsl diff --git a/.gitignore b/.gitignore index c0e1299..9e54fad 100644 --- a/.gitignore +++ b/.gitignore @@ -398,4 +398,5 @@ FodyWeavers.xsd *.sln.iml # CUSTOM -target \ No newline at end of file +target +jsmile* diff --git a/pom.xml b/pom.xml index 5617dd0..80bfdd5 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,16 @@ 1.17 1.17 + 2.2.0 + + + bayesfusion-repo + BayesFusion Repository + https://support.bayesfusion.com/maven-A + + org.junit.jupiter @@ -20,6 +28,122 @@ 5.9.2 test + + com.bayesfusion + jsmile + ${smile.version} + + + + + MacNative + + + mac + + + + macos + jsmile.jnilib + + + + WinNative + + + Windows + + + + win64 + jsmile.dll + + + + LinuxNative + + + Unix + + + + linux64 + jsmile.so + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + resource-dependencies + compile + + unpack + + + + + com.bayesfusion + jsmile-native-${nativeSuffix} + ${smile.version} + zip + true + *jsmile* + + + ${project.basedir}/src/main/resources/ + + + + + + + com.coderplus.maven.plugins + copy-rename-maven-plugin + 1.0 + + + rename-file + compile + + copy + + + ${project.basedir}/src/main/resources/${smileFile} + ${project.basedir}/src/main/resources/jsmile + + + + copy-file + compile + + copy + + + + + + ${project.basedir}/src/main/resources/jsmile + ${project.basedir}/src/test/resources/jsmile + + + ${project.basedir}/src/main/resources/${smileFile} + ${project.basedir}/src/test/resources/${smileFile} + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/net/berack/upo/ai/problem3/SmileLib.java b/src/main/java/net/berack/upo/ai/problem3/SmileLib.java new file mode 100644 index 0000000..30134d6 --- /dev/null +++ b/src/main/java/net/berack/upo/ai/problem3/SmileLib.java @@ -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(); + } +} diff --git a/src/main/resources/VentureBN.xdsl b/src/main/resources/VentureBN.xdsl new file mode 100644 index 0000000..a27a54f --- /dev/null +++ b/src/main/resources/VentureBN.xdsl @@ -0,0 +1,41 @@ + + + + + + + 0.2 0.8 + + + + + + Success + + 0.4 0.4 0.2 0.1 0.3 0.6 + + + + + + + Success of the venture + + + + 54 11 138 62 + + + Expert forecast + + + + 63 105 130 155 + + + + + + \ No newline at end of file