master
Daan Vanoverloop 1 year ago
parent b6c65ee436
commit a3382ccbb2
Signed by: Danacus
GPG Key ID: F2272B50E129FC5C

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
Subproject commit 1e479c23486cfb03ec1e6c7e43d3a9a69ed6efa5

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="SpringSOAP" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="SpringSOAP" options="-parameters" />
</option>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

@ -0,0 +1,71 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SpringSOAP</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringSOAP</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>/home/daan/Documents/School/Gedistribueerde Systemen/ds-lab-2/src/main/resources/meals.xsd</source>
</sources>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,9 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gs="http://foodmenu.io/cs/webservice">
<soapenv:Header/>
<soapenv:Body>
<gs:getMealRequest>
<gs:name>Portobello</gs:name>
</gs:getMealRequest>
</soapenv:Body>
</soapenv:Envelope>

@ -0,0 +1,7 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gs="http://foodmenu.io/cs/webservice">
<soapenv:Header/>
<soapenv:Body>
<gs:getLargestMealRequest/>
</soapenv:Body>
</soapenv:Envelope>

@ -0,0 +1,67 @@
package com.example.springsoap;
import javax.annotation.PostConstruct;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import io.foodmenu.cs.webservice.*;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@Component
public class MealRepository {
private static final Map<String, Meal> meals = new HashMap<String, Meal>();
@PostConstruct
public void initData() {
Meal a = new Meal();
a.setName("Steak");
a.setDescription("Steak with fries");
a.setMealtype(Mealtype.MEAT);
a.setKcal(1100);
meals.put(a.getName(), a);
Meal b = new Meal();
b.setName("Portobello");
b.setDescription("Portobello Mushroom Burger");
b.setMealtype(Mealtype.VEGAN);
b.setKcal(637);
meals.put(b.getName(), b);
Meal c = new Meal();
c.setName("Fish and Chips");
c.setDescription("Fried fish with chips");
c.setMealtype(Mealtype.FISH);
c.setKcal(950);
meals.put(c.getName(), c);
}
public Meal findMeal(String name) {
Assert.notNull(name, "The meal's code must not be null");
return meals.get(name);
}
public Meal findBiggestMeal() {
if (meals == null) return null;
if (meals.size() == 0) return null;
var values = meals.values();
return values.stream().max(Comparator.comparing(Meal::getKcal)).orElseThrow(NoSuchElementException::new);
}
}

@ -0,0 +1,43 @@
package com.example.springsoap;
import io.foodmenu.cs.webservice.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
@Endpoint
public class MenuEndpoint {
private static final String NAMESPACE_URI = "http://foodmenu.io/cs/webservice";
private MealRepository mealrepo;
@Autowired
public MenuEndpoint(MealRepository mealrepo) {
this.mealrepo = mealrepo;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getMealRequest")
@ResponsePayload
public GetMealResponse getMeal(@RequestPayload GetMealRequest request) {
GetMealResponse response = new GetMealResponse();
response.setMeal(mealrepo.findMeal(request.getName()));
return response;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getLargestMealRequest")
@ResponsePayload
public GetLargestMealResponse getLargestMeal(@RequestPayload GetLargestMealRequest request) {
GetLargestMealResponse response = new GetLargestMealResponse();
response.setMeal(mealrepo.findBiggestMeal());
return response;
}
}

@ -0,0 +1,13 @@
package com.example.springsoap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringSoapApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSoapApplication.class, args);
}
}

@ -0,0 +1,41 @@
package com.example.springsoap;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean(name = "meals")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema mealsSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("MealsPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://foodmenu.io/cs/webservice");
wsdl11Definition.setSchema(mealsSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema mealsSchema() {
return new SimpleXsdSchema(new ClassPathResource("meals.xsd"));
}
}

@ -0,0 +1,55 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://foodmenu.io/cs/webservice"
targetNamespace="http://foodmenu.io/cs/webservice" elementFormDefault="qualified">
<xs:element name="getMealRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getMealResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="meal" type="tns:meal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getLargestMealRequest">
<xs:complexType>
<xs:sequence></xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getLargestMealResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="meal" type="tns:meal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="meal">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kcal" type="xs:int"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="mealtype" type="tns:mealtype"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="mealtype">
<xs:restriction base="xs:string">
<xs:enumeration value="vegan"/>
<xs:enumeration value="veggie"/>
<xs:enumeration value="meat"/>
<xs:enumeration value="fish"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

@ -0,0 +1,20 @@
# Ruimten
- Spiegeling (januari 2017) - 5
- Orientatieomkerend == schuifspiegeling (januari 2015) - 2
- Dubbelverhouding (juni 2018)
- Affiene transformatie (augustus 2017)
- Affien onafhankelijk <=> lineair onafhankelijk (augustus 2017)
- Definieer Affiene Meetkunde volgens Felix Klein (augustus 2017)
- Barycentrische coordinaten (januari 2016)
- Rotaties en vaste punten (januari 2011)
- Rotatie en schroefbeweging in E^3 (januari 2010)
# Krommen
- Bewijs Frenet (E^2 en/of E^3) (juni 2018) - 3
- Intrisieke vergelijking (augustus 2017) - 3
- Rotatieindex (januari 2015) - 2
- Kromme deel van cirkel <=> kromming constant != 0 (januari 2011) - 2
- Congruentiestelling E^3 (januari 2012)
- Heel vage vraag over Frenet in sferen (februari 2011)

