public void writeRecommendations(Output output, Map<String, Recommendation> recommendations) { kryo.writeObject(output, recommendations.size()); for (String key : recommendations.keySet()) { Recommendation rec = recommendations.get(key); rec.clean(); kryo.writeObject(output, rec.source.key()); kryo.writeObject(output, rec.target.key()); kryo.writeObject(output, rec); } }
private boolean containsRecommendation(Recommendation recommendation) { EntityManager mgr = getEntityManager(); boolean contains = true; try { Recommendation item = mgr.find(Recommendation.class, recommendation.getKey()); if (item == null) { contains = false; } } finally { mgr.close(); } return contains; }
// The implementing class can assume that the provided LogAbstraction // partialTrace is // of the same class, i.e. this.getClass().equals(partialTrace.getClass()) = // true // // The implementing class can assume that the LogEvent provided is in the // set returned by // getPossibleNextLogEvents(partialTrace), i.e. in all instances // represented by this abstraction, the given LogEvent is a possible // next step. public final Recommendation getRecommendation( LogEvent logEventToDo, LogAbstraction partialTrace, SortedSet<LogEvent> enabledEvents) { Recommendation rec = new Recommendation(); rec.setTask(logEventToDo.getModelElementName()); rec.setEventType(logEventToDo.getEventType()); double weight = calculateFitness(partialTrace); if (weight > 0) { SortedSet<LogEvent> possibleEvents = getPossibleNextLogEvents(partialTrace); if (possibleEvents.contains(logEventToDo) && enabledEvents.contains(logEventToDo)) { // It is possible to do this event, so give a recommendation double[] vals = getAllValuesAndWeights(weight); rec.setDoExpectedValue(vals[0]); rec.setDoExpectedSquaredValue(vals[1]); rec.setDoWeight(vals[2]); } else { // It is not possible to do this event, so give a "negative" // recommendation double w = 0; double e = 0; double e2 = 0; for (LogEvent evt : possibleEvents) { if (!enabledEvents.contains(evt)) { continue; } // Event evt is not a possible event in this case, // but is enabled in the query double[] vals = getAllValuesAndWeights(weight); double newW = w + vals[2]; e = (e * w + vals[0] * vals[2]) / newW; e2 = (e2 * w + vals[1] * vals[2]) / newW; w = newW; } rec.setDontExpectedValue(e); rec.setDontExpectedSquaredValue(e2); rec.setDontWeight(w); } } return rec; }
public void addRecommendation(Recommendation recommendation) { recommendations.put(recommendation.getQuery(), recommendation); }
@Override public Recommendation read(Kryo kryo, Input input, Class<Recommendation> type) { kryo.readObject(input, String.class); CosineScore scoring = new CosineScore(); int limits = kryo.readObject(input, int.class); int sortersSize = kryo.readObject(input, int.class); Recommendation rec = new Recommendation(source, target, scoring, limits); while (sortersSize > 0) { int size = kryo.readObject(input, int.class); long srcId = kryo.readObject(input, long.class); float waterline = kryo.readObject(input, float.class); while (size > 0) { long tgtId = kryo.readObject(input, long.class); float score = kryo.readObject(input, float.class); rec.add(srcId, tgtId, score); size--; } if (rec.sorters.containsKey(srcId)) { rec.sorters.get(srcId).waterline = waterline; } else { logger.warn(String.format("vecid[%d] not in sorters", srcId)); } sortersSize--; } return rec; }