Skip to content

Commit

Permalink
Ingest categorical coefficients as an object (Map) (#56)
Browse files Browse the repository at this point in the history
* ingest categorial coefficients as object

* bump version
  • Loading branch information
aarsilv authored May 29, 2024
1 parent 4eca261 commit be2130d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cloud.eppo</groupId>
<artifactId>eppo-server-sdk</artifactId>
<version>2.4.4</version>
<version>2.4.5</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Eppo Server-Side SDK for Java</description>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/eppo/sdk/deserializer/BanditsDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ private Map<String, BanditCategoricalAttributeCoefficients> parseCategoricalAttr
categoricalAttributeCoefficientsArrayNode.iterator().forEachRemaining(categoricalAttributeCoefficientsNode -> {
String attributeKey = categoricalAttributeCoefficientsNode.get("attributeKey").asText();
Double missingValueCoefficient = categoricalAttributeCoefficientsNode.get("missingValueCoefficient").asDouble();

Map<String, Double> valueCoefficients = new HashMap<>();
JsonNode valuesNode = categoricalAttributeCoefficientsNode.get("values");
valuesNode.iterator().forEachRemaining(valueNode -> {
String value = valueNode.get("value").asText();
Double coefficient = valueNode.get("coefficient").asDouble();
JsonNode valuesNode = categoricalAttributeCoefficientsNode.get("valueCoefficients");
Iterator<Map.Entry<String, JsonNode>> coefficientIterator = valuesNode.fields();
coefficientIterator.forEachRemaining(field -> {
String value = field.getKey();
Double coefficient = field.getValue().asDouble();
valueCoefficients.put(value, coefficient);
});

Expand Down
34 changes: 17 additions & 17 deletions src/test/resources/bandits/bandits-parameters-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"actionCategoricalCoefficients": [
{
"attributeKey": "loyalty_tier",
"values": [
{ "value": "gold", "coefficient": 4.5 },
{ "value": "silver", "coefficient": 3.2 },
{ "value": "bronze", "coefficient": 1.9 }
],
"valueCoefficients": {
"gold": 4.5,
"silver": 3.2,
"bronze": 1.9
},
"missingValueCoefficient": 0.0
}
],
Expand All @@ -42,10 +42,10 @@
"subjectCategoricalCoefficients": [
{
"attributeKey": "gender_identity",
"values": [
{ "value": "female", "coefficient": 0.5 },
{ "value": "male", "coefficient": -0.5 }
],
"valueCoefficients": {
"female": 0.5,
"male": -0.5
},
"missingValueCoefficient": 2.3
}
]
Expand All @@ -63,21 +63,21 @@
"actionCategoricalCoefficients": [
{
"attributeKey": "purchased_last_30_days",
"values": [
{ "value": "true", "coefficient": 9.0 },
{ "value": "false", "coefficient": 0.0 }
],
"valueCoefficients": {
"true": 9.0,
"false": 0.0
},
"missingValueCoefficient": 0.0
}
],
"subjectNumericCoefficients": [],
"subjectCategoricalCoefficients": [
{
"attributeKey": "gender_identity",
"values": [
{ "value": "female", "coefficient": 0.0 },
{ "value": "male", "coefficient": 0.3 }
],
"valueCoefficients": {
"female": 0.0,
"male": 0.3
},
"missingValueCoefficient": 0.45
}
]
Expand Down

0 comments on commit be2130d

Please sign in to comment.