@ -0,0 +1,129 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.datasets import make_moons
def main():
loss = "binary_crossentropy"
# Generate the training and test data
rand = np.random.RandomState(31)
X, y = make_moons(1000, noise=0.3, random_state=rand)
Xtest, ytest = make_moons(1000, noise=0.3, random_state=rand)
fig, ax = plt.subplots()
ax.scatter(X[:, 0], X[:, 1], c=y, marker=".")
ax.set_title("The data")
plt.show()
# We have a number of possible hyper parameters for our classifier
# We want to determine the best hyper parameter set
settings = [
{"learning_rate": 0.5, "num_trees": 10, "max_leaf_nodes": 7},
{"learning_rate": 0.5, "num_trees": 10, "max_leaf_nodes": 15},
{"learning_rate": 0.2, "num_trees": 20, "max_leaf_nodes": 31},
{"learning_rate": 0.4, "num_trees": 20, "max_leaf_nodes": 31},
{"learning_rate": 0.2, "num_trees": 60, "max_leaf_nodes": 63},
{"learning_rate": 0.4, "num_trees": 60, "max_leaf_nodes": 63}]
# K-fold cross validation
# To find the best parameter set, we train and evaluate the model on
# different subsets of the training data. This gives us an a good idea of
# how the model performs.
K = 10
perm = rand.permutation(X.shape[0])
fold_size = perm.shape[0] / K
folds = [perm[int(i*fold_size):int((i+1)*fold_size)] for i in range(10)]
accuracies_train = np.zeros((K, len(settings)))
accuracies_val = np.zeros((K, len(settings)))
for i in range(K): # leave one fold as validation set
Itrain = np.hstack([folds[j] for j in range(K) if i!=j])
Xtrain = X[Itrain, :]
ytrain = y[Itrain]
Ival = folds[i]
Xval = X[Ival, :]
yval = y[Ival]
print(f"Training fold {i}")
for j, s in enumerate(settings):
print(f"- {s} -> ", end="")
clf = HistGradientBoostingClassifier(
loss=loss,
max_iter=s["num_trees"],
max_leaf_nodes=s["max_leaf_nodes"],
learning_rate=s["learning_rate"],
random_state=rand)
clf.fit(Xtrain, ytrain)
acc_train = np.mean(clf.predict(Xtrain) == ytrain)
acc_val = np.mean(clf.predict(Xval) == yval)
print(f"accuracy train: {acc_train*100:.1f}%, test: {acc_val*100:.1f}%")
accuracies_train[i, j] = acc_train
accuracies_val[i, j] = acc_val
print("Mean accuracies train:", accuracies_train.mean(axis=0).round(3))
print(" std train:", accuracies_train.std(axis=0).round(3))
print("Mean accuracies validation:", accuracies_val.mean(axis=0).round(3))
print(" std validation:", accuracies_val.std(axis=0).round(3))
print("QUESTION: Which model do you think performs best?")
print(" Which model would you pick based on the training accuracy?")
print(" Which model would you pick based on the validation accuracy?")
# We pick the first and the last configuration, and train a model on all
# training data, and plot the decision surfaces.
fig, ax = plt.subplots(1, 2, figsize=(15, 8), sharex=True, sharey=True)
fig_test, ax_test = plt.subplots(1, 2, figsize=(15, 8))
for i in [0, -1]:
s = settings[i]
clf = HistGradientBoostingClassifier(
loss=loss,
max_iter=s["num_trees"],
max_leaf_nodes=s["max_leaf_nodes"],
learning_rate=s["learning_rate"],
random_state=rand)
clf.fit(X, y)
acc = np.mean(clf.predict(X) == y)
acc_test = np.mean(clf.predict(Xtest) == ytest)
print(f"Accuracy train: {acc*100:.1f}% test: {acc_test*100:.1f}%, "
f"gap={(acc-acc_test)*100:.1f}%")
plot_step = 0.01
xmin, xmax = X[:, 0].min()-0.1, X[:, 0].max()+0.1
ymin, ymax = X[:, 1].min()-0.1, X[:, 1].max()+0.1
xx, yy = np.meshgrid(np.arange(xmin, xmax, plot_step),
np.arange(ymin, ymax, plot_step))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
cs = ax[i].contourf(xx, yy, Z, cmap=plt.cm.RdYlBu)
cs = ax_test[i].contourf(xx, yy, Z, cmap=plt.cm.RdYlBu)
ax[i].scatter(X[:, 0], X[:, 1], c=y, marker=".")
ax_test[i].scatter(Xtest[:, 0], Xtest[:, 1], c=ytest, marker=".")
conf_name = "Simple model" if i==0 else "Complex model"
fig.suptitle("Scatter points are training data")
ax[i].set_title(f"{conf_name} accuracy train: {acc*100:.1f}% test: {acc_test*100:.1f}%")
fig_test.suptitle("Scatter points are testing data")
ax_test[i].set_title(f"{conf_name} accuracy train: {acc*100:.1f}% test: {acc_test*100:.1f}%")
plt.show()
print("QUESTION: Looking at the decision boundaries of the two models,")
print(" which of the two would you prefer and why?")
print()
print("QUESTION: Use `clf.predict_proba` to predict probabilities instead")
print(" of classes and use these probability values to compute the")
print(" values in a confusion matrix for an arbitrary threshold.")
print(" Then, repeat this for all possible thresholds and plot the")
print(" ROC curve.")
if __name__ == "__main__":
main()
Loading…
Cancel
Save